OLD | NEW |
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 // |
(...skipping 10 matching lines...) Expand all Loading... |
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/common/important_file_writer.h" | 26 #include "chrome/common/important_file_writer.h" |
27 | 27 |
28 class NotificationObserver; | 28 class NotificationObserver; |
29 class Preference; | 29 class Preference; |
30 | 30 |
31 namespace base { | |
32 class Thread; | |
33 } | |
34 | |
35 class PrefService : public NonThreadSafe, | 31 class PrefService : public NonThreadSafe, |
36 public ImportantFileWriter::DataSerializer { | 32 public ImportantFileWriter::DataSerializer { |
37 public: | 33 public: |
38 | 34 |
39 // A helper class to store all the information associated with a preference. | 35 // A helper class to store all the information associated with a preference. |
40 class Preference { | 36 class Preference { |
41 public: | 37 public: |
42 | 38 |
43 // The type of the preference is determined by the type of |default_value|. | 39 // The type of the preference is determined by the type of |default_value|. |
44 // Therefore, the type needs to be a boolean, integer, real, string, | 40 // Therefore, the type needs to be a boolean, integer, real, string, |
(...skipping 25 matching lines...) Expand all Loading... |
70 std::wstring name_; | 66 std::wstring name_; |
71 scoped_ptr<Value> default_value_; | 67 scoped_ptr<Value> default_value_; |
72 | 68 |
73 // A reference to the pref service's persistent prefs. | 69 // A reference to the pref service's persistent prefs. |
74 DictionaryValue* root_pref_; | 70 DictionaryValue* root_pref_; |
75 | 71 |
76 DISALLOW_COPY_AND_ASSIGN(Preference); | 72 DISALLOW_COPY_AND_ASSIGN(Preference); |
77 }; | 73 }; |
78 | 74 |
79 // |pref_filename| is the path to the prefs file we will try to load or save | 75 // |pref_filename| is the path to the prefs file we will try to load or save |
80 // to. Saves will be executed on |backend_thread|. It should be the file | 76 // to. Saves will be executed on the file thread. |
81 // thread in Chrome. You can pass NULL for unit tests, and then no separate | 77 explicit PrefService(const FilePath& pref_filename); |
82 // thread will be used. | |
83 PrefService(const FilePath& pref_filename, | |
84 const base::Thread* backend_thread); | |
85 ~PrefService(); | 78 ~PrefService(); |
86 | 79 |
87 // Reloads the data from file. This should only be called when the importer | 80 // Reloads the data from file. This should only be called when the importer |
88 // is running during first run, and the main process may not change pref | 81 // is running during first run, and the main process may not change pref |
89 // values while the importer process is running. Returns true on success. | 82 // values while the importer process is running. Returns true on success. |
90 bool ReloadPersistentPrefs(); | 83 bool ReloadPersistentPrefs(); |
91 | 84 |
92 // Writes the data to disk. The return value only reflects whether | 85 // Writes the data to disk. The return value only reflects whether |
93 // serialization was successful; we don't know whether the data actually made | 86 // serialization was successful; we don't know whether the data actually made |
94 // it on disk (since it's on a different thread). This should only be used if | 87 // it on disk (since it's on a different thread). This should only be used if |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // order they are added. | 218 // order they are added. |
226 typedef ObserverList<NotificationObserver> NotificationObserverList; | 219 typedef ObserverList<NotificationObserver> NotificationObserverList; |
227 typedef base::hash_map<std::wstring, NotificationObserverList*> | 220 typedef base::hash_map<std::wstring, NotificationObserverList*> |
228 PrefObserverMap; | 221 PrefObserverMap; |
229 PrefObserverMap pref_observers_; | 222 PrefObserverMap pref_observers_; |
230 | 223 |
231 DISALLOW_COPY_AND_ASSIGN(PrefService); | 224 DISALLOW_COPY_AND_ASSIGN(PrefService); |
232 }; | 225 }; |
233 | 226 |
234 #endif // CHROME_COMMON_PREF_SERVICE_H_ | 227 #endif // CHROME_COMMON_PREF_SERVICE_H_ |
OLD | NEW |