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 primarily an implementation detail of |
Mattias Nissler (ping if slow)
2013/02/06 17:53:33
Can you elaborate on the "primarily"? I thought th
Jói
2013/02/07 14:52:32
Anyone who needs to know about the sync integratio
Mattias Nissler (ping if slow)
2013/02/08 11:26:56
Thanks!
| |
23 // or not. This is only used for profile prefs, not local state prefs. | 25 // profile and the sync mechanism, so Profile does not expose an |
24 // See the Register*Pref methods for profile prefs below. | 26 // accessor for it. Instead, you can use these accessors to retrieve |
25 enum PrefSyncStatus { | 27 // the PrefServiceSyncable (or its incognito version) from a Profile. |
26 UNSYNCABLE_PREF, | 28 static PrefServiceSyncable* FromProfile(Profile* profile); |
27 SYNCABLE_PREF | 29 static PrefServiceSyncable* IncognitoFromProfile(Profile* profile); |
28 }; | |
29 | 30 |
30 // You may wish to use PrefServiceBuilder or one of its subclasses | 31 // You may wish to use PrefServiceBuilder or one of its subclasses |
31 // for simplified construction. | 32 // for simplified construction. |
32 PrefServiceSyncable( | 33 PrefServiceSyncable( |
33 PrefNotifierImpl* pref_notifier, | 34 PrefNotifierImpl* pref_notifier, |
34 PrefValueStore* pref_value_store, | 35 PrefValueStore* pref_value_store, |
35 PersistentPrefStore* user_prefs, | 36 PersistentPrefStore* user_prefs, |
36 PrefRegistry* pref_registry, | 37 PrefRegistrySyncable* pref_registry, |
37 base::Callback<void(PersistentPrefStore::PrefReadError)> | 38 base::Callback<void(PersistentPrefStore::PrefReadError)> |
38 read_error_callback, | 39 read_error_callback, |
39 bool async); | 40 bool async); |
40 virtual ~PrefServiceSyncable(); | 41 virtual ~PrefServiceSyncable(); |
41 | 42 |
42 // Creates an incognito copy of the pref service that shares most pref stores | 43 // 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 | 44 // 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 | 45 // individual extension pref store (to cache the effective extension prefs for |
45 // incognito windows). | 46 // incognito windows). |
46 PrefServiceSyncable* CreateIncognitoPrefService( | 47 PrefServiceSyncable* CreateIncognitoPrefService( |
47 PrefStore* incognito_extension_prefs); | 48 PrefStore* incognito_extension_prefs); |
48 | 49 |
49 // Returns true if preferences state has synchronized with the remote | 50 // Returns true if preferences state has synchronized with the remote |
50 // preferences. If true is returned it can be assumed the local preferences | 51 // 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 | 52 // has applied changes from the remote preferences. The two may not be |
52 // identical if a change is in flight (from either side). | 53 // identical if a change is in flight (from either side). |
53 bool IsSyncing(); | 54 bool IsSyncing(); |
54 | 55 |
55 void AddObserver(PrefServiceSyncableObserver* observer); | 56 void AddObserver(PrefServiceSyncableObserver* observer); |
56 void RemoveObserver(PrefServiceSyncableObserver* observer); | 57 void RemoveObserver(PrefServiceSyncableObserver* observer); |
57 | 58 |
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 | 59 // TODO(zea): Have PrefServiceSyncable implement |
105 // syncer::SyncableService directly. | 60 // syncer::SyncableService directly. |
106 syncer::SyncableService* GetSyncableService(); | 61 syncer::SyncableService* GetSyncableService(); |
107 | 62 |
108 // Do not call this after having derived an incognito or per tab pref service. | 63 // Do not call this after having derived an incognito or per tab pref service. |
109 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; | 64 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; |
110 | 65 |
111 private: | 66 private: |
112 friend class PrefModelAssociator; | 67 friend class PrefModelAssociator; |
113 | 68 |
69 void AddRegisteredSyncablePreference(const char* path); | |
70 virtual void RemoveRegisteredPreference(const char* path) OVERRIDE; | |
71 | |
114 // Invoked internally when the IsSyncing() state changes. | 72 // Invoked internally when the IsSyncing() state changes. |
115 void OnIsSyncingChanged(); | 73 void OnIsSyncingChanged(); |
116 | 74 |
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 | 75 // Whether CreateIncognitoPrefService() has been called to create a |
125 // "forked" PrefService. | 76 // "forked" PrefService. |
126 bool pref_service_forked_; | 77 bool pref_service_forked_; |
127 | 78 |
128 PrefModelAssociator pref_sync_associator_; | 79 PrefModelAssociator pref_sync_associator_; |
129 | 80 |
130 ObserverList<PrefServiceSyncableObserver> observer_list_; | 81 ObserverList<PrefServiceSyncableObserver> observer_list_; |
131 | 82 |
132 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); | 83 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); |
133 }; | 84 }; |
134 | 85 |
135 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 86 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
OLD | NEW |