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

Unified Diff: chrome/browser/prefs/pref_value_store.cc

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed whitespaces in mac files Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_value_store.cc
diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc
index 0fd3449ad2b407f23ab902e96f9129c89830bd38..c86accdb58395edbd2bc1da7118a9f5b178507b6 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -24,7 +24,7 @@ void PrefValueStore::PrefStoreKeeper::Initialize(
pref_store_->RemoveObserver(this);
type_ = type;
pref_value_store_ = store;
- pref_store_.reset(pref_store);
+ pref_store_ = pref_store;
if (pref_store_.get())
pref_store_->AddObserver(this);
}
@@ -60,49 +60,63 @@ PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
PrefValueStore::~PrefValueStore() {}
+PrefValueStore* PrefValueStore::CloneAndSpecialize(
+ PrefStore* managed_platform_prefs,
+ PrefStore* device_management_prefs,
+ PrefStore* extension_prefs,
+ PrefStore* command_line_prefs,
+ PrefStore* user_prefs,
+ PrefStore* recommended_prefs,
+ PrefStore* default_prefs,
+ PrefNotifier* pref_notifier) {
+ DCHECK(pref_notifier);
+ if (!managed_platform_prefs)
+ managed_platform_prefs = GetPrefStore(MANAGED_PLATFORM_STORE);
+ if (!device_management_prefs)
+ device_management_prefs = GetPrefStore(DEVICE_MANAGEMENT_STORE);
+ if (!extension_prefs)
+ extension_prefs = GetPrefStore(EXTENSION_STORE);
+ if (!command_line_prefs)
+ command_line_prefs = GetPrefStore(COMMAND_LINE_STORE);
+ if (!user_prefs)
+ user_prefs = GetPrefStore(USER_STORE);
+ if (!recommended_prefs)
+ recommended_prefs = GetPrefStore(RECOMMENDED_STORE);
+ if (!default_prefs)
+ default_prefs = GetPrefStore(DEFAULT_STORE);
+
+ return new PrefValueStore(
+ managed_platform_prefs, device_management_prefs, extension_prefs,
+ command_line_prefs, user_prefs, recommended_prefs, default_prefs,
+ pref_notifier);
+}
+
bool PrefValueStore::GetValue(const std::string& name,
+ Value::ValueType type,
Value** out_value) const {
+ *out_value = NULL;
// Check the |PrefStore|s in order of their priority from highest to lowest
// to find the value of the preference described by the given preference name.
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i),
- out_value))
+ out_value)) {
+ if (!(*out_value)->IsType(type)) {
+ LOG(WARNING) << "Expected type for " << name << " is " << type
+ << " but got " << (*out_value)->GetType()
+ << " in store " << i;
+ continue;
+ }
return true;
+ }
}
return false;
}
-void PrefValueStore::RegisterPreferenceType(const std::string& name,
- Value::ValueType type) {
- pref_types_[name] = type;
-}
-
-Value::ValueType PrefValueStore::GetRegisteredType(
- const std::string& name) const {
- PrefTypeMap::const_iterator found = pref_types_.find(name);
- if (found == pref_types_.end())
- return Value::TYPE_NULL;
- return found->second;
-}
-
-bool PrefValueStore::HasPrefPath(const char* path) const {
- Value* tmp_value = NULL;
- const std::string name(path);
- bool rv = GetValue(name, &tmp_value);
- // Merely registering a pref doesn't count as "having" it: we require a
- // non-default value set.
- return rv && !PrefValueFromDefaultStore(path);
-}
-
void PrefValueStore::NotifyPrefChanged(
const char* path,
PrefValueStore::PrefStoreType new_store) {
DCHECK(new_store != INVALID_STORE);
- // If this pref is not registered, just discard the notification.
- if (!pref_types_.count(path))
- return;
-
bool changed = true;
// Replying that the pref has changed in case the new store is invalid may
// cause problems, but it's the safer choice.
@@ -155,24 +169,6 @@ bool PrefValueStore::PrefValueUserModifiable(const char* name) const {
effective_store == INVALID_STORE;
}
-// Returns true if the actual value is a valid type for the expected type when
-// found in the given store.
-bool PrefValueStore::IsValidType(Value::ValueType expected,
- Value::ValueType actual,
- PrefValueStore::PrefStoreType store) {
- if (expected == actual)
- return true;
-
- // Dictionaries and lists are allowed to hold TYPE_NULL values too, but only
- // in the default pref store.
- if (store == DEFAULT_STORE &&
- actual == Value::TYPE_NULL &&
- (expected == Value::TYPE_DICTIONARY || expected == Value::TYPE_LIST)) {
- return true;
- }
- return false;
-}
-
bool PrefValueStore::PrefValueInStore(
const char* name,
PrefValueStore::PrefStoreType store) const {
@@ -224,12 +220,7 @@ bool PrefValueStore::GetValueFromStore(const char* name,
}
// Fall through...
case PrefStore::READ_OK:
- if (IsValidType(GetRegisteredType(name),
- (*out_value)->GetType(),
- store_type)) {
- return true;
- }
- break;
+ return true;
case PrefStore::READ_NO_VALUE:
break;
}
@@ -257,7 +248,8 @@ void PrefValueStore::InitPrefStore(PrefValueStore::PrefStoreType type,
void PrefValueStore::CheckInitializationCompleted() {
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
- PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(i));
+ scoped_refptr<PrefStore> store =
+ GetPrefStore(static_cast<PrefStoreType>(i));
if (store && !store->IsInitializationComplete())
return;
}

Powered by Google App Engine
This is Rietveld 408576698