Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/prefs/pref_service_syncable.h

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
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 // or not. This is only used for profile prefs, not local state prefs.
24 // See the Register*Pref methods for profile prefs below.
25 enum PrefSyncStatus {
26 UNSYNCABLE_PREF,
27 SYNCABLE_PREF
28 };
29
30 // You may wish to use PrefServiceBuilder or one of its subclasses 23 // You may wish to use PrefServiceBuilder or one of its subclasses
31 // for simplified construction. 24 // for simplified construction.
32 PrefServiceSyncable( 25 PrefServiceSyncable(
33 PrefNotifierImpl* pref_notifier, 26 PrefNotifierImpl* pref_notifier,
34 PrefValueStore* pref_value_store, 27 PrefValueStore* pref_value_store,
35 PersistentPrefStore* user_prefs, 28 PersistentPrefStore* user_prefs,
36 PrefRegistry* pref_registry, 29 PrefRegistrySyncable* pref_registry,
37 base::Callback<void(PersistentPrefStore::PrefReadError)> 30 base::Callback<void(PersistentPrefStore::PrefReadError)>
38 read_error_callback, 31 read_error_callback,
39 bool async); 32 bool async);
40 virtual ~PrefServiceSyncable(); 33 virtual ~PrefServiceSyncable();
41 34
42 // Creates an incognito copy of the pref service that shares most pref stores 35 // 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 36 // 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 37 // individual extension pref store (to cache the effective extension prefs for
45 // incognito windows). 38 // incognito windows).
46 PrefServiceSyncable* CreateIncognitoPrefService( 39 PrefServiceSyncable* CreateIncognitoPrefService(
47 PrefStore* incognito_extension_prefs); 40 PrefStore* incognito_extension_prefs);
48 41
49 // Returns true if preferences state has synchronized with the remote 42 // Returns true if preferences state has synchronized with the remote
50 // preferences. If true is returned it can be assumed the local preferences 43 // 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 44 // has applied changes from the remote preferences. The two may not be
52 // identical if a change is in flight (from either side). 45 // identical if a change is in flight (from either side).
53 bool IsSyncing(); 46 bool IsSyncing();
54 47
55 void AddObserver(PrefServiceSyncableObserver* observer); 48 void AddObserver(PrefServiceSyncableObserver* observer);
56 void RemoveObserver(PrefServiceSyncableObserver* observer); 49 void RemoveObserver(PrefServiceSyncableObserver* observer);
57 50
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 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 51 // TODO(zea): Have PrefServiceSyncable implement
105 // syncer::SyncableService directly. 52 // syncer::SyncableService directly.
106 syncer::SyncableService* GetSyncableService(); 53 syncer::SyncableService* GetSyncableService();
107 54
108 // Do not call this after having derived an incognito or per tab pref service. 55 // Do not call this after having derived an incognito or per tab pref service.
109 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE; 56 virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE;
110 57
111 private: 58 private:
112 friend class PrefModelAssociator; 59 friend class PrefModelAssociator;
113 60
61 void AddRegisteredSyncablePreference(const char* path);
62 virtual void RemoveRegisteredPreference(const char* path) OVERRIDE;
63
114 // Invoked internally when the IsSyncing() state changes. 64 // Invoked internally when the IsSyncing() state changes.
115 void OnIsSyncingChanged(); 65 void OnIsSyncingChanged();
116 66
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 67 // Whether CreateIncognitoPrefService() has been called to create a
125 // "forked" PrefService. 68 // "forked" PrefService.
126 bool pref_service_forked_; 69 bool pref_service_forked_;
127 70
128 PrefModelAssociator pref_sync_associator_; 71 PrefModelAssociator pref_sync_associator_;
129 72
130 ObserverList<PrefServiceSyncableObserver> observer_list_; 73 ObserverList<PrefServiceSyncableObserver> observer_list_;
131 74
132 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable); 75 DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable);
133 }; 76 };
134 77
135 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_ 78 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698