summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/command_line_pref_store.cc66
-rw-r--r--chrome/browser/command_line_pref_store.h59
-rw-r--r--chrome/browser/command_line_pref_store_unittest.cc130
-rw-r--r--chrome/browser/extensions/extension_pref_store.h3
-rw-r--r--chrome/browser/extensions/extension_pref_store_unittest.cc3
-rw-r--r--chrome/browser/managed_prefs_banner_base_unittest.cc3
-rw-r--r--chrome/browser/net/chrome_url_request_context_unittest.cc2
-rw-r--r--chrome/browser/pref_member_unittest.cc6
-rw-r--r--chrome/browser/pref_service.cc5
-rw-r--r--chrome/browser/pref_service_unittest.cc11
-rw-r--r--chrome/browser/pref_value_store.cc2
-rw-r--r--chrome/browser/pref_value_store.h4
-rw-r--r--chrome/browser/pref_value_store_unittest.cc59
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc7
-rw-r--r--chrome/chrome_browser.gypi20
-rw-r--r--chrome/chrome_tests.gypi1
16 files changed, 356 insertions, 25 deletions
diff --git a/chrome/browser/command_line_pref_store.cc b/chrome/browser/command_line_pref_store.cc
new file mode 100644
index 0000000..26bd0d3
--- /dev/null
+++ b/chrome/browser/command_line_pref_store.cc
@@ -0,0 +1,66 @@
+// 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/browser/command_line_pref_store.h"
+
+#include "app/app_switches.h"
+#include "base/values.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+
+const CommandLinePrefStore::StringSwitchToPreferenceMapEntry
+ CommandLinePrefStore::string_switch_map_[] = {
+ { switches::kLang, prefs::kApplicationLocale },
+ { switches::kProxyServer, prefs::kProxyServer },
+ { switches::kProxyPacUrl, prefs::kProxyPacUrl },
+ { switches::kProxyBypassList, prefs::kProxyBypassList },
+};
+
+const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
+ CommandLinePrefStore::boolean_switch_map_[] = {
+ { switches::kNoProxyServer, prefs::kNoProxyServer, true },
+ { switches::kProxyAutoDetect, prefs::kProxyAutoDetect, true },
+};
+
+CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line)
+ : command_line_(command_line),
+ prefs_(new DictionaryValue()) {}
+
+PrefStore::PrefReadError CommandLinePrefStore::ReadPrefs() {
+ ApplySimpleSwitches();
+ ValidateProxySwitches();
+ return PrefStore::PREF_READ_ERROR_NONE;
+}
+
+void CommandLinePrefStore::ApplySimpleSwitches() {
+ // Look for each switch we know about and set its preference accordingly.
+ for (size_t i = 0; i < arraysize(string_switch_map_); ++i) {
+ if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) {
+ Value* value = Value::CreateStringValue(command_line_->
+ GetSwitchValueASCII(string_switch_map_[i].switch_name));
+ prefs_->Set(string_switch_map_[i].preference_path, value);
+ }
+ }
+
+ for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) {
+ if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) {
+ Value* value = Value::CreateBooleanValue(
+ boolean_switch_map_[i].set_value);
+ prefs_->Set(boolean_switch_map_[i].preference_path, value);
+ }
+ }
+}
+
+bool CommandLinePrefStore::ValidateProxySwitches() {
+ if (command_line_->HasSwitch(switches::kNoProxyServer) &&
+ (command_line_->HasSwitch(switches::kProxyAutoDetect) ||
+ command_line_->HasSwitch(switches::kProxyServer) ||
+ command_line_->HasSwitch(switches::kProxyPacUrl) ||
+ command_line_->HasSwitch(switches::kProxyBypassList))) {
+ LOG(WARNING) << "Additional command-line proxy switches specified when --"
+ << switches::kNoProxyServer << " was also specified.";
+ return false;
+ }
+ return true;
+}
diff --git a/chrome/browser/command_line_pref_store.h b/chrome/browser/command_line_pref_store.h
new file mode 100644
index 0000000..d13c2fe
--- /dev/null
+++ b/chrome/browser/command_line_pref_store.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef CHROME_BROWSER_COMMAND_LINE_PREF_STORE_H_
+#define CHROME_BROWSER_COMMAND_LINE_PREF_STORE_H_
+
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/scoped_ptr.h"
+#include "chrome/common/pref_store.h"
+
+class DictionaryValue;
+
+// This PrefStore keeps track of preferences set by command-line switches,
+// such as proxy settings.
+class CommandLinePrefStore : public PrefStore {
+ public:
+ explicit CommandLinePrefStore(const CommandLine* command_line);
+ virtual ~CommandLinePrefStore() {}
+
+ // PrefStore methods:
+ virtual PrefReadError ReadPrefs();
+ virtual DictionaryValue* prefs() { return prefs_.get(); }
+
+ protected:
+ // Logs a message and returns false if the proxy switches are
+ // self-contradictory. Protected so it can be used in unit testing.
+ bool ValidateProxySwitches();
+
+ private:
+ // Weak reference.
+ const CommandLine* command_line_;
+
+ scoped_ptr<DictionaryValue> prefs_;
+
+ struct StringSwitchToPreferenceMapEntry {
+ const char* switch_name;
+ const wchar_t* preference_path;
+ };
+ static const StringSwitchToPreferenceMapEntry string_switch_map_[];
+
+ // |set_value| indicates what the preference should be set to if the switch
+ // is present.
+ struct BooleanSwitchToPreferenceMapEntry {
+ const char* switch_name;
+ const wchar_t* preference_path;
+ bool set_value;
+ };
+ static const BooleanSwitchToPreferenceMapEntry boolean_switch_map_[];
+
+ // Using the string and boolean maps, apply command-line switches to their
+ // corresponding preferences in this pref store.
+ void ApplySimpleSwitches();
+
+ DISALLOW_COPY_AND_ASSIGN(CommandLinePrefStore);
+};
+
+#endif // CHROME_BROWSER_COMMAND_LINE_PREF_STORE_H_
diff --git a/chrome/browser/command_line_pref_store_unittest.cc b/chrome/browser/command_line_pref_store_unittest.cc
new file mode 100644
index 0000000..eb5dab4
--- /dev/null
+++ b/chrome/browser/command_line_pref_store_unittest.cc
@@ -0,0 +1,130 @@
+// 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 <gtest/gtest.h>
+
+#include "app/app_switches.h"
+#include "base/command_line.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/command_line_pref_store.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+
+namespace {
+
+class TestCommandLinePrefStore : public CommandLinePrefStore {
+ public:
+ explicit TestCommandLinePrefStore(CommandLine* cl)
+ : CommandLinePrefStore(cl) {}
+
+ bool ProxySwitchesAreValid() {
+ return ValidateProxySwitches();
+ }
+};
+
+static const wchar_t* unknown_bool = L"unknown_switch";
+static const wchar_t* unknown_string = L"unknown_other_switch";
+
+} // namespace
+
+// Tests a simple string pref on the command line.
+TEST(CommandLinePrefStoreTest, SimpleStringPref) {
+ CommandLine cl(CommandLine::ARGUMENTS_ONLY);
+ cl.AppendSwitchWithValue(switches::kLang, "hi-MOM");
+ CommandLinePrefStore store(&cl);
+ EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+
+ std::string result;
+ EXPECT_TRUE(store.prefs()->GetString(prefs::kApplicationLocale, &result));
+ EXPECT_EQ("hi-MOM", result);
+}
+
+// Tests a simple boolean pref on the command line.
+TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
+ CommandLine cl(CommandLine::ARGUMENTS_ONLY);
+ cl.AppendSwitch(switches::kNoProxyServer);
+ CommandLinePrefStore store(&cl);
+ EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+
+ bool result;
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &result));
+ EXPECT_TRUE(result);
+}
+
+// Tests a command line with no recognized prefs.
+TEST(CommandLinePrefStoreTest, NoPrefs) {
+ CommandLine cl(CommandLine::ARGUMENTS_ONLY);
+ cl.AppendSwitch(WideToASCII(unknown_string));
+ cl.AppendSwitchWithValue(WideToASCII(unknown_bool), "a value");
+ CommandLinePrefStore store(&cl);
+ EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+
+ bool bool_result = false;
+ EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result));
+ EXPECT_FALSE(bool_result);
+
+ std::string string_result = "";
+ EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result));
+ EXPECT_EQ("", string_result);
+}
+
+// Tests a complex command line with multiple known and unknown switches.
+TEST(CommandLinePrefStoreTest, MultipleSwitches) {
+ CommandLine cl(CommandLine::ARGUMENTS_ONLY);
+ cl.AppendSwitch(WideToASCII(unknown_string));
+ cl.AppendSwitch(switches::kProxyAutoDetect);
+ cl.AppendSwitchWithValue(switches::kProxyServer, "proxy");
+ cl.AppendSwitchWithValue(switches::kProxyBypassList, "list");
+ cl.AppendSwitchWithValue(WideToASCII(unknown_bool), "a value");
+ CommandLinePrefStore store(&cl);
+ EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+
+ bool bool_result = false;
+ EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result));
+ EXPECT_FALSE(bool_result);
+ EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
+ EXPECT_TRUE(bool_result);
+
+ std::string string_result = "";
+ EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result));
+ EXPECT_EQ("", string_result);
+ EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_EQ("proxy", string_result);
+ EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_EQ("list", string_result);
+}
+
+// Tests proxy switch validation.
+TEST(CommandLinePrefStoreTest, ProxySwitchValidation) {
+ CommandLine cl(CommandLine::ARGUMENTS_ONLY);
+
+ // No switches.
+ TestCommandLinePrefStore store(&cl);
+ EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+ EXPECT_TRUE(store.ProxySwitchesAreValid());
+
+ // Only no-proxy.
+ cl.AppendSwitch(switches::kNoProxyServer);
+ TestCommandLinePrefStore store2(&cl);
+ EXPECT_EQ(store2.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+ EXPECT_TRUE(store2.ProxySwitchesAreValid());
+
+ // Another proxy switch too.
+ cl.AppendSwitch(switches::kProxyAutoDetect);
+ TestCommandLinePrefStore store3(&cl);
+ EXPECT_EQ(store3.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+ EXPECT_FALSE(store3.ProxySwitchesAreValid());
+
+ // All proxy switches except no-proxy.
+ CommandLine cl2(CommandLine::ARGUMENTS_ONLY);
+ cl2.AppendSwitch(switches::kProxyAutoDetect);
+ cl2.AppendSwitchWithValue(switches::kProxyServer, "server");
+ cl2.AppendSwitchWithValue(switches::kProxyPacUrl, "url");
+ cl2.AppendSwitchWithValue(switches::kProxyBypassList, "list");
+ TestCommandLinePrefStore store4(&cl2);
+ EXPECT_EQ(store4.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
+ EXPECT_TRUE(store4.ProxySwitchesAreValid());
+}
diff --git a/chrome/browser/extensions/extension_pref_store.h b/chrome/browser/extensions/extension_pref_store.h
index 384537c..fc10b5b 100644
--- a/chrome/browser/extensions/extension_pref_store.h
+++ b/chrome/browser/extensions/extension_pref_store.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/common/pref_store.h"
@@ -82,6 +83,8 @@ class ExtensionPrefStore : public PrefStore {
// the values in the extensions' PrefValueMaps.
typedef std::list<ExtensionPrefs*> ExtensionStack;
ExtensionStack extension_stack_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore);
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_
diff --git a/chrome/browser/extensions/extension_pref_store_unittest.cc b/chrome/browser/extensions/extension_pref_store_unittest.cc
index 69187cb..8bbb4b8 100644
--- a/chrome/browser/extensions/extension_pref_store_unittest.cc
+++ b/chrome/browser/extensions/extension_pref_store_unittest.cc
@@ -259,7 +259,8 @@ TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) {
// The PrefValueStore takes ownership of the PrefStores; in this case, that's
// only an ExtensionPrefStore.
- PrefValueStore* value_store = new PrefValueStore(NULL, &eps, NULL, NULL);
+ PrefValueStore* value_store = new PrefValueStore(NULL, &eps, NULL, NULL,
+ NULL);
MockPrefService* pref_service = new MockPrefService(value_store);
eps.SetPrefService(pref_service);
pref_service->RegisterStringPref(kPref1, std::string());
diff --git a/chrome/browser/managed_prefs_banner_base_unittest.cc b/chrome/browser/managed_prefs_banner_base_unittest.cc
index 16c9f98..7955ebf 100644
--- a/chrome/browser/managed_prefs_banner_base_unittest.cc
+++ b/chrome/browser/managed_prefs_banner_base_unittest.cc
@@ -22,10 +22,12 @@ class ManagedPrefsBannerBaseTest : public testing::Test {
virtual void SetUp() {
managed_prefs_ = new DummyPrefStore;
extension_prefs_ = new DummyPrefStore;
+ command_line_prefs_ = new DummyPrefStore;
user_prefs_ = new DummyPrefStore;
default_prefs_ = new DummyPrefStore;
pref_service_.reset(new PrefService(new PrefValueStore(managed_prefs_,
extension_prefs_,
+ command_line_prefs_,
user_prefs_,
default_prefs_)));
pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com");
@@ -36,6 +38,7 @@ class ManagedPrefsBannerBaseTest : public testing::Test {
scoped_ptr<PrefService> pref_service_;
DummyPrefStore* managed_prefs_;
DummyPrefStore* extension_prefs_;
+ DummyPrefStore* command_line_prefs_;
DummyPrefStore* user_prefs_;
DummyPrefStore* default_prefs_;
};
diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc
index f8907b5..7ba2dff 100644
--- a/chrome/browser/net/chrome_url_request_context_unittest.cc
+++ b/chrome/browser/net/chrome_url_request_context_unittest.cc
@@ -160,7 +160,7 @@ TEST(ChromeURLRequestContextTest, CreateProxyConfigTest) {
CommandLine command_line(tests[i].command_line);
PrefService prefs(new PrefValueStore(
new ConfigurationPolicyPrefStore(&command_line, NULL),
- NULL, NULL, NULL)); // No extension, user, or recommended prefs.
+ NULL, NULL, NULL, NULL)); // Only configuration-policy prefs.
ChromeURLRequestContextGetter::RegisterUserPrefs(&prefs);
scoped_ptr<net::ProxyConfig> config(CreateProxyConfig(&prefs));
diff --git a/chrome/browser/pref_member_unittest.cc b/chrome/browser/pref_member_unittest.cc
index 2a46c63..98d11a7 100644
--- a/chrome/browser/pref_member_unittest.cc
+++ b/chrome/browser/pref_member_unittest.cc
@@ -53,7 +53,7 @@ class PrefMemberTestClass : public NotificationObserver {
} // anonymous namespace
TEST(PrefMemberTest, BasicGetAndSet) {
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
RegisterTestPrefs(&prefs);
@@ -144,7 +144,7 @@ TEST(PrefMemberTest, BasicGetAndSet) {
TEST(PrefMemberTest, TwoPrefs) {
// Make sure two RealPrefMembers stay in sync.
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
RegisterTestPrefs(&prefs);
@@ -165,7 +165,7 @@ TEST(PrefMemberTest, TwoPrefs) {
}
TEST(PrefMemberTest, Observer) {
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
RegisterTestPrefs(&prefs);
diff --git a/chrome/browser/pref_service.cc b/chrome/browser/pref_service.cc
index fcc8af3..a6f824c 100644
--- a/chrome/browser/pref_service.cc
+++ b/chrome/browser/pref_service.cc
@@ -29,6 +29,7 @@
#endif
#include "chrome/browser/dummy_configuration_policy_provider.h"
+#include "chrome/browser/command_line_pref_store.h"
#include "chrome/browser/configuration_policy_pref_store.h"
#include "chrome/browser/extensions/extension_pref_store.h"
#include "chrome/common/chrome_paths.h"
@@ -94,6 +95,8 @@ void NotifyReadError(PrefService* pref, int message_id) {
PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) {
PrefStore* managed_prefs = NULL;
ExtensionPrefStore* extension_prefs = new ExtensionPrefStore(NULL);
+ CommandLinePrefStore* command_line_prefs = new CommandLinePrefStore(
+ CommandLine::ForCurrentProcess());
PrefStore* local_prefs = new JsonPrefStore(
pref_filename,
ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE));
@@ -134,6 +137,7 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) {
PrefValueStore* value_store = new PrefValueStore(
managed_prefs,
extension_prefs,
+ command_line_prefs,
local_prefs,
recommended_prefs);
@@ -149,6 +153,7 @@ PrefService* PrefService::CreateUserPrefService(
PrefValueStore* value_store = new PrefValueStore(
NULL, /* no enforced prefs */
NULL, /* no extension prefs */
+ NULL, /* no command-line prefs */
new JsonPrefStore(
pref_filename,
ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)),
diff --git a/chrome/browser/pref_service_unittest.cc b/chrome/browser/pref_service_unittest.cc
index 591e00e..45b840d 100644
--- a/chrome/browser/pref_service_unittest.cc
+++ b/chrome/browser/pref_service_unittest.cc
@@ -64,7 +64,7 @@ class TestPrefObserver : public NotificationObserver {
// TODO(port): port this test to POSIX.
#if defined(OS_WIN)
TEST(PrefServiceTest, LocalizedPrefs) {
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
const wchar_t kBoolean[] = L"boolean";
const wchar_t kInteger[] = L"integer";
@@ -88,7 +88,7 @@ TEST(PrefServiceTest, LocalizedPrefs) {
#endif
TEST(PrefServiceTest, NoObserverFire) {
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
const wchar_t pref_name[] = L"homepage";
@@ -124,7 +124,7 @@ TEST(PrefServiceTest, NoObserverFire) {
}
TEST(PrefServiceTest, HasPrefPath) {
- PrefService prefs(new PrefValueStore(NULL, NULL, new DummyPrefStore(),
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
NULL));
const wchar_t path[] = L"fake.path";
@@ -149,7 +149,7 @@ TEST(PrefServiceTest, Observers) {
dict->SetString(pref_name, std::string("http://www.cnn.com"));
DummyPrefStore* pref_store = new DummyPrefStore();
pref_store->set_prefs(dict);
- PrefService prefs(new PrefValueStore(NULL, NULL, pref_store, NULL));
+ PrefService prefs(new PrefValueStore(NULL, NULL, NULL, pref_store, NULL));
prefs.RegisterStringPref(pref_name, "");
const std::string new_pref_value("http://www.google.com/");
@@ -190,7 +190,8 @@ class PrefServiceSetValueTest : public testing::Test {
static const char value_[];
PrefServiceSetValueTest()
- : prefs_(new PrefValueStore(NULL, NULL, new DummyPrefStore(), NULL)),
+ : prefs_(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
+ NULL)),
name_string_(name_),
null_value_(Value::CreateNullValue()) {}
diff --git a/chrome/browser/pref_value_store.cc b/chrome/browser/pref_value_store.cc
index 81ed480..a5fae75 100644
--- a/chrome/browser/pref_value_store.cc
+++ b/chrome/browser/pref_value_store.cc
@@ -6,10 +6,12 @@
PrefValueStore::PrefValueStore(PrefStore* managed_prefs,
PrefStore* extension_prefs,
+ PrefStore* command_line_prefs,
PrefStore* user_prefs,
PrefStore* recommended_prefs) {
pref_stores_[MANAGED].reset(managed_prefs);
pref_stores_[EXTENSION].reset(extension_prefs);
+ pref_stores_[COMMAND_LINE].reset(command_line_prefs);
pref_stores_[USER].reset(user_prefs);
pref_stores_[RECOMMENDED].reset(recommended_prefs);
}
diff --git a/chrome/browser/pref_value_store.h b/chrome/browser/pref_value_store.h
index 0ba62af..885b7c0 100644
--- a/chrome/browser/pref_value_store.h
+++ b/chrome/browser/pref_value_store.h
@@ -31,10 +31,13 @@ class PrefValueStore {
// In decreasing order of precedence:
// |managed_prefs| contains all managed (policy) preference values.
// |extension_prefs| contains preference values set by extensions.
+ // |command_line_prefs| contains preference values set by command-line
+ // switches.
// |user_prefs| contains all user-set preference values.
// |recommended_prefs| contains all recommended (policy) preference values.
PrefValueStore(PrefStore* managed_prefs,
PrefStore* extension_prefs,
+ PrefStore* command_line_prefs,
PrefStore* user_prefs,
PrefStore* recommended_prefs);
@@ -98,6 +101,7 @@ class PrefValueStore {
enum PrefStoreType {
MANAGED = 0,
EXTENSION,
+ COMMAND_LINE,
USER,
RECOMMENDED,
PREF_STORE_TYPE_MAX = RECOMMENDED
diff --git a/chrome/browser/pref_value_store_unittest.cc b/chrome/browser/pref_value_store_unittest.cc
index 3e0f496..bd10e7b 100644
--- a/chrome/browser/pref_value_store_unittest.cc
+++ b/chrome/browser/pref_value_store_unittest.cc
@@ -24,6 +24,10 @@ namespace prefs {
const wchar_t kRecommendedPref[] = L"this.pref.recommended_value_only";
const wchar_t kSampleDict[] = L"sample.dict";
const wchar_t kSampleList[] = L"sample.list";
+
+ // This must match the actual pref name so the command-line store knows about
+ // it.
+ const wchar_t kApplicationLocale[] = L"intl.app_locale";
}
// Potentailly expected values of all preferences used in this test program.
@@ -34,6 +38,7 @@ namespace user_pref {
const bool kDeleteCacheValue = true;
const std::wstring kCurrentThemeIDValue = L"abcdefg";
const std::wstring kHomepageValue = L"http://www.google.com";
+ const std::wstring kApplicationLocaleValue = L"is-WRONG";
}
namespace enforced_pref {
@@ -45,6 +50,12 @@ namespace extension_pref {
const std::wstring kHomepageValue = L"http://www.chromium.org";
}
+namespace command_line_pref {
+ const std::wstring kApplicationLocaleValue = L"hi-MOM";
+ const std::wstring kCurrentThemeIDValue = L"zyxwvut";
+ const std::wstring kHomepageValue = L"http://www.ferretcentral.org";
+}
+
namespace recommended_pref {
const int kMaxTabsValue = 10;
const bool kRecommendedPrefValue = true;
@@ -57,12 +68,14 @@ class PrefValueStoreTest : public testing::Test {
// |PrefStore|s are owned by the |PrefValueStore|.
DummyPrefStore* enforced_pref_store_;
DummyPrefStore* extension_pref_store_;
+ DummyPrefStore* command_line_pref_store_;
DummyPrefStore* recommended_pref_store_;
DummyPrefStore* user_pref_store_;
// Preferences are owned by the individual |DummyPrefStores|.
DictionaryValue* enforced_prefs_;
DictionaryValue* extension_prefs_;
+ DictionaryValue* command_line_prefs_;
DictionaryValue* user_prefs_;
DictionaryValue* recommended_prefs_;
@@ -70,6 +83,7 @@ class PrefValueStoreTest : public testing::Test {
// Create dummy user preferences.
enforced_prefs_= CreateEnforcedPrefs();
extension_prefs_ = CreateExtensionPrefs();
+ command_line_prefs_ = CreateCommandLinePrefs();
user_prefs_ = CreateUserPrefs();
recommended_prefs_ = CreateRecommendedPrefs();
@@ -78,6 +92,8 @@ class PrefValueStoreTest : public testing::Test {
enforced_pref_store_->set_prefs(enforced_prefs_);
extension_pref_store_ = new DummyPrefStore();
extension_pref_store_->set_prefs(extension_prefs_);
+ command_line_pref_store_ = new DummyPrefStore();
+ command_line_pref_store_->set_prefs(command_line_prefs_);
user_pref_store_ = new DummyPrefStore();
user_pref_store_->set_read_only(false);
user_pref_store_->set_prefs(user_prefs_);
@@ -87,6 +103,7 @@ class PrefValueStoreTest : public testing::Test {
// Create a new pref-value-store.
pref_value_store_.reset(new PrefValueStore(enforced_pref_store_,
extension_pref_store_,
+ command_line_pref_store_,
user_pref_store_,
recommended_pref_store_));
}
@@ -99,6 +116,8 @@ class PrefValueStoreTest : public testing::Test {
user_prefs->SetInteger(prefs::kMaxTabs, user_pref::kMaxTabsValue);
user_prefs->SetString(prefs::kCurrentThemeID,
user_pref::kCurrentThemeIDValue);
+ user_prefs->SetString(prefs::kApplicationLocale,
+ user_pref::kApplicationLocaleValue);
user_prefs->SetString(prefs::kHomepage, user_pref::kHomepageValue);
return user_prefs;
}
@@ -118,6 +137,17 @@ class PrefValueStoreTest : public testing::Test {
return extension_prefs;
}
+ DictionaryValue* CreateCommandLinePrefs() {
+ DictionaryValue* command_line_prefs = new DictionaryValue();
+ command_line_prefs->SetString(prefs::kCurrentThemeID,
+ command_line_pref::kCurrentThemeIDValue);
+ command_line_prefs->SetString(prefs::kApplicationLocale,
+ command_line_pref::kApplicationLocaleValue);
+ 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,
@@ -151,6 +181,7 @@ class PrefValueStoreTest : public testing::Test {
TEST_F(PrefValueStoreTest, IsReadOnly) {
enforced_pref_store_->set_read_only(true);
extension_pref_store_->set_read_only(true);
+ command_line_pref_store_->set_read_only(true);
user_pref_store_->set_read_only(true);
recommended_pref_store_->set_read_only(true);
EXPECT_TRUE(pref_value_store_->ReadOnly());
@@ -170,12 +201,19 @@ TEST_F(PrefValueStoreTest, GetValue) {
EXPECT_TRUE(value->GetAsString(&actual_str_value));
EXPECT_EQ(enforced_pref::kHomepageValue, actual_str_value);
- // Test getting an extension value overwriting a user-defined value.
+ // Test getting an extension value overwriting a user-defined and
+ // command-line-defined value.
value = NULL;
ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCurrentThemeID, &value));
EXPECT_TRUE(value->GetAsString(&actual_str_value));
EXPECT_EQ(extension_pref::kCurrentThemeIDValue, actual_str_value);
+ // Test getting a command-line value overwriting a user-defined value.
+ value = NULL;
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kApplicationLocale, &value));
+ EXPECT_TRUE(value->GetAsString(&actual_str_value));
+ EXPECT_EQ(command_line_pref::kApplicationLocaleValue, actual_str_value);
+
// Test getting a user-set value.
value = NULL;
ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDeleteCache, &value));
@@ -293,6 +331,11 @@ TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
prefs::kCurrentThemeID));
+ // Test a command-line preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kApplicationLocale));
+
// Test a user preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMaxTabs));
@@ -321,6 +364,13 @@ TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
prefs::kCurrentThemeID));
+ // Test a command-line preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kApplicationLocale));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kApplicationLocale));
+
// Test a user preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(prefs::kMaxTabs));
@@ -354,6 +404,13 @@ TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
prefs::kCurrentThemeID));
+ // Test a command-line preference.
+ ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
+ prefs::kApplicationLocale));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kApplicationLocale));
+
// Test a user preference.
ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kMaxTabs));
EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kMaxTabs));
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
index 003c64b..49248a7 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
@@ -102,11 +102,8 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
FilePath preferences_file = temp_dir.path().AppendASCII("Preferences");
file_util::WriteFile(preferences_file, pref_data, sizeof(pref_data));
- scoped_ptr<PrefService> prefs(new PrefService(new PrefValueStore(
- NULL, new JsonPrefStore(preferences_file,
- ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)),
- NULL, NULL)));
-
+ scoped_ptr<PrefService> prefs(
+ PrefService::CreateUserPrefService(preferences_file));
TemplateURLPrepopulateData::RegisterUserPrefs(prefs.get());
int version = TemplateURLPrepopulateData::GetDataVersion(prefs.get());
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index aa1af65..50d10f2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -996,10 +996,21 @@
'browser/cocoa/window_size_autosaver.mm',
'browser/cocoa/wrench_menu_controller.h',
'browser/cocoa/wrench_menu_controller.mm',
+ 'browser/command_line_pref_store.cc',
+ 'browser/command_line_pref_store.h',
'browser/command_updater.cc',
'browser/command_updater.h',
'browser/config_dir_policy_provider.cc',
'browser/config_dir_policy_provider.h',
+ 'browser/configuration_policy_store.h',
+ 'browser/configuration_policy_pref_store.cc',
+ 'browser/configuration_policy_pref_store.h',
+ 'browser/configuration_policy_provider.cc',
+ 'browser/configuration_policy_provider.h',
+ 'browser/configuration_policy_provider_mac.cc',
+ 'browser/configuration_policy_provider_mac.h',
+ 'browser/configuration_policy_provider_win.cc',
+ 'browser/configuration_policy_provider_win.h',
'browser/content_exceptions_table_model.cc',
'browser/content_exceptions_table_model.h',
'browser/content_setting_bubble_model.cc',
@@ -1016,15 +1027,6 @@
'browser/cookie_prompt_modal_dialog_delegate.h',
'browser/cookies_tree_model.cc',
'browser/cookies_tree_model.h',
- 'browser/configuration_policy_store.h',
- 'browser/configuration_policy_pref_store.cc',
- 'browser/configuration_policy_pref_store.h',
- 'browser/configuration_policy_provider.cc',
- 'browser/configuration_policy_provider.h',
- 'browser/configuration_policy_provider_mac.cc',
- 'browser/configuration_policy_provider_mac.h',
- 'browser/configuration_policy_provider_win.cc',
- 'browser/configuration_policy_provider_win.h',
'browser/cross_site_request_manager.cc',
'browser/cross_site_request_manager.h',
'browser/custom_home_pages_table_model.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 69e2c35..093e356 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -879,6 +879,7 @@
'browser/cocoa/window_size_autosaver_unittest.mm',
'browser/cocoa/wrench_menu_controller_unittest.mm',
'browser/config_dir_policy_provider_unittest.cc',
+ 'browser/command_line_pref_store_unittest.cc',
'browser/command_updater_unittest.cc',
'browser/configuration_policy_pref_store_unittest.cc',
'browser/configuration_policy_provider_mac_unittest.cc',