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