diff options
-rw-r--r-- | base/values.cc | 52 | ||||
-rw-r--r-- | base/values.h | 26 | ||||
-rw-r--r-- | base/values_unittest.cc | 93 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store.cc | 4 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider_win.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history2_ui.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 6 | ||||
-rw-r--r-- | chrome/browser/geolocation/access_token_store.cc | 2 | ||||
-rw-r--r-- | chrome/browser/plugin_updater.cc | 2 |
9 files changed, 107 insertions, 86 deletions
diff --git a/base/values.cc b/base/values.cc index 3688c35..031e1ca 100644 --- a/base/values.cc +++ b/base/values.cc @@ -90,43 +90,49 @@ Value* Value::CreateStringValue(const std::string& in_value) { } // static -Value* Value::CreateStringValue(const std::wstring& in_value) { +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::CreateStringValueFromUTF16(const string16& in_value) { +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); } -bool Value::GetAsBoolean(bool* in_value) const { +bool Value::GetAsBoolean(bool* out_value) const { return false; } -bool Value::GetAsInteger(int* in_value) const { +bool Value::GetAsInteger(int* out_value) const { return false; } -bool Value::GetAsReal(double* in_value) const { +bool Value::GetAsReal(double* out_value) const { return false; } -bool Value::GetAsString(std::string* in_value) const { +bool Value::GetAsString(std::string* out_value) const { return false; } -bool Value::GetAsString(std::wstring* in_value) const { +bool Value::GetAsString(string16* out_value) const { return false; } -bool Value::GetAsUTF16(string16* out_value) const { +#if !defined(WCHAR_T_IS_UTF16) +// TODO(viettrungluu): Deprecated and to be removed: +bool Value::GetAsString(std::wstring* out_value) const { return false; } +#endif Value* Value::DeepCopy() const { // This method should only be getting called for null Values--all subclasses @@ -228,15 +234,16 @@ StringValue::StringValue(const std::string& in_value) DCHECK(IsStringUTF8(in_value)); } -StringValue::StringValue(const std::wstring& in_value) +StringValue::StringValue(const string16& in_value) : Value(TYPE_STRING), - value_(WideToUTF8(in_value)) { + value_(UTF16ToUTF8(in_value)) { } #if !defined(WCHAR_T_IS_UTF16) -StringValue::StringValue(const string16& in_value) +// TODO(viettrungluu): Deprecated and to be removed: +StringValue::StringValue(const std::wstring& in_value) : Value(TYPE_STRING), - value_(UTF16ToUTF8(in_value)) { + value_(WideToUTF8(in_value)) { } #endif @@ -249,17 +256,20 @@ bool StringValue::GetAsString(std::string* out_value) const { return true; } -bool StringValue::GetAsString(std::wstring* out_value) const { +bool StringValue::GetAsString(string16* out_value) const { if (out_value) - *out_value = UTF8ToWide(value_); + *out_value = UTF8ToUTF16(value_); return true; } -bool StringValue::GetAsUTF16(string16* out_value) const { +#if !defined(WCHAR_T_IS_UTF16) +// TODO(viettrungluu): Deprecated and to be removed: +bool StringValue::GetAsString(std::wstring* out_value) const { if (out_value) - *out_value = UTF8ToUTF16(value_); + *out_value = UTF8ToWide(value_); return true; } +#endif Value* StringValue::DeepCopy() const { return CreateStringValue(value_); @@ -440,7 +450,7 @@ void DictionaryValue::SetString(const std::string& path, void DictionaryValue::SetStringFromUTF16(const std::string& path, const string16& in_value) { - Set(path, CreateStringValueFromUTF16(in_value)); + Set(path, CreateStringValue(in_value)); } // TODO(viettrungluu): Deprecated and to be removed: @@ -473,7 +483,7 @@ void DictionaryValue::SetString(const std::wstring& path, // TODO(viettrungluu): Deprecated and to be removed: void DictionaryValue::SetStringFromUTF16(const std::wstring& path, const string16& in_value) { - Set(path, CreateStringValueFromUTF16(in_value)); + Set(path, CreateStringValue(in_value)); } void DictionaryValue::SetWithoutPathExpansion(const std::string& key, @@ -559,7 +569,7 @@ bool DictionaryValue::GetStringAsUTF16(const std::string& path, if (!Get(path, &value)) return false; - return value->GetAsUTF16(out_value); + return value->GetAsString(out_value); } bool DictionaryValue::GetStringASCII(const std::string& path, @@ -718,7 +728,7 @@ bool DictionaryValue::GetStringAsUTF16WithoutPathExpansion( if (!GetWithoutPathExpansion(key, &value)) return false; - return value->GetAsUTF16(out_value); + return value->GetAsString(out_value); } bool DictionaryValue::GetDictionaryWithoutPathExpansion( @@ -951,7 +961,7 @@ bool ListValue::GetStringAsUTF16(size_t index, string16* out_value) const { if (!Get(index, &value)) return false; - return value->GetAsUTF16(out_value); + return value->GetAsString(out_value); } bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { diff --git a/base/values.h b/base/values.h index 2fc2044..d99a46f 100644 --- a/base/values.h +++ b/base/values.h @@ -56,8 +56,10 @@ class Value { static Value* CreateIntegerValue(int in_value); static Value* CreateRealValue(double in_value); static Value* CreateStringValue(const std::string& in_value); - static Value* CreateStringValue(const std::wstring& in_value); - static Value* CreateStringValueFromUTF16(const string16& 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. @@ -92,8 +94,10 @@ class Value { virtual bool GetAsInteger(int* out_value) const; virtual bool GetAsReal(double* out_value) const; virtual bool GetAsString(std::string* out_value) const; - virtual bool GetAsString(std::wstring* out_value) const; - virtual bool GetAsUTF16(string16* out_value) const; + virtual bool GetAsString(string16* out_value) const; +#if !defined(WCHAR_T_IS_UTF16) + /*DEPRECATED*/virtual bool GetAsString(std::wstring* out_value) const; +#endif // This creates a deep copy of the entire Value tree, and returns a pointer // to the copy. The caller gets ownership of the copy, of course. @@ -145,20 +149,22 @@ class StringValue : public Value { // Initializes a StringValue with a UTF-8 narrow character string. explicit StringValue(const std::string& in_value); - // Initializes a StringValue with a wide character string. - explicit StringValue(const std::wstring& in_value); - -#if !defined(WCHAR_T_IS_UTF16) // Initializes a StringValue with a string16. explicit StringValue(const string16& in_value); + +#if !defined(WCHAR_T_IS_UTF16) + // Initializes a StringValue with a wide character string. + /*DEPRECATED*/explicit StringValue(const std::wstring& in_value); #endif ~StringValue(); // Subclassed methods bool GetAsString(std::string* out_value) const; - bool GetAsString(std::wstring* out_value) const; - bool GetAsUTF16(string16* out_value) const; + bool GetAsString(string16* out_value) const; +#if !defined(WCHAR_T_IS_UTF16) + /*DEPRECATED*/bool GetAsString(std::wstring* out_value) const; +#endif Value* DeepCopy() const; virtual bool Equals(const Value* other) const; diff --git a/base/values_unittest.cc b/base/values_unittest.cc index f0b9d9e..fb414c1 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -18,7 +18,8 @@ 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. +// methods are removed. There are also parts of tests marked DEPRECATED which +// are to be deleted. TEST(ValuesTest, Basic) { // Test basic dictionary getting/setting @@ -182,11 +183,36 @@ TEST(ValuesTest, StringValue) { scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); ASSERT_TRUE(narrow_value.get()); ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); + scoped_ptr<Value> utf16_value( + Value::CreateStringValue(ASCIIToUTF16("utf16"))); + ASSERT_TRUE(utf16_value.get()); + ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); + + // Test overloaded GetString. + std::string narrow = "http://google.com"; + string16 utf16 = ASCIIToUTF16("http://google.com"); + ASSERT_TRUE(narrow_value->GetAsString(&narrow)); + ASSERT_TRUE(narrow_value->GetAsString(&utf16)); + ASSERT_EQ(std::string("narrow"), narrow); + ASSERT_EQ(ASCIIToUTF16("narrow"), utf16); + + ASSERT_TRUE(utf16_value->GetAsString(&narrow)); + ASSERT_TRUE(utf16_value->GetAsString(&utf16)); + ASSERT_EQ(std::string("utf16"), narrow); + ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); +} + +// TODO(viettrungluu): deprecate: +TEST(ValuesTest, StringValueDeprecated) { + // Test overloaded CreateStringValue. + 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::CreateStringValueFromUTF16(ASCIIToUTF16("utf16"))); + Value::CreateStringValue(ASCIIToUTF16("utf16"))); ASSERT_TRUE(utf16_value.get()); ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); @@ -196,21 +222,21 @@ TEST(ValuesTest, StringValue) { string16 utf16 = ASCIIToUTF16("http://google.com"); ASSERT_TRUE(narrow_value->GetAsString(&narrow)); ASSERT_TRUE(narrow_value->GetAsString(&wide)); - ASSERT_TRUE(narrow_value->GetAsUTF16(&utf16)); + ASSERT_TRUE(narrow_value->GetAsString(&utf16)); ASSERT_EQ(std::string("narrow"), narrow); 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->GetAsUTF16(&utf16)); + 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->GetAsUTF16(&utf16)); + ASSERT_TRUE(utf16_value->GetAsString(&utf16)); ASSERT_EQ(std::string("utf16"), narrow); ASSERT_EQ(std::wstring(L"utf16"), wide); ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); @@ -483,11 +509,8 @@ TEST(ValuesTest, DeepCopy) { original_dict.Set("real", original_real); Value* original_string = Value::CreateStringValue("hello"); original_dict.Set("string", original_string); - Value* original_wstring = Value::CreateStringValue(L"peek-a-boo"); - original_dict.Set("wstring", original_wstring); - Value* original_utf16 = - Value::CreateStringValueFromUTF16(ASCIIToUTF16("hello16")); - original_dict.Set("utf16", original_utf16); + Value* original_string16 = Value::CreateStringValue(ASCIIToUTF16("hello16")); + original_dict.Set("string16", original_string16); char* original_buffer = new char[42]; memset(original_buffer, '!', 42); @@ -545,38 +568,21 @@ TEST(ValuesTest, DeepCopy) { ASSERT_NE(copy_string, original_string); ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING)); std::string copy_string_value; - std::wstring copy_wstring_value; - string16 copy_utf16_value; + string16 copy_string16_value; ASSERT_TRUE(copy_string->GetAsString(©_string_value)); - ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_string->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_string->GetAsString(©_string16_value)); ASSERT_EQ(std::string("hello"), copy_string_value); - 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("wstring", ©_wstring)); - ASSERT_TRUE(copy_wstring); - ASSERT_NE(copy_wstring, original_wstring); - ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); - ASSERT_TRUE(copy_wstring->GetAsString(©_string_value)); - ASSERT_TRUE(copy_wstring->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_wstring->GetAsUTF16(©_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("utf16", ©_utf16)); - ASSERT_TRUE(copy_utf16); - ASSERT_NE(copy_utf16, original_utf16); - ASSERT_TRUE(copy_utf16->IsType(Value::TYPE_STRING)); - ASSERT_TRUE(copy_utf16->GetAsString(©_string_value)); - ASSERT_TRUE(copy_utf16->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_utf16->GetAsUTF16(©_utf16_value)); + ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value); + + Value* copy_string16 = NULL; + ASSERT_TRUE(copy_dict->Get("string16", ©_string16)); + ASSERT_TRUE(copy_string16); + ASSERT_NE(copy_string16, original_string16); + ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING)); + ASSERT_TRUE(copy_string16->GetAsString(©_string_value)); + ASSERT_TRUE(copy_string16->GetAsString(©_string16_value)); ASSERT_EQ(std::string("hello16"), copy_string_value); - ASSERT_EQ(std::wstring(L"hello16"), copy_wstring_value); - ASSERT_EQ(ASCIIToUTF16("hello16"), copy_utf16_value); + ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value); Value* copy_binary = NULL; ASSERT_TRUE(copy_dict->Get("binary", ©_binary)); @@ -631,8 +637,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { 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::CreateStringValueFromUTF16(ASCIIToUTF16("hello16")); + Value* original_utf16 = Value::CreateStringValue(ASCIIToUTF16("hello16")); original_dict.Set(L"utf16", original_utf16); char* original_buffer = new char[42]; @@ -695,7 +700,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { string16 copy_utf16_value; ASSERT_TRUE(copy_string->GetAsString(©_string_value)); ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_string->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_string->GetAsString(©_utf16_value)); ASSERT_EQ(std::string("hello"), copy_string_value); ASSERT_EQ(std::wstring(L"hello"), copy_wstring_value); ASSERT_EQ(ASCIIToUTF16("hello"), copy_utf16_value); @@ -707,7 +712,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); ASSERT_TRUE(copy_wstring->GetAsString(©_string_value)); ASSERT_TRUE(copy_wstring->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_wstring->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_wstring->GetAsString(©_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); @@ -719,7 +724,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { ASSERT_TRUE(copy_utf16->IsType(Value::TYPE_STRING)); ASSERT_TRUE(copy_utf16->GetAsString(©_string_value)); ASSERT_TRUE(copy_utf16->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_utf16->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_utf16->GetAsString(©_utf16_value)); ASSERT_EQ(std::string("hello16"), copy_string_value); ASSERT_EQ(std::wstring(L"hello16"), copy_wstring_value); ASSERT_EQ(ASCIIToUTF16("hello16"), copy_utf16_value); diff --git a/chrome/browser/configuration_policy_pref_store.cc b/chrome/browser/configuration_policy_pref_store.cc index e1a2100..34942af 100644 --- a/chrome/browser/configuration_policy_pref_store.cc +++ b/chrome/browser/configuration_policy_pref_store.cc @@ -287,7 +287,7 @@ bool ConfigurationPolicyPrefStore::ApplyPluginPolicy(PolicyType policy, Value* value) { if (policy == kPolicyDisabledPlugins) { string16 plugin_list; - if (value->GetAsUTF16(&plugin_list)) { + if (value->GetAsString(&plugin_list)) { std::vector<string16> plugin_names; // Change commas into tabs so that we can change escaped // tabs back into commas, leaving non-escaped commas as tabs @@ -304,7 +304,7 @@ bool ConfigurationPolicyPrefStore::ApplyPluginPolicy(PolicyType policy, for (std::vector<string16>::const_iterator i(plugin_names.begin()); i != plugin_names.end(); ++i) { if (!i->empty()) { - list->Append(Value::CreateStringValueFromUTF16(*i)); + list->Append(Value::CreateStringValue(*i)); added_plugin = true; } } diff --git a/chrome/browser/configuration_policy_provider_win.cc b/chrome/browser/configuration_policy_provider_win.cc index a52c123..61d264c 100644 --- a/chrome/browser/configuration_policy_provider_win.cc +++ b/chrome/browser/configuration_policy_provider_win.cc @@ -104,7 +104,7 @@ bool ConfigurationPolicyProviderWin::Provide( if (GetRegistryPolicyString(name.c_str(), &string_value)) { store->Apply( current->policy_type, - Value::CreateStringValueFromUTF16(string_value)); + Value::CreateStringValue(string_value)); } break; case Value::TYPE_BOOLEAN: diff --git a/chrome/browser/dom_ui/history2_ui.cc b/chrome/browser/dom_ui/history2_ui.cc index 067fec3..59b1ff3 100644 --- a/chrome/browser/dom_ui/history2_ui.cc +++ b/chrome/browser/dom_ui/history2_ui.cc @@ -222,7 +222,7 @@ void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const Value* value) { continue; const StringValue* string_value = static_cast<const StringValue*>(*v); string16 string16_value; - if (!string_value->GetAsUTF16(&string16_value)) + if (!string_value->GetAsString(&string16_value)) continue; urls.insert(GURL(string16_value)); } @@ -311,7 +311,7 @@ void BrowsingHistoryHandler2::ExtractSearchHistoryArguments(const Value* value, list_member->GetType() == Value::TYPE_STRING) { const StringValue* string_value = static_cast<const StringValue*>(list_member); - string_value->GetAsUTF16(query); + string_value->GetAsString(query); } // Get search month. @@ -320,7 +320,7 @@ void BrowsingHistoryHandler2::ExtractSearchHistoryArguments(const Value* value, const StringValue* string_value = static_cast<const StringValue*>(list_member); string16 string16_value; - string_value->GetAsUTF16(&string16_value); + string_value->GetAsString(&string16_value); base::StringToInt(string16_value, month); } } diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index fc4fd63..4cf5bf3 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -222,7 +222,7 @@ void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const Value* value) { continue; const StringValue* string_value = static_cast<const StringValue*>(*v); string16 string16_value; - if (!string_value->GetAsUTF16(&string16_value)) + if (!string_value->GetAsString(&string16_value)) continue; urls.insert(GURL(string16_value)); } @@ -311,7 +311,7 @@ void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, list_member->GetType() == Value::TYPE_STRING) { const StringValue* string_value = static_cast<const StringValue*>(list_member); - string_value->GetAsUTF16(query); + string_value->GetAsString(query); } // Get search month. @@ -320,7 +320,7 @@ void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, const StringValue* string_value = static_cast<const StringValue*>(list_member); string16 string16_value; - string_value->GetAsUTF16(&string16_value); + string_value->GetAsString(&string16_value); base::StringToInt(string16_value, month); } } diff --git a/chrome/browser/geolocation/access_token_store.cc b/chrome/browser/geolocation/access_token_store.cc index f790c51..ec0ca387 100644 --- a/chrome/browser/geolocation/access_token_store.cc +++ b/chrome/browser/geolocation/access_token_store.cc @@ -71,7 +71,7 @@ void SetAccessTokenOnUIThread(const GURL& server_url, const string16& token) { prefs::kGeolocationAccessToken); access_token_dictionary->SetWithoutPathExpansion( UTF8ToWide(server_url.spec()), - Value::CreateStringValueFromUTF16(token)); + Value::CreateStringValue(token)); } void ChromePrefsAccessTokenStore::SaveAccessToken( diff --git a/chrome/browser/plugin_updater.cc b/chrome/browser/plugin_updater.cc index 0691bac..1664456 100644 --- a/chrome/browser/plugin_updater.cc +++ b/chrome/browser/plugin_updater.cc @@ -173,7 +173,7 @@ void DisablePluginGroupsFromPrefs(Profile* profile) { for (ListValue::const_iterator current(plugin_blacklist->begin()); current != end; ++current) { string16 plugin_name; - if ((*current)->GetAsUTF16(&plugin_name)) { + if ((*current)->GetAsString(&plugin_name)) { policy_disabled_plugins.insert(plugin_name); } } |