summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 17:02:25 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 17:02:25 +0000
commit5879cef53e60384391c36e6d7e4062e8b763c976 (patch)
tree4718389bd1adff25f6741d630f2f87bf003e6574 /base
parent6f75eb5610fe3144a16942c4fd5da8eb59ec2146 (diff)
downloadchromium_src-5879cef53e60384391c36e6d7e4062e8b763c976.zip
chromium_src-5879cef53e60384391c36e6d7e4062e8b763c976.tar.gz
chromium_src-5879cef53e60384391c36e6d7e4062e8b763c976.tar.bz2
Fix prefs registration in BrowserInstantController.
Registration should happen prior to PrefService construction, so accepting a PrefService parameter to RegisterUserPrefs is a no-no. To keep the existing semantics, this change adds a PrefService::SetDefaultPrefValue method that allows you to change the default value for a pref. As BrowserInstantController was the last method called from chrome::RegisterUserPrefs that required a PrefService pointer, this also removes the PrefService parameter from the latter function and updates callers. TBR=ben@chromium.org BUG=155525 Review URL: https://chromiumcodereview.appspot.com/12315116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/prefs/pref_registry.cc15
-rw-r--r--base/prefs/pref_registry.h5
-rw-r--r--base/prefs/pref_service.cc6
-rw-r--r--base/prefs/pref_service.h6
4 files changed, 32 insertions, 0 deletions
diff --git a/base/prefs/pref_registry.cc b/base/prefs/pref_registry.cc
index c6fad4e..9ca1102 100644
--- a/base/prefs/pref_registry.cc
+++ b/base/prefs/pref_registry.cc
@@ -28,6 +28,21 @@ PrefRegistry::const_iterator PrefRegistry::end() const {
return defaults_->end();
}
+void PrefRegistry::SetDefaultPrefValue(const char* pref_name,
+ base::Value* value) {
+ DCHECK(value);
+ if (DCHECK_IS_ON()) {
+ const base::Value* current_value = NULL;
+ DCHECK(defaults_->GetValue(pref_name, &current_value))
+ << "Setting default for unregistered pref: " << pref_name;
+ DCHECK(value->IsType(current_value->GetType()))
+ << "Wrong type for new default: " << pref_name;
+ }
+
+ defaults_->RemoveDefaultValue(pref_name);
+ defaults_->SetDefaultValue(pref_name, value);
+}
+
void PrefRegistry::SetRegistrationCallback(
const RegistrationCallback& callback) {
registration_callback_ = callback;
diff --git a/base/prefs/pref_registry.h b/base/prefs/pref_registry.h
index 8f39341c..6c7eac9f 100644
--- a/base/prefs/pref_registry.h
+++ b/base/prefs/pref_registry.h
@@ -40,6 +40,11 @@ class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
const_iterator begin() const;
const_iterator end() const;
+ // Changes the default value for a preference. Takes ownership of |value|.
+ //
+ // |pref_name| must be a previously registered preference.
+ void SetDefaultPrefValue(const char* pref_name, base::Value* value);
+
// Exactly one callback can be set for registration. The callback
// will be invoked each time registration has been performed on this
// object.
diff --git a/base/prefs/pref_service.cc b/base/prefs/pref_service.cc
index 67ab898..b1f4f3f 100644
--- a/base/prefs/pref_service.cc
+++ b/base/prefs/pref_service.cc
@@ -273,6 +273,12 @@ const base::Value* PrefService::GetUserPrefValue(const char* path) const {
return value;
}
+void PrefService::SetDefaultPrefValue(const char* path,
+ base::Value* value) {
+ DCHECK(CalledOnValidThread());
+ pref_registry_->SetDefaultPrefValue(path, value);
+}
+
const base::Value* PrefService::GetDefaultPrefValue(const char* path) const {
DCHECK(CalledOnValidThread());
// Lookup the preference in the default store.
diff --git a/base/prefs/pref_service.h b/base/prefs/pref_service.h
index d9cc8f5..9ba78be 100644
--- a/base/prefs/pref_service.h
+++ b/base/prefs/pref_service.h
@@ -220,6 +220,12 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// the preference is not set in the user pref store, returns NULL.
const base::Value* GetUserPrefValue(const char* path) const;
+ // Changes the default value for a preference. Takes ownership of |value|.
+ //
+ // Will cause a pref change notification to be fired if this causes
+ // the effective value to change.
+ void SetDefaultPrefValue(const char* path, base::Value* value);
+
// Returns the default value of the given preference. |path| must point to a
// registered preference. In that case, will never return NULL.
const base::Value* GetDefaultPrefValue(const char* path) const;