Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / components / syncable_prefs / pref_service_syncable.h
blob81224ac35234a5778ee1d963dcf2b5c7f2720a42
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_
8 #include <vector>
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 namespace syncer {
17 class SyncableService;
20 namespace syncable_prefs {
22 class PrefModelAssociatorClient;
23 class PrefServiceSyncableObserver;
25 // A PrefService that can be synced. Users are forced to declare
26 // whether preferences are syncable or not when registering them to
27 // this PrefService.
28 class PrefServiceSyncable : public PrefService {
29 public:
30 // You may wish to use PrefServiceFactory or one of its subclasses
31 // for simplified construction.
32 PrefServiceSyncable(
33 PrefNotifierImpl* pref_notifier,
34 PrefValueStore* pref_value_store,
35 PersistentPrefStore* user_prefs,
36 user_prefs::PrefRegistrySyncable* pref_registry,
37 const PrefModelAssociatorClient* pref_model_associato_client,
38 base::Callback<void(PersistentPrefStore::PrefReadError)>
39 read_error_callback,
40 bool async);
41 ~PrefServiceSyncable() override;
43 // Creates an incognito copy of the pref service that shares most pref stores
44 // but uses a fresh non-persistent overlay for the user pref store and an
45 // individual extension pref store (to cache the effective extension prefs for
46 // incognito windows). |overlay_pref_names| is a list of preference names
47 // whose changes will not be persisted by the returned incognito pref service.
48 PrefServiceSyncable* CreateIncognitoPrefService(
49 PrefStore* incognito_extension_pref_store,
50 const std::vector<const char*>& overlay_pref_names);
52 // Returns true if preferences state has synchronized with the remote
53 // preferences. If true is returned it can be assumed the local preferences
54 // has applied changes from the remote preferences. The two may not be
55 // identical if a change is in flight (from either side).
57 // TODO(albertb): Given that we now support priority preferences, callers of
58 // this method are likely better off making the preferences they care about
59 // into priority preferences and calling IsPrioritySyncing().
60 bool IsSyncing();
62 // Returns true if priority preferences state has synchronized with the remote
63 // priority preferences.
64 bool IsPrioritySyncing();
66 // Returns true if the pref under the given name is pulled down from sync.
67 // Note this does not refer to SYNCABLE_PREF.
68 bool IsPrefSynced(const std::string& name) const;
70 void AddObserver(PrefServiceSyncableObserver* observer);
71 void RemoveObserver(PrefServiceSyncableObserver* observer);
73 // TODO(zea): Have PrefServiceSyncable implement
74 // syncer::SyncableService directly.
75 syncer::SyncableService* GetSyncableService(const syncer::ModelType& type);
77 // Do not call this after having derived an incognito or per tab pref service.
78 void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) override;
80 void AddSyncedPrefObserver(const std::string& name,
81 SyncedPrefObserver* observer);
82 void RemoveSyncedPrefObserver(const std::string& name,
83 SyncedPrefObserver* observer);
85 protected:
86 // Set the PrefModelAssociatorClient to use for that object during tests.
87 void SetPrefModelAssociatorClientForTesting(
88 const PrefModelAssociatorClient* pref_model_associator_client);
90 private:
91 friend class PrefModelAssociator;
93 void AddRegisteredSyncablePreference(const std::string& path, uint32 flags);
95 // Invoked internally when the IsSyncing() state changes.
96 void OnIsSyncingChanged();
98 // Process a local preference change. This can trigger new SyncChanges being
99 // sent to the syncer.
100 void ProcessPrefChange(const std::string& name);
102 // Whether CreateIncognitoPrefService() has been called to create a
103 // "forked" PrefService.
104 bool pref_service_forked_;
106 PrefModelAssociator pref_sync_associator_;
107 PrefModelAssociator priority_pref_sync_associator_;
109 base::ObserverList<PrefServiceSyncableObserver> observer_list_;
111 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable);
114 } // namespace syncable_prefs
116 #endif // COMPONENTS_SYNCABLE_PREFS_PREF_SERVICE_SYNCABLE_H_