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

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: Whitespaces + fixes for trybot Created 10 years 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 3ad6c44f009bc614e641d271d666f9f7e0237c9f..f55c5d4798a37249dda26adcf90acd5426e05820 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -21,13 +21,13 @@ PrefValueStore::PrefStoreKeeper::~PrefStoreKeeper() {
void PrefValueStore::PrefStoreKeeper::Initialize(
PrefValueStore* store,
- PrefStore* pref_store,
+ scoped_refptr<PrefStore> pref_store,
PrefValueStore::PrefStoreType type) {
if (pref_store_.get())
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);
}
@@ -41,13 +41,13 @@ void PrefValueStore::PrefStoreKeeper::OnInitializationCompleted() {
pref_value_store_->OnInitializationCompleted(type_);
}
-PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
- PrefStore* device_management_prefs,
- PrefStore* extension_prefs,
- PrefStore* command_line_prefs,
- PrefStore* user_prefs,
- PrefStore* recommended_prefs,
- PrefStore* default_prefs,
+PrefValueStore::PrefValueStore(scoped_refptr<PrefStore> managed_platform_prefs,
+ scoped_refptr<PrefStore> device_management_prefs,
+ scoped_refptr<PrefStore> extension_prefs,
+ scoped_refptr<PrefStore> command_line_prefs,
+ scoped_refptr<PrefStore> user_prefs,
+ scoped_refptr<PrefStore> recommended_prefs,
+ scoped_refptr<PrefStore> default_prefs,
PrefNotifier* pref_notifier,
Profile* profile)
: pref_notifier_(pref_notifier),
@@ -70,49 +70,46 @@ PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
PrefValueStore::~PrefValueStore() {}
+PrefValueStore* PrefValueStore::Derive(scoped_refptr<PrefStore> extension_prefs,
+ scoped_refptr<PrefStore> user_prefs,
+ PrefNotifier* pref_notifier) {
+ return new PrefValueStore(GetPrefStore(MANAGED_PLATFORM_STORE),
+ GetPrefStore(DEVICE_MANAGEMENT_STORE),
+ extension_prefs,
+ GetPrefStore(COMMAND_LINE_STORE),
+ user_prefs,
+ GetPrefStore(RECOMMENDED_STORE),
+ GetPrefStore(DEFAULT_STORE),
+ pref_notifier,
+ profile_);
+}
+
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.
@@ -165,24 +162,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 {
@@ -223,7 +202,8 @@ bool PrefValueStore::GetValueFromStore(const char* name,
Value** out_value) const {
// Only return true if we find a value and it is the correct type, so stale
// values with the incorrect type will be ignored.
- const PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(store_type));
+ scoped_refptr<PrefStore> store =
+ GetPrefStore(static_cast<PrefStoreType>(store_type));
if (store) {
switch (store->GetValue(name, out_value)) {
case PrefStore::READ_USE_DEFAULT:
@@ -234,12 +214,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;
}
@@ -252,24 +227,21 @@ bool PrefValueStore::GetValueFromStore(const char* name,
void PrefValueStore::RefreshPolicyPrefsOnFileThread(
BrowserThread::ID calling_thread_id,
- policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store,
- policy::ConfigurationPolicyPrefStore* new_device_management_pref_store,
- policy::ConfigurationPolicyPrefStore* new_recommended_pref_store) {
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_managed_platform_pref_store,
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_device_management_pref_store,
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_recommended_pref_store) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- scoped_ptr<policy::ConfigurationPolicyPrefStore> managed_platform_pref_store(
- new_managed_platform_pref_store);
- scoped_ptr<policy::ConfigurationPolicyPrefStore> device_management_pref_store(
- new_device_management_pref_store);
- scoped_ptr<policy::ConfigurationPolicyPrefStore> recommended_pref_store(
- new_recommended_pref_store);
BrowserThread::PostTask(
calling_thread_id, FROM_HERE,
NewRunnableMethod(this,
&PrefValueStore::RefreshPolicyPrefsCompletion,
- managed_platform_pref_store.release(),
- device_management_pref_store.release(),
- recommended_pref_store.release()));
+ new_managed_platform_pref_store,
+ new_device_management_pref_store,
+ new_recommended_pref_store));
}
void PrefValueStore::RefreshPolicyPrefs() {
@@ -281,12 +253,12 @@ void PrefValueStore::RefreshPolicyPrefs() {
// created and the refreshed policy read into them. The new stores
// are swapped with the old from a Task on the UI thread after the
// load is complete.
- ConfigurationPolicyPrefStore* new_managed_platform_pref_store(
+ scoped_refptr<ConfigurationPolicyPrefStore> new_managed_platform_pref_store(
ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore());
- ConfigurationPolicyPrefStore* new_device_management_pref_store(
+ scoped_refptr<ConfigurationPolicyPrefStore> new_device_management_pref_store(
ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore(
profile_));
- ConfigurationPolicyPrefStore* new_recommended_pref_store(
+ scoped_refptr<ConfigurationPolicyPrefStore> new_recommended_pref_store(
ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore());
BrowserThread::ID current_thread_id;
CHECK(BrowserThread::GetCurrentThreadIdentifier(&current_thread_id));
@@ -301,25 +273,28 @@ void PrefValueStore::RefreshPolicyPrefs() {
}
void PrefValueStore::RefreshPolicyPrefsCompletion(
- policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store,
- policy::ConfigurationPolicyPrefStore* new_device_management_pref_store,
- policy::ConfigurationPolicyPrefStore* new_recommended_pref_store) {
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_managed_platform_pref_store,
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_device_management_pref_store,
+ scoped_refptr<policy::ConfigurationPolicyPrefStore>
+ new_recommended_pref_store) {
// Determine the paths of all the changed preferences values in the three
// policy-related stores (managed platform, device management and
// recommended).
DictionaryValue* managed_platform_prefs_before(
static_cast<policy::ConfigurationPolicyPrefStore*>(
- GetPrefStore(MANAGED_PLATFORM_STORE))->prefs());
+ GetPrefStore(MANAGED_PLATFORM_STORE).get())->prefs());
DictionaryValue* managed_platform_prefs_after(
new_managed_platform_pref_store->prefs());
DictionaryValue* device_management_prefs_before(
static_cast<policy::ConfigurationPolicyPrefStore*>(
- GetPrefStore(DEVICE_MANAGEMENT_STORE))->prefs());
+ GetPrefStore(DEVICE_MANAGEMENT_STORE).get())->prefs());
DictionaryValue* device_management_prefs_after(
new_device_management_pref_store->prefs());
DictionaryValue* recommended_prefs_before(
static_cast<policy::ConfigurationPolicyPrefStore*>(
- GetPrefStore(RECOMMENDED_STORE))->prefs());
+ GetPrefStore(RECOMMENDED_STORE).get())->prefs());
DictionaryValue* recommended_prefs_after(new_recommended_pref_store->prefs());
std::vector<std::string> changed_managed_platform_paths;
@@ -397,13 +372,14 @@ void PrefValueStore::OnInitializationCompleted(
}
void PrefValueStore::InitPrefStore(PrefValueStore::PrefStoreType type,
- PrefStore* pref_store) {
+ scoped_refptr<PrefStore> pref_store) {
pref_stores_[type].Initialize(this, pref_store, 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