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

Unified Diff: chrome/browser/prefs/pref_service_syncable.h

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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_syncable.h
diff --git a/chrome/browser/prefs/pref_service_syncable.h b/chrome/browser/prefs/pref_service_syncable.h
new file mode 100644
index 0000000000000000000000000000000000000000..77e56a1997e419d1e3a6a8b1bb4e5d30788dc9a1
--- /dev/null
+++ b/chrome/browser/prefs/pref_service_syncable.h
@@ -0,0 +1,144 @@
+// Copyright (c) 2012 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_PREF_SERVICE_SYNCABLE_H_
+#define CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
+
+#include "chrome/browser/prefs/pref_model_associator.h"
+#include "chrome/browser/prefs/pref_service.h"
+
+// TODO(joi) Move to c/b/prefs and rename PrefServiceSyncableObserver.
+class PrefServiceObserver;
+
+namespace syncer {
+class SyncableService;
+}
+
+// A PrefService that can be synced. Users are forced to declare
+// whether preferences are syncable or not when registering them to
+// this PrefService.
+class PrefServiceSyncable : public PrefService {
+ public:
+ // Enum used when registering preferences to determine if it should be synced
+ // or not. This is only used for profile prefs, not local state prefs.
+ // See the Register*Pref methods for profile prefs below.
+ enum PrefSyncStatus {
+ UNSYNCABLE_PREF,
+ SYNCABLE_PREF
+ };
+
+ virtual ~PrefServiceSyncable();
+
+ // Creates an incognito copy of the pref service that shares most pref stores
+ // but uses a fresh non-persistent overlay for the user pref store and an
+ // individual extension pref store (to cache the effective extension prefs for
+ // incognito windows).
+ PrefServiceSyncable* CreateIncognitoPrefService(
+ PrefStore* incognito_extension_prefs);
+
+ // Returns true if preferences state has synchronized with the remote
+ // preferences. If true is returned it can be assumed the local preferences
+ // has applied changes from the remote preferences. The two may not be
+ // identical if a change is in flight (from either side).
+ bool IsSyncing();
+
+ void AddObserver(PrefServiceObserver* observer);
+ void RemoveObserver(PrefServiceObserver* observer);
+
+ virtual void UnregisterPreference(const char* path) OVERRIDE;
+
+ void RegisterBooleanPref(const char* path,
+ bool default_value,
+ PrefSyncStatus sync_status);
+ void RegisterIntegerPref(const char* path,
+ int default_value,
+ PrefSyncStatus sync_status);
+ void RegisterDoublePref(const char* path,
+ double default_value,
+ PrefSyncStatus sync_status);
+ void RegisterStringPref(const char* path,
+ const std::string& default_value,
+ PrefSyncStatus sync_status);
+ void RegisterFilePathPref(const char* path,
+ const FilePath& default_value,
+ PrefSyncStatus sync_status);
+ void RegisterListPref(const char* path,
+ PrefSyncStatus sync_status);
+ void RegisterDictionaryPref(const char* path,
+ PrefSyncStatus sync_status);
+ void RegisterListPref(const char* path,
+ base::ListValue* default_value,
+ PrefSyncStatus sync_status);
+ void RegisterDictionaryPref(const char* path,
+ base::DictionaryValue* default_value,
+ PrefSyncStatus sync_status);
+ void RegisterLocalizedBooleanPref(const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status);
+ void RegisterLocalizedIntegerPref(const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status);
+ void RegisterLocalizedDoublePref(const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status);
+ void RegisterLocalizedStringPref(const char* path,
+ int locale_default_message_id,
+ PrefSyncStatus sync_status);
+ void RegisterInt64Pref(const char* path,
+ int64 default_value,
+ PrefSyncStatus sync_status);
+ void RegisterUint64Pref(const char* path,
+ uint64 default_value,
+ PrefSyncStatus sync_status);
+
+ // TODO(zea): Have PrefServiceSyncable implement
+ // syncer::SyncableService directly.
+ syncer::SyncableService* GetSyncableService();
+
+ // Do not call this after having derived an incognito or per tab pref service.
+ virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE;
+
+ protected:
+ // Only use ChromePrefServiceFactory to create initialized PrefServiceSyncable
+ // objects.
+ PrefServiceSyncable();
+
+ virtual void Initialize(
+ PrefNotifierImpl* pref_notifier,
+ PrefValueStore* pref_value_store,
+ PersistentPrefStore* user_prefs,
+ DefaultPrefStore* default_store,
+ base::Callback<void(PersistentPrefStore::PrefReadError)>
+ read_error_callback,
+ bool async) OVERRIDE;
+
+ private:
+ friend class PrefModelAssociator;
+
+ // Constructs instances.
+ friend class ChromePrefServiceFactory;
+ friend class PrefServiceMockBuilder;
+
+ // Invoked internally when the IsSyncing() state changes.
+ void OnIsSyncingChanged();
+
+ // Registers a preference at |path| with |default_value|. If the
+ // preference is syncable per |sync_status|, also registers it with
+ // PrefModelAssociator.
+ void RegisterSyncablePreference(const char* path,
+ Value* default_value,
+ PrefSyncStatus sync_status);
+
+ // Whether CreateIncognitoPrefService() has been called to create a
+ // "forked" PrefService.
+ bool pref_service_forked_;
+
+ PrefModelAssociator pref_sync_associator_;
+
+ ObserverList<PrefServiceObserver> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable);
+};
+
+#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_

Powered by Google App Engine
This is Rietveld 408576698