OLD | NEW |
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 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // a mutable from the user preferences store. | 204 // a mutable from the user preferences store. |
205 DictionaryValue* GetMutableDictionary(const char* path); | 205 DictionaryValue* GetMutableDictionary(const char* path); |
206 ListValue* GetMutableList(const char* path); | 206 ListValue* GetMutableList(const char* path); |
207 | 207 |
208 // Returns true if a value has been set for the specified path. | 208 // Returns true if a value has been set for the specified path. |
209 // NOTE: this is NOT the same as FindPreference. In particular | 209 // NOTE: this is NOT the same as FindPreference. In particular |
210 // FindPreference returns whether RegisterXXX has been invoked, where as | 210 // FindPreference returns whether RegisterXXX has been invoked, where as |
211 // this checks if a value exists for the path. | 211 // this checks if a value exists for the path. |
212 bool HasPrefPath(const char* path) const; | 212 bool HasPrefPath(const char* path) const; |
213 | 213 |
214 class PreferencePathComparator { | 214 // Returns a dictionary with effective preference values. The ownership |
215 public: | 215 // is passed to the caller. |
216 bool operator() (Preference* lhs, Preference* rhs) const { | 216 DictionaryValue* GetPreferenceValues() const; |
217 return lhs->name() < rhs->name(); | |
218 } | |
219 }; | |
220 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; | |
221 const PreferenceSet& preference_set() const { return prefs_; } | |
222 | 217 |
223 // A helper method to quickly look up a preference. Returns NULL if the | 218 // A helper method to quickly look up a preference. Returns NULL if the |
224 // preference is not registered. | 219 // preference is not registered. |
225 const Preference* FindPreference(const char* pref_name) const; | 220 const Preference* FindPreference(const char* pref_name) const; |
226 | 221 |
227 bool ReadOnly() const; | 222 bool ReadOnly() const; |
228 | 223 |
229 // TODO(mnissler): This should not be public. Change client code to call a | 224 // TODO(mnissler): This should not be public. Change client code to call a |
230 // preference setter or use ScopedPrefUpdate. | 225 // preference setter or use ScopedPrefUpdate. |
231 PrefNotifier* pref_notifier() const; | 226 PrefNotifier* pref_notifier() const; |
232 | 227 |
233 protected: | 228 protected: |
234 // Construct a new pref service, specifying the pref sources as explicit | 229 // Construct a new pref service, specifying the pref sources as explicit |
235 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 230 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
236 // calling. It's also used for unit tests. | 231 // calling. It's also used for unit tests. |
237 PrefService(PrefStore* managed_platform_prefs, | 232 PrefService(PrefStore* managed_platform_prefs, |
238 PrefStore* device_management_prefs, | 233 PrefStore* device_management_prefs, |
239 PrefStore* extension_prefs, | 234 PrefStore* extension_prefs, |
240 PrefStore* command_line_prefs, | 235 PrefStore* command_line_prefs, |
241 PersistentPrefStore* user_prefs, | 236 PersistentPrefStore* user_prefs, |
242 PrefStore* recommended_prefs, | 237 PrefStore* recommended_prefs, |
243 DefaultPrefStore* default_store); | 238 DefaultPrefStore* default_store); |
244 | 239 |
245 // The PrefNotifier handles registering and notifying preference observers. | 240 // The PrefNotifier handles registering and notifying preference observers. |
246 // It is created and owned by this PrefService. Subclasses may access it for | 241 // It is created and owned by this PrefService. Subclasses may access it for |
247 // unit testing. | 242 // unit testing. |
248 scoped_ptr<PrefNotifierImpl> pref_notifier_; | 243 scoped_ptr<PrefNotifierImpl> pref_notifier_; |
249 | 244 |
250 private: | 245 private: |
| 246 class PreferencePathComparator { |
| 247 public: |
| 248 bool operator() (Preference* lhs, Preference* rhs) const { |
| 249 return lhs->name() < rhs->name(); |
| 250 } |
| 251 }; |
| 252 typedef std::set<Preference*, PreferencePathComparator> PreferenceSet; |
| 253 |
251 friend class PrefServiceMockBuilder; | 254 friend class PrefServiceMockBuilder; |
252 | 255 |
253 // Registration of pref change observers must be done using the | 256 // Registration of pref change observers must be done using the |
254 // PrefChangeRegistrar, which is declared as a friend here to grant it | 257 // PrefChangeRegistrar, which is declared as a friend here to grant it |
255 // access to the otherwise protected members Add/RemovePrefObserver. | 258 // access to the otherwise protected members Add/RemovePrefObserver. |
256 // PrefMember registers for preferences changes notification directly to | 259 // PrefMember registers for preferences changes notification directly to |
257 // avoid the storage overhead of the registrar, so its base class must be | 260 // avoid the storage overhead of the registrar, so its base class must be |
258 // declared as a friend, too. | 261 // declared as a friend, too. |
259 friend class PrefChangeRegistrar; | 262 friend class PrefChangeRegistrar; |
260 friend class subtle::PrefMemberBase; | 263 friend class subtle::PrefMemberBase; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 296 |
294 // Local cache of registered Preference objects. The default_store_ | 297 // Local cache of registered Preference objects. The default_store_ |
295 // is authoritative with respect to what the types and default values | 298 // is authoritative with respect to what the types and default values |
296 // of registered preferences are. | 299 // of registered preferences are. |
297 mutable PreferenceSet prefs_; | 300 mutable PreferenceSet prefs_; |
298 | 301 |
299 DISALLOW_COPY_AND_ASSIGN(PrefService); | 302 DISALLOW_COPY_AND_ASSIGN(PrefService); |
300 }; | 303 }; |
301 | 304 |
302 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 305 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
OLD | NEW |