OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_PREF_VALUE_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREF_VALUE_STORE_H_ |
6 #define CHROME_BROWSER_PREF_VALUE_STORE_H_ | 6 #define CHROME_BROWSER_PREF_VALUE_STORE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // admin for example). They have the highest priority and can not be | 21 // admin for example). They have the highest priority and can not be |
22 // altered by the user. | 22 // altered by the user. |
23 // User-defined values are chosen by the user. If there is already | 23 // User-defined values are chosen by the user. If there is already |
24 // a managed value for a preference the user-defined value is ignored and | 24 // a managed value for a preference the user-defined value is ignored and |
25 // the managed value is used (returned). | 25 // the managed value is used (returned). |
26 // Otherwise user-defined values have a higher precedence than recommended | 26 // Otherwise user-defined values have a higher precedence than recommended |
27 // values. Recommended preference values are set by a third person | 27 // values. Recommended preference values are set by a third person |
28 // (like an admin). | 28 // (like an admin). |
29 class PrefValueStore { | 29 class PrefValueStore { |
30 public: | 30 public: |
31 // |managed_prefs| contains all managed preference values. They have the | 31 // In decreasing order of precedence: |
32 // highest priority and precede user-defined preference values. |user_prefs| | 32 // |managed_prefs| contains all managed (policy) preference values. |
33 // contains all user-defined preference values. User-defined values precede | 33 // |extension_prefs| contains preference values set by extensions. |
34 // recommended values. |recommended_prefs| contains all recommended | 34 // |user_prefs| contains all user-set preference values. |
35 // preference values. | 35 // |recommended_prefs| contains all recommended (policy) preference values. |
36 PrefValueStore(PrefStore* managed_prefs, | 36 PrefValueStore(PrefStore* managed_prefs, |
| 37 PrefStore* extension_prefs, |
37 PrefStore* user_prefs, | 38 PrefStore* user_prefs, |
38 PrefStore* recommended_prefs); | 39 PrefStore* recommended_prefs); |
39 | 40 |
40 ~PrefValueStore(); | 41 ~PrefValueStore(); |
41 | 42 |
42 // Get the preference value for the given preference name. | 43 // Get the preference value for the given preference name. |
43 // Return true if a value for the given preference name was found. | 44 // Return true if a value for the given preference name was found. |
44 bool GetValue(const std::wstring& name, Value** out_value) const; | 45 bool GetValue(const std::wstring& name, Value** out_value) const; |
45 | 46 |
46 // Read preference values into the three PrefStores so that they are available | 47 // Read preference values into the three PrefStores so that they are available |
47 // through the GetValue method. | 48 // through the GetValue method. Return the first error that occurs (but |
| 49 // continue reading the remaining PrefStores). |
48 PrefStore::PrefReadError ReadPrefs(); | 50 PrefStore::PrefReadError ReadPrefs(); |
49 | 51 |
50 // Write user settable preference values. Return true if writing values was | 52 // Persists prefs (to disk or elsewhere). Returns true if writing values was |
51 // successfull. | 53 // successful. In practice, only the user prefs are expected to be written |
| 54 // out. |
52 bool WritePrefs(); | 55 bool WritePrefs(); |
53 | 56 |
54 // Calls the method ScheduleWritePrefs on the PrefStores. | 57 // Calls the method ScheduleWritePrefs on the PrefStores. In practice, only |
| 58 // the user prefs are expected to be written out. |
55 void ScheduleWritePrefs(); | 59 void ScheduleWritePrefs(); |
56 | 60 |
57 // Returns true if the PrefValueStore contains the given preference. | 61 // Returns true if the PrefValueStore contains the given preference. |
58 bool HasPrefPath(const wchar_t* name) const; | 62 bool HasPrefPath(const wchar_t* name) const; |
59 | 63 |
60 // Returns true if the PrefValueStore is read-only. | 64 // Returns true if the PrefValueStore is read-only. |
61 // Because the managed and recommended PrefStores are always read-only, the | 65 // Because the managed and recommended PrefStores are always read-only, the |
62 // PrefValueStore as a whole is read-only if the PrefStore containing the user | 66 // PrefValueStore as a whole is read-only if the PrefStore containing the user |
63 // preferences is read-only. | 67 // preferences is read-only. |
64 bool ReadOnly(); | 68 bool ReadOnly(); |
65 | 69 |
66 // Alters the user-defined value of a preference. Even if the preference is | 70 // Alters the user-defined value of a preference. Even if the preference is |
67 // managed this method allows the user-defined value of the preference to be | 71 // managed this method allows the user-defined value of the preference to be |
68 // set. But GetValue calls will not return this value as long as the | 72 // set. But GetValue calls will not return this value as long as the |
69 // preference is managed. Instead GetValue will return the managed value | 73 // preference is managed. Instead GetValue will return the managed value |
70 // of the preference. Note that the PrefValueStore takes the ownership of | 74 // of the preference. Note that the PrefValueStore takes the ownership of |
71 // the value referenced by |in_value|. | 75 // the value referenced by |in_value|. It is an error to call this when no |
| 76 // user PrefStore has been set. |
72 void SetUserPrefValue(const wchar_t* name, Value* in_value); | 77 void SetUserPrefValue(const wchar_t* name, Value* in_value); |
73 | 78 |
74 // Removes a value from the PrefValueStore. If a preference is managed | 79 // Removes a value from the PrefValueStore. If a preference is managed |
75 // or recommended this function should have no effect. | 80 // or recommended this function should have no effect. |
76 void RemoveUserPrefValue(const wchar_t* name); | 81 void RemoveUserPrefValue(const wchar_t* name); |
77 | 82 |
78 // Returns true if the preference with the given name is managed. | 83 // Returns true if the preference with the given name is managed. |
79 // A preference is managed if a managed value is available for that | 84 // A preference is managed if a managed value is available for that |
80 // preference. | 85 // preference. |
81 bool PrefValueIsManaged(const wchar_t* name); | 86 bool PrefValueIsManaged(const wchar_t* name); |
82 | 87 |
83 private: | 88 private: |
84 scoped_ptr<PrefStore> managed_prefs_; | 89 // PrefStores must be listed here in order from highest to lowest priority. |
85 scoped_ptr<PrefStore> user_prefs_; | 90 enum PrefStoreType { |
86 scoped_ptr<PrefStore> recommended_prefs_; | 91 MANAGED = 0, |
| 92 EXTENSION, |
| 93 USER, |
| 94 RECOMMENDED, |
| 95 PREF_STORE_TYPE_MAX = RECOMMENDED |
| 96 }; |
| 97 |
| 98 scoped_ptr<PrefStore> pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
87 | 99 |
88 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 100 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
89 }; | 101 }; |
90 | 102 |
91 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ | 103 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ |
OLD | NEW |