diff options
author | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 20:21:01 +0000 |
---|---|---|
committer | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 20:21:01 +0000 |
commit | 32c147158f76e19aa22efa2a7b14d3f0e1e23a02 (patch) | |
tree | a84b94bc6c2e4e52d009db317ed49a343658634c /chrome/common | |
parent | 600a41fb05efe99eb2890e884a7af0541456c365 (diff) | |
download | chromium_src-32c147158f76e19aa22efa2a7b14d3f0e1e23a02.zip chromium_src-32c147158f76e19aa22efa2a7b14d3f0e1e23a02.tar.gz chromium_src-32c147158f76e19aa22efa2a7b14d3f0e1e23a02.tar.bz2 |
Port DictionaryValue to use string16 instead of wstring.
Review URL: http://codereview.chromium.org/31014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/json_value_serializer_unittest.cc | 42 | ||||
-rw-r--r-- | chrome/common/pref_service.cc | 50 |
2 files changed, 49 insertions, 43 deletions
diff --git a/chrome/common/json_value_serializer_unittest.cc b/chrome/common/json_value_serializer_unittest.cc index 1fc9e97..f09f8d3 100644 --- a/chrome/common/json_value_serializer_unittest.cc +++ b/chrome/common/json_value_serializer_unittest.cc @@ -24,20 +24,20 @@ TEST(JSONValueSerializerTest, Roundtrip) { DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); Value* null_value = NULL; - ASSERT_TRUE(root_dict->Get(L"null", &null_value)); + ASSERT_TRUE(root_dict->Get(LIT16("null"), &null_value)); ASSERT_TRUE(null_value); ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); bool bool_value = false; - ASSERT_TRUE(root_dict->GetBoolean(L"bool", &bool_value)); + ASSERT_TRUE(root_dict->GetBoolean(LIT16("bool"), &bool_value)); ASSERT_TRUE(bool_value); int int_value = 0; - ASSERT_TRUE(root_dict->GetInteger(L"int", &int_value)); + ASSERT_TRUE(root_dict->GetInteger(LIT16("int"), &int_value)); ASSERT_EQ(42, int_value); double real_value = 0.0; - ASSERT_TRUE(root_dict->GetReal(L"real", &real_value)); + ASSERT_TRUE(root_dict->GetReal(LIT16("real"), &real_value)); ASSERT_DOUBLE_EQ(3.14, real_value); // We shouldn't be able to write using this serializer, since it was @@ -92,7 +92,7 @@ TEST(JSONValueSerializerTest, StringEscape) { // Test JSONWriter interface std::string output_js; DictionaryValue valueRoot; - valueRoot.SetString(L"all_chars", all_chars); + valueRoot.SetString(LIT16("all_chars"), WideToUTF16Hack(all_chars)); JSONWriter::Write(&valueRoot, false, &output_js); ASSERT_EQ(expected_output, output_js); @@ -106,7 +106,7 @@ TEST(JSONValueSerializerTest, UnicodeStrings) { // unicode string json -> escaped ascii text DictionaryValue root; std::wstring test(L"\x7F51\x9875"); - root.SetString(L"web", test); + root.SetString(LIT16("web"), WideToUTF16Hack(test)); std::string expected = "{\"web\":\"\\u7F51\\u9875\"}"; @@ -121,16 +121,16 @@ TEST(JSONValueSerializerTest, UnicodeStrings) { ASSERT_TRUE(deserial_root.get()); DictionaryValue* dict_root = static_cast<DictionaryValue*>(deserial_root.get()); - std::wstring web_value; - ASSERT_TRUE(dict_root->GetString(L"web", &web_value)); - ASSERT_EQ(test, web_value); + string16 web_value; + ASSERT_TRUE(dict_root->GetString(LIT16("web"), &web_value)); + ASSERT_EQ(test, UTF16ToWideHack(web_value)); } TEST(JSONValueSerializerTest, HexStrings) { // hex string json -> escaped ascii text DictionaryValue root; std::wstring test(L"\x01\x02"); - root.SetString(L"test", test); + root.SetString(LIT16("test"), WideToUTF16Hack(test)); std::string expected = "{\"test\":\"\\x01\\x02\"}"; @@ -145,9 +145,9 @@ TEST(JSONValueSerializerTest, HexStrings) { ASSERT_TRUE(deserial_root.get()); DictionaryValue* dict_root = static_cast<DictionaryValue*>(deserial_root.get()); - std::wstring test_value; - ASSERT_TRUE(dict_root->GetString(L"test", &test_value)); - ASSERT_EQ(test, test_value); + string16 test_value; + ASSERT_TRUE(dict_root->GetString(LIT16("test"), &test_value)); + ASSERT_EQ(test, UTF16ToWideHack(test_value)); // Test converting escaped regular chars std::string escaped_chars = "{\"test\":\"\\x67\\x6f\"}"; @@ -155,8 +155,8 @@ TEST(JSONValueSerializerTest, HexStrings) { deserial_root.reset(deserializer2.Deserialize(NULL)); ASSERT_TRUE(deserial_root.get()); dict_root = static_cast<DictionaryValue*>(deserial_root.get()); - ASSERT_TRUE(dict_root->GetString(L"test", &test_value)); - ASSERT_EQ(std::wstring(L"go"), test_value); + ASSERT_TRUE(dict_root->GetString(LIT16("test"), &test_value)); + ASSERT_EQ(L"go", UTF16ToWideHack(test_value)); } TEST(JSONValueSerializerTest, AllowTrailingComma) { @@ -260,21 +260,21 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) { DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); Value* null_value = NULL; - ASSERT_TRUE(root_dict->Get(L"null", &null_value)); + ASSERT_TRUE(root_dict->Get(LIT16("null"), &null_value)); ASSERT_TRUE(null_value); ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); bool bool_value = false; - ASSERT_TRUE(root_dict->GetBoolean(L"bool", &bool_value)); + ASSERT_TRUE(root_dict->GetBoolean(LIT16("bool"), &bool_value)); ASSERT_TRUE(bool_value); int int_value = 0; - ASSERT_TRUE(root_dict->GetInteger(L"int", &int_value)); + ASSERT_TRUE(root_dict->GetInteger(LIT16("int"), &int_value)); ASSERT_EQ(42, int_value); - std::wstring string_value; - ASSERT_TRUE(root_dict->GetString(L"string", &string_value)); - ASSERT_EQ(L"hello", string_value); + string16 string_value; + ASSERT_TRUE(root_dict->GetString(LIT16("string"), &string_value)); + ASSERT_EQ(L"hello", UTF16ToWideHack(string_value)); // Now try writing. std::wstring written_file_path = test_dir_; diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc index b728a87..fd27de1 100644 --- a/chrome/common/pref_service.cc +++ b/chrome/common/pref_service.cc @@ -289,7 +289,7 @@ bool PrefService::GetBoolean(const wchar_t* path) const { DCHECK(CalledOnValidThread()); bool result = false; - if (transient_->GetBoolean(path, &result)) + if (transient_->GetBoolean(WideToUTF16Hack(path), &result)) return result; const Preference* pref = FindPreference(path); @@ -306,7 +306,7 @@ int PrefService::GetInteger(const wchar_t* path) const { DCHECK(CalledOnValidThread()); int result = 0; - if (transient_->GetInteger(path, &result)) + if (transient_->GetInteger(WideToUTF16Hack(path), &result)) return result; const Preference* pref = FindPreference(path); @@ -323,7 +323,7 @@ double PrefService::GetReal(const wchar_t* path) const { DCHECK(CalledOnValidThread()); double result = 0.0; - if (transient_->GetReal(path, &result)) + if (transient_->GetReal(WideToUTF16Hack(path), &result)) return result; const Preference* pref = FindPreference(path); @@ -339,10 +339,11 @@ double PrefService::GetReal(const wchar_t* path) const { std::wstring PrefService::GetString(const wchar_t* path) const { DCHECK(CalledOnValidThread()); - std::wstring result; - if (transient_->GetString(path, &result)) - return result; + string16 result16; + if (transient_->GetString(WideToUTF16Hack(path), &result16)) + return UTF16ToWideHack(result16); + std::wstring result; const Preference* pref = FindPreference(path); if (!pref) { #if defined(OS_WIN) @@ -359,7 +360,8 @@ std::wstring PrefService::GetString(const wchar_t* path) const { bool PrefService::HasPrefPath(const wchar_t* path) const { Value* value = NULL; - return (transient_->Get(path, &value) || persistent_->Get(path, &value)); + string16 path16 = WideToUTF16Hack(path); + return (transient_->Get(path16, &value) || persistent_->Get(path16, &value)); } const PrefService::Preference* PrefService::FindPreference( @@ -374,7 +376,7 @@ const DictionaryValue* PrefService::GetDictionary(const wchar_t* path) const { DCHECK(CalledOnValidThread()); DictionaryValue* result = NULL; - if (transient_->GetDictionary(path, &result)) + if (transient_->GetDictionary(WideToUTF16Hack(path), &result)) return result; const Preference* pref = FindPreference(path); @@ -392,7 +394,7 @@ const ListValue* PrefService::GetList(const wchar_t* path) const { DCHECK(CalledOnValidThread()); ListValue* result = NULL; - if (transient_->GetList(path, &result)) + if (transient_->GetList(WideToUTF16Hack(path), &result)) return result; const Preference* pref = FindPreference(path); @@ -473,10 +475,11 @@ void PrefService::ClearPref(const wchar_t* path) { return; } - transient_->Remove(path, NULL); + string16 path16 = WideToUTF16Hack(path); + transient_->Remove(path16, NULL); Value* value; - bool has_old_value = persistent_->Get(path, &value); - persistent_->Remove(path, NULL); + bool has_old_value = persistent_->Get(path16, &value); + persistent_->Remove(path16, NULL); if (has_old_value) FireObservers(path); @@ -496,7 +499,7 @@ void PrefService::SetBoolean(const wchar_t* path, bool value) { } scoped_ptr<Value> old_value(GetPrefCopy(path)); - bool rv = persistent_->SetBoolean(path, value); + bool rv = persistent_->SetBoolean(WideToUTF16Hack(path), value); DCHECK(rv); FireObserversIfChanged(path, old_value.get()); @@ -516,7 +519,7 @@ void PrefService::SetInteger(const wchar_t* path, int value) { } scoped_ptr<Value> old_value(GetPrefCopy(path)); - bool rv = persistent_->SetInteger(path, value); + bool rv = persistent_->SetInteger(WideToUTF16Hack(path), value); DCHECK(rv); FireObserversIfChanged(path, old_value.get()); @@ -536,7 +539,7 @@ void PrefService::SetReal(const wchar_t* path, double value) { } scoped_ptr<Value> old_value(GetPrefCopy(path)); - bool rv = persistent_->SetReal(path, value); + bool rv = persistent_->SetReal(WideToUTF16Hack(path), value); DCHECK(rv); FireObserversIfChanged(path, old_value.get()); @@ -556,7 +559,8 @@ void PrefService::SetString(const wchar_t* path, const std::wstring& value) { } scoped_ptr<Value> old_value(GetPrefCopy(path)); - bool rv = persistent_->SetString(path, value); + bool rv = persistent_->SetString(WideToUTF16Hack(path), + WideToUTF16Hack(value)); DCHECK(rv); FireObserversIfChanged(path, old_value.get()); @@ -576,10 +580,11 @@ DictionaryValue* PrefService::GetMutableDictionary(const wchar_t* path) { } DictionaryValue* dict = NULL; - bool rv = persistent_->GetDictionary(path, &dict); + string16 path16 = WideToUTF16Hack(path); + bool rv = persistent_->GetDictionary(path16, &dict); if (!rv) { dict = new DictionaryValue; - rv = persistent_->Set(path, dict); + rv = persistent_->Set(path16, dict); DCHECK(rv); } return dict; @@ -599,10 +604,11 @@ ListValue* PrefService::GetMutableList(const wchar_t* path) { } ListValue* list = NULL; - bool rv = persistent_->GetList(path, &list); + string16 path16 = WideToUTF16Hack(path); + bool rv = persistent_->GetList(path16, &list); if (!rv) { list = new ListValue; - rv = persistent_->Set(path, list); + rv = persistent_->Set(path16, list); DCHECK(rv); } return list; @@ -619,7 +625,7 @@ Value* PrefService::GetPrefCopy(const wchar_t* path) { void PrefService::FireObserversIfChanged(const wchar_t* path, const Value* old_value) { Value* new_value = NULL; - persistent_->Get(path, &new_value); + persistent_->Get(WideToUTF16Hack(path), &new_value); if (!old_value->Equals(new_value)) FireObservers(path); } @@ -672,7 +678,7 @@ const Value* PrefService::Preference::GetValue() const { "Must register pref before getting its value"; Value* temp_value = NULL; - if (root_pref_->Get(name_.c_str(), &temp_value) && + if (root_pref_->Get(WideToUTF16Hack(name_), &temp_value) && temp_value->GetType() == type_) { return temp_value; } |