diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-22 17:24:44 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-22 17:24:44 +0000 |
commit | 5b19952e27008d9cca170c1a517987795d145928 (patch) | |
tree | 34fea6a6f74a0388c68c4ba8cd8846f3ac879027 /chrome/browser/prefs/pref_service_syncable.h | |
parent | 96828ec57f67f91b3b1b2269963680501a6de4b9 (diff) | |
download | chromium_src-5b19952e27008d9cca170c1a517987795d145928.zip chromium_src-5b19952e27008d9cca170c1a517987795d145928.tar.gz chromium_src-5b19952e27008d9cca170c1a517987795d145928.tar.bz2 |
Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable.
The first two (PrefServiceSimple is a subclass of PrefService) know
nothing about sync or any Chrome or content concepts.
The third (PrefServiceSyncable, a separate subclass of PrefService)
knows about sync and requires users to choose whether each individual
preference is syncable or not when it is registered.
BrowserProcess::local_state() is a PrefServiceSimple after this
change, and Profile::prefs() is a PrefServiceSyncable.
COLLABORATOR=kaiwang@chromium.org
TBR=ben@chromium.org
BUG=155525
Review URL: https://chromiumcodereview.appspot.com/11570009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs/pref_service_syncable.h')
-rw-r--r-- | chrome/browser/prefs/pref_service_syncable.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/chrome/browser/prefs/pref_service_syncable.h b/chrome/browser/prefs/pref_service_syncable.h new file mode 100644 index 0000000..0360772 --- /dev/null +++ b/chrome/browser/prefs/pref_service_syncable.h @@ -0,0 +1,136 @@ +// 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 + }; + + // You may wish to use PrefServiceBuilder or one of its subclasses + // for simplified construction. + PrefServiceSyncable( + PrefNotifierImpl* pref_notifier, + PrefValueStore* pref_value_store, + PersistentPrefStore* user_prefs, + DefaultPrefStore* default_store, + base::Callback<void(PersistentPrefStore::PrefReadError)> + read_error_callback, + bool async); + 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; + + private: + friend class PrefModelAssociator; + + // 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_ |