| 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 "chrome/browser/prefs/pref_model_associator.h" | 8 #include "chrome/browser/prefs/pref_model_associator.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 | 10 |
| 11 class PrefRegistrySyncable; |
| 11 class PrefServiceSyncableObserver; | 12 class PrefServiceSyncableObserver; |
| 13 class Profile; |
| 12 | 14 |
| 13 namespace syncer { | 15 namespace syncer { |
| 14 class SyncableService; | 16 class SyncableService; |
| 15 } | 17 } |
| 16 | 18 |
| 17 // A PrefService that can be synced. Users are forced to declare | 19 // A PrefService that can be synced. Users are forced to declare |
| 18 // whether preferences are syncable or not when registering them to | 20 // whether preferences are syncable or not when registering them to |
| 19 // this PrefService. | 21 // this PrefService. |
| 20 class PrefServiceSyncable : public PrefService { | 22 class PrefServiceSyncable : public PrefService { |
| 21 public: | 23 public: |
| 22 // Enum used when registering preferences to determine if it should be synced | 24 // PrefServiceSyncable is a PrefService with added integration for |
| 23 // or not. This is only used for profile prefs, not local state prefs. | 25 // sync, and knowledge of how to create an incognito |
| 24 // See the Register*Pref methods for profile prefs below. | 26 // PrefService. For code that does not need to know about the sync |
| 25 enum PrefSyncStatus { | 27 // integration, you should use only the plain PrefService type. |
| 26 UNSYNCABLE_PREF, | 28 // |
| 27 SYNCABLE_PREF | 29 // For this reason, Profile does not expose an accessor for the |
| 28 }; | 30 // PrefServiceSyncable type. Instead, you can use the utilities |
| 31 // below to retrieve the PrefServiceSyncable (or its incognito |
| 32 // version) from a Profile. |
| 33 static PrefServiceSyncable* FromProfile(Profile* profile); |
| 34 static PrefServiceSyncable* IncognitoFromProfile(Profile* profile); |
| 29 | 35 |
| 30 // You may wish to use PrefServiceBuilder or one of its subclasses | 36 // You may wish to use PrefServiceBuilder or one of its subclasses |
| 31 // for simplified construction. | 37 // for simplified construction. |
| 32 PrefServiceSyncable( | 38 PrefServiceSyncable( |
| 33 PrefNotifierImpl* pref_notifier, | 39 PrefNotifierImpl* pref_notifier, |
| 34 PrefValueStore* pref_value_store, | 40 PrefValueStore* pref_value_store, |
| 35 PersistentPrefStore* user_prefs, | 41 PersistentPrefStore* user_prefs, |
| 36 PrefRegistry* pref_registry, | 42 PrefRegistrySyncable* pref_registry, |
| 37 base::Callback<void(PersistentPrefStore::PrefReadError)> | 43 base::Callback<void(PersistentPrefStore::PrefReadError)> |
| 38 read_error_callback, | 44 read_error_callback, |
| 39 bool async); | 45 bool async); |
| 40 virtual ~PrefServiceSyncable(); | 46 virtual ~PrefServiceSyncable(); |
| 41 | 47 |
| 42 // Creates an incognito copy of the pref service that shares most pref stores | 48 // Creates an incognito copy of the pref service that shares most pref stores |
| 43 // but uses a fresh non-persistent overlay for the user pref store and an | 49 // but uses a fresh non-persistent overlay for the user pref store and an |
| 44 // individual extension pref store (to cache the effective extension prefs for | 50 // individual extension pref store (to cache the effective extension prefs for |
| 45 // incognito windows). | 51 // incognito windows). |
| 46 PrefServiceSyncable* CreateIncognitoPrefService( | 52 PrefServiceSyncable* CreateIncognitoPrefService( |
| 47 PrefStore* incognito_extension_prefs); | 53 PrefStore* incognito_extension_prefs); |
| 48 | 54 |
| 49 // Returns true if preferences state has synchronized with the remote | 55 // Returns true if preferences state has synchronized with the remote |
| 50 // preferences. If true is returned it can be assumed the local preferences | 56 // preferences. If true is returned it can be assumed the local preferences |
| 51 // has applied changes from the remote preferences. The two may not be | 57 // has applied changes from the remote preferences. The two may not be |
| 52 // identical if a change is in flight (from either side). | 58 // identical if a change is in flight (from either side). |
| 53 bool IsSyncing(); | 59 bool IsSyncing(); |
| 54 | 60 |
| 55 void AddObserver(PrefServiceSyncableObserver* observer); | 61 void AddObserver(PrefServiceSyncableObserver* observer); |
| 56 void RemoveObserver(PrefServiceSyncableObserver* observer); | 62 void RemoveObserver(PrefServiceSyncableObserver* observer); |
| 57 | 63 |
| 58 void RegisterBooleanPref(const char* path, | |
| 59 bool default_value, | |
| 60 PrefSyncStatus sync_status); | |
| 61 void RegisterIntegerPref(const char* path, | |
| 62 int default_value, | |
| 63 PrefSyncStatus sync_status); | |
| 64 void RegisterDoublePref(const char* path, | |
| 65 double default_value, | |
| 66 PrefSyncStatus sync_status); | |
| 67 void RegisterStringPref(const char* path, | |
| 68 const std::string& default_value, | |
| 69 PrefSyncStatus sync_status); | |
| 70 void RegisterFilePathPref(const char* path, | |
| 71 const base::FilePath& default_value, | |
| 72 PrefSyncStatus sync_status); | |
| 73 void RegisterListPref(const char* path, | |
| 74 PrefSyncStatus sync_status); | |
| 75 void RegisterDictionaryPref(const char* path, | |
| 76 PrefSyncStatus sync_status); | |
| 77 void RegisterListPref(const char* path, | |
| 78 base::ListValue* default_value, | |
| 79 PrefSyncStatus sync_status); | |
| 80 void RegisterDictionaryPref(const char* path, | |
| 81 base::DictionaryValue* default_value, | |
| 82 PrefSyncStatus sync_status); | |
| 83 void RegisterLocalizedBooleanPref(const char* path, | |
| 84 int locale_default_message_id, | |
| 85 PrefSyncStatus sync_status); | |
| 86 void RegisterLocalizedIntegerPref(const char* path, | |
| 87 int locale_default_message_id, | |
| 88 PrefSyncStatus sync_status); | |
| 89 void RegisterLocalizedDoublePref(const char* path, | |
| 90 int locale_default_message_id, | |
| 91 PrefSyncStatus sync_status); | |
| 92 void RegisterLocalizedStringPref(const char* path, | |
| 93 int locale_default_message_id, | |
| 94 PrefSyncStatus sync_status); | |
| 95 void RegisterInt64Pref(const char* path, | |
| 96 int64 default_value, | |
| 97 PrefSyncStatus sync_status); | |
| 98 void RegisterUint64Pref(const char* path, | |
| 99 uint64 default_value, | |
| 100 PrefSyncStatus sync_status); | |
| 101 | |
| 102 void UnregisterPreference(const char* path); | |
| 103 | |
| 104 // TODO(zea): Have PrefServiceSyncable implement | 64 // TODO(zea): Have PrefServiceSyncable implement |
| 105 // syncer::SyncableService directly. | 65 // syncer::SyncableService directly. |
| 106 syncer::SyncableService* GetSyncableService(); | 66 syncer::SyncableService* GetSyncableService(); |
| 107 | 67 |
| 108 // Do not call this after having derived an incognito or per tab pref service. | 68 // Do not call this after having derived an incognito or per tab pref service. |
| 109 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; | 69 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; |
| 110 | 70 |
| 111 private: | 71 private: |
| 112 friend class PrefModelAssociator; | 72 friend class PrefModelAssociator; |
| 113 | 73 |
| 74 void AddRegisteredSyncablePreference(const char* path); |
| 75 virtual void RemoveRegisteredPreference(const char* path) OVERRIDE; |
| 76 |
| 114 // Invoked internally when the IsSyncing() state changes. | 77 // Invoked internally when the IsSyncing() state changes. |
| 115 void OnIsSyncingChanged(); | 78 void OnIsSyncingChanged(); |
| 116 | 79 |
| 117 // Registers a preference at |path| with |default_value|. If the | |
| 118 // preference is syncable per |sync_status|, also registers it with | |
| 119 // PrefModelAssociator. | |
| 120 void RegisterSyncablePreference(const char* path, | |
| 121 Value* default_value, | |
| 122 PrefSyncStatus sync_status); | |
| 123 | |
| 124 // Whether CreateIncognitoPrefService() has been called to create a | 80 // Whether CreateIncognitoPrefService() has been called to create a |
| 125 // "forked" PrefService. | 81 // "forked" PrefService. |
| 126 bool pref_service_forked_; | 82 bool pref_service_forked_; |
| 127 | 83 |
| 128 PrefModelAssociator pref_sync_associator_; | 84 PrefModelAssociator pref_sync_associator_; |
| 129 | 85 |
| 130 ObserverList<PrefServiceSyncableObserver> observer_list_; | 86 ObserverList<PrefServiceSyncableObserver> observer_list_; |
| 131 | 87 |
| 132 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); | 88 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); |
| 133 }; | 89 }; |
| 134 | 90 |
| 135 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 91 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
| OLD | NEW |