diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 01:33:08 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 01:33:08 +0000 |
commit | c3453302fbaad636d925b9940cb80c1bc54c761e (patch) | |
tree | 0933e3c132bb92e5ec2259aa7208eb46f90d4dd5 | |
parent | 9c00acacfbd2742ff923b6f819c5aaf828348ca7 (diff) | |
download | chromium_src-c3453302fbaad636d925b9940cb80c1bc54c761e.zip chromium_src-c3453302fbaad636d925b9940cb80c1bc54c761e.tar.gz chromium_src-c3453302fbaad636d925b9940cb80c1bc54c761e.tar.bz2 |
Remove the transient layer from PrefService. There are no more callers
so it's not needed anymore.
BUG=28992
Review URL: http://codereview.chromium.org/449028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33406 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/pref_service.cc | 29 | ||||
-rw-r--r-- | chrome/common/pref_service.h | 3 | ||||
-rw-r--r-- | chrome/common/pref_service_unittest.cc | 141 | ||||
-rw-r--r-- | chrome/test/data/pref_service/overlay.json | 22 |
4 files changed, 3 insertions, 192 deletions
diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc index 50ff1f5..9236497 100644 --- a/chrome/common/pref_service.cc +++ b/chrome/common/pref_service.cc @@ -62,7 +62,6 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { PrefService::PrefService(const FilePath& pref_filename) : persistent_(new DictionaryValue), - transient_(new DictionaryValue), writer_(pref_filename) { ReloadPersistentPrefs(); } @@ -211,8 +210,6 @@ bool PrefService::GetBoolean(const wchar_t* path) const { DCHECK(CalledOnValidThread()); bool result = false; - if (transient_->GetBoolean(path, &result)) - return result; const Preference* pref = FindPreference(path); if (!pref) { @@ -228,8 +225,6 @@ int PrefService::GetInteger(const wchar_t* path) const { DCHECK(CalledOnValidThread()); int result = 0; - if (transient_->GetInteger(path, &result)) - return result; const Preference* pref = FindPreference(path); if (!pref) { @@ -245,8 +240,6 @@ double PrefService::GetReal(const wchar_t* path) const { DCHECK(CalledOnValidThread()); double result = 0.0; - if (transient_->GetReal(path, &result)) - return result; const Preference* pref = FindPreference(path); if (!pref) { @@ -262,8 +255,6 @@ std::wstring PrefService::GetString(const wchar_t* path) const { DCHECK(CalledOnValidThread()); std::wstring result; - if (transient_->GetString(path, &result)) - return result; const Preference* pref = FindPreference(path); if (!pref) { @@ -279,8 +270,6 @@ FilePath PrefService::GetFilePath(const wchar_t* path) const { DCHECK(CalledOnValidThread()); FilePath::StringType result; - if (transient_->GetString(path, &result)) - return FilePath(result); const Preference* pref = FindPreference(path); if (!pref) { @@ -298,7 +287,7 @@ FilePath PrefService::GetFilePath(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)); + return persistent_->Get(path, &value); } const PrefService::Preference* PrefService::FindPreference( @@ -312,10 +301,6 @@ const PrefService::Preference* PrefService::FindPreference( const DictionaryValue* PrefService::GetDictionary(const wchar_t* path) const { DCHECK(CalledOnValidThread()); - DictionaryValue* result = NULL; - if (transient_->GetDictionary(path, &result)) - return result; - const Preference* pref = FindPreference(path); if (!pref) { NOTREACHED() << "Trying to read an unregistered pref: " << path; @@ -330,10 +315,6 @@ const DictionaryValue* PrefService::GetDictionary(const wchar_t* path) const { const ListValue* PrefService::GetList(const wchar_t* path) const { DCHECK(CalledOnValidThread()); - ListValue* result = NULL; - if (transient_->GetList(path, &result)) - return result; - const Preference* pref = FindPreference(path); if (!pref) { NOTREACHED() << "Trying to read an unregistered pref: " << path; @@ -412,7 +393,6 @@ void PrefService::ClearPref(const wchar_t* path) { return; } - transient_->Remove(path, NULL); Value* value; bool has_old_value = persistent_->Get(path, &value); persistent_->Remove(path, NULL); @@ -563,15 +543,12 @@ void PrefService::SetInt64(const wchar_t* path, int64 value) { int64 PrefService::GetInt64(const wchar_t* path) const { DCHECK(CalledOnValidThread()); - std::wstring result; - if (transient_->GetString(path, &result)) - return StringToInt64(WideToUTF16Hack(result)); - const Preference* pref = FindPreference(path); if (!pref) { NOTREACHED() << "Trying to read an unregistered pref: " << path; - return StringToInt64(WideToUTF16Hack(result)); + return 0; } + std::wstring result(L"0"); bool rv = pref->GetValue()->GetAsString(&result); DCHECK(rv); return StringToInt64(WideToUTF16Hack(result)); diff --git a/chrome/common/pref_service.h b/chrome/common/pref_service.h index 62c7a93..929145e 100644 --- a/chrome/common/pref_service.h +++ b/chrome/common/pref_service.h @@ -92,8 +92,6 @@ class PrefService : public NonThreadSafe, // Serializes the data and schedules save using ImportantFileWriter. void ScheduleSavePersistentPrefs(); - DictionaryValue* transient() { return transient_.get(); } - // Make the PrefService aware of a pref. void RegisterBooleanPref(const wchar_t* path, bool default_value); @@ -207,7 +205,6 @@ class PrefService : public NonThreadSafe, const Value* old_value); scoped_ptr<DictionaryValue> persistent_; - scoped_ptr<DictionaryValue> transient_; // Helper for safe writing pref data. ImportantFileWriter writer_; diff --git a/chrome/common/pref_service_unittest.cc b/chrome/common/pref_service_unittest.cc index bfb96b0..c60b38b 100644 --- a/chrome/common/pref_service_unittest.cc +++ b/chrome/common/pref_service_unittest.cc @@ -115,14 +115,6 @@ TEST_F(PrefServiceTest, Basic) { FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); prefs.RegisterFilePathPref(kSomeDirectory, FilePath()); - // Now test that the transient value overrides the persistent value, - // without actually altering the persistent store. - prefs.transient()->SetString(prefs::kHomePage, microsoft); - EXPECT_TRUE(prefs.transient()->GetString(prefs::kHomePage, &homepage)); - EXPECT_EQ(microsoft, homepage); - - EXPECT_EQ(microsoft, prefs.GetString(prefs::kHomePage)); - // Test reading some other data types from sub-dictionaries, and // writing to the persistent store. EXPECT_TRUE(prefs.GetBoolean(kNewWindowsInTabs)); @@ -155,139 +147,6 @@ TEST_F(PrefServiceTest, Basic) { ASSERT_TRUE(file_util::Delete(output_file, false)); } -TEST_F(PrefServiceTest, Overlay) { - const std::string transient = - "{\"bool\":true, \"int\":2, \"real\":2.0, \"string\":\"transient\"," - "\"dictionary\":{\"value\":\"transient\"}," - "\"list\":[\"transient\"]}"; - - std::wstring persistent_string(L"persistent"); - std::wstring transient_string(L"transient"); - - FilePath persistent_file = data_dir_.AppendASCII("overlay.json"); - PrefService prefs(persistent_file); - EXPECT_TRUE(prefs.ReloadPersistentPrefs()); - - Value* transient_value; - { - JSONStringValueSerializer serializer(transient); - transient_value = serializer.Deserialize(NULL); - ASSERT_TRUE(transient_value); - } - prefs.transient()->Set(transient_string, transient_value); - - Value* both_transient_value; - { - JSONStringValueSerializer serializer(transient); - both_transient_value = serializer.Deserialize(NULL); - ASSERT_TRUE(both_transient_value); - } - prefs.transient()->Set(L"both", both_transient_value); - - // Register test prefs - static const std::wstring kTypes[] = - { L"neither.", L"persistent.", L"transient.", L"both." }; - for (size_t i = 0; i < arraysize(kTypes); ++i) { - prefs.RegisterBooleanPref((kTypes[i] + L"bool").c_str(), false); - prefs.RegisterIntegerPref((kTypes[i] + L"int").c_str(), 0); - prefs.RegisterRealPref((kTypes[i] + L"real").c_str(), 0.0); - prefs.RegisterStringPref((kTypes[i] + L"string").c_str(), L""); - prefs.RegisterListPref((kTypes[i] + L"list").c_str()); - prefs.RegisterDictionaryPref((kTypes[i] + L"dictionary").c_str()); - } - - ASSERT_FALSE(prefs.GetBoolean(L"neither.bool")); - ASSERT_FALSE(prefs.GetBoolean(L"persistent.bool")); - ASSERT_TRUE(prefs.GetBoolean(L"transient.bool")); - ASSERT_TRUE(prefs.GetBoolean(L"both.bool")); - - ASSERT_EQ(0, prefs.GetInteger(L"neither.int")); - ASSERT_EQ(1, prefs.GetInteger(L"persistent.int")); - ASSERT_EQ(2, prefs.GetInteger(L"transient.int")); - ASSERT_EQ(2, prefs.GetInteger(L"both.int")); - - ASSERT_EQ(0.0, prefs.GetReal(L"neither.real")); - ASSERT_EQ(1.0, prefs.GetReal(L"persistent.real")); - ASSERT_EQ(2.0, prefs.GetReal(L"transient.real")); - ASSERT_EQ(2.0, prefs.GetReal(L"both.real")); - - ASSERT_EQ(std::wstring(), prefs.GetString(L"neither.string")); - ASSERT_EQ(persistent_string, prefs.GetString(L"persistent.string")); - ASSERT_EQ(transient_string, prefs.GetString(L"transient.string")); - ASSERT_EQ(transient_string, prefs.GetString(L"both.string")); - - { - const DictionaryValue* result_value = - prefs.GetDictionary(L"neither.dictionary"); - ASSERT_FALSE(result_value); - } - - { - const DictionaryValue* result_value = - prefs.GetDictionary(L"persistent.dictionary"); - ASSERT_TRUE(result_value); - std::wstring result_string; - ASSERT_TRUE(result_value->GetString(L"value", &result_string)); - ASSERT_EQ(persistent_string, result_string); - } - - { - const DictionaryValue* result_value = - prefs.GetDictionary(L"transient.dictionary"); - ASSERT_TRUE(result_value); - std::wstring result_string; - ASSERT_TRUE(result_value->GetString(L"value", &result_string)); - ASSERT_EQ(transient_string, result_string); - } - - { - const DictionaryValue* result_value = - prefs.GetDictionary(L"both.dictionary"); - ASSERT_TRUE(result_value); - std::wstring result_string; - ASSERT_TRUE(result_value->GetString(L"value", &result_string)); - ASSERT_EQ(transient_string, result_string); - } - - { - const ListValue* result_value = prefs.GetList(L"neither.list"); - ASSERT_FALSE(result_value); - } - - { - const ListValue* result_value = prefs.GetList(L"persistent.list"); - ASSERT_TRUE(result_value); - Value* member_value; - ASSERT_TRUE(result_value->Get(0, &member_value)); - ASSERT_TRUE(member_value); - std::wstring result_string; - ASSERT_TRUE(member_value->GetAsString(&result_string)); - ASSERT_EQ(persistent_string, result_string); - } - - { - const ListValue* result_value = prefs.GetList(L"transient.list"); - ASSERT_TRUE(result_value); - Value* member_value; - ASSERT_TRUE(result_value->Get(0, &member_value)); - ASSERT_TRUE(member_value); - std::wstring result_string; - ASSERT_TRUE(member_value->GetAsString(&result_string)); - ASSERT_EQ(transient_string, result_string); - } - - { - const ListValue* result_value = prefs.GetList(L"both.list"); - ASSERT_TRUE(result_value); - Value* member_value; - ASSERT_TRUE(result_value->Get(0, &member_value)); - ASSERT_TRUE(member_value); - std::wstring result_string; - ASSERT_TRUE(member_value->GetAsString(&result_string)); - ASSERT_EQ(transient_string, result_string); - } -} - TEST_F(PrefServiceTest, Observers) { FilePath input_file = data_dir_.AppendASCII("read.json"); EXPECT_TRUE(file_util::PathExists(input_file)); diff --git a/chrome/test/data/pref_service/overlay.json b/chrome/test/data/pref_service/overlay.json deleted file mode 100644 index 11c0293..0000000 --- a/chrome/test/data/pref_service/overlay.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "both": { - "bool": false, - "dictionary": { - "value": "persistent" - }, - "int": 1, - "list": [ "persistent" ], - "real": 1, - "string": "persistent" - }, - "persistent": { - "bool": false, - "dictionary": { - "value": "persistent" - }, - "int": 1, - "list": [ "persistent" ], - "real": 1.0, - "string": "persistent" - } -} |