diff options
| author | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-09 11:14:01 +0000 |
|---|---|---|
| committer | pam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-09 11:14:01 +0000 |
| commit | 40a47c1697c8597153a2e0450ca7f95e8f2c7fe2 (patch) | |
| tree | ae22fce34f33a7a3a215537cc3c384f2d7501a06 | |
| parent | cc0424241b32f8ae14180bd2e3e69896c5e0c380 (diff) | |
| download | chromium_src-40a47c1697c8597153a2e0450ca7f95e8f2c7fe2.zip chromium_src-40a47c1697c8597153a2e0450ca7f95e8f2c7fe2.tar.gz chromium_src-40a47c1697c8597153a2e0450ca7f95e8f2c7fe2.tar.bz2 | |
Revert 58920 - Create a DefaultPrefStore to hold registered application-default preference values.
This allows notifications to be sent properly when another PrefStore takes control from a default value.
BUG=52719
TEST=covered by PrefValueStoreTest.* unit tests
Review URL: http://codereview.chromium.org/3331016
TBR=pam@chromium.org
[Reverting because it causes PrefsControllerTest.ValidateCustomHomePagesTable to crash on Mac.]
Review URL: http://codereview.chromium.org/3353019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58925 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/extensions/extension_pref_store_unittest.cc | 11 | ||||
| -rw-r--r-- | chrome/browser/net/chrome_url_request_context_unittest.cc | 5 | ||||
| -rw-r--r-- | chrome/browser/prefs/default_pref_store.cc | 21 | ||||
| -rw-r--r-- | chrome/browser/prefs/default_pref_store.h | 32 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_member_unittest.cc | 11 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_notifier.h | 4 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_notifier_unittest.cc | 2 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_service.cc | 156 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_service.h | 40 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_service_unittest.cc | 37 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_value_store.cc | 57 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_value_store.h | 36 | ||||
| -rw-r--r-- | chrome/browser/prefs/pref_value_store_unittest.cc | 86 | ||||
| -rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
| -rw-r--r-- | chrome/test/testing_pref_service.cc | 8 | ||||
| -rw-r--r-- | chrome/test/testing_pref_service.h | 4 |
16 files changed, 144 insertions, 368 deletions
diff --git a/chrome/browser/extensions/extension_pref_store_unittest.cc b/chrome/browser/extensions/extension_pref_store_unittest.cc index e7f783c..78d433a 100644 --- a/chrome/browser/extensions/extension_pref_store_unittest.cc +++ b/chrome/browser/extensions/extension_pref_store_unittest.cc @@ -9,7 +9,6 @@ #include "base/scoped_temp_dir.h" #include "base/values.h" #include "chrome/browser/extensions/extension_pref_store.h" -#include "chrome/browser/prefs/default_pref_store.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/common/extensions/extension.h" @@ -329,14 +328,13 @@ TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) { using testing::Mock; TestExtensionPrefStore* eps = new TestExtensionPrefStore; - DefaultPrefStore* dps = new DefaultPrefStore; ASSERT_TRUE(eps->ext1 != NULL); // The PrefValueStore takes ownership of the PrefStores; in this case, that's // only an ExtensionPrefStore. Likewise, the PrefService takes ownership of // the PrefValueStore and PrefNotifier. PrefValueStore* value_store = new TestingPrefService::TestingPrefValueStore( - NULL, eps, NULL, NULL, NULL, dps); + NULL, eps, NULL, NULL, NULL); scoped_ptr<MockPrefService> pref_service(new MockPrefService(value_store)); MockPrefNotifier* pref_notifier = new MockPrefNotifier(pref_service.get(), value_store); @@ -350,12 +348,7 @@ TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) { Value::CreateStringValue("https://www.chromium.org")); Mock::VerifyAndClearExpectations(pref_notifier); - // At the moment, re-setting a pref to the same value in the same store - // always triggers notifications, because the PrefValueStore has no way to - // know that the default value isn't being overridden. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0); - EXPECT_CALL(*pref_notifier, FireObservers(kPref1)); + EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0); eps->InstallExtensionPref(eps->ext1, kPref1, Value::CreateStringValue("https://www.chromium.org")); Mock::VerifyAndClearExpectations(pref_notifier); diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc index 5665224..80b7578 100644 --- a/chrome/browser/net/chrome_url_request_context_unittest.cc +++ b/chrome/browser/net/chrome_url_request_context_unittest.cc @@ -7,7 +7,6 @@ #include "base/command_line.h" #include "base/format_macros.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" -#include "chrome/browser/prefs/default_pref_store.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/testing_pref_service.h" @@ -159,11 +158,9 @@ TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, tests[i].description.c_str())); CommandLine command_line(tests[i].command_line); - // Only configuration-policy and default prefs are needed. PrefService prefs(new TestingPrefService::TestingPrefValueStore( new ConfigurationPolicyPrefStore(&command_line, NULL), - NULL, NULL, NULL, NULL, - new DefaultPrefStore())); + NULL, NULL, NULL, NULL)); // Only configuration-policy prefs. ChromeURLRequestContextGetter::RegisterUserPrefs(&prefs); scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(&prefs)); diff --git a/chrome/browser/prefs/default_pref_store.cc b/chrome/browser/prefs/default_pref_store.cc deleted file mode 100644 index 6b0aa71..0000000 --- a/chrome/browser/prefs/default_pref_store.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/prefs/default_pref_store.h" - -#include "base/values.h" - -DefaultPrefStore::DefaultPrefStore() : prefs_(new DictionaryValue()) { -} - -DefaultPrefStore::~DefaultPrefStore() { -} - -DictionaryValue* DefaultPrefStore::prefs() { - return prefs_.get(); -} - -PrefStore::PrefReadError DefaultPrefStore::ReadPrefs() { - return PrefStore::PREF_READ_ERROR_NONE; -} diff --git a/chrome/browser/prefs/default_pref_store.h b/chrome/browser/prefs/default_pref_store.h deleted file mode 100644 index c84aec7..0000000 --- a/chrome/browser/prefs/default_pref_store.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PREFS_DEFAULT_PREF_STORE_H_ -#define CHROME_BROWSER_PREFS_DEFAULT_PREF_STORE_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/scoped_ptr.h" -#include "chrome/common/pref_store.h" - - -// This PrefStore keeps track of default preference values set when a -// preference is registered with the PrefService. -class DefaultPrefStore : public PrefStore { - public: - DefaultPrefStore(); - virtual ~DefaultPrefStore(); - - // PrefStore methods: - virtual DictionaryValue* prefs(); - virtual PrefStore::PrefReadError ReadPrefs(); - - private: - // The default preference values. - scoped_ptr<DictionaryValue> prefs_; - - DISALLOW_COPY_AND_ASSIGN(DefaultPrefStore); -}; - -#endif // CHROME_BROWSER_PREFS_DEFAULT_PREF_STORE_H_ diff --git a/chrome/browser/prefs/pref_member_unittest.cc b/chrome/browser/prefs/pref_member_unittest.cc index 5685ff6..f59f937 100644 --- a/chrome/browser/prefs/pref_member_unittest.cc +++ b/chrome/browser/prefs/pref_member_unittest.cc @@ -180,18 +180,11 @@ TEST(PrefMemberTest, Observer) { // Not changing the value should not fire the observer. prefs.SetString(kStringPref, "world"); - // At the moment, re-setting a pref to the same value in the same store - // always triggers notifications, because the PrefValueStore has no way to - // know that the default value isn't being overridden. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // EXPECT_EQ(1, test_obj.observe_cnt_); - EXPECT_EQ(2, test_obj.observe_cnt_); + EXPECT_EQ(1, test_obj.observe_cnt_); EXPECT_EQ("world", *(test_obj.str_)); prefs.SetString(kStringPref, "hello"); - // TODO(pamg): see above - // EXPECT_EQ(2, test_obj.observe_cnt_); - EXPECT_EQ(3, test_obj.observe_cnt_); + EXPECT_EQ(2, test_obj.observe_cnt_); EXPECT_EQ("hello", prefs.GetString(kStringPref)); } diff --git a/chrome/browser/prefs/pref_notifier.h b/chrome/browser/prefs/pref_notifier.h index 65b9838..c627de9 100644 --- a/chrome/browser/prefs/pref_notifier.h +++ b/chrome/browser/prefs/pref_notifier.h @@ -32,7 +32,6 @@ class PrefNotifier : public NonThreadSafe, // COMMAND_LINE contains preference values set by command-line switches. // USER contains all user-set preference values. // RECOMMENDED contains all recommended (policy) preference values. - // DEFAULT contains all application default preference values. // This enum is kept in pref_notifier.h rather than pref_value_store.h in // order to minimize additional headers needed by the *PrefStore files. enum PrefStoreType { @@ -44,8 +43,7 @@ class PrefNotifier : public NonThreadSafe, COMMAND_LINE_STORE, USER_STORE, RECOMMENDED_STORE, - DEFAULT_STORE, - PREF_STORE_TYPE_MAX = DEFAULT_STORE + PREF_STORE_TYPE_MAX = RECOMMENDED_STORE }; // The |service| with which this notifier is associated will be sent as the diff --git a/chrome/browser/prefs/pref_notifier_unittest.cc b/chrome/browser/prefs/pref_notifier_unittest.cc index 2772772..5a1a6f4 100644 --- a/chrome/browser/prefs/pref_notifier_unittest.cc +++ b/chrome/browser/prefs/pref_notifier_unittest.cc @@ -59,7 +59,7 @@ class MockPrefNotifier : public PrefNotifier { // PrefHasChanged(). class MockPrefValueStore : public PrefValueStore { public: - MockPrefValueStore() : PrefValueStore(NULL, NULL, NULL, NULL, NULL, NULL) {} + MockPrefValueStore() : PrefValueStore(NULL, NULL, NULL, NULL, NULL) {} virtual ~MockPrefValueStore() {} diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 437ea9e..1ab671a 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -61,7 +61,7 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { default: { NOTREACHED() << - "list and dictionary types cannot have default locale values"; + "list and dictionary types can not have default locale values"; } } NOTREACHED(); @@ -149,7 +149,7 @@ PrefStore::PrefReadError PrefService::LoadPersistentPrefs() { for (PreferenceSet::iterator it = prefs_.begin(); it != prefs_.end(); ++it) { - (*it)->pref_service_ = this; + (*it)->pref_value_store_ = pref_value_store_.get(); } return pref_error; @@ -169,61 +169,75 @@ void PrefService::ScheduleSavePersistentPrefs() { void PrefService::RegisterBooleanPref(const char* path, bool default_value) { - RegisterPreference(path, Value::CreateBooleanValue(default_value)); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateBooleanValue(default_value)); + RegisterPreference(pref); } void PrefService::RegisterIntegerPref(const char* path, int default_value) { - RegisterPreference(path, Value::CreateIntegerValue(default_value)); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateIntegerValue(default_value)); + RegisterPreference(pref); } void PrefService::RegisterRealPref(const char* path, double default_value) { - RegisterPreference(path, Value::CreateRealValue(default_value)); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateRealValue(default_value)); + RegisterPreference(pref); } void PrefService::RegisterStringPref(const char* path, const std::string& default_value) { - RegisterPreference(path, Value::CreateStringValue(default_value)); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateStringValue(default_value)); + RegisterPreference(pref); } void PrefService::RegisterFilePathPref(const char* path, const FilePath& default_value) { - RegisterPreference(path, Value::CreateStringValue(default_value.value())); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateStringValue(default_value.value())); + RegisterPreference(pref); } void PrefService::RegisterListPref(const char* path) { - RegisterPreference(path, new ListValue()); + Preference* pref = new Preference(pref_value_store_.get(), path, + new ListValue); + RegisterPreference(pref); } void PrefService::RegisterDictionaryPref(const char* path) { - RegisterPreference(path, new DictionaryValue()); + Preference* pref = new Preference(pref_value_store_.get(), path, + new DictionaryValue()); + RegisterPreference(pref); } void PrefService::RegisterLocalizedBooleanPref(const char* path, int locale_default_message_id) { - RegisterPreference( - path, + Preference* pref = new Preference(pref_value_store_.get(), path, CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id)); + RegisterPreference(pref); } void PrefService::RegisterLocalizedIntegerPref(const char* path, int locale_default_message_id) { - RegisterPreference( - path, + Preference* pref = new Preference(pref_value_store_.get(), path, CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id)); + RegisterPreference(pref); } void PrefService::RegisterLocalizedRealPref(const char* path, int locale_default_message_id) { - RegisterPreference( - path, + Preference* pref = new Preference(pref_value_store_.get(), path, CreateLocaleDefaultValue(Value::TYPE_REAL, locale_default_message_id)); + RegisterPreference(pref); } void PrefService::RegisterLocalizedStringPref(const char* path, int locale_default_message_id) { - RegisterPreference( - path, + Preference* pref = new Preference(pref_value_store_.get(), path, CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id)); + RegisterPreference(pref); } bool PrefService::GetBoolean(const char* path) const { @@ -312,10 +326,7 @@ bool PrefService::HasPrefPath(const char* path) const { const PrefService::Preference* PrefService::FindPreference( const char* pref_name) const { DCHECK(CalledOnValidThread()); - // We only look up prefs by name, so the type is irrelevant, except that it - // must be one that Preference() allows (i.e., neither TYPE_NULL nor - // TYPE_BINARY). - Preference p(this, pref_name, Value::TYPE_INTEGER); + Preference p(NULL, pref_name, NULL); PreferenceSet::const_iterator it = prefs_.find(&p); return it == prefs_.end() ? NULL : *it; } @@ -366,29 +377,15 @@ void PrefService::RemovePrefObserver(const char* path, pref_notifier_->RemovePrefObserver(path, obs); } -void PrefService::RegisterPreference(const char* path, Value* default_value) { +void PrefService::RegisterPreference(Preference* pref) { DCHECK(CalledOnValidThread()); - // The main code path takes ownership, but most don't. We'll be safe. - scoped_ptr<Value> scoped_value(default_value); - - if (FindPreference(path)) { - NOTREACHED() << "Tried to register duplicate pref " << path; + if (FindPreference(pref->name().c_str())) { + NOTREACHED() << "Tried to register duplicate pref " << pref->name(); + delete pref; return; } - - // We set the default value of dictionaries and lists to be null so it's - // easier for callers to check for empty dict/list prefs. The PrefValueStore - // accepts ownership of the value (null or default_value). - Value::ValueType orig_type = default_value->GetType(); - if (Value::TYPE_LIST == orig_type || Value::TYPE_DICTIONARY == orig_type) { - pref_value_store_->SetDefaultPrefValue(path, Value::CreateNullValue()); - } else { - // Hand off ownership. - pref_value_store_->SetDefaultPrefValue(path, scoped_value.release()); - } - - prefs_.insert(new Preference(this, path, orig_type)); + prefs_.insert(pref); } void PrefService::ClearPref(const char* path) { @@ -610,8 +607,9 @@ int64 PrefService::GetInt64(const char* path) const { } void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { - RegisterPreference( - path, Value::CreateStringValue(base::Int64ToString(default_value))); + Preference* pref = new Preference(pref_value_store_.get(), path, + Value::CreateStringValue(base::Int64ToString(default_value))); + RegisterPreference(pref); } DictionaryValue* PrefService::GetMutableDictionary(const char* path) { @@ -654,8 +652,7 @@ ListValue* PrefService::GetMutableList(const char* path) { ListValue* list = NULL; Value* tmp_value = NULL; - if (!pref_value_store_->GetValue(path, &tmp_value) || - !tmp_value->IsType(Value::TYPE_LIST)) { + if (!pref_value_store_->GetValue(path, &tmp_value)) { list = new ListValue; pref_value_store_->SetUserPrefValue(path, list); } else { @@ -675,69 +672,66 @@ Value* PrefService::GetPrefCopy(const char* path) { /////////////////////////////////////////////////////////////////////////////// // PrefService::Preference -PrefService::Preference::Preference(const PrefService* service, +PrefService::Preference::Preference(PrefValueStore* pref_value_store, const char* name, - Value::ValueType type) - : type_(type), + Value* default_value) + : type_(Value::TYPE_NULL), name_(name), - pref_service_(service) { + default_value_(default_value), + pref_value_store_(pref_value_store) { DCHECK(name); - DCHECK(service); - DCHECK(type != Value::TYPE_NULL && type != Value::TYPE_BINARY) << - "invalid preference type: " << type; + + if (default_value) { + type_ = default_value->GetType(); + DCHECK(type_ != Value::TYPE_NULL && type_ != Value::TYPE_BINARY) << + "invalid preference type: " << type_; + } + + // We set the default value of lists and dictionaries to be null so it's + // easier for callers to check for empty list/dict prefs. + if (Value::TYPE_LIST == type_ || Value::TYPE_DICTIONARY == type_) + default_value_.reset(Value::CreateNullValue()); } const Value* PrefService::Preference::GetValue() const { - DCHECK(pref_service_->FindPreference(name_.c_str())) << + DCHECK(NULL != pref_value_store_) << "Must register pref before getting its value"; - Value* found_value = NULL; - if (pref_service_->pref_value_store_->GetValue(name_, &found_value)) { - Value::ValueType found_type = found_value->GetType(); - // Dictionaries and lists have default values of TYPE_NULL. - if (found_type == type_ || - (found_type == Value::TYPE_NULL - && (type_ == Value::TYPE_LIST || type_ == Value::TYPE_DICTIONARY))) { - return found_value; - } + Value* temp_value = NULL; + if (pref_value_store_->GetValue(name_, &temp_value) && + temp_value->GetType() == type_) { + return temp_value; } - // Every registered preference has at least a default value. - NOTREACHED() << "no default value for registered pref " << name_; - return NULL; + // Pref not found, just return the app default. + return default_value_.get(); +} + +bool PrefService::Preference::IsDefaultValue() const { + DCHECK(default_value_.get()); + return default_value_->Equals(GetValue()); } bool PrefService::Preference::IsManaged() const { - return pref_service_->pref_value_store_-> - PrefValueInManagedStore(name_.c_str()); + return pref_value_store_->PrefValueInManagedStore(name_.c_str()); } bool PrefService::Preference::HasExtensionSetting() const { - return pref_service_->pref_value_store_-> - PrefValueInExtensionStore(name_.c_str()); + return pref_value_store_->PrefValueInExtensionStore(name_.c_str()); } bool PrefService::Preference::HasUserSetting() const { - return pref_service_->pref_value_store_-> - PrefValueInUserStore(name_.c_str()); + return pref_value_store_->PrefValueInUserStore(name_.c_str()); } bool PrefService::Preference::IsExtensionControlled() const { - return pref_service_->pref_value_store_-> - PrefValueFromExtensionStore(name_.c_str()); + return pref_value_store_->PrefValueFromExtensionStore(name_.c_str()); } bool PrefService::Preference::IsUserControlled() const { - return pref_service_->pref_value_store_-> - PrefValueFromUserStore(name_.c_str()); -} - -bool PrefService::Preference::IsDefaultValue() const { - return pref_service_->pref_value_store_-> - PrefValueFromDefaultStore(name_.c_str()); + return pref_value_store_->PrefValueFromUserStore(name_.c_str()); } bool PrefService::Preference::IsUserModifiable() const { - return pref_service_->pref_value_store_-> - PrefValueUserModifiable(name_.c_str()); + return pref_value_store_->PrefValueUserModifiable(name_.c_str()); } diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h index 49312ad..07fa5e5 100644 --- a/chrome/browser/prefs/pref_service.h +++ b/chrome/browser/prefs/pref_service.h @@ -28,13 +28,14 @@ class PrefService : public NonThreadSafe { class Preference { public: - // The type of the preference is determined by the type with which it is - // registered. This type needs to be a boolean, integer, real, string, + // The type of the preference is determined by the type of |default_value|. + // Therefore, the type needs to be a boolean, integer, real, string, // dictionary (a branch), or list. You shouldn't need to construct this on - // your own; use the PrefService::Register*Pref methods instead. - Preference(const PrefService* service, + // your own, use the PrefService::Register*Pref methods instead. + // |default_value| will be owned by the Preference object. + Preference(PrefValueStore* pref_value_store, const char* name, - Value::ValueType type); + Value* default_value); ~Preference() {} Value::ValueType type() const { return type_; } @@ -43,10 +44,13 @@ class PrefService : public NonThreadSafe { // browser.window_placement). const std::string name() const { return name_; } - // Returns the value of the Preference, falling back to the registered - // default value if no other has been set. + // Returns the value of the Preference. If there is no user specified + // value, it returns the default value. const Value* GetValue() const; + // Returns true if the current value matches the default value. + bool IsDefaultValue() const; + // Returns true if the Preference is managed, i.e. set by an admin policy. // Since managed prefs have the highest priority, this also indicates // whether the pref is actually being controlled by the policy setting. @@ -68,11 +72,6 @@ class PrefService : public NonThreadSafe { // user setting, and not by any higher-priority source. bool IsUserControlled() const; - // Returns true if the Preference is currently using its default value, - // and has not been set by any higher-priority source (even with the same - // value). - bool IsDefaultValue() const; - // Returns true if the user can change the Preference value, which is the // case if no higher-priority source than the user store controls the // Preference. @@ -83,9 +82,10 @@ class PrefService : public NonThreadSafe { Value::ValueType type_; std::string name_; + scoped_ptr<Value> default_value_; - // Reference to the PrefService in which this pref was created. - const PrefService* pref_service_; + // A reference to the pref service's pref_value_store_. + PrefValueStore* pref_value_store_; DISALLOW_COPY_AND_ASSIGN(Preference); }; @@ -100,8 +100,8 @@ class PrefService : public NonThreadSafe { // Convenience factory method for use in unit tests. Creates a new // PrefService that uses a PrefValueStore with user preferences at the given - // |pref_filename|, a default PrefStore, and no other PrefStores (i.e., no - // other types of preferences). + // |pref_filename|, and no other PrefStores (i.e., no other types of + // preferences). static PrefService* CreateUserPrefService(const FilePath& pref_filename); // This constructor is primarily used by tests. The |pref_value_store| @@ -171,9 +171,7 @@ class PrefService : public NonThreadSafe { void ClearPref(const char* path); // If the path is valid (i.e., registered), update the pref value in the user - // prefs. Seting a null value on a preference of List or Dictionary type is - // equivalent to removing the user value for that preference, allowing the - // default value to take effect unless another value takes precedence. + // prefs. void Set(const char* path, const Value& value); void SetBoolean(const char* path, bool value); void SetInteger(const char* path, int value); @@ -229,8 +227,8 @@ class PrefService : public NonThreadSafe { private: // Add a preference to the PreferenceMap. If the pref already exists, return - // false. This method takes ownership of |default_value|. - void RegisterPreference(const char* path, Value* default_value); + // false. This method takes ownership of |pref|. + void RegisterPreference(Preference* pref); // Returns a copy of the current pref value. The caller is responsible for // deleting the returned object. diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc index 5e7aa31..b6dd531 100644 --- a/chrome/browser/prefs/pref_service_unittest.cc +++ b/chrome/browser/prefs/pref_service_unittest.cc @@ -105,11 +105,7 @@ TEST(PrefServiceTest, NoObserverFire) { // time. obs.Reset(new_pref_value); prefs.SetString(pref_name, new_pref_value); - // At the moment this does trigger notifications, because the PrefValueStore - // has no way to know that the default value isn't being overridden. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // EXPECT_FALSE(obs.observer_fired()); - EXPECT_TRUE(obs.observer_fired()); + EXPECT_FALSE(obs.observer_fired()); // Clearing the pref should cause the pref to fire. obs.Reset(""); @@ -119,9 +115,7 @@ TEST(PrefServiceTest, NoObserverFire) { // Clearing the pref again should not cause the pref to fire. obs.Reset(""); prefs.ClearPref(pref_name); - // TODO(pamg): see above - // EXPECT_FALSE(obs.observer_fired()); - EXPECT_TRUE(obs.observer_fired()); + EXPECT_FALSE(obs.observer_fired()); // Ok, clean up. prefs.RemovePrefObserver(pref_name, &obs); @@ -218,16 +212,7 @@ TEST_F(PrefServiceSetValueTest, SetStringValue) { scoped_ptr<Value> default_value(Value::CreateStringValue(default_string)); prefs_.RegisterStringPref(name_, default_string); prefs_.AddPrefObserver(name_, &observer_); - // Changing the controlling store from default to user triggers notification. - SetExpectPrefChanged(); - prefs_.Set(name_, *default_value); - Mock::VerifyAndClearExpectations(&observer_); - - // At the moment this also triggers notifications, because the PrefValueStore - // has no way to know that the default value isn't being overridden again. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // SetExpectNoNotification(); - SetExpectPrefChanged(); + SetExpectNoNotification(); prefs_.Set(name_, *default_value); Mock::VerifyAndClearExpectations(&observer_); @@ -243,8 +228,6 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { prefs_.RegisterDictionaryPref(name_); prefs_.AddPrefObserver(name_, &observer_); - // Dictionary values are special: setting one to NULL is the same as clearing - // the user value, allowing the NULL default to take (or keep) control. SetExpectNoNotification(); prefs_.Set(name_, *null_value_); Mock::VerifyAndClearExpectations(&observer_); @@ -260,11 +243,7 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { dict->GetString(name_, &out_value); EXPECT_EQ(value_, out_value); - // At the moment this also triggers notifications, because the PrefValueStore - // has no way to know that the default value isn't being overridden again. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // SetExpectNoNotification(); - SetExpectPrefChanged(); + SetExpectNoNotification(); prefs_.Set(name_, new_value); Mock::VerifyAndClearExpectations(&observer_); @@ -281,8 +260,6 @@ TEST_F(PrefServiceSetValueTest, SetListValue) { prefs_.RegisterListPref(name_); prefs_.AddPrefObserver(name_, &observer_); - // List values are special: setting one to NULL is the same as clearing the - // user value, allowing the NULL default to take (or keep) control. SetExpectNoNotification(); prefs_.Set(name_, *null_value_); Mock::VerifyAndClearExpectations(&observer_); @@ -298,11 +275,7 @@ TEST_F(PrefServiceSetValueTest, SetListValue) { list->GetString(0, &out_value); EXPECT_EQ(value_, out_value); - // At the moment this also triggers notifications, because the PrefValueStore - // has no way to know that the default value isn't being overridden again. - // TODO(pamg): Fix this expectation when the above problem is fixed. - // SetExpectNoNotification(); - SetExpectPrefChanged(); + SetExpectNoNotification(); prefs_.Set(name_, new_value); Mock::VerifyAndClearExpectations(&observer_); diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc index 9faf5d7..501f1e1 100644 --- a/chrome/browser/prefs/pref_value_store.cc +++ b/chrome/browser/prefs/pref_value_store.cc @@ -9,7 +9,6 @@ #include "chrome/browser/extensions/extension_pref_store.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/prefs/command_line_pref_store.h" -#include "chrome/browser/prefs/default_pref_store.h" #include "chrome/common/json_pref_store.h" #include "chrome/common/notification_service.h" @@ -21,12 +20,12 @@ PrefValueStore* PrefValueStore::CreatePrefValueStore( ConfigurationPolicyPrefStore* managed = NULL; ExtensionPrefStore* extension = NULL; CommandLinePrefStore* command_line = NULL; + JsonPrefStore* user = NULL; ConfigurationPolicyPrefStore* recommended = NULL; - JsonPrefStore* user = new JsonPrefStore( + user = new JsonPrefStore( pref_filename, ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); - DefaultPrefStore* default_store = new DefaultPrefStore(); if (!user_only) { managed = ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(); @@ -36,7 +35,7 @@ PrefValueStore* PrefValueStore::CreatePrefValueStore( ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); } return new PrefValueStore(managed, extension, command_line, user, - recommended, default_store); + recommended); } PrefValueStore::~PrefValueStore() {} @@ -51,7 +50,7 @@ bool PrefValueStore::GetValue(const std::string& name, return true; } } - // No value found for the given preference name: set the return false. + // No value found for the given preference name, set the return false. *out_value = NULL; return false; } @@ -90,9 +89,7 @@ bool PrefValueStore::HasPrefPath(const char* path) const { Value* tmp_value = NULL; const std::string name(path); bool rv = GetValue(name, &tmp_value); - // Merely registering a pref doesn't count as "having" it: we require a - // non-default value set. - return rv && !PrefValueFromDefaultStore(path); + return rv; } bool PrefValueStore::PrefHasChanged(const char* path, @@ -113,9 +110,8 @@ bool PrefValueStore::PrefHasChanged(const char* path, // If there's a value in a store with lower priority than the |new_store|, // and no value in a store with higher priority, assume the |new_store| just // took control of the pref. (This assumption is wrong if the new value - // and store are both the same as the old one.) - // TODO(pamg): This happens often, because every pref has a value in the - // default pref store. Fix it. + // and store are both the same as the old one, but that situation should be + // rare, and reporting a change when none happened should not be harmful.) if (PrefValueInStoreRange(path, new_store, false) && !PrefValueInStoreRange(path, new_store, true)) return true; @@ -123,20 +119,13 @@ bool PrefValueStore::PrefHasChanged(const char* path, return false; } -// Note the |DictionaryValue| referenced by the |PrefStore| USER_STORE +// Note the |DictionaryValue| referenced by the |PrefStore| user_prefs_ // (returned by the method prefs()) takes the ownership of the Value referenced // by in_value. void PrefValueStore::SetUserPrefValue(const char* name, Value* in_value) { pref_stores_[PrefNotifier::USER_STORE]->prefs()->Set(name, in_value); } -// Note the |DictionaryValue| referenced by the |PrefStore| DEFAULT_STORE -// (returned by the method prefs()) takes the ownership of the Value referenced -// by in_value. -void PrefValueStore::SetDefaultPrefValue(const char* name, Value* in_value) { - pref_stores_[PrefNotifier::DEFAULT_STORE]->prefs()->Set(name, in_value); -} - bool PrefValueStore::ReadOnly() { return pref_stores_[PrefNotifier::USER_STORE]->ReadOnly(); } @@ -147,31 +136,27 @@ void PrefValueStore::RemoveUserPrefValue(const char* name) { } } -bool PrefValueStore::PrefValueInManagedStore(const char* name) const { +bool PrefValueStore::PrefValueInManagedStore(const char* name) { return PrefValueInStore(name, PrefNotifier::MANAGED_STORE); } -bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { +bool PrefValueStore::PrefValueInExtensionStore(const char* name) { return PrefValueInStore(name, PrefNotifier::EXTENSION_STORE); } -bool PrefValueStore::PrefValueInUserStore(const char* name) const { +bool PrefValueStore::PrefValueInUserStore(const char* name) { return PrefValueInStore(name, PrefNotifier::USER_STORE); } -bool PrefValueStore::PrefValueFromExtensionStore(const char* name) const { +bool PrefValueStore::PrefValueFromExtensionStore(const char* name) { return ControllingPrefStoreForPref(name) == PrefNotifier::EXTENSION_STORE; } -bool PrefValueStore::PrefValueFromUserStore(const char* name) const { +bool PrefValueStore::PrefValueFromUserStore(const char* name) { return ControllingPrefStoreForPref(name) == PrefNotifier::USER_STORE; } -bool PrefValueStore::PrefValueFromDefaultStore(const char* name) const { - return ControllingPrefStoreForPref(name) == PrefNotifier::DEFAULT_STORE; -} - -bool PrefValueStore::PrefValueUserModifiable(const char* name) const { +bool PrefValueStore::PrefValueUserModifiable(const char* name) { PrefNotifier::PrefStoreType effective_store = ControllingPrefStoreForPref(name); return effective_store >= PrefNotifier::USER_STORE || @@ -179,7 +164,7 @@ bool PrefValueStore::PrefValueUserModifiable(const char* name) const { } bool PrefValueStore::PrefValueInStore(const char* name, - PrefNotifier::PrefStoreType type) const { + PrefNotifier::PrefStoreType type) { if (!pref_stores_[type].get()) { // No store of that type set, so this pref can't be in it. return false; @@ -190,7 +175,7 @@ bool PrefValueStore::PrefValueInStore(const char* name, bool PrefValueStore::PrefValueInStoreRange(const char* name, PrefNotifier::PrefStoreType boundary, - bool higher_priority) const { + bool higher_priority) { // Higher priorities are lower PrefStoreType values. The range is // non-inclusive of the boundary. int start = higher_priority ? 0 : boundary + 1; @@ -204,8 +189,9 @@ bool PrefValueStore::PrefValueInStoreRange(const char* name, return false; } + PrefNotifier::PrefStoreType PrefValueStore::ControllingPrefStoreForPref( - const char* name) const { + const char* name) { for (int i = 0; i <= PrefNotifier::PREF_STORE_TYPE_MAX; ++i) { if (PrefValueInStore(name, static_cast<PrefNotifier::PrefStoreType>(i))) return static_cast<PrefNotifier::PrefStoreType>(i); @@ -302,15 +288,10 @@ PrefValueStore::PrefValueStore(PrefStore* managed_prefs, PrefStore* extension_prefs, PrefStore* command_line_prefs, PrefStore* user_prefs, - PrefStore* recommended_prefs, - PrefStore* default_prefs) { - // NULL default pref store is usually bad, but may be OK for some unit tests. - if (!default_prefs) - LOG(WARNING) << "default pref store is null"; + PrefStore* recommended_prefs) { pref_stores_[PrefNotifier::MANAGED_STORE].reset(managed_prefs); pref_stores_[PrefNotifier::EXTENSION_STORE].reset(extension_prefs); pref_stores_[PrefNotifier::COMMAND_LINE_STORE].reset(command_line_prefs); pref_stores_[PrefNotifier::USER_STORE].reset(user_prefs); pref_stores_[PrefNotifier::RECOMMENDED_STORE].reset(recommended_prefs); - pref_stores_[PrefNotifier::DEFAULT_STORE].reset(default_prefs); } diff --git a/chrome/browser/prefs/pref_value_store.h b/chrome/browser/prefs/pref_value_store.h index fe9e291..fb1cb21 100644 --- a/chrome/browser/prefs/pref_value_store.h +++ b/chrome/browser/prefs/pref_value_store.h @@ -49,9 +49,7 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { ~PrefValueStore(); // Get the preference value for the given preference name. - // Return true if a value for the given preference name was found in any of - // the available PrefStores. Most callers should use Preference::GetValue() - // instead of calling this method directly. + // Return true if a value for the given preference name was found. bool GetValue(const std::string& name, Value** out_value) const; // Read preference values into the three PrefStores so that they are available @@ -79,8 +77,7 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { // TODO(pamg): If we're setting the same value as we already had, into the // same store that was controlling it before, and there's also a value set in // a lower-priority store, *and* we're not the highest-priority store, then - // this will return true when it shouldn't. This comes up frequently because - // every pref has a value in the default PrefStore. + // this will return true when it shouldn't. Fix that if it causes problems. virtual bool PrefHasChanged(const char* path, PrefNotifier::PrefStoreType new_store, const Value* old_value); @@ -104,26 +101,22 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { // or recommended this function should have no effect. void RemoveUserPrefValue(const char* name); - // Sets a value in the DefaultPrefStore, which takes ownership of the Value. - void SetDefaultPrefValue(const char* name, Value* in_value); - // These methods return true if a preference with the given name is in the // indicated pref store, even if that value is currently being overridden by // a higher-priority source. - bool PrefValueInManagedStore(const char* name) const; - bool PrefValueInExtensionStore(const char* name) const; - bool PrefValueInUserStore(const char* name) const; + bool PrefValueInManagedStore(const char* name); + bool PrefValueInExtensionStore(const char* name); + bool PrefValueInUserStore(const char* name); // These methods return true if a preference with the given name is actually // being controlled by the indicated pref store and not being overridden by // a higher-priority source. - bool PrefValueFromExtensionStore(const char* name) const; - bool PrefValueFromUserStore(const char* name) const; - bool PrefValueFromDefaultStore(const char* name) const; + bool PrefValueFromExtensionStore(const char* name); + bool PrefValueFromUserStore(const char* name); // Check whether a Preference value is modifiable by the user, i.e. whether // there is no higher-priority source controlling it. - bool PrefValueUserModifiable(const char* name) const; + bool PrefValueUserModifiable(const char* name); // Signature of callback triggered after policy refresh. Parameter is not // passed as reference to prevent passing along a pointer to a set whose @@ -151,8 +144,6 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { // switches. // |user_prefs| contains all user-set preference values. // |recommended_prefs| contains all recommended (policy) preference values. - // |default_prefs| contains application-default preference values. It must - // be non-null if any preferences are to be registered. // // This constructor should only be used internally, or by subclasses in // testing. The usual way to create a PrefValueStore is by creating a @@ -161,8 +152,7 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { PrefStore* extension_prefs, PrefStore* command_line_prefs, PrefStore* user_prefs, - PrefStore* recommended_prefs, - PrefStore* default_prefs); + PrefStore* recommended_prefs); private: friend class PrefValueStoreTest; @@ -171,8 +161,7 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { scoped_ptr<PrefStore> pref_stores_[PrefNotifier::PREF_STORE_TYPE_MAX + 1]; - bool PrefValueInStore(const char* name, - PrefNotifier::PrefStoreType type) const; + bool PrefValueInStore(const char* name, PrefNotifier::PrefStoreType type); // Returns true if the preference |name| is found in any PrefStore starting // just beyond the |boundary|, non-inclusive, and checking either @@ -180,13 +169,12 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { // stores. bool PrefValueInStoreRange(const char* name, PrefNotifier::PrefStoreType boundary, - bool higher_priority) const; + bool higher_priority); // Returns the pref store type identifying the source that controls the // Preference identified by |name|. If none of the sources has a value, // INVALID is returned. - PrefNotifier::PrefStoreType ControllingPrefStoreForPref( - const char* name) const; + PrefNotifier::PrefStoreType ControllingPrefStoreForPref(const char* name); // Called during policy refresh after ReadPrefs completes on the thread // that initiated the policy refresh. RefreshPolicyPrefsCompletion takes diff --git a/chrome/browser/prefs/pref_value_store_unittest.cc b/chrome/browser/prefs/pref_value_store_unittest.cc index 98a2c13..96af616 100644 --- a/chrome/browser/prefs/pref_value_store_unittest.cc +++ b/chrome/browser/prefs/pref_value_store_unittest.cc @@ -35,7 +35,6 @@ namespace prefs { const char kRecommendedPref[] = "this.pref.recommended_value_only"; const char kSampleDict[] = "sample.dict"; const char kSampleList[] = "sample.list"; - const char kDefaultPref[] = "default.pref"; // This must match the actual pref name so the command-line store knows about // it. @@ -73,10 +72,6 @@ namespace recommended_pref { const bool kRecommendedPrefValue = true; } -namespace default_pref { - const int kDefaultValue = 7; -} - class PrefValueStoreTest : public testing::Test { protected: virtual void SetUp() { @@ -86,7 +81,6 @@ class PrefValueStoreTest : public testing::Test { command_line_prefs_ = CreateCommandLinePrefs(); user_prefs_ = CreateUserPrefs(); recommended_prefs_ = CreateRecommendedPrefs(); - default_prefs_ = CreateDefaultPrefs(); // Create |DummyPrefStore|s. enforced_pref_store_ = new DummyPrefStore(); @@ -100,8 +94,6 @@ class PrefValueStoreTest : public testing::Test { user_pref_store_->set_prefs(user_prefs_); recommended_pref_store_ = new DummyPrefStore(); recommended_pref_store_->set_prefs(recommended_prefs_); - default_pref_store_ = new DummyPrefStore(); - default_pref_store_->set_prefs(default_prefs_); // Create a new pref-value-store. pref_value_store_ = new TestingPrefService::TestingPrefValueStore( @@ -109,8 +101,7 @@ class PrefValueStoreTest : public testing::Test { extension_pref_store_, command_line_pref_store_, user_pref_store_, - recommended_pref_store_, - default_pref_store_); + recommended_pref_store_); ui_thread_.reset(new ChromeThread(ChromeThread::UI, &loop_)); file_thread_.reset(new ChromeThread(ChromeThread::FILE, &loop_)); @@ -172,14 +163,7 @@ class PrefValueStoreTest : public testing::Test { expected_differing_paths_.push_back("this"); expected_differing_paths_.push_back("this.pref"); expected_differing_paths_.push_back(prefs::kRecommendedPref); - return recommended_prefs; - } - - DictionaryValue* CreateDefaultPrefs() { - DictionaryValue* default_prefs = new DictionaryValue(); - default_prefs->SetInteger(prefs::kDefaultPref, default_pref::kDefaultValue); - return default_prefs; - } + return recommended_prefs; } DictionaryValue* CreateSampleDictValue() { DictionaryValue* sample_dict = new DictionaryValue(); @@ -210,9 +194,8 @@ class PrefValueStoreTest : public testing::Test { DummyPrefStore* enforced_pref_store_; DummyPrefStore* extension_pref_store_; DummyPrefStore* command_line_pref_store_; - DummyPrefStore* user_pref_store_; DummyPrefStore* recommended_pref_store_; - DummyPrefStore* default_pref_store_; + DummyPrefStore* user_pref_store_; // A vector of the preferences paths in the managed and recommended // PrefStores that are set at the beginning of a test. Can be modified @@ -226,7 +209,6 @@ class PrefValueStoreTest : public testing::Test { DictionaryValue* command_line_prefs_; DictionaryValue* user_prefs_; DictionaryValue* recommended_prefs_; - DictionaryValue* default_prefs_; private: scoped_ptr<ChromeThread> ui_thread_; @@ -239,7 +221,6 @@ TEST_F(PrefValueStoreTest, IsReadOnly) { command_line_pref_store_->set_read_only(true); user_pref_store_->set_read_only(true); recommended_pref_store_->set_read_only(true); - default_pref_store_->set_read_only(true); EXPECT_TRUE(pref_value_store_->ReadOnly()); user_pref_store_->set_read_only(false); @@ -291,13 +272,6 @@ TEST_F(PrefValueStoreTest, GetValue) { EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); EXPECT_EQ(recommended_pref::kRecommendedPrefValue, actual_bool_value); - // Test getting a default value. - value = NULL; - ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, &value)); - actual_int_value = -1; - EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); - EXPECT_EQ(default_pref::kDefaultValue, actual_int_value); - // Test getting a preference value that the |PrefValueStore| // does not contain. FundamentalValue tmp_dummy_value(true); @@ -313,8 +287,6 @@ TEST_F(PrefValueStoreTest, HasPrefPath) { EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); // Recommended preference EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); - // Default preference - EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); // Unknown preference EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); } @@ -476,11 +448,6 @@ TEST_F(PrefValueStoreTest, PrefValueInManagedStore) { EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( prefs::kRecommendedPref)); - // Test a preference from the default pref store. - ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); - EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( - prefs::kDefaultPref)); - // Test a preference for which the PrefValueStore does not contain a value. ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMissingPref)); @@ -519,13 +486,6 @@ TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) { EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( prefs::kRecommendedPref)); - // Test a preference from the default pref store. - ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); - EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( - prefs::kDefaultPref)); - EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( - prefs::kDefaultPref)); - // Test a preference for which the PrefValueStore does not contain a value. ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( @@ -566,52 +526,12 @@ TEST_F(PrefValueStoreTest, PrefValueInUserStore) { EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore( prefs::kRecommendedPref)); - // Test a preference from the default pref store. - ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); - EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kDefaultPref)); - EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kDefaultPref)); - // Test a preference for which the PrefValueStore does not contain a value. ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref)); EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref)); } -TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) { - // Test an enforced preference. - ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage)); - EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomepage)); - - // Test an extension preference. - ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID)); - EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore( - prefs::kCurrentThemeID)); - - // Test a command-line preference. - ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale)); - EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore( - prefs::kApplicationLocale)); - - // Test a user preference. - ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs)); - EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kMaxTabs)); - - // Test a preference from the recommended pref store. - ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); - EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore( - prefs::kRecommendedPref)); - - // Test a preference from the default pref store. - ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); - EXPECT_TRUE( - pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref)); - - // Test a preference for which the PrefValueStore does not contain a value. - ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); - EXPECT_FALSE( - pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); -} - TEST_F(PrefValueStoreTest, TestPolicyRefresh) { // pref_value_store_ is initialized by PrefValueStoreTest to have values // in both it's managed and recommended store. By replacing them with diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1cf7e10..83ad314 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2231,8 +2231,6 @@ 'browser/prefs/browser_prefs.h', 'browser/prefs/command_line_pref_store.cc', 'browser/prefs/command_line_pref_store.h', - 'browser/prefs/default_pref_store.cc', - 'browser/prefs/default_pref_store.h', 'browser/prefs/pref_member.cc', 'browser/prefs/pref_member.h', 'browser/prefs/pref_notifier.cc', diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc index efa18e6..398bf35 100644 --- a/chrome/test/testing_pref_service.cc +++ b/chrome/test/testing_pref_service.cc @@ -12,10 +12,9 @@ TestingPrefService::TestingPrefValueStore::TestingPrefValueStore( PrefStore* extension_prefs, PrefStore* command_line_prefs, PrefStore* user_prefs, - PrefStore* recommended_prefs, - PrefStore* default_prefs) + PrefStore* recommended_prefs) : PrefValueStore(managed_prefs, extension_prefs, command_line_prefs, - user_prefs, recommended_prefs, default_prefs) { + user_prefs, recommended_prefs) { } // TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify @@ -26,8 +25,7 @@ TestingPrefService::TestingPrefService() NULL, NULL, user_prefs_ = new DummyPrefStore(), - NULL, - default_prefs_ = new DummyPrefStore())) { + NULL)) { } const Value* TestingPrefService::GetManagedPref(const char* path) { diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h index bb164c5..9d45af7 100644 --- a/chrome/test/testing_pref_service.h +++ b/chrome/test/testing_pref_service.h @@ -22,8 +22,7 @@ class TestingPrefService : public PrefService { PrefStore* extension_prefs, PrefStore* command_line_prefs, PrefStore* user_prefs, - PrefStore* recommended_prefs, - PrefStore* default_prefs); + PrefStore* recommended_prefs); }; // Create an empty instance. @@ -60,7 +59,6 @@ class TestingPrefService : public PrefService { // Pointers to the pref stores our value store uses. PrefStore* managed_prefs_; PrefStore* user_prefs_; - PrefStore* default_prefs_; DISALLOW_COPY_AND_ASSIGN(TestingPrefService); }; |
