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

Side by Side Diff: chrome/browser/prefs/pref_value_store.cc

Issue 10821047: Provide access to recommended pref values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits addressed. Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/prefs/pref_value_store.h" 5 #include "chrome/browser/prefs/pref_value_store.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/prefs/pref_model_associator.h" 8 #include "chrome/browser/prefs/pref_model_associator.h"
9 #include "chrome/browser/prefs/pref_notifier.h" 9 #include "chrome/browser/prefs/pref_notifier.h"
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 default_prefs = GetPrefStore(DEFAULT_STORE); 93 default_prefs = GetPrefStore(DEFAULT_STORE);
94 94
95 return new PrefValueStore( 95 return new PrefValueStore(
96 managed_prefs, extension_prefs, command_line_prefs, user_prefs, 96 managed_prefs, extension_prefs, command_line_prefs, user_prefs,
97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier); 97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier);
98 } 98 }
99 99
100 bool PrefValueStore::GetValue(const std::string& name, 100 bool PrefValueStore::GetValue(const std::string& name,
101 base::Value::Type type, 101 base::Value::Type type,
102 const Value** out_value) const { 102 const Value** out_value) const {
103 *out_value = NULL; 103 // Check the |PrefStore|s in order of their priority from highest to lowest,
104 // Check the |PrefStore|s in order of their priority from highest to lowest 104 // looking for the first preference value with the given |name| and |type|.
105 // to find the value of the preference described by the given preference name.
106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 105 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
107 if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i), 106 if (GetValueFromStoreWithType(name.c_str(), type,
108 out_value)) { 107 static_cast<PrefStoreType>(i), out_value))
109 if (!(*out_value)->IsType(type)) {
110 LOG(WARNING) << "Expected type for " << name << " is " << type
111 << " but got " << (*out_value)->GetType()
112 << " in store " << i;
113 continue;
114 }
115 return true; 108 return true;
116 }
117 } 109 }
118 return false; 110 return false;
119 } 111 }
120 112
113 bool PrefValueStore::GetRecommendedValue(const std::string& name,
114 base::Value::Type type,
115 const Value** out_value) const {
116 return GetValueFromStoreWithType(name.c_str(), type, RECOMMENDED_STORE,
117 out_value);
118 }
119
121 void PrefValueStore::NotifyPrefChanged( 120 void PrefValueStore::NotifyPrefChanged(
122 const char* path, 121 const char* path,
123 PrefValueStore::PrefStoreType new_store) { 122 PrefValueStore::PrefStoreType new_store) {
124 DCHECK(new_store != INVALID_STORE); 123 DCHECK(new_store != INVALID_STORE);
125 124 // A notification is sent when the pref value in any store changes. If this
126 // If the pref is controlled by a higher-priority store, its effective value 125 // store is currently being overridden by a higher-priority store, the
127 // cannot have changed. 126 // effective value of the pref will not have changed.
128 PrefStoreType controller = ControllingPrefStoreForPref(path); 127 pref_notifier_->OnPreferenceChanged(path);
129 if (controller == INVALID_STORE || controller >= new_store) { 128 if (pref_sync_associator_)
130 pref_notifier_->OnPreferenceChanged(path); 129 pref_sync_associator_->ProcessPrefChange(path);
131 if (pref_sync_associator_)
132 pref_sync_associator_->ProcessPrefChange(path);
133 }
134 } 130 }
135 131
136 bool PrefValueStore::PrefValueInManagedStore(const char* name) const { 132 bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
137 return PrefValueInStore(name, MANAGED_STORE); 133 return PrefValueInStore(name, MANAGED_STORE);
138 } 134 }
139 135
140 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { 136 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const {
141 return PrefValueInStore(name, EXTENSION_STORE); 137 return PrefValueInStore(name, EXTENSION_STORE);
142 } 138 }
143 139
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 case PrefStore::READ_NO_VALUE: 228 case PrefStore::READ_NO_VALUE:
233 break; 229 break;
234 } 230 }
235 } 231 }
236 232
237 // No valid value found for the given preference name: set the return false. 233 // No valid value found for the given preference name: set the return false.
238 *out_value = NULL; 234 *out_value = NULL;
239 return false; 235 return false;
240 } 236 }
241 237
238 bool PrefValueStore::GetValueFromStoreWithType(const char* name,
239 base::Value::Type type,
240 PrefStoreType store,
241 const Value** out_value) const {
242 if (GetValueFromStore(name, store, out_value)) {
243 if ((*out_value)->IsType(type))
244 return true;
245
246 LOG(WARNING) << "Expected type for " << name << " is " << type
247 << " but got " << (*out_value)->GetType()
248 << " in store " << store;
249 }
250
251 *out_value = NULL;
252 return false;
253 }
254
242 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type, 255 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type,
243 const std::string& key) { 256 const std::string& key) {
244 NotifyPrefChanged(key.c_str(), type); 257 NotifyPrefChanged(key.c_str(), type);
245 } 258 }
246 259
247 void PrefValueStore::OnInitializationCompleted( 260 void PrefValueStore::OnInitializationCompleted(
248 PrefValueStore::PrefStoreType type, bool succeeded) { 261 PrefValueStore::PrefStoreType type, bool succeeded) {
249 if (initialization_failed_) 262 if (initialization_failed_)
250 return; 263 return;
251 if (!succeeded) { 264 if (!succeeded) {
(...skipping 13 matching lines...) Expand all
265 if (initialization_failed_) 278 if (initialization_failed_)
266 return; 279 return;
267 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { 280 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
268 scoped_refptr<PrefStore> store = 281 scoped_refptr<PrefStore> store =
269 GetPrefStore(static_cast<PrefStoreType>(i)); 282 GetPrefStore(static_cast<PrefStoreType>(i));
270 if (store && !store->IsInitializationComplete()) 283 if (store && !store->IsInitializationComplete())
271 return; 284 return;
272 } 285 }
273 pref_notifier_->OnInitializationCompleted(true); 286 pref_notifier_->OnInitializationCompleted(true);
274 } 287 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_value_store.h ('k') | chrome/browser/prefs/pref_value_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698