Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | |
| 8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/prefs/pref_model_associator.h" | 10 #include "chrome/browser/prefs/pref_model_associator.h" |
| 10 #include "chrome/browser/prefs/synced_pref_observer.h" | 11 #include "chrome/browser/prefs/synced_pref_observer.h" |
| 11 #include "components/pref_registry/pref_registry_syncable.h" | 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 12 | 13 |
| 14 class OverlayUserPrefStore; | |
| 15 class PrefModelAssociatorClient; | |
| 13 class PrefServiceSyncableObserver; | 16 class PrefServiceSyncableObserver; |
| 14 class Profile; | |
| 15 | 17 |
| 16 namespace syncer { | 18 namespace syncer { |
| 17 class SyncableService; | 19 class SyncableService; |
| 18 } | 20 } |
| 19 | 21 |
| 20 // A PrefService that can be synced. Users are forced to declare | 22 // A PrefService that can be synced. Users are forced to declare |
| 21 // whether preferences are syncable or not when registering them to | 23 // whether preferences are syncable or not when registering them to |
| 22 // this PrefService. | 24 // this PrefService. |
| 23 class PrefServiceSyncable : public PrefService { | 25 class PrefServiceSyncable : public PrefService { |
| 24 public: | 26 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. | |
| 29 // | |
| 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); | |
| 36 | |
| 37 // You may wish to use PrefServiceFactory or one of its subclasses | 27 // You may wish to use PrefServiceFactory or one of its subclasses |
| 38 // for simplified construction. | 28 // for simplified construction. |
| 39 PrefServiceSyncable( | 29 PrefServiceSyncable(PrefNotifierImpl* pref_notifier, |
| 40 PrefNotifierImpl* pref_notifier, | 30 PrefValueStore* pref_value_store, |
| 41 PrefValueStore* pref_value_store, | 31 PersistentPrefStore* user_prefs, |
| 42 PersistentPrefStore* user_prefs, | 32 user_prefs::PrefRegistrySyncable* pref_registry, |
| 43 user_prefs::PrefRegistrySyncable* pref_registry, | 33 base::Callback<void(PersistentPrefStore::PrefReadError)> |
| 44 base::Callback<void(PersistentPrefStore::PrefReadError)> | 34 read_error_callback, |
| 45 read_error_callback, | 35 bool async); |
| 46 bool async); | |
| 47 ~PrefServiceSyncable() override; | 36 ~PrefServiceSyncable() override; |
| 48 | 37 |
| 38 // Sets the PrefModelAssociatorClient that control special treatment of | |
| 39 // some preferences during synchronisation. Must be called before starting | |
| 40 // the synchronisation. | |
| 41 void SetPrefModelAssociatorClient( | |
| 42 PrefModelAssociatorClient* pref_model_associator_client); | |
|
gab
2015/09/10 14:15:09
Feels this should be a constructor input (since it
| |
| 43 | |
| 49 // Creates an incognito copy of the pref service that shares most pref stores | 44 // 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 | 45 // 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 | 46 // individual extension pref store (to cache the effective extension prefs for |
| 52 // incognito windows). | 47 // incognito windows). |
|
gab
2015/09/10 14:15:09
Update comment.
| |
| 53 PrefServiceSyncable* CreateIncognitoPrefService( | 48 PrefServiceSyncable* CreateIncognitoPrefService( |
| 54 PrefStore* incognito_extension_prefs); | 49 PrefStore* incognito_extension_prefs, |
| 50 const base::Callback<void(OverlayUserPrefStore*)>& | |
| 51 incognito_pref_created_cb); | |
| 55 | 52 |
| 56 // Returns true if preferences state has synchronized with the remote | 53 // Returns true if preferences state has synchronized with the remote |
| 57 // preferences. If true is returned it can be assumed the local preferences | 54 // 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 | 55 // has applied changes from the remote preferences. The two may not be |
| 59 // identical if a change is in flight (from either side). | 56 // identical if a change is in flight (from either side). |
| 60 // | 57 // |
| 61 // TODO(albertb): Given that we now support priority preferences, callers of | 58 // TODO(albertb): Given that we now support priority preferences, callers of |
| 62 // this method are likely better off making the preferences they care about | 59 // this method are likely better off making the preferences they care about |
| 63 // into priority preferences and calling IsPrioritySyncing(). | 60 // into priority preferences and calling IsPrioritySyncing(). |
| 64 bool IsSyncing(); | 61 bool IsSyncing(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // Process a local preference change. This can trigger new SyncChanges being | 94 // Process a local preference change. This can trigger new SyncChanges being |
| 98 // sent to the syncer. | 95 // sent to the syncer. |
| 99 void ProcessPrefChange(const std::string& name); | 96 void ProcessPrefChange(const std::string& name); |
| 100 | 97 |
| 101 // Whether CreateIncognitoPrefService() has been called to create a | 98 // Whether CreateIncognitoPrefService() has been called to create a |
| 102 // "forked" PrefService. | 99 // "forked" PrefService. |
| 103 bool pref_service_forked_; | 100 bool pref_service_forked_; |
| 104 | 101 |
| 105 PrefModelAssociator pref_sync_associator_; | 102 PrefModelAssociator pref_sync_associator_; |
| 106 PrefModelAssociator priority_pref_sync_associator_; | 103 PrefModelAssociator priority_pref_sync_associator_; |
| 104 PrefModelAssociatorClient* pref_model_associator_client_; | |
| 107 | 105 |
| 108 base::ObserverList<PrefServiceSyncableObserver> observer_list_; | 106 base::ObserverList<PrefServiceSyncableObserver> observer_list_; |
| 109 | 107 |
| 110 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); | 108 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 111 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
| OLD | NEW |