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

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

Issue 1549020: Add a scoped notifier for pref dictionaries / lists. (Closed)
Patch Set: Fix props. Created 10 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // This service has two preference stores, one for "persistent" preferences, 6 // This service has two preference stores, one for "persistent" preferences,
7 // which get serialized for use in the next session, and one for "transient" 7 // which get serialized for use in the next session, and one for "transient"
8 // preferences, which are in effect for only the current session 8 // preferences, which are in effect for only the current session
9 // (this usually encodes things like command-line switches). 9 // (this usually encodes things like command-line switches).
10 // 10 //
11 // Calling the getter functions in this class basically looks at both the 11 // Calling the getter functions in this class basically looks at both the
12 // persistent and transient stores, where any corresponding value in the 12 // persistent and transient stores, where any corresponding value in the
13 // transient store overrides the one in the persistent store. 13 // transient store overrides the one in the persistent store.
14 14
15 #ifndef CHROME_BROWSER_PREF_SERVICE_H_ 15 #ifndef CHROME_BROWSER_PREF_SERVICE_H_
16 #define CHROME_BROWSER_PREF_SERVICE_H_ 16 #define CHROME_BROWSER_PREF_SERVICE_H_
17 17
18 #include <set> 18 #include <set>
19 19
20 #include "base/file_path.h" 20 #include "base/file_path.h"
21 #include "base/hash_tables.h" 21 #include "base/hash_tables.h"
22 #include "base/non_thread_safe.h" 22 #include "base/non_thread_safe.h"
23 #include "base/observer_list.h" 23 #include "base/observer_list.h"
24 #include "base/scoped_ptr.h" 24 #include "base/scoped_ptr.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "chrome/browser/important_file_writer.h" 26 #include "chrome/browser/important_file_writer.h"
27 27
28 class NotificationObserver; 28 class NotificationObserver;
29 class Preference; 29 class Preference;
30 class ScopedPrefUpdate;
30 31
31 class PrefService : public NonThreadSafe, 32 class PrefService : public NonThreadSafe,
32 public ImportantFileWriter::DataSerializer { 33 public ImportantFileWriter::DataSerializer {
33 public: 34 public:
34 35
35 // A helper class to store all the information associated with a preference. 36 // A helper class to store all the information associated with a preference.
36 class Preference { 37 class Preference {
37 public: 38 public:
38 39
39 // The type of the preference is determined by the type of |default_value|. 40 // The type of the preference is determined by the type of |default_value|.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Value type will be TYPE_STRING. 152 // Value type will be TYPE_STRING.
152 void SetInt64(const wchar_t* path, int64 value); 153 void SetInt64(const wchar_t* path, int64 value);
153 int64 GetInt64(const wchar_t* path) const; 154 int64 GetInt64(const wchar_t* path) const;
154 void RegisterInt64Pref(const wchar_t* path, int64 default_value); 155 void RegisterInt64Pref(const wchar_t* path, int64 default_value);
155 156
156 // Used to set the value of dictionary or list values in the pref tree. This 157 // Used to set the value of dictionary or list values in the pref tree. This
157 // will create a dictionary or list if one does not exist in the pref tree. 158 // will create a dictionary or list if one does not exist in the pref tree.
158 // This method returns NULL only if you're requesting an unregistered pref or 159 // This method returns NULL only if you're requesting an unregistered pref or
159 // a non-dict/non-list pref. 160 // a non-dict/non-list pref.
160 // WARNING: Changes to the dictionary or list will not automatically notify 161 // WARNING: Changes to the dictionary or list will not automatically notify
161 // pref observers. TODO(tc): come up with a way to still fire observers. 162 // pref observers.
163 // Use a ScopedPrefUpdate to update observers on changes.
162 DictionaryValue* GetMutableDictionary(const wchar_t* path); 164 DictionaryValue* GetMutableDictionary(const wchar_t* path);
163 ListValue* GetMutableList(const wchar_t* path); 165 ListValue* GetMutableList(const wchar_t* path);
164 166
165 // Returns true if a value has been set for the specified path. 167 // Returns true if a value has been set for the specified path.
166 // NOTE: this is NOT the same as FindPreference. In particular 168 // NOTE: this is NOT the same as FindPreference. In particular
167 // FindPreference returns whether RegisterXXX has been invoked, where as 169 // FindPreference returns whether RegisterXXX has been invoked, where as
168 // this checks if a value exists for the path. 170 // this checks if a value exists for the path.
169 bool HasPrefPath(const wchar_t* path) const; 171 bool HasPrefPath(const wchar_t* path) const;
170 172
171 class PreferencePathComparator { 173 class PreferencePathComparator {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // A set of all the registered Preference objects. 211 // A set of all the registered Preference objects.
210 PreferenceSet prefs_; 212 PreferenceSet prefs_;
211 213
212 // A map from pref names to a list of observers. Observers get fired in the 214 // A map from pref names to a list of observers. Observers get fired in the
213 // order they are added. 215 // order they are added.
214 typedef ObserverList<NotificationObserver> NotificationObserverList; 216 typedef ObserverList<NotificationObserver> NotificationObserverList;
215 typedef base::hash_map<std::wstring, NotificationObserverList*> 217 typedef base::hash_map<std::wstring, NotificationObserverList*>
216 PrefObserverMap; 218 PrefObserverMap;
217 PrefObserverMap pref_observers_; 219 PrefObserverMap pref_observers_;
218 220
221 friend class ScopedPrefUpdate;
222
219 DISALLOW_COPY_AND_ASSIGN(PrefService); 223 DISALLOW_COPY_AND_ASSIGN(PrefService);
220 }; 224 };
221 225
222 #endif // CHROME_BROWSER_PREF_SERVICE_H_ 226 #endif // CHROME_BROWSER_PREF_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/preferences_window_controller.mm ('k') | chrome/browser/scoped_pref_update.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698