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_registry.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
10 | 11 |
11 class PrefServiceSyncableObserver; | 12 class PrefServiceSyncableObserver; |
12 | 13 |
13 namespace syncer { | 14 namespace syncer { |
14 class SyncableService; | 15 class SyncableService; |
15 } | 16 } |
16 | 17 |
17 // A PrefService that can be synced. Users are forced to declare | 18 // A PrefService that can be synced. Users are forced to declare |
18 // whether preferences are syncable or not when registering them to | 19 // whether preferences are syncable or not when registering them to |
19 // this PrefService. | 20 // this PrefService. |
20 class PrefServiceSyncable : public PrefService { | 21 class PrefServiceSyncable : public PrefService { |
21 public: | 22 public: |
22 // Enum used when registering preferences to determine if it should be synced | 23 // Enum used when registering preferences to determine if it should be synced |
23 // or not. This is only used for profile prefs, not local state prefs. | 24 // or not. This is only used for profile prefs, not local state prefs. |
24 // See the Register*Pref methods for profile prefs below. | 25 // See the Register*Pref methods for profile prefs below. |
25 enum PrefSyncStatus { | 26 enum PrefSyncStatus { |
26 UNSYNCABLE_PREF, | 27 UNSYNCABLE_PREF, |
27 SYNCABLE_PREF | 28 SYNCABLE_PREF |
28 }; | 29 }; |
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 DefaultPrefStore* default_store, | 37 scoped_ptr<PrefRegistry> 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 virtual void UnregisterPreference(const char* path) OVERRIDE; | |
59 | |
60 void RegisterBooleanPref(const char* path, | 59 void RegisterBooleanPref(const char* path, |
61 bool default_value, | 60 bool default_value, |
62 PrefSyncStatus sync_status); | 61 PrefSyncStatus sync_status); |
63 void RegisterIntegerPref(const char* path, | 62 void RegisterIntegerPref(const char* path, |
64 int default_value, | 63 int default_value, |
65 PrefSyncStatus sync_status); | 64 PrefSyncStatus sync_status); |
66 void RegisterDoublePref(const char* path, | 65 void RegisterDoublePref(const char* path, |
67 double default_value, | 66 double default_value, |
68 PrefSyncStatus sync_status); | 67 PrefSyncStatus sync_status); |
69 void RegisterStringPref(const char* path, | 68 void RegisterStringPref(const char* path, |
(...skipping 24 matching lines...) Expand all Loading... |
94 void RegisterLocalizedStringPref(const char* path, | 93 void RegisterLocalizedStringPref(const char* path, |
95 int locale_default_message_id, | 94 int locale_default_message_id, |
96 PrefSyncStatus sync_status); | 95 PrefSyncStatus sync_status); |
97 void RegisterInt64Pref(const char* path, | 96 void RegisterInt64Pref(const char* path, |
98 int64 default_value, | 97 int64 default_value, |
99 PrefSyncStatus sync_status); | 98 PrefSyncStatus sync_status); |
100 void RegisterUint64Pref(const char* path, | 99 void RegisterUint64Pref(const char* path, |
101 uint64 default_value, | 100 uint64 default_value, |
102 PrefSyncStatus sync_status); | 101 PrefSyncStatus sync_status); |
103 | 102 |
| 103 void UnregisterPreference(const char* path); |
| 104 |
104 // TODO(zea): Have PrefServiceSyncable implement | 105 // TODO(zea): Have PrefServiceSyncable implement |
105 // syncer::SyncableService directly. | 106 // syncer::SyncableService directly. |
106 syncer::SyncableService* GetSyncableService(); | 107 syncer::SyncableService* GetSyncableService(); |
107 | 108 |
108 // Do not call this after having derived an incognito or per tab pref service. | 109 // Do not call this after having derived an incognito or per tab pref service. |
109 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; | 110 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; |
110 | 111 |
111 private: | 112 private: |
112 friend class PrefModelAssociator; | 113 friend class PrefModelAssociator; |
113 | 114 |
| 115 // TODO(joi): Temporary; to be replaced with PrefRegistrarSyncable. |
| 116 friend class PrefsTabHelper; |
| 117 |
| 118 virtual bool AllowPrefRegistrarSimple() const OVERRIDE; |
| 119 |
114 // Invoked internally when the IsSyncing() state changes. | 120 // Invoked internally when the IsSyncing() state changes. |
115 void OnIsSyncingChanged(); | 121 void OnIsSyncingChanged(); |
116 | 122 |
117 // Registers a preference at |path| with |default_value|. If the | 123 // Registers a preference at |path| with |default_value|. If the |
118 // preference is syncable per |sync_status|, also registers it with | 124 // preference is syncable per |sync_status|, also registers it with |
119 // PrefModelAssociator. | 125 // PrefModelAssociator. |
120 void RegisterSyncablePreference(const char* path, | 126 void RegisterSyncablePreference(const char* path, |
121 Value* default_value, | 127 Value* default_value, |
122 PrefSyncStatus sync_status); | 128 PrefSyncStatus sync_status); |
123 | 129 |
124 // Whether CreateIncognitoPrefService() has been called to create a | 130 // Whether CreateIncognitoPrefService() has been called to create a |
125 // "forked" PrefService. | 131 // "forked" PrefService. |
126 bool pref_service_forked_; | 132 bool pref_service_forked_; |
127 | 133 |
128 PrefModelAssociator pref_sync_associator_; | 134 PrefModelAssociator pref_sync_associator_; |
129 | 135 |
130 ObserverList<PrefServiceSyncableObserver> observer_list_; | 136 ObserverList<PrefServiceSyncableObserver> observer_list_; |
131 | 137 |
132 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); | 138 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); |
133 }; | 139 }; |
134 | 140 |
135 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ | 141 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ |
OLD | NEW |