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

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

Issue 6905044: Refactor preference syncing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix syncing of platform specific prefs Created 9 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This provides a way to access the application's current preferences. 5 // This provides a way to access the application's current preferences.
6 6
7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_
8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_
9 #pragma once 9 #pragma once
10 10
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/json_pref_store.h" 18 #include "chrome/common/json_pref_store.h"
19 19
20 class DefaultPrefStore; 20 class DefaultPrefStore;
21 class FilePath; 21 class FilePath;
22 class NotificationObserver; 22 class NotificationObserver;
23 class PersistentPrefStore; 23 class PersistentPrefStore;
24 class PrefChangeObserver; 24 class PrefModelAssociator;
25 class PrefNotifier; 25 class PrefNotifier;
26 class PrefNotifierImpl; 26 class PrefNotifierImpl;
27 class PrefStore; 27 class PrefStore;
28 class PrefValueStore; 28 class PrefValueStore;
29 class Profile; 29 class Profile;
30 30
31 namespace subtle { 31 namespace subtle {
32 class PrefMemberBase; 32 class PrefMemberBase;
33 class ScopedUserPrefUpdateBase; 33 class ScopedUserPrefUpdateBase;
34 }; 34 };
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // we need to save immediately (basically, during shutdown). Otherwise, you 164 // we need to save immediately (basically, during shutdown). Otherwise, you
165 // should use ScheduleSavePersistentPrefs. 165 // should use ScheduleSavePersistentPrefs.
166 bool SavePersistentPrefs(); 166 bool SavePersistentPrefs();
167 167
168 // Serializes the data and schedules save using ImportantFileWriter. 168 // Serializes the data and schedules save using ImportantFileWriter.
169 void ScheduleSavePersistentPrefs(); 169 void ScheduleSavePersistentPrefs();
170 170
171 // Lands pending writes to disk. 171 // Lands pending writes to disk.
172 void CommitPendingWrite(); 172 void CommitPendingWrite();
173 173
174 // Make the PrefService aware of a pref. 174 // Make the PrefService aware of a pref, and inform the Sync model associator
175 void RegisterBooleanPref(const char* path, bool default_value); 175 // if we want to synchronize it.
176 void RegisterIntegerPref(const char* path, int default_value); 176 void RegisterBooleanPref(const char* path,
177 void RegisterDoublePref(const char* path, double default_value); 177 bool default_value,
178 void RegisterStringPref(const char* path, const std::string& default_value); 178 bool syncable);
179 void RegisterFilePathPref(const char* path, const FilePath& default_value); 179 void RegisterIntegerPref(const char* path,
180 void RegisterListPref(const char* path); 180 int default_value,
181 void RegisterDictionaryPref(const char* path); 181 bool syncable);
182 void RegisterDoublePref(const char* path,
183 double default_value,
184 bool syncable);
185 void RegisterStringPref(const char* path,
186 const std::string& default_value,
187 bool syncable);
188 void RegisterFilePathPref(const char* path,
189 const FilePath& default_value,
190 bool syncable);
191 void RegisterListPref(const char* path, bool syncable);
192 void RegisterDictionaryPref(const char* path, bool syncable);
182 // These take ownership of the default_value: 193 // These take ownership of the default_value:
183 void RegisterListPref(const char* path, ListValue* default_value); 194 void RegisterListPref(const char* path,
184 void RegisterDictionaryPref(const char* path, DictionaryValue* default_value); 195 ListValue* default_value,
196 bool syncable);
197 void RegisterDictionaryPref(const char* path,
198 DictionaryValue* default_value,
199 bool syncable);
185 200
186 // These variants use a default value from the locale dll instead. 201 // These variants use a default value from the locale dll instead.
187 void RegisterLocalizedBooleanPref(const char* path, 202 void RegisterLocalizedBooleanPref(const char* path,
188 int locale_default_message_id); 203 int locale_default_message_id,
204 bool syncable);
189 void RegisterLocalizedIntegerPref(const char* path, 205 void RegisterLocalizedIntegerPref(const char* path,
190 int locale_default_message_id); 206 int locale_default_message_id,
207 bool syncable);
191 void RegisterLocalizedDoublePref(const char* path, 208 void RegisterLocalizedDoublePref(const char* path,
192 int locale_default_message_id); 209 int locale_default_message_id,
210 bool syncable);
193 void RegisterLocalizedStringPref(const char* path, 211 void RegisterLocalizedStringPref(const char* path,
194 int locale_default_message_id); 212 int locale_default_message_id,
213 bool syncable);
195 214
196 // If the path is valid and the value at the end of the path matches the type 215 // If the path is valid and the value at the end of the path matches the type
197 // specified, it will return the specified value. Otherwise, the default 216 // specified, it will return the specified value. Otherwise, the default
198 // value (set when the pref was registered) will be returned. 217 // value (set when the pref was registered) will be returned.
199 bool GetBoolean(const char* path) const; 218 bool GetBoolean(const char* path) const;
200 int GetInteger(const char* path) const; 219 int GetInteger(const char* path) const;
201 double GetDouble(const char* path) const; 220 double GetDouble(const char* path) const;
202 std::string GetString(const char* path) const; 221 std::string GetString(const char* path) const;
203 FilePath GetFilePath(const char* path) const; 222 FilePath GetFilePath(const char* path) const;
204 223
(...skipping 19 matching lines...) Expand all
224 void SetFilePath(const char* path, const FilePath& value); 243 void SetFilePath(const char* path, const FilePath& value);
225 // SetList() takes ownership of |value|. Pass a copy of the ListValue to 244 // SetList() takes ownership of |value|. Pass a copy of the ListValue to
226 // keep ownership of the original list, if necessary. 245 // keep ownership of the original list, if necessary.
227 void SetList(const char* path, ListValue* value); 246 void SetList(const char* path, ListValue* value);
228 247
229 // Int64 helper methods that actually store the given value as a string. 248 // Int64 helper methods that actually store the given value as a string.
230 // Note that if obtaining the named value via GetDictionary or GetList, the 249 // Note that if obtaining the named value via GetDictionary or GetList, the
231 // Value type will be TYPE_STRING. 250 // Value type will be TYPE_STRING.
232 void SetInt64(const char* path, int64 value); 251 void SetInt64(const char* path, int64 value);
233 int64 GetInt64(const char* path) const; 252 int64 GetInt64(const char* path) const;
234 void RegisterInt64Pref(const char* path, int64 default_value); 253 void RegisterInt64Pref(const char* path, int64 default_value, bool syncable);
235 254
236 // Returns true if a value has been set for the specified path. 255 // Returns true if a value has been set for the specified path.
237 // NOTE: this is NOT the same as FindPreference. In particular 256 // NOTE: this is NOT the same as FindPreference. In particular
238 // FindPreference returns whether RegisterXXX has been invoked, where as 257 // FindPreference returns whether RegisterXXX has been invoked, where as
239 // this checks if a value exists for the path. 258 // this checks if a value exists for the path.
240 bool HasPrefPath(const char* path) const; 259 bool HasPrefPath(const char* path) const;
241 260
242 // Returns a dictionary with effective preference values. The ownership 261 // Returns a dictionary with effective preference values. The ownership
243 // is passed to the caller. 262 // is passed to the caller.
244 DictionaryValue* GetPreferenceValues() const; 263 DictionaryValue* GetPreferenceValues() const;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // method with PREF_CHANGED. Note that observers should not call these methods 323 // method with PREF_CHANGED. Note that observers should not call these methods
305 // directly but rather use a PrefChangeRegistrar to make sure the observer 324 // directly but rather use a PrefChangeRegistrar to make sure the observer
306 // gets cleaned up properly. 325 // gets cleaned up properly.
307 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); 326 virtual void AddPrefObserver(const char* path, NotificationObserver* obs);
308 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); 327 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs);
309 328
310 // Registers a new preference at |path|. The |default_value| must not be 329 // Registers a new preference at |path|. The |default_value| must not be
311 // NULL as it determines the preference value's type. 330 // NULL as it determines the preference value's type.
312 // RegisterPreference must not be called twice for the same path. 331 // RegisterPreference must not be called twice for the same path.
313 // This method takes ownership of |default_value|. 332 // This method takes ownership of |default_value|.
314 void RegisterPreference(const char* path, Value* default_value); 333 void RegisterPreference(const char* path,
334 Value* default_value,
335 bool syncable);
315 336
316 // Sets the value for this pref path in the user pref store and informs the 337 // Sets the value for this pref path in the user pref store and informs the
317 // PrefNotifier of the change. 338 // PrefNotifier of the change.
318 void SetUserPrefValue(const char* path, Value* new_value); 339 void SetUserPrefValue(const char* path, Value* new_value);
319 340
320 // Load preferences from storage, attempting to diagnose and handle errors. 341 // Load preferences from storage, attempting to diagnose and handle errors.
321 // This should only be called from the constructor. 342 // This should only be called from the constructor.
322 void InitFromStorage(); 343 void InitFromStorage();
323 344
324 // Used to set the value of dictionary or list values in the user pref store. 345 // Used to set the value of dictionary or list values in the user pref store.
(...skipping 15 matching lines...) Expand all
340 361
341 // Local cache of registered Preference objects. The default_store_ 362 // Local cache of registered Preference objects. The default_store_
342 // is authoritative with respect to what the types and default values 363 // is authoritative with respect to what the types and default values
343 // of registered preferences are. 364 // of registered preferences are.
344 mutable PreferenceSet prefs_; 365 mutable PreferenceSet prefs_;
345 366
346 // Holds delegator to be called after initialization, if async version 367 // Holds delegator to be called after initialization, if async version
347 // is used. 368 // is used.
348 PrefServiceDelegate* delegate_; 369 PrefServiceDelegate* delegate_;
349 370
371 // The model associator that maintains the links with the sync db.
372 scoped_refptr<PrefModelAssociator> pref_sync_associator_;
373
350 DISALLOW_COPY_AND_ASSIGN(PrefService); 374 DISALLOW_COPY_AND_ASSIGN(PrefService);
351 }; 375 };
352 376
353 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ 377 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698