Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: chrome/browser/prefs/pref_service.cc

Issue 11741003: Remove PrefServiceSimple, replacing it with PrefService and PrefRegistrySimple. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to desired interfaces. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_service.cc
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 61f54f7f1f36acdf5ca20d96b01ae0cc27764c2c..b780995ed1a09ec2220b392bc1c1059bddf8c3e1 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -18,6 +18,7 @@
#include "base/value_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/prefs/pref_notifier_impl.h"
+#include "chrome/browser/prefs/pref_registry.h"
#include "chrome/browser/prefs/pref_value_store.h"
using content::BrowserContext;
@@ -43,16 +44,21 @@ PrefService::PrefService(
PrefNotifierImpl* pref_notifier,
PrefValueStore* pref_value_store,
PersistentPrefStore* user_prefs,
- DefaultPrefStore* default_store,
+ scoped_ptr<PrefRegistry> pref_registry,
base::Callback<void(PersistentPrefStore::PrefReadError)>
read_error_callback,
bool async)
: pref_notifier_(pref_notifier),
pref_value_store_(pref_value_store),
user_pref_store_(user_prefs),
- default_store_(default_store),
- read_error_callback_(read_error_callback) {
+ read_error_callback_(read_error_callback),
+ pref_registry_(pref_registry.Pass()) {
pref_notifier_->SetPrefService(this);
+
+ pref_registry_->RetrieveDefaults(&default_store_);
+ pref_registry_->pref_service_ = this;
+ RegisterInitialPreferences();
+
InitFromStorage(async);
}
@@ -300,8 +306,37 @@ void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) {
pref_notifier_->AddInitObserver(obs);
}
+PrefRegistry* PrefService::DeprecatedGetPrefRegistry() const {
+ return pref_registry_.get();
+}
+
+void PrefService::RegisterInitialPreferences() {
+ // Invariant: default_store_ is valid and contains the preferences
+ // registered prior to construction time.
+ for (DefaultPrefStore::const_iterator it = default_store_->begin();
+ it != default_store_->end();
+ ++it) {
+ RegisterPreference(it->first.c_str(), it->second, true);
+ }
+}
+
+// TODO(joi): Once all registration is done before the PrefService is
+// constructed, we can stop exposing a separate RegisterPreference
+// method, and we can simplify the registration logic. Possibly at the
+// same point we can remove UnregisterPreference. For now, because a
+// few remaining places register preferences after PrefService
+// construction, it is better to leave this here and have PrefRegistry
+// delegate to PrefService::RegisterPreference after that
+// point. Otherwise, PrefRegistry would need to control PrefService's
+// default_store_ and user_pref_store_ members, as well as the
+// pref_map_ member for UnregisterPreference.
Mattias Nissler (ping if slow) 2013/01/25 14:57:11 The default_store_ it controls already! The user_p
Jói 2013/01/29 16:10:02 Registration is now fully owned by PrefRegistry. P
+//
+// We are, however, able to implement the interface we desire in the
+// long term on PrefRegistry, and make this relationship an
+// implementation detail.
void PrefService::RegisterPreference(const char* path,
- Value* default_value) {
+ Value* default_value,
+ bool in_default_store) {
DCHECK(CalledOnValidThread());
// The main code path takes ownership, but most don't. We'll be safe.
@@ -330,8 +365,10 @@ void PrefService::RegisterPreference(const char* path,
if (needs_empty_value)
user_pref_store_->MarkNeedsEmptyValue(path);
- // Hand off ownership.
- default_store_->SetDefaultValue(path, scoped_value.release());
+ if (!in_default_store) {
+ // Hand off ownership.
+ default_store_->SetDefaultValue(path, scoped_value.release());
+ }
}
void PrefService::UnregisterPreference(const char* path) {
@@ -345,6 +382,10 @@ void PrefService::UnregisterPreference(const char* path) {
default_store_->RemoveDefaultValue(path);
}
+bool PrefService::AllowPrefRegistrarSimple() const {
+ return true;
+}
+
void PrefService::ClearPref(const char* path) {
DCHECK(CalledOnValidThread());

Powered by Google App Engine
This is Rietveld 408576698