summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 08:40:58 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 08:40:58 +0000
commitce1850e90e8472a05fd9efdb8379c0d399d0be78 (patch)
tree4d1c28169195a01381d23fac5b07187f0ef7ab25 /chrome
parent817b6121b50d77b2eacc5ce594cc20fe4fddef6d (diff)
downloadchromium_src-ce1850e90e8472a05fd9efdb8379c0d399d0be78.zip
chromium_src-ce1850e90e8472a05fd9efdb8379c0d399d0be78.tar.gz
chromium_src-ce1850e90e8472a05fd9efdb8379c0d399d0be78.tar.bz2
When a proxy command line switches are specified, policy admin warning shouldn't be shown
Removed the logic from the ConfigurationPolicyPrefStore that sets managed preferences, it's now completely handled by CommandLinePrefStore. Moved the detection of conflicting proxy settings between the managed and other stores into the PrefValueStore. Implemented a sentinel value that can be used by stores to signal that they are returning the default value. Changed managed store to use this sentinel to hide non-managed proxy settings proxy settings when proxy policy is specified. BUG=54792 TEST=manual Review URL: http://codereview.chromium.org/3367021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/net/chrome_url_request_context_unittest.cc5
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc109
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.h26
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc153
-rw-r--r--chrome/browser/prefs/pref_notifier.cc2
-rw-r--r--chrome/browser/prefs/pref_service.cc1
-rw-r--r--chrome/browser/prefs/pref_service_unittest.cc165
-rw-r--r--chrome/browser/prefs/pref_value_store.cc73
-rw-r--r--chrome/browser/prefs/pref_value_store.h34
-rw-r--r--chrome/browser/prefs/pref_value_store_unittest.cc193
-rw-r--r--chrome/chrome_common.gypi2
-rw-r--r--chrome/common/json_pref_store.h1
-rw-r--r--chrome/common/pref_store.cc14
-rw-r--r--chrome/common/pref_store.h17
-rw-r--r--chrome/test/testing_pref_service.cc40
-rw-r--r--chrome/test/testing_pref_service.h23
16 files changed, 540 insertions, 318 deletions
diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc
index 906c1d1..f0947bd 100644
--- a/chrome/browser/net/chrome_url_request_context_unittest.cc
+++ b/chrome/browser/net/chrome_url_request_context_unittest.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/format_macros.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
+#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/prefs/default_pref_store.h"
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/common/chrome_switches.h"
@@ -161,8 +162,8 @@ TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) {
CommandLine command_line(tests[i].command_line);
// Only configuration-policy and default prefs are needed.
PrefService prefs(new TestingPrefService::TestingPrefValueStore(
- new policy::ConfigurationPolicyPrefStore(&command_line, NULL),
- NULL, NULL, NULL, NULL,
+ new policy::ConfigurationPolicyPrefStore(NULL), NULL,
+ new CommandLinePrefStore(&command_line), NULL, NULL,
new DefaultPrefStore()));
ChromeURLRequestContextGetter::RegisterUserPrefs(&prefs);
scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(&prefs));
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index 534c56b..0e73975 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/policy/configuration_policy_pref_store.h"
-#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/singleton.h"
@@ -244,27 +243,30 @@ ConfigurationPolicyPrefStore::GetChromePolicyValueMap() {
return map;
}
+void ConfigurationPolicyPrefStore::GetProxyPreferenceSet(
+ ProxyPreferenceSet* proxy_pref_set) {
+ proxy_pref_set->clear();
+ for (size_t current = 0; current < arraysize(proxy_policy_map_); ++current) {
+ proxy_pref_set->insert(proxy_policy_map_[current].preference_path);
+ }
+ proxy_pref_set->insert(prefs::kNoProxyServer);
+ proxy_pref_set->insert(prefs::kProxyAutoDetect);
+}
+
ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore(
- const CommandLine* command_line,
ConfigurationPolicyProvider* provider)
- : command_line_(command_line),
- provider_(provider),
+ : provider_(provider),
prefs_(new DictionaryValue()),
- command_line_proxy_settings_cleared_(false),
+ lower_priority_proxy_settings_overridden_(false),
proxy_disabled_(false),
proxy_configuration_specified_(false),
use_system_proxy_(false) {
}
PrefStore::PrefReadError ConfigurationPolicyPrefStore::ReadPrefs() {
- // Initialize proxy preference values from command-line switches. This is done
- // before calling Provide to allow the provider to overwrite proxy-related
- // preferences that are specified by line settings.
- ApplyProxySwitches();
-
proxy_disabled_ = false;
proxy_configuration_specified_ = false;
- command_line_proxy_settings_cleared_ = false;
+ lower_priority_proxy_settings_overridden_ = false;
bool success = (provider_ == NULL || provider_->Provide(this));
FinalizeDefaultSearchPolicySettings();
@@ -298,17 +300,17 @@ void ConfigurationPolicyPrefStore::Apply(PolicyType policy, Value* value) {
// static
ConfigurationPolicyPrefStore*
ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore() {
- return new ConfigurationPolicyPrefStore(CommandLine::ForCurrentProcess(),
- Singleton<ConfigurationPolicyProviderKeeper>::get()->managed_provider());
+ ConfigurationPolicyProviderKeeper* keeper =
+ Singleton<ConfigurationPolicyProviderKeeper>::get();
+ return new ConfigurationPolicyPrefStore(keeper->managed_provider());
}
// static
ConfigurationPolicyPrefStore*
ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() {
- ConfigurationPolicyProviderKeeper* manager =
+ ConfigurationPolicyProviderKeeper* keeper =
Singleton<ConfigurationPolicyProviderKeeper>::get();
- return new ConfigurationPolicyPrefStore(CommandLine::ForCurrentProcess(),
- manager->recommended_provider());
+ return new ConfigurationPolicyPrefStore(keeper->recommended_provider());
}
const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry*
@@ -345,40 +347,6 @@ bool ConfigurationPolicyPrefStore::ApplyPolicyFromMap(PolicyType policy,
return false;
}
-void ConfigurationPolicyPrefStore::ApplyProxySwitches() {
- bool proxy_disabled = command_line_->HasSwitch(switches::kNoProxyServer);
- if (proxy_disabled) {
- prefs_->Set(prefs::kNoProxyServer, Value::CreateBooleanValue(true));
- }
- bool has_explicit_proxy_config = false;
- if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
- has_explicit_proxy_config = true;
- prefs_->Set(prefs::kProxyAutoDetect, Value::CreateBooleanValue(true));
- }
- if (command_line_->HasSwitch(switches::kProxyServer)) {
- has_explicit_proxy_config = true;
- prefs_->Set(prefs::kProxyServer, Value::CreateStringValue(
- command_line_->GetSwitchValueASCII(switches::kProxyServer)));
- }
- if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
- has_explicit_proxy_config = true;
- prefs_->Set(prefs::kProxyPacUrl, Value::CreateStringValue(
- command_line_->GetSwitchValueASCII(switches::kProxyPacUrl)));
- }
- if (command_line_->HasSwitch(switches::kProxyBypassList)) {
- has_explicit_proxy_config = true;
- prefs_->Set(prefs::kProxyBypassList, Value::CreateStringValue(
- command_line_->GetSwitchValueASCII(switches::kProxyBypassList)));
- }
-
- // Warn about all the other proxy config switches we get if
- // the --no-proxy-server command-line argument is present.
- if (proxy_disabled && has_explicit_proxy_config) {
- LOG(WARNING) << "Additional command-line proxy switches specified when --"
- << switches::kNoProxyServer << " was also specified.";
- }
-}
-
bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(PolicyType policy,
Value* value) {
bool result = false;
@@ -389,23 +357,22 @@ bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(PolicyType policy,
FindPolicyInMap(policy, proxy_policy_map_, arraysize(proxy_policy_map_));
// When the first proxy-related policy is applied, ALL proxy-related
- // preferences that have been set by command-line switches must be
- // removed. Otherwise it's possible for a user to interfere with proxy
- // policy by using proxy-related switches that are related to, but not
- // identical, to the ones set through policy.
- if ((match_entry ||
- policy == ConfigurationPolicyPrefStore::kPolicyProxyServerMode) &&
- !command_line_proxy_settings_cleared_) {
- if (RemovePreferencesOfMap(proxy_policy_map_,
- arraysize(proxy_policy_map_))) {
- LOG(WARNING) << "proxy configuration options were specified on the"
- " command-line but will be ignored because an"
- " explicit proxy configuration has been specified"
- " through a centrally-administered policy.";
+ // preferences that have been set by command-line switches, extensions,
+ // user preferences or any other mechanism are overridden. Otherwise
+ // it's possible for a user to interfere with proxy policy by setting
+ // proxy-related command-line switches or set proxy-related prefs in an
+ // extension that are related, but not identical, to the ones set through
+ // policy.
+ if (!lower_priority_proxy_settings_overridden_ &&
+ (match_entry ||
+ policy == ConfigurationPolicyPrefStore::kPolicyProxyServerMode)) {
+ ProxyPreferenceSet proxy_preference_set;
+ GetProxyPreferenceSet(&proxy_preference_set);
+ for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin();
+ i != proxy_preference_set.end(); ++i) {
+ prefs_->Set(*i, PrefStore::CreateUseDefaultSentinelValue());
}
- prefs_->Remove(prefs::kNoProxyServer, NULL);
- prefs_->Remove(prefs::kProxyAutoDetect, NULL);
- command_line_proxy_settings_cleared_ = true;
+ lower_priority_proxy_settings_overridden_ = true;
}
// Translate the proxy policy into preferences.
@@ -446,16 +413,6 @@ bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(PolicyType policy,
prefs_->Set(prefs::kProxyAutoDetect,
Value::CreateBooleanValue(proxy_auto_detect));
}
-
- // No proxy and system proxy mode should ensure that no other
- // proxy preferences are set.
- if (int_value == ConfigurationPolicyStore::kPolicyNoProxyServerMode ||
- int_value == kPolicyUseSystemProxyMode) {
- for (const PolicyToPreferenceMapEntry* current = proxy_policy_map_;
- current != proxy_policy_map_ + arraysize(proxy_policy_map_);
- ++current)
- prefs_->Remove(current->preference_path, NULL);
- }
}
} else if (match_entry) {
// Determine if the applied proxy policy settings conflict and issue
diff --git a/chrome/browser/policy/configuration_policy_pref_store.h b/chrome/browser/policy/configuration_policy_pref_store.h
index 0776cec..8f8167d 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.h
+++ b/chrome/browser/policy/configuration_policy_pref_store.h
@@ -7,7 +7,7 @@
#pragma once
#include <string>
-
+#include <set>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
@@ -16,8 +16,6 @@
#include "chrome/browser/policy/configuration_policy_store.h"
#include "chrome/common/pref_store.h"
-class CommandLine;
-
namespace policy {
// An implementation of the |PrefStore| that holds a Dictionary
@@ -27,8 +25,7 @@ class ConfigurationPolicyPrefStore : public PrefStore,
public:
// The ConfigurationPolicyPrefStore does not take ownership of the
// passed-in |provider|.
- ConfigurationPolicyPrefStore(const CommandLine* command_line,
- ConfigurationPolicyProvider* provider);
+ explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider);
virtual ~ConfigurationPolicyPrefStore() { }
// PrefStore methods:
@@ -48,6 +45,12 @@ class ConfigurationPolicyPrefStore : public PrefStore,
static ConfigurationPolicyProvider::StaticPolicyValueMap
GetChromePolicyValueMap();
+ typedef std::set<const char*> ProxyPreferenceSet;
+
+ // Returns the set of preference paths that can be affected by a proxy
+ // policy.
+ static void GetProxyPreferenceSet(ProxyPreferenceSet* proxy_pref_set);
+
private:
// Policies that map to a single preference are handled
// by an automated converter. Each one of these policies
@@ -64,14 +67,13 @@ class ConfigurationPolicyPrefStore : public PrefStore,
static const ConfigurationPolicyProvider::StaticPolicyValueMap
policy_value_map_;
- const CommandLine* command_line_;
ConfigurationPolicyProvider* provider_;
scoped_ptr<DictionaryValue> prefs_;
- // Set to false until the first proxy-relevant policy is applied. Allows
- // the Apply method to erase all switch-specified proxy configuration before
- // applying proxy policy configuration;
- bool command_line_proxy_settings_cleared_;
+ // Set to false until the first proxy-relevant policy is applied. At that
+ // time, default values are provided for all proxy-relevant prefs
+ // to override any values set from stores with a lower priority.
+ bool lower_priority_proxy_settings_overridden_;
// The following are used to track what proxy-relevant policy has been applied
// accross calls to Apply to provide a warning if a policy specifies a
@@ -98,10 +100,6 @@ class ConfigurationPolicyPrefStore : public PrefStore,
bool ApplyPolicyFromMap(PolicyType policy, Value* value,
const PolicyToPreferenceMapEntry map[], int size);
- // Initializes default preference values from proxy-related command-line
- // switches in |command_line_|.
- void ApplyProxySwitches();
-
// Processes proxy-specific policies. Returns true if the specified policy
// is a proxy-related policy. ApplyProxyPolicy assumes the ownership
// of |value| in the case that the policy is proxy-specific.
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index 0774cb7..2d13c2f 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -4,7 +4,6 @@
#include <gtest/gtest.h>
-#include "base/command_line.h"
#include "base/file_path.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/policy/mock_configuration_policy_provider.h"
@@ -34,13 +33,13 @@ class ConfigurationPolicyPrefStoreListTest
};
TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
ListValue* list = NULL;
EXPECT_FALSE(store.prefs()->GetList(GetParam().pref_name(), &list));
}
TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
ListValue* in_value = new ListValue();
in_value->Append(Value::CreateStringValue("test1"));
in_value->Append(Value::CreateStringValue("test2,"));
@@ -80,13 +79,13 @@ class ConfigurationPolicyPrefStoreStringTest
};
TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
std::string result;
EXPECT_FALSE(store.prefs()->GetString(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(GetParam().type(),
Value::CreateStringValue("http://chromium.org"));
std::string result;
@@ -115,13 +114,13 @@ class ConfigurationPolicyPrefStoreBooleanTest
};
TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
bool result = false;
EXPECT_FALSE(store.prefs()->GetBoolean(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(GetParam().type(), Value::CreateBooleanValue(false));
bool result = true;
EXPECT_TRUE(store.prefs()->GetBoolean(GetParam().pref_name(), &result));
@@ -180,13 +179,13 @@ class ConfigurationPolicyPrefStoreIntegerTest
};
TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
int result = 0;
EXPECT_FALSE(store.prefs()->GetInteger(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(GetParam().type(), Value::CreateIntegerValue(2));
int result = 0;
EXPECT_TRUE(store.prefs()->GetInteger(GetParam().pref_name(), &result));
@@ -204,79 +203,38 @@ INSTANTIATE_TEST_CASE_P(
class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
};
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, CommandLine) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- command_line.AppendSwitch(switches::kNoProxyServer);
- command_line.AppendSwitch(switches::kProxyAutoDetect);
- command_line.AppendSwitchASCII(switches::kProxyPacUrl,
- "http://chromium.org/test.pac");
- command_line.AppendSwitchASCII(switches::kProxyServer,
- "http://chromium2.org");
- command_line.AppendSwitchASCII(switches::kProxyBypassList,
- "http://chromium3.org");
-
- ConfigurationPolicyPrefStore store(&command_line, NULL);
- EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
-
- // Ensure that all traces of the command-line specified proxy
- // switches have been overriden.
- std::string string_result;
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_EQ(string_result, "http://chromium3.org");
-
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_EQ(string_result, "http://chromium.org/test.pac");
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
- EXPECT_EQ(string_result, "http://chromium2.org");
- bool bool_result;
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
- EXPECT_TRUE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
- EXPECT_TRUE(bool_result);
-}
-
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOverride) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- command_line.AppendSwitch(switches::kNoProxyServer);
- command_line.AppendSwitch(switches::kProxyAutoDetect);
- command_line.AppendSwitchASCII(switches::kProxyPacUrl,
- "http://chromium.org/test.pac");
- command_line.AppendSwitchASCII(switches::kProxyServer,
- "http://chromium.org");
- command_line.AppendSwitchASCII(switches::kProxyBypassList,
- "http://chromium.org");
-
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
+ provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
+ Value::CreateStringValue("http://chromium.org/override"));
+ provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyPacUrl,
+ Value::CreateStringValue("http://chromium.org/proxy.pac"));
+ provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServer,
+ Value::CreateStringValue("chromium.org"));
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode,
Value::CreateIntegerValue(
ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode));
- provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
- Value::CreateStringValue("http://chromium.org/override"));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
- // Ensure that all traces of the command-line specified proxy
- // switches have been overriden.
std::string string_result;
EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
&string_result));
- EXPECT_EQ(string_result, "http://chromium.org/override");
-
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_EQ("http://chromium.org/override", string_result);
+ EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_EQ("http://chromium.org/proxy.pac", string_result);
+ EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_EQ("chromium.org", string_result);
bool bool_result;
EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_FALSE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
EXPECT_FALSE(bool_result);
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
@@ -285,25 +243,22 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
Value::CreateIntegerValue(
ConfigurationPolicyStore::kPolicyNoProxyServerMode));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
std::string string_result;
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
&string_result));
-
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_TRUE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
EXPECT_FALSE(bool_result);
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode,
@@ -312,55 +267,44 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
Value::CreateStringValue("http://chromium.org/override"));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
std::string string_result;
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
&string_result));
-
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_TRUE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
EXPECT_FALSE(bool_result);
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
- provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
- Value::CreateStringValue("http://chromium.org/override"));
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode,
Value::CreateIntegerValue(
ConfigurationPolicyStore::kPolicyAutoDetectProxyMode));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
- // Ensure that all traces of the command-line specified proxy
- // switches have been overriden.
std::string string_result;
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_EQ(string_result, "http://chromium.org/override");
-
+ EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_FALSE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
EXPECT_TRUE(bool_result);
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
@@ -369,14 +313,12 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
Value::CreateIntegerValue(
ConfigurationPolicyStore::kPolicyUseSystemProxyMode));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
std::string string_result;
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_EQ(string_result, "");
-
+ &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
@@ -386,7 +328,6 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
scoped_ptr<MockConfigurationPolicyProvider> provider(
new MockConfigurationPolicyProvider());
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode,
@@ -395,14 +336,12 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList,
Value::CreateStringValue("http://chromium.org/override"));
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
std::string string_result;
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_EQ(string_result, "");
-
+ &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
@@ -427,8 +366,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL,
Value::CreateStringValue(search_url));
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
DictionaryValue* prefs = store.prefs();
@@ -492,8 +430,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
DictionaryValue* prefs = store.prefs();
@@ -557,8 +494,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
DictionaryValue* prefs = store.prefs();
@@ -610,8 +546,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
- ConfigurationPolicyPrefStore store(&command_line, provider.get());
+ ConfigurationPolicyPrefStore store(provider.get());
EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
DictionaryValue* prefs = store.prefs();
@@ -637,13 +572,13 @@ class ConfigurationPolicyPrefStoreSyncTest : public testing::Test {
};
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
bool result = false;
EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result));
}
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(ConfigurationPolicyPrefStore::kPolicySyncDisabled,
Value::CreateBooleanValue(false));
// Enabling Sync should not set the pref.
@@ -652,7 +587,7 @@ TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
}
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(ConfigurationPolicyPrefStore::kPolicySyncDisabled,
Value::CreateBooleanValue(true));
// Sync should be flagged as managed.
@@ -666,13 +601,13 @@ class ConfigurationPolicyPrefStoreAutoFillTest : public testing::Test {
};
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
bool result = false;
EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
}
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(ConfigurationPolicyPrefStore::kPolicyAutoFillEnabled,
Value::CreateBooleanValue(true));
// Enabling AutoFill should not set the pref.
@@ -681,7 +616,7 @@ TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
}
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) {
- ConfigurationPolicyPrefStore store(NULL, NULL);
+ ConfigurationPolicyPrefStore store(NULL);
store.Apply(ConfigurationPolicyPrefStore::kPolicyAutoFillEnabled,
Value::CreateBooleanValue(false));
// Disabling AutoFill should switch the pref to managed.
diff --git a/chrome/browser/prefs/pref_notifier.cc b/chrome/browser/prefs/pref_notifier.cc
index 7c02fc7..151b128 100644
--- a/chrome/browser/prefs/pref_notifier.cc
+++ b/chrome/browser/prefs/pref_notifier.cc
@@ -132,8 +132,6 @@ void PrefNotifier::Observe(NotificationType type,
NewRunnableMethod(
pref_value_store_,
&PrefValueStore::RefreshPolicyPrefs,
- ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(),
- ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(),
callback));
}
}
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 80b3d38..c249789 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -385,6 +385,7 @@ void PrefService::RegisterPreference(const char* path, Value* default_value) {
pref_value_store_->SetDefaultPrefValue(path, Value::CreateNullValue());
} else {
// Hand off ownership.
+ DCHECK(!PrefStore::IsUseDefaultSentinelValue(default_value));
pref_value_store_->SetDefaultPrefValue(path, scoped_value.release());
}
diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc
index d62679d..44161d7 100644
--- a/chrome/browser/prefs/pref_service_unittest.cc
+++ b/chrome/browser/prefs/pref_service_unittest.cc
@@ -5,12 +5,19 @@
#include <string>
#include "app/test/data/resource.h"
+#include "base/command_line.h"
#include "base/scoped_ptr.h"
#include "base/values.h"
+#include "chrome/browser/policy/configuration_policy_pref_store.h"
+#include "chrome/browser/policy/mock_configuration_policy_provider.h"
+#include "chrome/browser/prefs/browser_prefs.h"
+#include "chrome/browser/prefs/command_line_pref_store.h"
+#include "chrome/browser/prefs/default_pref_store.h"
#include "chrome/browser/prefs/dummy_pref_store.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_observer_mock.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
@@ -178,6 +185,164 @@ TEST(PrefServiceTest, Observers) {
EXPECT_TRUE(obs2.observer_fired());
}
+TEST(PrefServiceTest, ProxyFromCommandLineNotPolicy) {
+ CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
+ command_line.AppendSwitch(switches::kProxyAutoDetect);
+ TestingPrefService prefs(NULL, &command_line);
+ browser::RegisterUserPrefs(&prefs);
+ EXPECT_TRUE(prefs.GetBoolean(prefs::kProxyAutoDetect));
+ const PrefService::Preference* pref =
+ prefs.FindPreference(prefs::kProxyAutoDetect);
+ ASSERT_TRUE(pref);
+ EXPECT_FALSE(pref->IsManaged());
+}
+
+TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
+ CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
+ command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
+ command_line.AppendSwitchASCII(switches::kProxyPacUrl, "456");
+ command_line.AppendSwitchASCII(switches::kProxyServer, "789");
+ scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
+ new policy::MockConfigurationPolicyProvider());
+ Value* mode_value = Value::CreateIntegerValue(
+ policy::ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode);
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyServerMode,
+ mode_value);
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyBypassList,
+ Value::CreateStringValue("abc"));
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyPacUrl,
+ Value::CreateStringValue("def"));
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyServer,
+ Value::CreateStringValue("ghi"));
+
+ // First verify that command-line options are set correctly when
+ // there is no policy in effect.
+ TestingPrefService prefs(NULL, &command_line);
+ browser::RegisterUserPrefs(&prefs);
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("789", prefs.GetString(prefs::kProxyServer));
+ EXPECT_EQ("456", prefs.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("123", prefs.GetString(prefs::kProxyBypassList));
+
+ // Try a second time time with the managed PrefStore in place, the
+ // manual proxy policy should have removed all traces of the command
+ // line and replaced them with the policy versions.
+ TestingPrefService prefs2(provider.get(), &command_line);
+ browser::RegisterUserPrefs(&prefs2);
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("ghi", prefs2.GetString(prefs::kProxyServer));
+ EXPECT_EQ("def", prefs2.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("abc", prefs2.GetString(prefs::kProxyBypassList));
+}
+
+TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
+ CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
+ command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
+ command_line.AppendSwitchASCII(switches::kProxyPacUrl, "456");
+ command_line.AppendSwitchASCII(switches::kProxyServer, "789");
+ scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
+ new policy::MockConfigurationPolicyProvider());
+ Value* mode_value = Value::CreateIntegerValue(
+ policy::ConfigurationPolicyStore::kPolicyUseSystemProxyMode);
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyServerMode,
+ mode_value);
+
+ // First verify that command-line options are set correctly when
+ // there is no policy in effect.
+ TestingPrefService prefs(NULL, &command_line);
+ browser::RegisterUserPrefs(&prefs);
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("789", prefs.GetString(prefs::kProxyServer));
+ EXPECT_EQ("456", prefs.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("123", prefs.GetString(prefs::kProxyBypassList));
+
+ // Try a second time time with the managed PrefStore in place, the
+ // no proxy policy should have removed all traces of the command
+ // line proxy settings, even though they were not the specific one
+ // set in policy.
+ TestingPrefService prefs2(provider.get(), &command_line);
+ browser::RegisterUserPrefs(&prefs2);
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyBypassList));
+}
+
+TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
+ CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
+ command_line.AppendSwitch(switches::kNoProxyServer);
+ scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
+ new policy::MockConfigurationPolicyProvider());
+ Value* mode_value = Value::CreateIntegerValue(
+ policy::ConfigurationPolicyStore::kPolicyAutoDetectProxyMode);
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyServerMode,
+ mode_value);
+
+ // First verify that command-line options are set correctly when
+ // there is no policy in effect.
+ TestingPrefService prefs(NULL, &command_line);
+ browser::RegisterUserPrefs(&prefs);
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_TRUE(prefs.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyServer));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyBypassList));
+
+ // Try a second time time with the managed PrefStore in place, the
+ // auto-detect should be overridden. The default pref store must be
+ // in place with the appropriate default value for this to work.
+ TestingPrefService prefs2(provider.get(), &command_line);
+ browser::RegisterUserPrefs(&prefs2);
+ EXPECT_TRUE(prefs2.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyBypassList));
+}
+
+TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
+ CommandLine command_line(CommandLine::ARGUMENTS_ONLY);
+ command_line.AppendSwitch(switches::kProxyAutoDetect);
+ scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
+ new policy::MockConfigurationPolicyProvider());
+ Value* mode_value = Value::CreateIntegerValue(
+ policy::ConfigurationPolicyStore::kPolicyNoProxyServerMode);
+ provider->AddPolicy(
+ policy::ConfigurationPolicyStore::kPolicyProxyServerMode,
+ mode_value);
+
+ // First verify that the auto-detect is set if there is no managed
+ // PrefStore.
+ TestingPrefService prefs(NULL, &command_line);
+ browser::RegisterUserPrefs(&prefs);
+ EXPECT_TRUE(prefs.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_FALSE(prefs.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyServer));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("", prefs.GetString(prefs::kProxyBypassList));
+
+ // Try a second time time with the managed PrefStore in place, the
+ // auto-detect should be overridden. The default pref store must be
+ // in place with the appropriate default value for this to work.
+ TestingPrefService prefs2(provider.get(), &command_line);
+ browser::RegisterUserPrefs(&prefs2);
+ EXPECT_FALSE(prefs2.GetBoolean(prefs::kProxyAutoDetect));
+ EXPECT_TRUE(prefs2.GetBoolean(prefs::kNoProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyServer));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyPacUrl));
+ EXPECT_EQ("", prefs2.GetString(prefs::kProxyBypassList));
+}
+
class PrefServiceSetValueTest : public testing::Test {
protected:
static const char name_[];
diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc
index dce8388..dd3085a 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -118,6 +118,13 @@ PrefStore::PrefReadError PrefValueStore::ReadPrefs() {
result = this_error;
}
}
+
+ if (HasPolicyConflictingUserProxySettings()) {
+ LOG(WARNING) << "user-requested proxy options have been overridden"
+ << " by a proxy configuration specified in a centrally"
+ << " administered policy.";
+ }
+
// TODO(markusheintz): Return a better error status: maybe a struct with
// the error status of all PrefStores.
return result;
@@ -196,6 +203,23 @@ bool PrefValueStore::PrefValueInUserStore(const char* name) const {
return PrefValueInStore(name, PrefNotifier::USER_STORE);
}
+bool PrefValueStore::PrefValueInStoreRange(
+ const char* name,
+ PrefNotifier::PrefStoreType first_checked_store,
+ PrefNotifier::PrefStoreType last_checked_store) {
+ if (first_checked_store > last_checked_store) {
+ NOTREACHED();
+ return false;
+ }
+
+ for (size_t i = first_checked_store;
+ i <= static_cast<size_t>(last_checked_store); ++i) {
+ if (PrefValueInStore(name, static_cast<PrefNotifier::PrefStoreType>(i)))
+ return true;
+ }
+ return false;
+}
+
bool PrefValueStore::PrefValueFromExtensionStore(const char* name) const {
return ControllingPrefStoreForPref(name) == PrefNotifier::EXTENSION_STORE;
}
@@ -240,9 +264,23 @@ bool PrefValueStore::GetValueFromStore(
// Only return true if we find a value and it is the correct type, so stale
// values with the incorrect type will be ignored.
if (pref_stores_[store].get() &&
- pref_stores_[store]->prefs()->Get(name, out_value) &&
- IsValidType(GetRegisteredType(name), (*out_value)->GetType(), store)) {
- return true;
+ pref_stores_[store]->prefs()->Get(name, out_value)) {
+ // If the value is the sentinel that redirects to the default
+ // store, re-fetch the value from the default store explicitly.
+ // Because the default values are not available when creating
+ // stores, the default value must be fetched dynamically for every
+ // redirect.
+ if (PrefStore::IsUseDefaultSentinelValue(*out_value)) {
+ DCHECK(pref_stores_[PrefNotifier::DEFAULT_STORE].get());
+ if (!pref_stores_[PrefNotifier::DEFAULT_STORE]->prefs()->Get(name,
+ out_value)) {
+ *out_value = NULL;
+ return false;
+ }
+ store = PrefNotifier::DEFAULT_STORE;
+ }
+ if (IsValidType(GetRegisteredType(name), (*out_value)->GetType(), store))
+ return true;
}
// No valid value found for the given preference name: set the return false.
*out_value = NULL;
@@ -319,9 +357,19 @@ void PrefValueStore::RefreshPolicyPrefsOnFileThread(
}
void PrefValueStore::RefreshPolicyPrefs(
- PrefStore* new_managed_pref_store,
- PrefStore* new_recommended_pref_store,
AfterRefreshCallback* callback) {
+ using policy::ConfigurationPolicyPrefStore;
+ // Because loading of policy information must happen on the FILE
+ // thread, it's not possible to just replace the contents of the
+ // managed and recommended stores in place due to possible
+ // concurrent access from the UI thread. Instead, new stores are
+ // 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.
+ PrefStore* new_managed_pref_store(
+ ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore());
+ PrefStore* new_recommended_pref_store(
+ ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore());
BrowserThread::ID current_thread_id;
CHECK(BrowserThread::GetCurrentThreadIdentifier(&current_thread_id));
BrowserThread::PostTask(
@@ -334,6 +382,21 @@ void PrefValueStore::RefreshPolicyPrefs(
callback));
}
+bool PrefValueStore::HasPolicyConflictingUserProxySettings() {
+ using policy::ConfigurationPolicyPrefStore;
+ ConfigurationPolicyPrefStore::ProxyPreferenceSet proxy_prefs;
+ ConfigurationPolicyPrefStore::GetProxyPreferenceSet(&proxy_prefs);
+ ConfigurationPolicyPrefStore::ProxyPreferenceSet::const_iterator i;
+ for (i = proxy_prefs.begin(); i != proxy_prefs.end(); ++i) {
+ if (PrefValueInManagedStore(*i) &&
+ PrefValueInStoreRange(*i,
+ PrefNotifier::COMMAND_LINE_STORE,
+ PrefNotifier::USER_STORE))
+ return true;
+ }
+ return false;
+}
+
PrefValueStore::PrefValueStore(PrefStore* managed_prefs,
PrefStore* extension_prefs,
PrefStore* command_line_prefs,
diff --git a/chrome/browser/prefs/pref_value_store.h b/chrome/browser/prefs/pref_value_store.h
index b59179c..3970aeb 100644
--- a/chrome/browser/prefs/pref_value_store.h
+++ b/chrome/browser/prefs/pref_value_store.h
@@ -126,6 +126,14 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
bool PrefValueInExtensionStore(const char* name) const;
bool PrefValueInUserStore(const char* name) const;
+ // Returns true if a preference has an explicit value in any of the
+ // stores in the range specified by |first_checked_store| and
+ // |last_checked_store|, even if that value is currently being
+ // overridden by a higher-priority store.
+ bool PrefValueInStoreRange(const char* name,
+ PrefNotifier::PrefStoreType first_checked_store,
+ PrefNotifier::PrefStoreType last_checked_store);
+
// 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.
@@ -151,19 +159,19 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
typedef Callback1<std::vector<std::string> >::Type AfterRefreshCallback;
// Called as a result of a notification of policy change. Triggers a
- // reload of managed preferences from policy. Caller must pass in
- // new, uninitialized managed and recommended PrefStores in
- // |managed_pref_store| and |recommended_pref_store| respectively, since
- // PrefValueStore doesn't know about policy-specific PrefStores.
- // |callback| is called with the set of preferences changed by the policy
- // refresh. |callback| is called on the caller's thread as a Task
- // after RefreshPolicyPrefs has returned. RefreshPolicyPrefs takes ownership
- // of the |callback| object.
- void RefreshPolicyPrefs(PrefStore* managed_pref_store,
- PrefStore* recommended_pref_store,
- AfterRefreshCallback* callback);
-
- protected:
+ // reload of managed preferences from policy from a Task on the FILE
+ // thread. The Task will take ownership of the |callback|. |callback| is
+ // called with the set of preferences changed by the policy refresh.
+ // |callback| is called on the caller's thread as a Task after
+ // RefreshPolicyPrefs has returned.
+ void RefreshPolicyPrefs(AfterRefreshCallback* callback);
+
+ // Returns true if there are proxy preferences in user-modifiable
+ // preference stores (e.g. CommandLinePrefStore, ExtensionPrefStore)
+ // that conflict with proxy settings specified by proxy policy.
+ bool HasPolicyConflictingUserProxySettings();
+
+ protected:
// In decreasing order of precedence:
// |managed_prefs| contains all managed (policy) preference values.
// |extension_prefs| contains preference values set by extensions.
diff --git a/chrome/browser/prefs/pref_value_store_unittest.cc b/chrome/browser/prefs/pref_value_store_unittest.cc
index a5d40aa..8db6b36 100644
--- a/chrome/browser/prefs/pref_value_store_unittest.cc
+++ b/chrome/browser/prefs/pref_value_store_unittest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/prefs/dummy_pref_store.h"
#include "chrome/browser/prefs/pref_value_store.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -27,55 +28,47 @@ class MockPolicyRefreshCallback {
// Names of the preferences used in this test program.
namespace prefs {
- const char kCurrentThemeID[] = "extensions.theme.id";
- const char kDeleteCache[] = "browser.clear_data.cache";
- const char kHomepage[] = "homepage";
- const char kMaxTabs[] = "tabs.max_tabs";
- const char kMissingPref[] = "this.pref.does_not_exist";
- const char kRecommendedPref[] = "this.pref.recommended_value_only";
- const char kSampleDict[] = "sample.dict";
- const char kSampleList[] = "sample.list";
- const char kDefaultPref[] = "default.pref";
-
- // This must match the actual pref name so the command-line store knows about
- // it.
- const char kApplicationLocale[] = "intl.app_locale";
+const char kMissingPref[] = "this.pref.does_not_exist";
+const char kRecommendedPref[] = "this.pref.recommended_value_only";
+const char kSampleDict[] = "sample.dict";
+const char kSampleList[] = "sample.list";
+const char kDefaultPref[] = "default.pref";
}
// Potentially expected values of all preferences used in this test program.
namespace enforced_pref {
- const std::string kHomepageValue = "http://www.topeka.com";
+const std::string kHomepageValue = "http://www.topeka.com";
}
namespace extension_pref {
- const char kCurrentThemeIDValue[] = "set by extension";
- const char kHomepageValue[] = "http://www.chromium.org";
+const char kCurrentThemeIDValue[] = "set by extension";
+const char kHomepageValue[] = "http://www.chromium.org";
}
namespace command_line_pref {
- const char kApplicationLocaleValue[] = "hi-MOM";
- const char kCurrentThemeIDValue[] = "zyxwvut";
- const char kHomepageValue[] = "http://www.ferretcentral.org";
+const char kApplicationLocaleValue[] = "hi-MOM";
+const char kCurrentThemeIDValue[] = "zyxwvut";
+const char kHomepageValue[] = "http://www.ferretcentral.org";
}
// The "user" namespace is defined globally in an ARM system header, so we need
// something different here.
namespace user_pref {
- const int kMaxTabsValue = 31;
- const bool kDeleteCacheValue = true;
- const char kCurrentThemeIDValue[] = "abcdefg";
- const char kHomepageValue[] = "http://www.google.com";
- const char kApplicationLocaleValue[] = "is-WRONG";
+const int kStabilityLaunchCountValue = 31;
+const bool kDeleteCacheValue = true;
+const char kCurrentThemeIDValue[] = "abcdefg";
+const char kHomepageValue[] = "http://www.google.com";
+const char kApplicationLocaleValue[] = "is-WRONG";
}
namespace recommended_pref {
- const int kMaxTabsValue = 10;
- const bool kRecommendedPrefValue = true;
+const int kStabilityLaunchCountValue = 10;
+const bool kRecommendedPrefValue = true;
}
namespace default_pref {
- const int kDefaultValue = 7;
- const char kHomepageValue[] = "default homepage";
+const int kDefaultValue = 7;
+const char kHomepageValue[] = "default homepage";
}
class PrefValueStoreTest : public testing::Test {
@@ -120,9 +113,9 @@ class PrefValueStoreTest : public testing::Test {
Value::TYPE_STRING);
pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache,
Value::TYPE_BOOLEAN);
- pref_value_store_->RegisterPreferenceType(prefs::kHomepage,
+ pref_value_store_->RegisterPreferenceType(prefs::kHomePage,
Value::TYPE_STRING);
- pref_value_store_->RegisterPreferenceType(prefs::kMaxTabs,
+ pref_value_store_->RegisterPreferenceType(prefs::kStabilityLaunchCount,
Value::TYPE_INTEGER);
pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref,
Value::TYPE_BOOLEAN);
@@ -132,6 +125,8 @@ class PrefValueStoreTest : public testing::Test {
Value::TYPE_LIST);
pref_value_store_->RegisterPreferenceType(prefs::kDefaultPref,
Value::TYPE_INTEGER);
+ pref_value_store_->RegisterPreferenceType(prefs::kProxyAutoDetect,
+ Value::TYPE_BOOLEAN);
ui_thread_.reset(new BrowserThread(BrowserThread::UI, &loop_));
file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_));
@@ -142,19 +137,20 @@ class PrefValueStoreTest : public testing::Test {
DictionaryValue* CreateUserPrefs() {
DictionaryValue* user_prefs = new DictionaryValue();
user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue);
- user_prefs->SetInteger(prefs::kMaxTabs, user_pref::kMaxTabsValue);
+ user_prefs->SetInteger(prefs::kStabilityLaunchCount,
+ user_pref::kStabilityLaunchCountValue);
user_prefs->SetString(prefs::kCurrentThemeID,
user_pref::kCurrentThemeIDValue);
user_prefs->SetString(prefs::kApplicationLocale,
user_pref::kApplicationLocaleValue);
- user_prefs->SetString(prefs::kHomepage, user_pref::kHomepageValue);
+ user_prefs->SetString(prefs::kHomePage, user_pref::kHomepageValue);
return user_prefs;
}
DictionaryValue* CreateEnforcedPrefs() {
DictionaryValue* enforced_prefs = new DictionaryValue();
- enforced_prefs->SetString(prefs::kHomepage, enforced_pref::kHomepageValue);
- expected_differing_paths_.push_back(prefs::kHomepage);
+ enforced_prefs->SetString(prefs::kHomePage, enforced_pref::kHomepageValue);
+ expected_differing_paths_.push_back(prefs::kHomePage);
return enforced_prefs;
}
@@ -162,7 +158,7 @@ class PrefValueStoreTest : public testing::Test {
DictionaryValue* extension_prefs = new DictionaryValue();
extension_prefs->SetString(prefs::kCurrentThemeID,
extension_pref::kCurrentThemeIDValue);
- extension_prefs->SetString(prefs::kHomepage,
+ extension_prefs->SetString(prefs::kHomePage,
extension_pref::kHomepageValue);
return extension_prefs;
}
@@ -173,26 +169,27 @@ class PrefValueStoreTest : public testing::Test {
command_line_pref::kCurrentThemeIDValue);
command_line_prefs->SetString(prefs::kApplicationLocale,
command_line_pref::kApplicationLocaleValue);
- command_line_prefs->SetString(prefs::kHomepage,
+ command_line_prefs->SetString(prefs::kHomePage,
command_line_pref::kHomepageValue);
return command_line_prefs;
}
DictionaryValue* CreateRecommendedPrefs() {
DictionaryValue* recommended_prefs = new DictionaryValue();
- recommended_prefs->SetInteger(prefs::kMaxTabs,
- recommended_pref::kMaxTabsValue);
+ recommended_prefs->SetInteger(prefs::kStabilityLaunchCount,
+ recommended_pref::kStabilityLaunchCountValue);
recommended_prefs->SetBoolean(
prefs::kRecommendedPref,
recommended_pref::kRecommendedPrefValue);
// Expected differing paths must be added in lexicographic order
// to work properly
- expected_differing_paths_.push_back("tabs");
- expected_differing_paths_.push_back(prefs::kMaxTabs);
expected_differing_paths_.push_back("this");
expected_differing_paths_.push_back("this.pref");
expected_differing_paths_.push_back(prefs::kRecommendedPref);
+ expected_differing_paths_.push_back("user_experience_metrics");
+ expected_differing_paths_.push_back("user_experience_metrics.stability");
+ expected_differing_paths_.push_back(prefs::kStabilityLaunchCount);
return recommended_prefs;
}
@@ -273,7 +270,7 @@ TEST_F(PrefValueStoreTest, GetValue) {
// Test getting an enforced value overwriting a user-defined and
// extension-defined value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomepage, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value));
std::string actual_str_value;
EXPECT_TRUE(value->GetAsString(&actual_str_value));
EXPECT_EQ(enforced_pref::kHomepageValue, actual_str_value);
@@ -300,10 +297,11 @@ TEST_F(PrefValueStoreTest, GetValue) {
// Test getting a user set value overwriting a recommended value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kMaxTabs, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount,
+ &value));
int actual_int_value = -1;
EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
- EXPECT_EQ(user_pref::kMaxTabsValue, actual_int_value);
+ EXPECT_EQ(user_pref::kStabilityLaunchCountValue, actual_int_value);
// Test getting a recommended value.
value = NULL;
@@ -331,26 +329,28 @@ TEST_F(PrefValueStoreTest, GetValue) {
// the user pref file, it uses the correct fallback value instead.
TEST_F(PrefValueStoreTest, GetValueChangedType) {
// Check falling back to a recommended value.
- user_pref_store_->prefs()->SetString(prefs::kMaxTabs, "not an integer");
+ user_pref_store_->prefs()->SetString(prefs::kStabilityLaunchCount,
+ "not an integer");
Value* value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kMaxTabs, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount,
+ &value));
ASSERT_TRUE(value != NULL);
ASSERT_EQ(Value::TYPE_INTEGER, value->GetType());
int actual_int_value = -1;
EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
- EXPECT_EQ(recommended_pref::kMaxTabsValue, actual_int_value);
+ EXPECT_EQ(recommended_pref::kStabilityLaunchCountValue, actual_int_value);
// Check falling back multiple times, to a default string.
- enforced_pref_store_->prefs()->SetInteger(prefs::kHomepage, 1);
- extension_pref_store_->prefs()->SetInteger(prefs::kHomepage, 1);
- command_line_pref_store_->prefs()->SetInteger(prefs::kHomepage, 1);
- user_pref_store_->prefs()->SetInteger(prefs::kHomepage, 1);
- recommended_pref_store_->prefs()->SetInteger(prefs::kHomepage, 1);
- default_pref_store_->prefs()->SetString(prefs::kHomepage,
+ enforced_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
+ extension_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
+ command_line_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
+ user_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
+ recommended_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
+ default_pref_store_->prefs()->SetString(prefs::kHomePage,
default_pref::kHomepageValue);
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomepage, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value));
ASSERT_TRUE(value != NULL);
ASSERT_EQ(Value::TYPE_STRING, value->GetType());
std::string actual_str_value;
@@ -360,7 +360,7 @@ TEST_F(PrefValueStoreTest, GetValueChangedType) {
TEST_F(PrefValueStoreTest, HasPrefPath) {
// Enforced preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
+ EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
// User preference
EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache));
// Recommended preference
@@ -426,28 +426,29 @@ TEST_F(PrefValueStoreTest, SetUserPrefValue) {
Value* actual_value = NULL;
// Test that enforced values can not be set.
- ASSERT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomepage));
+ ASSERT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomePage));
// The Ownership is tranfered to |PrefValueStore|.
new_value = Value::CreateStringValue("http://www.youtube.com");
- pref_value_store_->SetUserPrefValue(prefs::kHomepage, new_value);
+ pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value);
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomepage, &actual_value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value));
std::string value_str;
actual_value->GetAsString(&value_str);
ASSERT_EQ(enforced_pref::kHomepageValue, value_str);
// User preferences values can be set
- ASSERT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
+ ASSERT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kStabilityLaunchCount));
actual_value = NULL;
- pref_value_store_->GetValue(prefs::kMaxTabs, &actual_value);
+ pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value);
int int_value;
EXPECT_TRUE(actual_value->GetAsInteger(&int_value));
- EXPECT_EQ(user_pref::kMaxTabsValue, int_value);
+ EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value);
new_value = Value::CreateIntegerValue(1);
- pref_value_store_->SetUserPrefValue(prefs::kMaxTabs, new_value);
+ pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value);
actual_value = NULL;
- pref_value_store_->GetValue(prefs::kMaxTabs, &actual_value);
+ pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value);
EXPECT_TRUE(new_value->Equals(actual_value));
// Set and Get |DictionaryValue|
@@ -475,8 +476,8 @@ TEST_F(PrefValueStoreTest, SetUserPrefValue) {
TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
// Test an enforced preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
- EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomepage));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
+ EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomePage));
// Test an extension preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
@@ -489,8 +490,9 @@ TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
prefs::kApplicationLocale));
// Test a user preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kStabilityLaunchCount));
// Test a preference from the recommended pref store.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
@@ -509,10 +511,10 @@ TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
// Test an enforced preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
- EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomepage));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
+ EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomePage));
EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kHomepage));
+ prefs::kHomePage));
// Test an extension preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
@@ -529,9 +531,11 @@ TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
prefs::kApplicationLocale));
// Test a user preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
- EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(prefs::kMaxTabs));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(prefs::kMaxTabs));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kStabilityLaunchCount));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kStabilityLaunchCount));
// Test a preference from the recommended pref store.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
@@ -555,11 +559,25 @@ TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
prefs::kMissingPref));
}
+TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) {
+ // There should be no conflicting proxy prefs in the default
+ // preference stores created for the test.
+ ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings());
+
+ // Create conflicting proxy settings in the managed and command-line
+ // preference stores.
+ command_line_prefs_->SetBoolean(prefs::kProxyAutoDetect,
+ Value::CreateBooleanValue(false));
+ enforced_prefs_->SetBoolean(prefs::kProxyAutoDetect,
+ Value::CreateBooleanValue(true));
+ ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings());
+}
+
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));
+ 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));
@@ -576,9 +594,11 @@ TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
prefs::kApplicationLocale));
// 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));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
+ prefs::kStabilityLaunchCount));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kStabilityLaunchCount));
// Test a preference from the recommended pref store.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
@@ -600,8 +620,8 @@ TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
// Test an enforced preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomepage));
- EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomepage));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomePage));
// Test an extension preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
@@ -614,8 +634,9 @@ TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
prefs::kApplicationLocale));
// Test a user preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
- EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kMaxTabs));
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
+ prefs::kStabilityLaunchCount));
// Test a preference from the recommended pref store.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
@@ -645,8 +666,6 @@ TEST_F(PrefValueStoreTest, TestPolicyRefresh) {
NewRunnableMethod(
pref_value_store_.get(),
&PrefValueStore::RefreshPolicyPrefs,
- new DummyPrefStore(),
- new DummyPrefStore(),
NewCallback(&callback,
&MockPolicyRefreshCallback::DoCallback)));
Mock::VerifyAndClearExpectations(&callback);
@@ -723,8 +742,6 @@ TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) {
NewRunnableMethod(
pref_value_store_.get(),
&PrefValueStore::RefreshPolicyPrefs,
- new DummyPrefStore(),
- new DummyPrefStore(),
NewCallback(&callback1,
&MockPolicyRefreshCallback::DoCallback)));
EXPECT_CALL(callback1, DoCallback(_)).Times(0);
@@ -735,8 +752,6 @@ TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) {
NewRunnableMethod(
pref_value_store_.get(),
&PrefValueStore::RefreshPolicyPrefs,
- new DummyPrefStore(),
- new DummyPrefStore(),
NewCallback(&callback2,
&MockPolicyRefreshCallback::DoCallback)));
EXPECT_CALL(callback2, DoCallback(_)).Times(0);
@@ -747,8 +762,6 @@ TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) {
NewRunnableMethod(
pref_value_store_.get(),
&PrefValueStore::RefreshPolicyPrefs,
- new DummyPrefStore(),
- new DummyPrefStore(),
NewCallback(&callback3,
&MockPolicyRefreshCallback::DoCallback)));
EXPECT_CALL(callback3, DoCallback(_)).Times(0);
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 00b42b6..463752c 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -273,6 +273,8 @@
'common/plugin_messages.cc',
'common/plugin_messages.h',
'common/plugin_messages_internal.h',
+ 'common/pref_store.cc',
+ 'common/pref_store.h',
'common/render_messages.cc',
'common/render_messages.h',
'common/render_messages_params.cc',
diff --git a/chrome/common/json_pref_store.h b/chrome/common/json_pref_store.h
index ed17bbe..5211889 100644
--- a/chrome/common/json_pref_store.h
+++ b/chrome/common/json_pref_store.h
@@ -54,4 +54,3 @@ class JsonPrefStore : public PrefStore,
};
#endif // CHROME_COMMON_JSON_PREF_STORE_H_
-
diff --git a/chrome/common/pref_store.cc b/chrome/common/pref_store.cc
new file mode 100644
index 0000000..cf85417
--- /dev/null
+++ b/chrome/common/pref_store.cc
@@ -0,0 +1,14 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/common/pref_store.h"
+#include "base/values.h"
+
+Value* PrefStore::CreateUseDefaultSentinelValue() {
+ return Value::CreateNullValue();
+}
+
+bool PrefStore::IsUseDefaultSentinelValue(Value* value) {
+ return value->IsType(Value::TYPE_NULL);
+}
diff --git a/chrome/common/pref_store.h b/chrome/common/pref_store.h
index 727c020..192ce14 100644
--- a/chrome/common/pref_store.h
+++ b/chrome/common/pref_store.h
@@ -7,6 +7,7 @@
#pragma once
class DictionaryValue;
+class Value;
// This is an abstract interface for reading and writing from/to a persistent
// preference store, used by |PrefService|. An implementation using a JSON file
@@ -31,6 +32,18 @@ class PrefStore {
PREF_READ_ERROR_FILE_NOT_SPECIFIED
};
+ // To require that the default value be used for a preference, a
+ // PrefStore can set the value in its own prefs dictionary to the
+ // sentinel Value returned by this function.
+ // TODO(danno): Instead of having a sentinel value, pref stores
+ // should return a richer set of information from the property
+ // accessor methods to indicate that the default should be used.
+ static Value* CreateUseDefaultSentinelValue();
+
+ // Returns true if a value is the special sentinel value created by
+ // CreateUseDefaultSentinelValue.
+ static bool IsUseDefaultSentinelValue(Value* value);
+
virtual ~PrefStore() { }
// Whether the store is in a pseudo-read-only mode where changes are not
@@ -38,6 +51,10 @@ class PrefStore {
// read errors during startup.
virtual bool ReadOnly() { return true; }
+ // TODO(danno): PrefValueStore shouldn't allow direct access to the
+ // DictionaryValue. Instead, it should have getters that return a
+ // richer set of information for a pref, including if the store
+ // wants to return the default value for a preference.
virtual DictionaryValue* prefs() = 0;
virtual PrefReadError ReadPrefs() = 0;
diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc
index b9f9927..5a4fde4 100644
--- a/chrome/test/testing_pref_service.cc
+++ b/chrome/test/testing_pref_service.cc
@@ -4,8 +4,10 @@
#include "chrome/test/testing_pref_service.h"
+#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/prefs/dummy_pref_store.h"
#include "chrome/browser/prefs/pref_value_store.h"
+#include "chrome/browser/policy/configuration_policy_pref_store.h"
TestingPrefService::TestingPrefValueStore::TestingPrefValueStore(
PrefStore* managed_prefs,
@@ -22,12 +24,38 @@ TestingPrefService::TestingPrefValueStore::TestingPrefValueStore(
// which they want, and expand usage of this class to more unit tests.
TestingPrefService::TestingPrefService()
: PrefService(new TestingPrefValueStore(
- managed_prefs_ = new DummyPrefStore(),
- NULL,
- NULL,
- user_prefs_ = new DummyPrefStore(),
- NULL,
- default_prefs_ = new DummyPrefStore())) {
+ managed_prefs_ = new DummyPrefStore(),
+ NULL,
+ NULL,
+ user_prefs_ = new DummyPrefStore(),
+ NULL,
+ default_prefs_ = new DummyPrefStore())) {
+}
+
+TestingPrefService::TestingPrefService(
+ policy::ConfigurationPolicyProvider* provider,
+ CommandLine* command_line)
+ : PrefService(new TestingPrefValueStore(
+ managed_prefs_ = CreateManagedPrefStore(provider),
+ NULL,
+ CreateCommandLinePrefStore(command_line),
+ user_prefs_ = new DummyPrefStore(),
+ NULL,
+ default_prefs_ = new DummyPrefStore())) {
+}
+
+PrefStore* TestingPrefService::CreateManagedPrefStore(
+ policy::ConfigurationPolicyProvider* provider) {
+ if (provider)
+ return new policy::ConfigurationPolicyPrefStore(provider);
+ return new DummyPrefStore();
+}
+
+PrefStore* TestingPrefService::CreateCommandLinePrefStore(
+ CommandLine* command_line) {
+ if (command_line)
+ return new CommandLinePrefStore(command_line);
+ return new DummyPrefStore();
}
const Value* TestingPrefService::GetManagedPref(const char* path) {
diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h
index e9ed1cc..b0954e2 100644
--- a/chrome/test/testing_pref_service.h
+++ b/chrome/test/testing_pref_service.h
@@ -8,6 +8,10 @@
#include "chrome/browser/prefs/pref_service.h"
+class CommandLine;
+namespace policy {
+class ConfigurationPolicyProvider;
+}
class PrefStore;
// A PrefService subclass for testing. It operates totally in memory and
@@ -29,6 +33,16 @@ class TestingPrefService : public PrefService {
// Create an empty instance.
TestingPrefService();
+ // Create an instance that has a managed PrefStore and a command-
+ // line PrefStore. |provider| contains the provider with which to
+ // initialize the managed PrefStore. If it is NULL, then a
+ // DummyPrefStore will be created. |command_line| contains the
+ // provider with which to initialize the command line PrefStore. If
+ // it is NULL then a DummyPrefStore will be created as the command
+ // line PrefStore.
+ TestingPrefService(policy::ConfigurationPolicyProvider* provider,
+ CommandLine* command_line);
+
// Read the value of a preference from the managed layer. Returns NULL if the
// preference is not defined at the managed layer.
const Value* GetManagedPref(const char* path);
@@ -59,6 +73,15 @@ class TestingPrefService : public PrefService {
void RemoveUserPref(const char* path);
private:
+ // Creates a ConfigurationPolicyPrefStore based on the provided
+ // |provider| or a DummyPrefStore if |provider| is NULL.
+ PrefStore* CreateManagedPrefStore(
+ policy::ConfigurationPolicyProvider* provider);
+
+ // Creates a CommandLinePrefStore based on the supplied
+ // |command_line| or a DummyPrefStore if |command_line| is NULL.
+ PrefStore* CreateCommandLinePrefStore(CommandLine* command_line);
+
// Reads the value of the preference indicated by |path| from |pref_store|.
// Returns NULL if the preference was not found.
const Value* GetPref(PrefStore* pref_store, const char* path);