summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 11:42:35 +0000
committerpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 11:42:35 +0000
commitd7449e879fbc3c53b6f8b5d544ab45b768ab0d10 (patch)
tree8935f0f9a3efb18fdd5d3f9f5c2d413463f5ab00
parentef52608ab2111dce735b426464af895d7b040767 (diff)
downloadchromium_src-d7449e879fbc3c53b6f8b5d544ab45b768ab0d10.zip
chromium_src-d7449e879fbc3c53b6f8b5d544ab45b768ab0d10.tar.gz
chromium_src-d7449e879fbc3c53b6f8b5d544ab45b768ab0d10.tar.bz2
Add methods for determining which PrefStore contains a given preference, and for which store is currently controlling it.
BUG=48952 TEST=covered by unit tests Review URL: http://codereview.chromium.org/2989002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52305 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/pref_service.cc17
-rw-r--r--chrome/browser/pref_service.h21
-rw-r--r--chrome/browser/pref_value_store.cc51
-rw-r--r--chrome/browser/pref_value_store.h20
-rw-r--r--chrome/browser/pref_value_store_unittest.cc85
5 files changed, 167 insertions, 27 deletions
diff --git a/chrome/browser/pref_service.cc b/chrome/browser/pref_service.cc
index 1450363..fcc8af3 100644
--- a/chrome/browser/pref_service.cc
+++ b/chrome/browser/pref_service.cc
@@ -837,6 +837,21 @@ bool PrefService::Preference::IsDefaultValue() const {
}
bool PrefService::Preference::IsManaged() const {
- return pref_value_store_->PrefValueIsManaged(name_.c_str());
+ return pref_value_store_->PrefValueInManagedStore(name_.c_str());
}
+bool PrefService::Preference::HasExtensionSetting() const {
+ return pref_value_store_->PrefValueInExtensionStore(name_.c_str());
+}
+
+bool PrefService::Preference::HasUserSetting() const {
+ return pref_value_store_->PrefValueInUserStore(name_.c_str());
+}
+
+bool PrefService::Preference::IsExtensionControlled() const {
+ return pref_value_store_->PrefValueFromExtensionStore(name_.c_str());
+}
+
+bool PrefService::Preference::IsUserControlled() const {
+ return pref_value_store_->PrefValueFromUserStore(name_.c_str());
+}
diff --git a/chrome/browser/pref_service.h b/chrome/browser/pref_service.h
index 483624b..9e31d9b 100644
--- a/chrome/browser/pref_service.h
+++ b/chrome/browser/pref_service.h
@@ -52,10 +52,27 @@ class PrefService : public NonThreadSafe {
// Returns true if the current value matches the default value.
bool IsDefaultValue() const;
- // Returns true if the Preference is managed, i.e. not changeable
- // by the user.
+ // Returns true if the Preference is managed, i.e. set by an admin policy.
+ // Since managed prefs have the highest priority, this also indicates
+ // whether the pref is actually being controlled by the policy setting.
bool IsManaged() const;
+ // Returns true if the Preference has a value set by an extension, even if
+ // that value is being overridden by a higher-priority source.
+ bool HasExtensionSetting() const;
+
+ // Returns true if the Preference has a user setting, even if that value is
+ // being overridden by a higher-priority source.
+ bool HasUserSetting() const;
+
+ // Returns true if the Preference value is currently being controlled by an
+ // extension, and not by any higher-priority source.
+ bool IsExtensionControlled() const;
+
+ // Returns true if the Preference value is currently being controlled by a
+ // user setting, and not by any higher-priority source.
+ bool IsUserControlled() const;
+
private:
friend class PrefService;
diff --git a/chrome/browser/pref_value_store.cc b/chrome/browser/pref_value_store.cc
index 6a87abe..81ed480 100644
--- a/chrome/browser/pref_value_store.cc
+++ b/chrome/browser/pref_value_store.cc
@@ -68,18 +68,6 @@ bool PrefValueStore::HasPrefPath(const wchar_t* path) const {
return rv;
}
-// The value of a Preference is managed if the PrefStore for managed
-// preferences contains a value for the given preference |name|.
-bool PrefValueStore::PrefValueIsManaged(const wchar_t* name) {
- if (pref_stores_[MANAGED].get() == NULL) {
- // No managed PreferenceStore set, hence there are no managed
- // preferences.
- return false;
- }
- Value* tmp_value;
- return pref_stores_[MANAGED]->prefs()->Get(name, &tmp_value);
-}
-
// Note the |DictionaryValue| referenced by the |PrefStore| user_prefs_
// (returned by the method prefs()) takes the ownership of the Value referenced
// by in_value.
@@ -96,3 +84,42 @@ void PrefValueStore::RemoveUserPrefValue(const wchar_t* name) {
pref_stores_[USER]->prefs()->Remove(name, NULL);
}
}
+
+bool PrefValueStore::PrefValueInManagedStore(const wchar_t* name) {
+ return PrefValueInStore(name, MANAGED);
+}
+
+bool PrefValueStore::PrefValueInExtensionStore(const wchar_t* name) {
+ return PrefValueInStore(name, EXTENSION);
+}
+
+bool PrefValueStore::PrefValueInUserStore(const wchar_t* name) {
+ return PrefValueInStore(name, USER);
+}
+
+bool PrefValueStore::PrefValueFromExtensionStore(const wchar_t* name) {
+ return PrefValueFromStore(name, EXTENSION);
+}
+
+bool PrefValueStore::PrefValueFromUserStore(const wchar_t* name) {
+ return PrefValueFromStore(name, USER);
+}
+
+bool PrefValueStore::PrefValueInStore(const wchar_t* name, PrefStoreType type) {
+ if (pref_stores_[type].get() == NULL) {
+ // No store of that type set, so this pref can't be in it.
+ return false;
+ }
+ Value* tmp_value;
+ return pref_stores_[type]->prefs()->Get(name, &tmp_value);
+}
+
+bool PrefValueStore::PrefValueFromStore(const wchar_t* name,
+ PrefStoreType type) {
+ // No need to look in PrefStores with lower priority than the one we want.
+ for (int i = 0; i <= type; ++i) {
+ if (PrefValueInStore(name, static_cast<PrefStoreType>(i)))
+ return (i == type);
+ }
+ return false;
+}
diff --git a/chrome/browser/pref_value_store.h b/chrome/browser/pref_value_store.h
index 0c4bf56..0ba62af 100644
--- a/chrome/browser/pref_value_store.h
+++ b/chrome/browser/pref_value_store.h
@@ -80,10 +80,18 @@ class PrefValueStore {
// or recommended this function should have no effect.
void RemoveUserPrefValue(const wchar_t* name);
- // Returns true if the preference with the given name is managed.
- // A preference is managed if a managed value is available for that
- // preference.
- bool PrefValueIsManaged(const wchar_t* name);
+ // These methods return true if a preference with the given name is in the
+ // indicated pref store, even if that value is currently being overridden by
+ // a higher-priority source.
+ bool PrefValueInManagedStore(const wchar_t* name);
+ bool PrefValueInExtensionStore(const wchar_t* name);
+ bool PrefValueInUserStore(const wchar_t* name);
+
+ // These methods return true if a preference with the given name is actually
+ // being controlled by the indicated pref store and not being overridden by
+ // a higher-priority source.
+ bool PrefValueFromExtensionStore(const wchar_t* name);
+ bool PrefValueFromUserStore(const wchar_t* name);
private:
// PrefStores must be listed here in order from highest to lowest priority.
@@ -97,6 +105,10 @@ class PrefValueStore {
scoped_ptr<PrefStore> pref_stores_[PREF_STORE_TYPE_MAX + 1];
+ bool PrefValueInStore(const wchar_t* name, PrefStoreType type);
+
+ bool PrefValueFromStore(const wchar_t* name, PrefStoreType type);
+
DISALLOW_COPY_AND_ASSIGN(PrefValueStore);
};
diff --git a/chrome/browser/pref_value_store_unittest.cc b/chrome/browser/pref_value_store_unittest.cc
index f18d676..3e0f496 100644
--- a/chrome/browser/pref_value_store_unittest.cc
+++ b/chrome/browser/pref_value_store_unittest.cc
@@ -18,7 +18,6 @@ using testing::Mock;
namespace prefs {
const wchar_t kCurrentThemeID[] = L"extensions.theme.id";
const wchar_t kDeleteCache[] = L"browser.clear_data.cache";
- const wchar_t kExtensionPref[] = L"extension.pref";
const wchar_t kHomepage[] = L"homepage";
const wchar_t kMaxTabs[] = L"tabs.max_tabs";
const wchar_t kMissingPref[] = L"this.pref.does_not_exist";
@@ -237,7 +236,7 @@ TEST_F(PrefValueStoreTest, SetUserPrefValue) {
Value* actual_value = NULL;
// Test that enforced values can not be set.
- ASSERT_TRUE(pref_value_store_->PrefValueIsManaged(prefs::kHomepage));
+ ASSERT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomepage));
// The Ownership is tranfered to |PrefValueStore|.
new_value = Value::CreateStringValue(L"http://www.youtube.com");
pref_value_store_->SetUserPrefValue(prefs::kHomepage, new_value);
@@ -248,7 +247,7 @@ TEST_F(PrefValueStoreTest, SetUserPrefValue) {
ASSERT_EQ(enforced_pref::kHomepageValue, value_str);
// User preferences values can be set
- ASSERT_FALSE(pref_value_store_->PrefValueIsManaged(prefs::kMaxTabs));
+ ASSERT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
actual_value = NULL;
pref_value_store_->GetValue(prefs::kMaxTabs, &actual_value);
int int_value;
@@ -284,21 +283,91 @@ TEST_F(PrefValueStoreTest, SetUserPrefValue) {
ASSERT_TRUE(expected_list_value->Equals(actual_value));
}
-TEST_F(PrefValueStoreTest, PrefValueIsManaged) {
+TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
// Test an enforced preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
- EXPECT_TRUE(pref_value_store_->PrefValueIsManaged(prefs::kHomepage));
+ EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomepage));
+
+ // Test an extension preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kCurrentThemeID));
+
+ // Test a user preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
+
+ // Test a preference from the recommended pref store.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kRecommendedPref));
+
+ // Test a preference for which the PrefValueStore does not contain a value.
+ ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMissingPref));
+}
+
+TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
+ // Test an enforced preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
+ EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomepage));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kHomepage));
+
+ // Test an extension preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kCurrentThemeID));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kCurrentThemeID));
// Test a user preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
- EXPECT_FALSE(pref_value_store_->PrefValueIsManaged(prefs::kMaxTabs));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(prefs::kMaxTabs));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(prefs::kMaxTabs));
// Test a preference from the recommended pref store.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
- EXPECT_FALSE(pref_value_store_->PrefValueIsManaged(prefs::kRecommendedPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kRecommendedPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kRecommendedPref));
// Test a preference for which the PrefValueStore does not contain a value.
ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
- EXPECT_FALSE(pref_value_store_->PrefValueIsManaged(prefs::kMissingPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kMissingPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kMissingPref));
}
+TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
+ // Test an enforced preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomepage));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomepage));
+
+ // Test an extension preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
+ prefs::kCurrentThemeID));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kCurrentThemeID));
+
+ // Test a user preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kMaxTabs));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(prefs::kMaxTabs));
+
+ // Test a preference from the recommended pref store.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
+ prefs::kRecommendedPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kRecommendedPref));
+
+ // Test a preference for which the PrefValueStore does not contain a value.
+ ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref));
+}