Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / prefs / pref_service_syncable.h
blobda52017911454d014c83796fee049b9e098056fa
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 CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/prefs/pref_model_associator.h"
10 #include "chrome/browser/prefs/synced_pref_observer.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
13 class PrefServiceSyncableObserver;
14 class Profile;
16 namespace syncer {
17 class SyncableService;
20 // A PrefService that can be synced. Users are forced to declare
21 // whether preferences are syncable or not when registering them to
22 // this PrefService.
23 class PrefServiceSyncable : public PrefService {
24 public:
25 // PrefServiceSyncable is a PrefService with added integration for
26 // sync, and knowledge of how to create an incognito
27 // PrefService. For code that does not need to know about the sync
28 // integration, you should use only the plain PrefService type.
30 // For this reason, Profile does not expose an accessor for the
31 // PrefServiceSyncable type. Instead, you can use the utilities
32 // below to retrieve the PrefServiceSyncable (or its incognito
33 // version) from a Profile.
34 static PrefServiceSyncable* FromProfile(Profile* profile);
35 static PrefServiceSyncable* IncognitoFromProfile(Profile* profile);
37 // You may wish to use PrefServiceFactory or one of its subclasses
38 // for simplified construction.
39 PrefServiceSyncable(
40 PrefNotifierImpl* pref_notifier,
41 PrefValueStore* pref_value_store,
42 PersistentPrefStore* user_prefs,
43 user_prefs::PrefRegistrySyncable* pref_registry,
44 base::Callback<void(PersistentPrefStore::PrefReadError)>
45 read_error_callback,
46 bool async);
47 ~PrefServiceSyncable() override;
49 // Creates an incognito copy of the pref service that shares most pref stores
50 // but uses a fresh non-persistent overlay for the user pref store and an
51 // individual extension pref store (to cache the effective extension prefs for
52 // incognito windows).
53 PrefServiceSyncable* CreateIncognitoPrefService(
54 PrefStore* incognito_extension_prefs);
56 // Returns true if preferences state has synchronized with the remote
57 // preferences. If true is returned it can be assumed the local preferences
58 // has applied changes from the remote preferences. The two may not be
59 // identical if a change is in flight (from either side).
61 // TODO(albertb): Given that we now support priority preferences, callers of
62 // this method are likely better off making the preferences they care about
63 // into priority preferences and calling IsPrioritySyncing().
64 bool IsSyncing();
66 // Returns true if priority preferences state has synchronized with the remote
67 // priority preferences.
68 bool IsPrioritySyncing();
70 // Returns true if the pref under the given name is pulled down from sync.
71 // Note this does not refer to SYNCABLE_PREF.
72 bool IsPrefSynced(const std::string& name) const;
74 void AddObserver(PrefServiceSyncableObserver* observer);
75 void RemoveObserver(PrefServiceSyncableObserver* observer);
77 // TODO(zea): Have PrefServiceSyncable implement
78 // syncer::SyncableService directly.
79 syncer::SyncableService* GetSyncableService(const syncer::ModelType& type);
81 // Do not call this after having derived an incognito or per tab pref service.
82 void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) override;
84 void AddSyncedPrefObserver(const std::string& name,
85 SyncedPrefObserver* observer);
86 void RemoveSyncedPrefObserver(const std::string& name,
87 SyncedPrefObserver* observer);
89 private:
90 friend class PrefModelAssociator;
92 void AddRegisteredSyncablePreference(const std::string& path, uint32 flags);
94 // Invoked internally when the IsSyncing() state changes.
95 void OnIsSyncingChanged();
97 // Process a local preference change. This can trigger new SyncChanges being
98 // sent to the syncer.
99 void ProcessPrefChange(const std::string& name);
101 // Whether CreateIncognitoPrefService() has been called to create a
102 // "forked" PrefService.
103 bool pref_service_forked_;
105 PrefModelAssociator pref_sync_associator_;
106 PrefModelAssociator priority_pref_sync_associator_;
108 base::ObserverList<PrefServiceSyncableObserver> observer_list_;
110 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable);
113 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_