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

Side by Side Diff: chrome/browser/prefs/pref_value_store.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, 7 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 #ifndef CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ 5 #ifndef CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_
6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ 6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/common/pref_store.h" 17 #include "chrome/common/pref_store.h"
18 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
19 19
20 class FilePath; 20 class FilePath;
21 class PrefModelAssociator;
21 class PrefNotifier; 22 class PrefNotifier;
22 class PrefStore; 23 class PrefStore;
23 24
24 // The PrefValueStore manages various sources of values for Preferences 25 // The PrefValueStore manages various sources of values for Preferences
25 // (e.g., configuration policies, extensions, and user settings). It returns 26 // (e.g., configuration policies, extensions, and user settings). It returns
26 // the value of a Preference from the source with the highest priority, and 27 // the value of a Preference from the source with the highest priority, and
27 // allows setting user-defined values for preferences that are not managed. 28 // allows setting user-defined values for preferences that are not managed.
28 // 29 //
29 // Unless otherwise explicitly noted, all of the methods of this class must 30 // Unless otherwise explicitly noted, all of the methods of this class must
30 // be called on the UI thread. 31 // be called on the UI thread.
(...skipping 18 matching lines...) Expand all
49 // |pref_notifier| facilitates broadcasting preference change notifications 50 // |pref_notifier| facilitates broadcasting preference change notifications
50 // to the world. 51 // to the world.
51 PrefValueStore(PrefStore* managed_platform_prefs, 52 PrefValueStore(PrefStore* managed_platform_prefs,
52 PrefStore* managed_cloud_prefs, 53 PrefStore* managed_cloud_prefs,
53 PrefStore* extension_prefs, 54 PrefStore* extension_prefs,
54 PrefStore* command_line_prefs, 55 PrefStore* command_line_prefs,
55 PrefStore* user_prefs, 56 PrefStore* user_prefs,
56 PrefStore* recommended_platform_prefs, 57 PrefStore* recommended_platform_prefs,
57 PrefStore* recommended_cloud_prefs, 58 PrefStore* recommended_cloud_prefs,
58 PrefStore* default_prefs, 59 PrefStore* default_prefs,
60 PrefModelAssociator* pref_sync_associator,
59 PrefNotifier* pref_notifier); 61 PrefNotifier* pref_notifier);
60 virtual ~PrefValueStore(); 62 virtual ~PrefValueStore();
61 63
62 // Creates a clone of this PrefValueStore with PrefStores overwritten 64 // Creates a clone of this PrefValueStore with PrefStores overwritten
63 // by the parameters passed, if unequal NULL. 65 // by the parameters passed, if unequal NULL.
64 PrefValueStore* CloneAndSpecialize(PrefStore* managed_platform_prefs, 66 PrefValueStore* CloneAndSpecialize(PrefStore* managed_platform_prefs,
65 PrefStore* managed_cloud_prefs, 67 PrefStore* managed_cloud_prefs,
66 PrefStore* extension_prefs, 68 PrefStore* extension_prefs,
67 PrefStore* command_line_prefs, 69 PrefStore* command_line_prefs,
68 PrefStore* user_prefs, 70 PrefStore* user_prefs,
69 PrefStore* recommended_platform_prefs, 71 PrefStore* recommended_platform_prefs,
70 PrefStore* recommended_cloud_prefs, 72 PrefStore* recommended_cloud_prefs,
71 PrefStore* default_prefs, 73 PrefStore* default_prefs,
74 PrefModelAssociator* pref_sync_associator,
72 PrefNotifier* pref_notifier); 75 PrefNotifier* pref_notifier);
73 76
74 // Gets the value for the given preference name that has the specified value 77 // Gets the value for the given preference name that has the specified value
75 // type. Values stored in a PrefStore that have the matching |name| but 78 // type. Values stored in a PrefStore that have the matching |name| but
76 // a non-matching |type| are silently skipped. Returns true if a valid value 79 // a non-matching |type| are silently skipped. Returns true if a valid value
77 // was found in any of the available PrefStores. Most callers should use 80 // was found in any of the available PrefStores. Most callers should use
78 // Preference::GetValue() instead of calling this method directly. 81 // Preference::GetValue() instead of calling this method directly.
79 bool GetValue(const std::string& name, 82 bool GetValue(const std::string& name,
80 Value::ValueType type, 83 Value::ValueType type,
81 const Value** out_value) const; 84 const Value** out_value) const;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 }; 170 };
168 171
169 typedef std::map<std::string, Value::ValueType> PrefTypeMap; 172 typedef std::map<std::string, Value::ValueType> PrefTypeMap;
170 173
171 friend class PrefValueStorePolicyRefreshTest; 174 friend class PrefValueStorePolicyRefreshTest;
172 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); 175 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh);
173 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, 176 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest,
174 TestRefreshPolicyPrefsCompletion); 177 TestRefreshPolicyPrefsCompletion);
175 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, 178 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest,
176 TestConcurrentPolicyRefresh); 179 TestConcurrentPolicyRefresh);
180 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, SyncablePrefs);
177 181
178 // Returns true if the preference with the given name has a value in the 182 // Returns true if the preference with the given name has a value in the
179 // given PrefStoreType, of the same value type as the preference was 183 // given PrefStoreType, of the same value type as the preference was
180 // registered with. 184 // registered with.
181 bool PrefValueInStore(const char* name, PrefStoreType store) const; 185 bool PrefValueInStore(const char* name, PrefStoreType store) const;
182 186
183 // Returns true if a preference has an explicit value in any of the 187 // Returns true if a preference has an explicit value in any of the
184 // stores in the range specified by |first_checked_store| and 188 // stores in the range specified by |first_checked_store| and
185 // |last_checked_store|, even if that value is currently being 189 // |last_checked_store|, even if that value is currently being
186 // overridden by a higher-priority store. 190 // overridden by a higher-priority store.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 PrefStore* GetPrefStore(PrefStoreType type) { 230 PrefStore* GetPrefStore(PrefStoreType type) {
227 return pref_stores_[type].store(); 231 return pref_stores_[type].store();
228 } 232 }
229 const PrefStore* GetPrefStore(PrefStoreType type) const { 233 const PrefStore* GetPrefStore(PrefStoreType type) const {
230 return pref_stores_[type].store(); 234 return pref_stores_[type].store();
231 } 235 }
232 236
233 // Keeps the PrefStore references in order of precedence. 237 // Keeps the PrefStore references in order of precedence.
234 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; 238 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1];
235 239
240 // The associator for syncing preferences.
241 PrefModelAssociator* pref_sync_associator_;
242
236 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED 243 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED
237 // notifications. This is a weak reference, since the notifier is owned by the 244 // notifications. This is a weak reference, since the notifier is owned by the
238 // corresponding PrefService. 245 // corresponding PrefService.
239 PrefNotifier* pref_notifier_; 246 PrefNotifier* pref_notifier_;
240 247
241 // A mapping of preference names to their registered types. 248 // A mapping of preference names to their registered types.
242 PrefTypeMap pref_types_; 249 PrefTypeMap pref_types_;
243 250
244 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); 251 DISALLOW_COPY_AND_ASSIGN(PrefValueStore);
245 }; 252 };
246 253
247 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ 254 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698