1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SYNCABLE_PREFS_PREF_SERVICE_SYNCABLE_H_
6 #define COMPONENTS_SYNCABLE_PREFS_PREF_SERVICE_SYNCABLE_H_
10 #include "base/callback_forward.h"
11 #include "base/prefs/pref_service.h"
12 #include "components/pref_registry/pref_registry_syncable.h"
13 #include "components/syncable_prefs/pref_model_associator.h"
14 #include "components/syncable_prefs/synced_pref_observer.h"
16 class PrefModelAssociatorClient
;
17 class PrefServiceSyncableObserver
;
20 class SyncableService
;
23 // A PrefService that can be synced. Users are forced to declare
24 // whether preferences are syncable or not when registering them to
26 class PrefServiceSyncable
: public PrefService
{
28 // You may wish to use PrefServiceFactory or one of its subclasses
29 // for simplified construction.
31 PrefNotifierImpl
* pref_notifier
,
32 PrefValueStore
* pref_value_store
,
33 PersistentPrefStore
* user_prefs
,
34 user_prefs::PrefRegistrySyncable
* pref_registry
,
35 const PrefModelAssociatorClient
* pref_model_associato_client
,
36 base::Callback
<void(PersistentPrefStore::PrefReadError
)>
39 ~PrefServiceSyncable() override
;
41 // Creates an incognito copy of the pref service that shares most pref stores
42 // but uses a fresh non-persistent overlay for the user pref store and an
43 // individual extension pref store (to cache the effective extension prefs for
44 // incognito windows). |overlay_pref_names| is a list of preference names
45 // whose changes will not be persisted by the returned incognito pref service.
46 PrefServiceSyncable
* CreateIncognitoPrefService(
47 PrefStore
* incognito_extension_pref_store
,
48 const std::vector
<const char*>& overlay_pref_names
);
50 // Returns true if preferences state has synchronized with the remote
51 // preferences. If true is returned it can be assumed the local preferences
52 // has applied changes from the remote preferences. The two may not be
53 // identical if a change is in flight (from either side).
55 // TODO(albertb): Given that we now support priority preferences, callers of
56 // this method are likely better off making the preferences they care about
57 // into priority preferences and calling IsPrioritySyncing().
60 // Returns true if priority preferences state has synchronized with the remote
61 // priority preferences.
62 bool IsPrioritySyncing();
64 // Returns true if the pref under the given name is pulled down from sync.
65 // Note this does not refer to SYNCABLE_PREF.
66 bool IsPrefSynced(const std::string
& name
) const;
68 void AddObserver(PrefServiceSyncableObserver
* observer
);
69 void RemoveObserver(PrefServiceSyncableObserver
* observer
);
71 // TODO(zea): Have PrefServiceSyncable implement
72 // syncer::SyncableService directly.
73 syncer::SyncableService
* GetSyncableService(const syncer::ModelType
& type
);
75 // Do not call this after having derived an incognito or per tab pref service.
76 void UpdateCommandLinePrefStore(PrefStore
* cmd_line_store
) override
;
78 void AddSyncedPrefObserver(const std::string
& name
,
79 SyncedPrefObserver
* observer
);
80 void RemoveSyncedPrefObserver(const std::string
& name
,
81 SyncedPrefObserver
* observer
);
84 // Set the PrefModelAssociatorClient to use for that object during tests.
85 void SetPrefModelAssociatorClientForTesting(
86 const PrefModelAssociatorClient
* pref_model_associator_client
);
89 friend class PrefModelAssociator
;
91 void AddRegisteredSyncablePreference(const std::string
& path
, uint32 flags
);
93 // Invoked internally when the IsSyncing() state changes.
94 void OnIsSyncingChanged();
96 // Process a local preference change. This can trigger new SyncChanges being
97 // sent to the syncer.
98 void ProcessPrefChange(const std::string
& name
);
100 // Whether CreateIncognitoPrefService() has been called to create a
101 // "forked" PrefService.
102 bool pref_service_forked_
;
104 PrefModelAssociator pref_sync_associator_
;
105 PrefModelAssociator priority_pref_sync_associator_
;
107 base::ObserverList
<PrefServiceSyncableObserver
> observer_list_
;
109 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable
);
112 #endif // COMPONENTS_SYNCABLE_PREFS_PREF_SERVICE_SYNCABLE_H_