Skip to content

Commit

Permalink
Remove (deprecated) wstring version of Value::CreateStringValue().
Browse files Browse the repository at this point in the history
BUG=23581
TEST=builds and passes tests

Review URL: http://codereview.chromium.org/3136012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56170 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
viettrungluu@chromium.org committed Aug 15, 2010
1 parent 0d93778 commit 16b5271
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 98 deletions.
2 changes: 1 addition & 1 deletion base/json/json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Value* JSONReader::DecodeString(const Token& token) {
decoded_str.push_back(c);
}
}
return Value::CreateStringValue(decoded_str);
return Value::CreateStringValue(WideToUTF16Hack(decoded_str));
}

JSONReader::Token JSONReader::ParseToken() {
Expand Down
10 changes: 1 addition & 9 deletions base/values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ Value* Value::CreateStringValue(const string16& in_value) {
return new StringValue(in_value);
}

#if !defined(WCHAR_T_IS_UTF16)
// TODO(viettrungluu): Deprecated and to be removed:
// static
Value* Value::CreateStringValue(const std::wstring& in_value) {
return new StringValue(in_value);
}
#endif

// static
BinaryValue* Value::CreateBinaryValue(char* buffer, size_t size) {
return BinaryValue::Create(buffer, size);
Expand Down Expand Up @@ -481,7 +473,7 @@ void DictionaryValue::SetString(const std::wstring& path,
// TODO(viettrungluu): Deprecated and to be removed:
void DictionaryValue::SetString(const std::wstring& path,
const std::wstring& in_value) {
Set(path, CreateStringValue(in_value));
Set(WideToUTF8(path), CreateStringValue(WideToUTF8(in_value)));
}
#endif

Expand Down
3 changes: 0 additions & 3 deletions base/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class Value {
static Value* CreateRealValue(double in_value);
static Value* CreateStringValue(const std::string& in_value);
static Value* CreateStringValue(const string16& in_value);
#if !defined(WCHAR_T_IS_UTF16)
/*DEPRECATED*/static Value* CreateStringValue(const std::wstring& in_value);
#endif

// This one can return NULL if the input isn't valid. If the return value
// is non-null, the new object has taken ownership of the buffer pointer.
Expand Down
27 changes: 1 addition & 26 deletions base/values_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class ValuesTest: public testing::Test {
// to std::string. I've temporarily kept the old methods taking std::wstring for
// compatibility. The ...Deprecated tests are the old tests which use these
// methods, and remain to test compatibility. They will be removed once the old
// methods are removed. There are also parts of tests marked DEPRECATED which
// are to be deleted.
// methods are removed.

TEST_F(ValuesTest, Basic) {
// Test basic dictionary getting/setting
Expand Down Expand Up @@ -228,9 +227,6 @@ TEST_F(ValuesTest, StringValueDeprecated) {
scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow"));
ASSERT_TRUE(narrow_value.get());
ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
scoped_ptr<Value> wide_value(Value::CreateStringValue(L"wide"));
ASSERT_TRUE(wide_value.get());
ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING));
scoped_ptr<Value> utf16_value(
Value::CreateStringValue(ASCIIToUTF16("utf16")));
ASSERT_TRUE(utf16_value.get());
Expand All @@ -247,13 +243,6 @@ TEST_F(ValuesTest, StringValueDeprecated) {
ASSERT_EQ(std::wstring(L"narrow"), wide);
ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);

ASSERT_TRUE(wide_value->GetAsString(&narrow));
ASSERT_TRUE(wide_value->GetAsString(&wide));
ASSERT_TRUE(wide_value->GetAsString(&utf16));
ASSERT_EQ(std::string("wide"), narrow);
ASSERT_EQ(std::wstring(L"wide"), wide);
ASSERT_EQ(ASCIIToUTF16("wide"), utf16);

ASSERT_TRUE(utf16_value->GetAsString(&narrow));
ASSERT_TRUE(utf16_value->GetAsString(&wide));
ASSERT_TRUE(utf16_value->GetAsString(&utf16));
Expand Down Expand Up @@ -632,8 +621,6 @@ TEST_F(ValuesTest, DeepCopyDeprecated) {
original_dict.Set(L"real", original_real);
Value* original_string = Value::CreateStringValue("hello");
original_dict.Set(L"string", original_string);
Value* original_wstring = Value::CreateStringValue(L"peek-a-boo");
original_dict.Set(L"wstring", original_wstring);
Value* original_utf16 = Value::CreateStringValue(ASCIIToUTF16("hello16"));
original_dict.Set(L"utf16", original_utf16);

Expand Down Expand Up @@ -702,18 +689,6 @@ TEST_F(ValuesTest, DeepCopyDeprecated) {
ASSERT_EQ(std::wstring(L"hello"), copy_wstring_value);
ASSERT_EQ(ASCIIToUTF16("hello"), copy_utf16_value);

Value* copy_wstring = NULL;
ASSERT_TRUE(copy_dict->Get(L"wstring", &copy_wstring));
ASSERT_TRUE(copy_wstring);
ASSERT_NE(copy_wstring, original_wstring);
ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING));
ASSERT_TRUE(copy_wstring->GetAsString(&copy_string_value));
ASSERT_TRUE(copy_wstring->GetAsString(&copy_wstring_value));
ASSERT_TRUE(copy_wstring->GetAsString(&copy_utf16_value));
ASSERT_EQ(std::string("peek-a-boo"), copy_string_value);
ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_wstring_value);
ASSERT_EQ(ASCIIToUTF16("peek-a-boo"), copy_utf16_value);

Value* copy_utf16 = NULL;
ASSERT_TRUE(copy_dict->Get(L"utf16", &copy_utf16));
ASSERT_TRUE(copy_utf16);
Expand Down
89 changes: 49 additions & 40 deletions chrome/browser/dom_ui/about_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/command_line.h"
#include "base/file_version_info.h"
#include "base/i18n/time_formatting.h"
#include "base/string16.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
Expand Down Expand Up @@ -138,21 +139,21 @@ void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
scoped_ptr<FileVersionInfo> version_info(chrome::GetChromeVersionInfo());
DCHECK(version_info.get() != NULL);

std::wstring browser_version = version_info->file_version();
string16 browser_version = WideToUTF16Hack(version_info->file_version());

string16 version_modifier = platform_util::GetVersionStringModifier();
if (version_modifier.length()) {
browser_version += L" ";
browser_version += UTF16ToWide(version_modifier);
browser_version += ASCIIToUTF16(" ");
browser_version += version_modifier;
}

#if !defined(GOOGLE_CHROME_BUILD)
browser_version += L" (";
browser_version += version_info->last_change();
browser_version += L")";
browser_version += ASCIIToUTF16(" (");
browser_version += WideToUTF16Hack(version_info->last_change());
browser_version += ASCIIToUTF16(")");
#endif

localized_strings->SetString(L"browser_version", browser_version);
localized_strings->SetString("browser_version", browser_version);

// license

Expand All @@ -170,62 +171,68 @@ void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
size_t link2_end = text.find(kEndLink, link2);
DCHECK(link1_end != std::wstring::npos);

localized_strings->SetString(L"license_content_0", text.substr(0, link1));
localized_strings->SetString(L"license_content_1", StringSubRange(text,
link1_end + wcslen(kEndLinkOss), link2));
localized_strings->SetString(L"license_content_2",
text.substr(link2_end + wcslen(kEndLinkOss)));
localized_strings->SetString("license_content_0",
WideToUTF16Hack(text.substr(0, link1)));
localized_strings->SetString("license_content_1",
WideToUTF16Hack(StringSubRange(text, link1_end + wcslen(kEndLinkOss),
link2)));
localized_strings->SetString("license_content_2",
WideToUTF16Hack(text.substr(link2_end + wcslen(kEndLinkOss))));

// The Chromium link within the main text of the dialog.
localized_strings->SetString(chromium_url_appears_first ?
L"license_link_content_0" : L"license_link_content_1",
StringSubRange(text, text.find(kBeginLinkChr) + wcslen(kBeginLinkChr),
text.find(kEndLinkChr)));
"license_link_content_0" : "license_link_content_1",
WideToUTF16Hack(StringSubRange(text,
text.find(kBeginLinkChr) + wcslen(kBeginLinkChr),
text.find(kEndLinkChr))));
localized_strings->SetString(chromium_url_appears_first ?
L"license_link_0" : L"license_link_1",
l10n_util::GetString(IDS_CHROMIUM_PROJECT_URL));
"license_link_0" : "license_link_1",
l10n_util::GetStringUTF16(IDS_CHROMIUM_PROJECT_URL));

// The Open Source link within the main text of the dialog.
localized_strings->SetString(chromium_url_appears_first ?
L"license_link_content_1" : L"license_link_content_0",
StringSubRange(text, text.find(kBeginLinkOss) + wcslen(kBeginLinkOss),
text.find(kEndLinkOss)));
"license_link_content_1" : "license_link_content_0",
WideToUTF16Hack(StringSubRange(text,
text.find(kBeginLinkOss) + wcslen(kBeginLinkOss),
text.find(kEndLinkOss))));
localized_strings->SetString(chromium_url_appears_first ?
L"license_link_1" : L"license_link_0", chrome::kAboutCreditsURL);
"license_link_1" : "license_link_0", chrome::kAboutCreditsURL);

// webkit

localized_strings->SetString(L"webkit_version",
localized_strings->SetString("webkit_version",
webkit_glue::GetWebKitVersion());

// javascript

#if defined(CHROME_V8)
localized_strings->SetString(L"js_engine", "V8");
localized_strings->SetString(L"js_engine_version", v8::V8::GetVersion());
localized_strings->SetString("js_engine", "V8");
localized_strings->SetString("js_engine_version", v8::V8::GetVersion());
#else
localized_strings->SetString(L"js_engine", "JavaScriptCore");
localized_strings->SetString(L"js_engine_version",
localized_strings->SetString("js_engine", "JavaScriptCore");
localized_strings->SetString("js_engine_version",
webkit_glue::GetWebKitVersion());
#endif

// user agent

localized_strings->SetString(L"user_agent_info",
localized_strings->SetString("user_agent_info",
webkit_glue::GetUserAgent(GURL()));

// command line

#if defined(OS_WIN)
localized_strings->SetString(L"command_line_info",
CommandLine::ForCurrentProcess()->command_line_string());
localized_strings->SetString("command_line_info",
WideToUTF16(CommandLine::ForCurrentProcess()->command_line_string()));
#elif defined(OS_POSIX)
// TODO(viettrungluu): something horrible might happen if there are non-UTF-8
// arguments (since |SetString()| requires Unicode).
std::string command_line = "";
typedef std::vector<std::string> ArgvList;
const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
command_line += " " + *iter;
localized_strings->SetString(L"command_line_info", command_line);
localized_strings->SetString("command_line_info", command_line);
#endif
}

Expand Down Expand Up @@ -262,46 +269,48 @@ void AboutPageHandler::CheckNow(const Value* value) {

void AboutPageHandler::UpdateStatus(
const chromeos::UpdateLibrary::Status& status) {
std::wstring message;
string16 message;
std::string image = "up-to-date";
bool enabled = false;

switch (status.status) {
case chromeos::UPDATE_STATUS_IDLE:
if (!sticky_) {
message = l10n_util::GetStringF(IDS_UPGRADE_ALREADY_UP_TO_DATE,
l10n_util::GetString(IDS_PRODUCT_OS_NAME));
message = l10n_util::GetStringFUTF16(IDS_UPGRADE_ALREADY_UP_TO_DATE,
l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME));
enabled = true;
}
break;
case chromeos::UPDATE_STATUS_CHECKING_FOR_UPDATE:
message = l10n_util::GetString(IDS_UPGRADE_CHECK_STARTED);
message = l10n_util::GetStringUTF16(IDS_UPGRADE_CHECK_STARTED);
sticky_ = false;
break;
case chromeos::UPDATE_STATUS_UPDATE_AVAILABLE:
message = l10n_util::GetString(IDS_UPDATE_AVAILABLE);
message = l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE);
started_ = true;
break;
case chromeos::UPDATE_STATUS_DOWNLOADING:
{
int progress = static_cast<int>(status.download_progress * 100.0);
if (progress != progress_) {
progress_ = progress;
message = l10n_util::GetStringF(IDS_UPDATE_DOWNLOADING, progress_);
// TODO(viettrungluu): need UTF-16 convenience form to eliminate hack.
message = WideToUTF16Hack(
l10n_util::GetStringF(IDS_UPDATE_DOWNLOADING, progress_));
}
started_ = true;
}
break;
case chromeos::UPDATE_STATUS_VERIFYING:
message = l10n_util::GetString(IDS_UPDATE_VERIFYING);
message = l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING);
started_ = true;
break;
case chromeos::UPDATE_STATUS_FINALIZING:
message = l10n_util::GetString(IDS_UPDATE_FINALIZING);
message = l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING);
started_ = true;
break;
case chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT:
message = l10n_util::GetString(IDS_UPDATE_COMPLETED);
message = l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED);
image = "available";
sticky_ = true;
break;
Expand All @@ -312,7 +321,7 @@ void AboutPageHandler::UpdateStatus(
// The error is only displayed if we were able to determine an
// update was available.
if (started_) {
message = l10n_util::GetString(IDS_UPDATE_ERROR);
message = l10n_util::GetStringUTF16(IDS_UPDATE_ERROR);
image = "fail";
enabled = true;
sticky_ = true;
Expand Down
9 changes: 4 additions & 5 deletions chrome/browser/extensions/extension_i18n_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty.";

bool GetAcceptLanguagesFunction::RunImpl() {
std::wstring acceptLanguages =
UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
string16 acceptLanguages =
UTF8ToUTF16(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
// Currently, there are 2 ways to set browser's accept-languages: through UI
// or directly modify the preference file. The accept-languages set through
// UI is guranteed to be valid, and the accept-languages string returned from
Expand All @@ -32,19 +32,18 @@ bool GetAcceptLanguagesFunction::RunImpl() {
}
size_t begin = 0;
size_t end;
std::wstring acceptLang;
while (1) {
end = acceptLanguages.find(',', begin);
if (end > begin) {
// Guard against a malformed value with multiple "," in a row.
acceptLang = acceptLanguages.substr(begin, end - begin);
string16 acceptLang = acceptLanguages.substr(begin, end - begin);
static_cast<ListValue*>(result_.get())->
Append(Value::CreateStringValue(acceptLang));
}
begin = end + 1;
// 'begin >= acceptLanguages.length()' to guard against a value
// ending with ','.
if (end == std::wstring::npos || begin >= acceptLanguages.length())
if (end == string16::npos || begin >= acceptLanguages.length())
break;
}
if (static_cast<ListValue*>(result_.get())->GetSize() == 0) {
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/pref_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ namespace {
// the string value in the locale dll. Because we control the values in a
// locale dll, this should always return a Value of the appropriate type.
Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) {
std::wstring resource_string = l10n_util::GetString(message_id);
std::string resource_string = l10n_util::GetStringUTF8(message_id);
DCHECK(!resource_string.empty());
switch (type) {
case Value::TYPE_BOOLEAN: {
if (L"true" == resource_string)
if ("true" == resource_string)
return Value::CreateBooleanValue(true);
if (L"false" == resource_string)
if ("false" == resource_string)
return Value::CreateBooleanValue(false);
break;
}

case Value::TYPE_INTEGER: {
int val;
base::StringToInt(WideToUTF8(resource_string), &val);
base::StringToInt(resource_string, &val);
return Value::CreateIntegerValue(val);
}

case Value::TYPE_REAL: {
double val;
base::StringToDouble(WideToUTF8(resource_string), &val);
base::StringToDouble(resource_string, &val);
return Value::CreateRealValue(val);
}

Expand Down
Loading

0 comments on commit 16b5271

Please sign in to comment.