summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-05-31 20:30:28 +0100
committerKristian Monsen <kristianm@google.com>2011-06-14 20:31:41 -0700
commit72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch)
tree382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/prefs
parentc4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff)
downloadexternal_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz
external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/prefs')
-rw-r--r--chrome/browser/prefs/browser_prefs.cc64
-rw-r--r--chrome/browser/prefs/browser_prefs.h12
-rw-r--r--chrome/browser/prefs/command_line_pref_store.cc33
-rw-r--r--chrome/browser/prefs/command_line_pref_store_unittest.cc94
-rw-r--r--chrome/browser/prefs/default_pref_store.cc20
-rw-r--r--chrome/browser/prefs/default_pref_store.h18
-rw-r--r--chrome/browser/prefs/overlay_persistent_pref_store.cc77
-rw-r--r--chrome/browser/prefs/overlay_persistent_pref_store.h54
-rw-r--r--chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc119
-rw-r--r--chrome/browser/prefs/pref_change_registrar.cc4
-rw-r--r--chrome/browser/prefs/pref_change_registrar_unittest.cc3
-rw-r--r--chrome/browser/prefs/pref_member.cc21
-rw-r--r--chrome/browser/prefs/pref_member.h17
-rw-r--r--chrome/browser/prefs/pref_member_unittest.cc44
-rw-r--r--chrome/browser/prefs/pref_service.cc213
-rw-r--r--chrome/browser/prefs/pref_service.h92
-rw-r--r--chrome/browser/prefs/pref_service_mock_builder.cc73
-rw-r--r--chrome/browser/prefs/pref_service_mock_builder.h29
-rw-r--r--chrome/browser/prefs/pref_service_uitest.cc98
-rw-r--r--chrome/browser/prefs/pref_service_unittest.cc180
-rw-r--r--chrome/browser/prefs/pref_set_observer.cc6
-rw-r--r--chrome/browser/prefs/pref_value_map.cc18
-rw-r--r--chrome/browser/prefs/pref_value_map.h10
-rw-r--r--chrome/browser/prefs/pref_value_store.cc131
-rw-r--r--chrome/browser/prefs/pref_value_store.h78
-rw-r--r--chrome/browser/prefs/pref_value_store_unittest.cc827
-rw-r--r--chrome/browser/prefs/proxy_config_dictionary.cc104
-rw-r--r--chrome/browser/prefs/proxy_config_dictionary.h56
-rw-r--r--chrome/browser/prefs/proxy_config_dictionary_unittest.cc84
-rw-r--r--chrome/browser/prefs/proxy_prefs.cc24
-rw-r--r--chrome/browser/prefs/proxy_prefs.h10
-rw-r--r--chrome/browser/prefs/proxy_prefs_unittest.cc4
-rw-r--r--chrome/browser/prefs/testing_pref_store.cc26
-rw-r--r--chrome/browser/prefs/testing_pref_store.h14
-rw-r--r--chrome/browser/prefs/value_map_pref_store.cc16
-rw-r--r--chrome/browser/prefs/value_map_pref_store.h12
36 files changed, 1818 insertions, 867 deletions
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 1aa3c9e..ba65eb9 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,32 +12,31 @@
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/content_settings/policy_content_settings_provider.h"
-#include "chrome/browser/content_settings/pref_content_settings_provider.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/dom_ui/flags_ui.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/dom_ui/plugins_ui.h"
#include "chrome/browser/download/download_prefs.h"
-#include "chrome/browser/extensions/extension_dom_ui.h"
#include "chrome/browser/extensions/extension_prefs.h"
+#include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/extensions/extensions_ui.h"
#include "chrome/browser/external_protocol_handler.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_prefs.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/host_zoom_map.h"
-#include "chrome/browser/intranet_redirect_detector.h"
#include "chrome/browser/instant/instant_controller.h"
+#include "chrome/browser/intranet_redirect_detector.h"
#include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_service.h"
+#include "chrome/browser/net/net_pref_observer.h"
#include "chrome/browser/net/predictor_api.h"
#include "chrome/browser/net/pref_proxy_config_service.h"
-#include "chrome/browser/net/net_pref_observer.h"
-#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/password_manager/password_manager.h"
+#include "chrome/browser/policy/profile_policy_context.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile_impl.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
@@ -54,23 +53,25 @@
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/upgrade_detector.h"
+#include "chrome/common/pref_names.h"
#if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port
-#include "chrome/browser/views/browser_actions_container.h"
-#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/browser_actions_container.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
#endif
#if defined(TOOLKIT_GTK)
-#include "chrome/browser/gtk/browser_window_gtk.h"
+#include "chrome/browser/ui/gtk/browser_window_gtk.h"
#endif
#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/audio_mixer_alsa.h"
#include "chrome/browser/chromeos/login/apply_services_customization.h"
#include "chrome/browser/chromeos/login/signed_settings_temp_storage.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/preferences.h"
-#include "chrome/browser/chromeos/status/input_method_menu_button.h"
+#include "chrome/browser/chromeos/status/input_method_menu.h"
#include "chrome/browser/chromeos/user_cros_settings_provider.h"
#endif
@@ -84,6 +85,7 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
void RegisterLocalState(PrefService* local_state) {
// Prefs in Local State
Browser::RegisterPrefs(local_state);
+ FlagsUI::RegisterPrefs(local_state);
WebCacheManager::RegisterPrefs(local_state);
ExternalProtocolHandler::RegisterPrefs(local_state);
GoogleURLTracker::RegisterPrefs(local_state);
@@ -103,10 +105,11 @@ void RegisterLocalState(PrefService* local_state) {
BackgroundPageTracker::RegisterPrefs(local_state);
NotificationUIManager::RegisterPrefs(local_state);
#if defined(OS_CHROMEOS)
+ chromeos::AudioMixerAlsa::RegisterPrefs(local_state);
chromeos::UserManager::RegisterPrefs(local_state);
chromeos::UserCrosSettingsProvider::RegisterPrefs(local_state);
WizardController::RegisterPrefs(local_state);
- chromeos::InputMethodMenuButton::RegisterPrefs(local_state);
+ chromeos::InputMethodMenu::RegisterPrefs(local_state);
chromeos::ApplyServicesCustomization::RegisterPrefs(local_state);
chromeos::SignedSettingsTempStorage::RegisterPrefs(local_state);
#endif
@@ -123,15 +126,12 @@ void RegisterUserPrefs(PrefService* user_prefs) {
bookmark_utils::RegisterUserPrefs(user_prefs);
TabContents::RegisterUserPrefs(user_prefs);
TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs);
- ExtensionDOMUI::RegisterUserPrefs(user_prefs);
+ ExtensionWebUI::RegisterUserPrefs(user_prefs);
ExtensionsUI::RegisterUserPrefs(user_prefs);
- FlagsUI::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
PluginsUI::RegisterUserPrefs(user_prefs);
ProfileImpl::RegisterUserPrefs(user_prefs);
HostContentSettingsMap::RegisterUserPrefs(user_prefs);
- PolicyContentSettingsProvider::RegisterUserPrefs(user_prefs);
- PrefContentSettingsProvider::RegisterUserPrefs(user_prefs);
HostZoomMap::RegisterUserPrefs(user_prefs);
DevToolsManager::RegisterUserPrefs(user_prefs);
PinnedTabCodec::RegisterUserPrefs(user_prefs);
@@ -153,6 +153,38 @@ void RegisterUserPrefs(PrefService* user_prefs) {
TemplateURLModel::RegisterUserPrefs(user_prefs);
InstantController::RegisterUserPrefs(user_prefs);
NetPrefObserver::RegisterPrefs(user_prefs);
+ policy::ProfilePolicyContext::RegisterUserPrefs(user_prefs);
+}
+
+void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) {
+ // Copy pref values which have been migrated to user_prefs from local_state,
+ // or remove them from local_state outright, if copying is not required.
+ int current_version =
+ local_state->GetInteger(prefs::kMultipleProfilePrefMigration);
+
+ if ((current_version & WINDOWS_PREFS) == 0) {
+ // Migrate the devtools split location preference.
+ local_state->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1);
+ DCHECK(user_prefs->FindPreference(prefs::kDevToolsSplitLocation));
+ if (local_state->HasPrefPath(prefs::kDevToolsSplitLocation)) {
+ user_prefs->SetInteger(prefs::kDevToolsSplitLocation,
+ local_state->GetInteger(prefs::kDevToolsSplitLocation));
+ }
+ local_state->ClearPref(prefs::kDevToolsSplitLocation);
+
+ // Migrate the browser window placement preference.
+ local_state->RegisterDictionaryPref(prefs::kBrowserWindowPlacement);
+ DCHECK(user_prefs->FindPreference(prefs::kBrowserWindowPlacement));
+ if (local_state->HasPrefPath(prefs::kBrowserWindowPlacement)) {
+ user_prefs->Set(prefs::kBrowserWindowPlacement,
+ *(local_state->FindPreference(prefs::kBrowserWindowPlacement)->
+ GetValue()));
+ }
+ local_state->ClearPref(prefs::kBrowserWindowPlacement);
+
+ local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
+ current_version | WINDOWS_PREFS);
+ }
}
} // namespace browser
diff --git a/chrome/browser/prefs/browser_prefs.h b/chrome/browser/prefs/browser_prefs.h
index ef109a4..4df26c1 100644
--- a/chrome/browser/prefs/browser_prefs.h
+++ b/chrome/browser/prefs/browser_prefs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,11 +10,19 @@ class PrefService;
namespace browser {
+// Bitmask for kMultipleProfilePrefMigration.
+enum MigratedPreferences {
+ NO_PREFS = 0,
+ DNS_PREFS = 1 << 0,
+ WINDOWS_PREFS = 1 << 1,
+};
+
// Makes the PrefService objects aware of all the prefs.
void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state);
void RegisterLocalState(PrefService* local_state);
void RegisterUserPrefs(PrefService* user_prefs);
-
+// Migrate prefs from local_state to user_prefs.
+void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state);
} // namespace browser
#endif // CHROME_BROWSER_PREFS_BROWSER_PREFS_H__
diff --git a/chrome/browser/prefs/command_line_pref_store.cc b/chrome/browser/prefs/command_line_pref_store.cc
index 4a386d6..97e0d39 100644
--- a/chrome/browser/prefs/command_line_pref_store.cc
+++ b/chrome/browser/prefs/command_line_pref_store.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,16 +7,14 @@
#include "app/app_switches.h"
#include "base/logging.h"
#include "base/values.h"
-#include "chrome/browser/prefs/proxy_prefs.h"
+#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "ui/base/ui_base_switches.h"
const CommandLinePrefStore::StringSwitchToPreferenceMapEntry
CommandLinePrefStore::string_switch_map_[] = {
{ switches::kLang, prefs::kApplicationLocale },
- { switches::kProxyServer, prefs::kProxyServer },
- { switches::kProxyPacUrl, prefs::kProxyPacUrl },
- { switches::kProxyBypassList, prefs::kProxyBypassList },
{ switches::kAuthSchemes, prefs::kAuthSchemes },
{ switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist },
{ switches::kAuthNegotiateDelegateWhitelist,
@@ -31,6 +29,8 @@ const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
{ switches::kEnableAuthNegotiatePort, prefs::kEnableAuthNegotiatePort,
true },
{ switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true },
+ { switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled,
+ true },
};
CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line)
@@ -76,16 +76,23 @@ bool CommandLinePrefStore::ValidateProxySwitches() {
void CommandLinePrefStore::ApplyProxyMode() {
if (command_line_->HasSwitch(switches::kNoProxyServer)) {
- SetValue(prefs::kProxyMode,
- Value::CreateIntegerValue(ProxyPrefs::MODE_DIRECT));
+ SetValue(prefs::kProxy,
+ ProxyConfigDictionary::CreateDirect());
} else if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
- SetValue(prefs::kProxyMode,
- Value::CreateIntegerValue(ProxyPrefs::MODE_PAC_SCRIPT));
+ std::string pac_script_url =
+ command_line_->GetSwitchValueASCII(switches::kProxyPacUrl);
+ SetValue(prefs::kProxy,
+ ProxyConfigDictionary::CreatePacScript(pac_script_url));
} else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
- SetValue(prefs::kProxyMode,
- Value::CreateIntegerValue(ProxyPrefs::MODE_AUTO_DETECT));
+ SetValue(prefs::kProxy,
+ ProxyConfigDictionary::CreateAutoDetect());
} else if (command_line_->HasSwitch(switches::kProxyServer)) {
- SetValue(prefs::kProxyMode,
- Value::CreateIntegerValue(ProxyPrefs::MODE_FIXED_SERVERS));
+ std::string proxy_server =
+ command_line_->GetSwitchValueASCII(switches::kProxyServer);
+ std::string bypass_list =
+ command_line_->GetSwitchValueASCII(switches::kProxyBypassList);
+ SetValue(prefs::kProxy,
+ ProxyConfigDictionary::CreateFixedServers(proxy_server,
+ bypass_list));
}
}
diff --git a/chrome/browser/prefs/command_line_pref_store_unittest.cc b/chrome/browser/prefs/command_line_pref_store_unittest.cc
index 1be9c0a..edc88d9 100644
--- a/chrome/browser/prefs/command_line_pref_store_unittest.cc
+++ b/chrome/browser/prefs/command_line_pref_store_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,12 +6,14 @@
#include "app/app_switches.h"
#include "base/command_line.h"
+#include "base/ref_counted.h"
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/prefs/command_line_pref_store.h"
-#include "chrome/browser/prefs/proxy_prefs.h"
+#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "ui/base/ui_base_switches.h"
namespace {
@@ -24,10 +26,14 @@ class TestCommandLinePrefStore : public CommandLinePrefStore {
return ValidateProxySwitches();
}
- void VerifyIntPref(const std::string& path, int expected_value) {
- Value* actual = NULL;
- ASSERT_EQ(PrefStore::READ_OK, GetValue(path, &actual));
- EXPECT_TRUE(FundamentalValue(expected_value).Equals(actual));
+ void VerifyProxyMode(ProxyPrefs::ProxyMode expected_mode) {
+ Value* value = NULL;
+ ASSERT_EQ(PrefStore::READ_OK, GetValue(prefs::kProxy, &value));
+ ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType());
+ ProxyConfigDictionary dict(static_cast<DictionaryValue*>(value));
+ ProxyPrefs::ProxyMode actual_mode;
+ ASSERT_TRUE(dict.GetMode(&actual_mode));
+ EXPECT_EQ(expected_mode, actual_mode);
}
};
@@ -40,11 +46,11 @@ const char unknown_string[] = "unknown_other_switch";
TEST(CommandLinePrefStoreTest, SimpleStringPref) {
CommandLine cl(CommandLine::NO_PROGRAM);
cl.AppendSwitchASCII(switches::kLang, "hi-MOM");
- CommandLinePrefStore store(&cl);
+ scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl);
Value* actual = NULL;
EXPECT_EQ(PrefStore::READ_OK,
- store.GetValue(prefs::kApplicationLocale, &actual));
+ store->GetValue(prefs::kApplicationLocale, &actual));
std::string result;
EXPECT_TRUE(actual->GetAsString(&result));
EXPECT_EQ("hi-MOM", result);
@@ -54,9 +60,10 @@ TEST(CommandLinePrefStoreTest, SimpleStringPref) {
TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
CommandLine cl(CommandLine::NO_PROGRAM);
cl.AppendSwitch(switches::kNoProxyServer);
- TestCommandLinePrefStore store(&cl);
+ scoped_refptr<TestCommandLinePrefStore> store =
+ new TestCommandLinePrefStore(&cl);
- store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_DIRECT);
+ store->VerifyProxyMode(ProxyPrefs::MODE_DIRECT);
}
// Tests a command line with no recognized prefs.
@@ -64,35 +71,40 @@ TEST(CommandLinePrefStoreTest, NoPrefs) {
CommandLine cl(CommandLine::NO_PROGRAM);
cl.AppendSwitch(unknown_string);
cl.AppendSwitchASCII(unknown_bool, "a value");
- CommandLinePrefStore store(&cl);
+ scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl);
Value* actual = NULL;
- EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
- EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual));
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual));
}
// Tests a complex command line with multiple known and unknown switches.
TEST(CommandLinePrefStoreTest, MultipleSwitches) {
CommandLine cl(CommandLine::NO_PROGRAM);
cl.AppendSwitch(unknown_string);
- cl.AppendSwitch(switches::kProxyAutoDetect);
cl.AppendSwitchASCII(switches::kProxyServer, "proxy");
cl.AppendSwitchASCII(switches::kProxyBypassList, "list");
cl.AppendSwitchASCII(unknown_bool, "a value");
- TestCommandLinePrefStore store(&cl);
+ scoped_refptr<TestCommandLinePrefStore> store =
+ new TestCommandLinePrefStore(&cl);
Value* actual = NULL;
- EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
- store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_AUTO_DETECT);
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual));
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual));
+
+ store->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS);
+
+ Value* value = NULL;
+ ASSERT_EQ(PrefStore::READ_OK, store->GetValue(prefs::kProxy, &value));
+ ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType());
+ ProxyConfigDictionary dict(static_cast<DictionaryValue*>(value));
- EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
std::string string_result = "";
- ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual));
- EXPECT_TRUE(actual->GetAsString(&string_result));
+
+ ASSERT_TRUE(dict.GetProxyServer(&string_result));
EXPECT_EQ("proxy", string_result);
- ASSERT_EQ(PrefStore::READ_OK,
- store.GetValue(prefs::kProxyBypassList, &actual));
- EXPECT_TRUE(actual->GetAsString(&string_result));
+
+ ASSERT_TRUE(dict.GetBypassList(&string_result));
EXPECT_EQ("list", string_result);
}
@@ -101,18 +113,21 @@ TEST(CommandLinePrefStoreTest, ProxySwitchValidation) {
CommandLine cl(CommandLine::NO_PROGRAM);
// No switches.
- TestCommandLinePrefStore store(&cl);
- EXPECT_TRUE(store.ProxySwitchesAreValid());
+ scoped_refptr<TestCommandLinePrefStore> store =
+ new TestCommandLinePrefStore(&cl);
+ EXPECT_TRUE(store->ProxySwitchesAreValid());
// Only no-proxy.
cl.AppendSwitch(switches::kNoProxyServer);
- TestCommandLinePrefStore store2(&cl);
- EXPECT_TRUE(store2.ProxySwitchesAreValid());
+ scoped_refptr<TestCommandLinePrefStore> store2 =
+ new TestCommandLinePrefStore(&cl);
+ EXPECT_TRUE(store2->ProxySwitchesAreValid());
// Another proxy switch too.
cl.AppendSwitch(switches::kProxyAutoDetect);
- TestCommandLinePrefStore store3(&cl);
- EXPECT_FALSE(store3.ProxySwitchesAreValid());
+ scoped_refptr<TestCommandLinePrefStore> store3 =
+ new TestCommandLinePrefStore(&cl);
+ EXPECT_FALSE(store3->ProxySwitchesAreValid());
// All proxy switches except no-proxy.
CommandLine cl2(CommandLine::NO_PROGRAM);
@@ -120,19 +135,28 @@ TEST(CommandLinePrefStoreTest, ProxySwitchValidation) {
cl2.AppendSwitchASCII(switches::kProxyServer, "server");
cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url");
cl2.AppendSwitchASCII(switches::kProxyBypassList, "list");
- TestCommandLinePrefStore store4(&cl2);
- EXPECT_TRUE(store4.ProxySwitchesAreValid());
+ scoped_refptr<TestCommandLinePrefStore> store4 =
+ new TestCommandLinePrefStore(&cl2);
+ EXPECT_TRUE(store4->ProxySwitchesAreValid());
}
TEST(CommandLinePrefStoreTest, ManualProxyModeInference) {
CommandLine cl1(CommandLine::NO_PROGRAM);
cl1.AppendSwitch(unknown_string);
cl1.AppendSwitchASCII(switches::kProxyServer, "proxy");
- TestCommandLinePrefStore store1(&cl1);
- store1.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_FIXED_SERVERS);
+ scoped_refptr<TestCommandLinePrefStore> store1 =
+ new TestCommandLinePrefStore(&cl1);
+ store1->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS);
CommandLine cl2(CommandLine::NO_PROGRAM);
cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy");
- TestCommandLinePrefStore store2(&cl2);
- store2.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_PAC_SCRIPT);
+ scoped_refptr<TestCommandLinePrefStore> store2 =
+ new TestCommandLinePrefStore(&cl2);
+ store2->VerifyProxyMode(ProxyPrefs::MODE_PAC_SCRIPT);
+
+ CommandLine cl3(CommandLine::NO_PROGRAM);
+ cl3.AppendSwitchASCII(switches::kProxyServer, "");
+ scoped_refptr<TestCommandLinePrefStore> store3 =
+ new TestCommandLinePrefStore(&cl3);
+ store3->VerifyProxyMode(ProxyPrefs::MODE_DIRECT);
}
diff --git a/chrome/browser/prefs/default_pref_store.cc b/chrome/browser/prefs/default_pref_store.cc
new file mode 100644
index 0000000..cacc833
--- /dev/null
+++ b/chrome/browser/prefs/default_pref_store.cc
@@ -0,0 +1,20 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prefs/default_pref_store.h"
+
+DefaultPrefStore::DefaultPrefStore() {}
+
+DefaultPrefStore::~DefaultPrefStore() {}
+
+void DefaultPrefStore::SetDefaultValue(const std::string& key, Value* value) {
+ CHECK(GetValue(key, NULL) == READ_NO_VALUE);
+ SetValue(key, value);
+}
+
+Value::ValueType DefaultPrefStore::GetType(const std::string& key) const {
+ Value* value;
+ return GetValue(key, &value) == READ_OK ? value->GetType()
+ : Value::TYPE_NULL;
+}
diff --git a/chrome/browser/prefs/default_pref_store.h b/chrome/browser/prefs/default_pref_store.h
index 9e2e715..79a6a0e 100644
--- a/chrome/browser/prefs/default_pref_store.h
+++ b/chrome/browser/prefs/default_pref_store.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,22 +6,24 @@
#define CHROME_BROWSER_PREFS_DEFAULT_PREF_STORE_H_
#pragma once
-#include <map>
+#include <string>
-#include "base/basictypes.h"
+#include "base/values.h"
#include "chrome/browser/prefs/value_map_pref_store.h"
// This PrefStore keeps track of default preference values set when a
// preference is registered with the PrefService.
class DefaultPrefStore : public ValueMapPrefStore {
public:
- DefaultPrefStore() {}
- virtual ~DefaultPrefStore() {}
+ DefaultPrefStore();
+ virtual ~DefaultPrefStore();
// Stores a new |value| for |key|. Assumes ownership of |value|.
- void SetDefaultValue(const std::string& key, Value* value) {
- SetValue(key, value);
- }
+ void SetDefaultValue(const std::string& key, Value* value);
+
+ // Returns the registered type for |key| or Value::TYPE_NULL if the |key|
+ // has not been registered.
+ Value::ValueType GetType(const std::string& key) const;
private:
DISALLOW_COPY_AND_ASSIGN(DefaultPrefStore);
diff --git a/chrome/browser/prefs/overlay_persistent_pref_store.cc b/chrome/browser/prefs/overlay_persistent_pref_store.cc
new file mode 100644
index 0000000..16c082a
--- /dev/null
+++ b/chrome/browser/prefs/overlay_persistent_pref_store.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prefs/overlay_persistent_pref_store.h"
+
+OverlayPersistentPrefStore::OverlayPersistentPrefStore(
+ PersistentPrefStore* underlay)
+ : underlay_(underlay) {
+ underlay_->AddObserver(this);
+}
+OverlayPersistentPrefStore::~OverlayPersistentPrefStore() {
+ underlay_->RemoveObserver(this);
+}
+
+void OverlayPersistentPrefStore::AddObserver(PrefStore::Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void OverlayPersistentPrefStore::RemoveObserver(PrefStore::Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool OverlayPersistentPrefStore::IsInitializationComplete() const {
+ return underlay_->IsInitializationComplete();
+}
+
+PrefStore::ReadResult OverlayPersistentPrefStore::GetValue(
+ const std::string& key, Value** result) const {
+ if (overlay_.GetValue(key, result))
+ return READ_OK;
+ return underlay_->GetValue(key, result);
+}
+
+void OverlayPersistentPrefStore::SetValue(const std::string& key,
+ Value* value) {
+ if (overlay_.SetValue(key, value))
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+}
+
+void OverlayPersistentPrefStore::SetValueSilently(const std::string& key,
+ Value* value) {
+ overlay_.SetValue(key, value);
+}
+
+void OverlayPersistentPrefStore::RemoveValue(const std::string& key) {
+ if (overlay_.RemoveValue(key))
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+}
+
+bool OverlayPersistentPrefStore::ReadOnly() const {
+ return false;
+}
+
+PersistentPrefStore::PrefReadError OverlayPersistentPrefStore::ReadPrefs() {
+ // We do not read intentionally.
+ return PersistentPrefStore::PREF_READ_ERROR_NONE;
+}
+
+bool OverlayPersistentPrefStore::WritePrefs() {
+ // We do not write intentionally.
+ return true;
+}
+
+void OverlayPersistentPrefStore::ScheduleWritePrefs() {
+ // We do not write intentionally.
+}
+
+void OverlayPersistentPrefStore::OnPrefValueChanged(const std::string& key) {
+ if (!overlay_.GetValue(key, NULL))
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+}
+
+void OverlayPersistentPrefStore::OnInitializationCompleted() {
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
+ OnInitializationCompleted());
+}
diff --git a/chrome/browser/prefs/overlay_persistent_pref_store.h b/chrome/browser/prefs/overlay_persistent_pref_store.h
new file mode 100644
index 0000000..dcc3161
--- /dev/null
+++ b/chrome/browser/prefs/overlay_persistent_pref_store.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
+#define CHROME_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/observer_list.h"
+#include "base/ref_counted.h"
+#include "chrome/browser/prefs/pref_value_map.h"
+#include "chrome/common/persistent_pref_store.h"
+
+// PersistentPrefStore that directs all write operations into a in-memory
+// PrefValueMap. Read operations are first answered by the PrefValueMap.
+// If the PrefValueMap does not contain a value for the requested key,
+// the look-up is passed on to an underlying PersistentPrefStore |underlay_|.
+class OverlayPersistentPrefStore : public PersistentPrefStore,
+ public PrefStore::Observer {
+ public:
+ explicit OverlayPersistentPrefStore(PersistentPrefStore* underlay);
+ virtual ~OverlayPersistentPrefStore();
+
+ // Methods of PrefStore.
+ virtual void AddObserver(PrefStore::Observer* observer);
+ virtual void RemoveObserver(PrefStore::Observer* observer);
+ virtual bool IsInitializationComplete() const;
+ virtual ReadResult GetValue(const std::string& key, Value** result) const;
+
+ // Methods of PersistentPrefStore.
+ virtual void SetValue(const std::string& key, Value* value);
+ virtual void SetValueSilently(const std::string& key, Value* value);
+ virtual void RemoveValue(const std::string& key);
+ virtual bool ReadOnly() const;
+ virtual PrefReadError ReadPrefs();
+ virtual bool WritePrefs();
+ virtual void ScheduleWritePrefs();
+
+ private:
+ // Methods of PrefStore::Observer.
+ virtual void OnPrefValueChanged(const std::string& key);
+ virtual void OnInitializationCompleted();
+
+ ObserverList<PrefStore::Observer, true> observers_;
+ PrefValueMap overlay_;
+ scoped_refptr<PersistentPrefStore> underlay_;
+
+ DISALLOW_COPY_AND_ASSIGN(OverlayPersistentPrefStore);
+};
+
+#endif // CHROME_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
diff --git a/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc b/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc
new file mode 100644
index 0000000..7e2e0a2
--- /dev/null
+++ b/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/browser/prefs/overlay_persistent_pref_store.h"
+#include "chrome/browser/prefs/testing_pref_store.h"
+#include "chrome/common/pref_store_observer_mock.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::Mock;
+using ::testing::StrEq;
+
+const char key[] = "test.key";
+
+class OverlayPersistentPrefStoreTest : public testing::Test {
+ public:
+ OverlayPersistentPrefStoreTest()
+ : underlay_(new TestingPrefStore()),
+ overlay_(new OverlayPersistentPrefStore(underlay_.get())) {
+ }
+
+ scoped_refptr<TestingPrefStore> underlay_;
+ scoped_refptr<OverlayPersistentPrefStore> overlay_;
+};
+
+TEST_F(OverlayPersistentPrefStoreTest, Observer) {
+ PrefStoreObserverMock obs;
+ overlay_->AddObserver(&obs);
+
+ // Check that underlay first value is reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1);
+ underlay_->SetValue(key, Value::CreateIntegerValue(42));
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check that underlay overwriting is reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1);
+ underlay_->SetValue(key, Value::CreateIntegerValue(43));
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check that overwriting change in overlay is reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1);
+ overlay_->SetValue(key, Value::CreateIntegerValue(44));
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check that hidden underlay change is not reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0);
+ underlay_->SetValue(key, Value::CreateIntegerValue(45));
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check that overlay remove is reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1);
+ overlay_->RemoveValue(key);
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check that underlay remove is reported.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1);
+ underlay_->RemoveValue(key);
+ Mock::VerifyAndClearExpectations(&obs);
+
+ // Check respecting of silence.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0);
+ overlay_->SetValueSilently(key, Value::CreateIntegerValue(46));
+ Mock::VerifyAndClearExpectations(&obs);
+
+ overlay_->RemoveObserver(&obs);
+
+ // Check successful unsubscription.
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0);
+ underlay_->SetValue(key, Value::CreateIntegerValue(47));
+ overlay_->SetValue(key, Value::CreateIntegerValue(48));
+ Mock::VerifyAndClearExpectations(&obs);
+}
+
+TEST_F(OverlayPersistentPrefStoreTest, GetAndSet) {
+ Value* value = NULL;
+ int i = -1;
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, overlay_->GetValue(key, &value));
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, underlay_->GetValue(key, &value));
+
+ underlay_->SetValue(key, Value::CreateIntegerValue(42));
+
+ // Value shines through:
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(42, i);
+
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(42, i);
+
+ overlay_->SetValue(key, Value::CreateIntegerValue(43));
+
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(43, i);
+
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(42, i);
+
+ overlay_->RemoveValue(key);
+
+ // Value shines through:
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(42, i);
+
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value));
+ ASSERT_TRUE(value);
+ EXPECT_TRUE(value->GetAsInteger(&i));
+ EXPECT_EQ(42, i);
+}
diff --git a/chrome/browser/prefs/pref_change_registrar.cc b/chrome/browser/prefs/pref_change_registrar.cc
index 5655a8e..64c6096 100644
--- a/chrome/browser/prefs/pref_change_registrar.cc
+++ b/chrome/browser/prefs/pref_change_registrar.cc
@@ -10,6 +10,10 @@
PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {}
PrefChangeRegistrar::~PrefChangeRegistrar() {
+ // If you see an invalid memory access in this destructor, this
+ // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that
+ // has been destroyed. This should not happen any more but be warned.
+ // Feel free to contact battre@chromium.org in case this happens.
RemoveAll();
}
diff --git a/chrome/browser/prefs/pref_change_registrar_unittest.cc b/chrome/browser/prefs/pref_change_registrar_unittest.cc
index 2e4cd0e..3ad036f 100644
--- a/chrome/browser/prefs/pref_change_registrar_unittest.cc
+++ b/chrome/browser/prefs/pref_change_registrar_unittest.cc
@@ -7,7 +7,6 @@
#include "chrome/common/notification_observer_mock.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.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"
@@ -21,7 +20,7 @@ namespace {
class MockPrefService : public TestingPrefService {
public:
MockPrefService() {}
- virtual ~MockPrefService() {};
+ virtual ~MockPrefService() {}
MOCK_METHOD2(AddPrefObserver, void(const char*, NotificationObserver*));
MOCK_METHOD2(RemovePrefObserver, void(const char*, NotificationObserver*));
diff --git a/chrome/browser/prefs/pref_member.cc b/chrome/browser/prefs/pref_member.cc
index cc14384..5ff0f0d 100644
--- a/chrome/browser/prefs/pref_member.cc
+++ b/chrome/browser/prefs/pref_member.cc
@@ -18,7 +18,7 @@ PrefMemberBase::PrefMemberBase()
}
PrefMemberBase::~PrefMemberBase() {
- if (!pref_name_.empty())
+ if (prefs_ && !pref_name_.empty())
prefs_->RemovePrefObserver(pref_name_.c_str(), this);
}
@@ -37,6 +37,13 @@ void PrefMemberBase::Init(const char* pref_name, PrefService* prefs,
prefs_->AddPrefObserver(pref_name, this);
}
+void PrefMemberBase::Destroy() {
+ if (prefs_) {
+ prefs_->RemovePrefObserver(pref_name_.c_str(), this);
+ prefs_ = NULL;
+ }
+}
+
bool PrefMemberBase::IsManaged() const {
DCHECK(!pref_name_.empty());
const PrefService::Preference* pref =
@@ -89,18 +96,18 @@ void IntegerPrefMember::UpdatePref(const int& value) {
prefs()->SetInteger(pref_name().c_str(), value);
}
-RealPrefMember::RealPrefMember() : PrefMember<double>() {
+DoublePrefMember::DoublePrefMember() : PrefMember<double>() {
}
-RealPrefMember::~RealPrefMember() {
+DoublePrefMember::~DoublePrefMember() {
}
-void RealPrefMember::UpdateValueFromPref() const {
- value_ = prefs()->GetReal(pref_name().c_str());
+void DoublePrefMember::UpdateValueFromPref() const {
+ value_ = prefs()->GetDouble(pref_name().c_str());
}
-void RealPrefMember::UpdatePref(const double& value) {
- prefs()->SetReal(pref_name().c_str(), value);
+void DoublePrefMember::UpdatePref(const double& value) {
+ prefs()->SetDouble(pref_name().c_str(), value);
}
StringPrefMember::StringPrefMember() : PrefMember<std::string>() {
diff --git a/chrome/browser/prefs/pref_member.h b/chrome/browser/prefs/pref_member.h
index 6d1ab5a..082ec6e 100644
--- a/chrome/browser/prefs/pref_member.h
+++ b/chrome/browser/prefs/pref_member.h
@@ -45,6 +45,9 @@ class PrefMemberBase : public NotificationObserver {
NotificationObserver* observer);
// See PrefMember<> for description.
+ void Destroy();
+
+ // See PrefMember<> for description.
bool IsManaged() const;
// NotificationObserver
@@ -92,6 +95,12 @@ class PrefMember : public subtle::PrefMemberBase {
subtle::PrefMemberBase::Init(pref_name, prefs, observer);
}
+ // Unsubscribes the PrefMember from the PrefService. After calling this
+ // function, the PrefMember may not be used any more.
+ void Destroy() {
+ subtle::PrefMemberBase::Destroy();
+ }
+
// Check whether the pref is managed, i.e. controlled externally through
// enterprise configuration management (e.g. windows group policy). Returns
// false for unknown prefs.
@@ -169,17 +178,17 @@ class IntegerPrefMember : public PrefMember<int> {
DISALLOW_COPY_AND_ASSIGN(IntegerPrefMember);
};
-class RealPrefMember : public PrefMember<double> {
+class DoublePrefMember : public PrefMember<double> {
public:
- RealPrefMember();
- virtual ~RealPrefMember();
+ DoublePrefMember();
+ virtual ~DoublePrefMember();
protected:
virtual void UpdateValueFromPref() const;
virtual void UpdatePref(const double& value);
private:
- DISALLOW_COPY_AND_ASSIGN(RealPrefMember);
+ DISALLOW_COPY_AND_ASSIGN(DoublePrefMember);
};
class StringPrefMember : public PrefMember<std::string> {
diff --git a/chrome/browser/prefs/pref_member_unittest.cc b/chrome/browser/prefs/pref_member_unittest.cc
index 3f786afb..f0bf181 100644
--- a/chrome/browser/prefs/pref_member_unittest.cc
+++ b/chrome/browser/prefs/pref_member_unittest.cc
@@ -14,13 +14,13 @@ namespace {
static const char kBoolPref[] = "bool";
static const char kIntPref[] = "int";
-static const char kRealPref[] = "real";
+static const char kDoublePref[] = "double";
static const char kStringPref[] = "string";
void RegisterTestPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(kBoolPref, false);
prefs->RegisterIntegerPref(kIntPref, 0);
- prefs->RegisterRealPref(kRealPref, 0.0);
+ prefs->RegisterDoublePref(kDoublePref, 0.0);
prefs->RegisterStringPref(kStringPref, "default");
}
@@ -98,26 +98,26 @@ TEST(PrefMemberTest, BasicGetAndSet) {
EXPECT_EQ(2, integer.GetValue());
EXPECT_EQ(2, *integer);
- // Test real (double)
- RealPrefMember real;
- real.Init(kRealPref, &prefs, NULL);
+ // Test double
+ DoublePrefMember double_member;
+ double_member.Init(kDoublePref, &prefs, NULL);
// Check the defaults
- EXPECT_EQ(0.0, prefs.GetReal(kRealPref));
- EXPECT_EQ(0.0, real.GetValue());
- EXPECT_EQ(0.0, *real);
+ EXPECT_EQ(0.0, prefs.GetDouble(kDoublePref));
+ EXPECT_EQ(0.0, double_member.GetValue());
+ EXPECT_EQ(0.0, *double_member);
// Try changing through the member variable.
- real.SetValue(1.0);
- EXPECT_EQ(1.0, real.GetValue());
- EXPECT_EQ(1.0, prefs.GetReal(kRealPref));
- EXPECT_EQ(1.0, *real);
+ double_member.SetValue(1.0);
+ EXPECT_EQ(1.0, double_member.GetValue());
+ EXPECT_EQ(1.0, prefs.GetDouble(kDoublePref));
+ EXPECT_EQ(1.0, *double_member);
// Try changing back through the pref.
- prefs.SetReal(kRealPref, 3.0);
- EXPECT_EQ(3.0, prefs.GetReal(kRealPref));
- EXPECT_EQ(3.0, real.GetValue());
- EXPECT_EQ(3.0, *real);
+ prefs.SetDouble(kDoublePref, 3.0);
+ EXPECT_EQ(3.0, prefs.GetDouble(kDoublePref));
+ EXPECT_EQ(3.0, double_member.GetValue());
+ EXPECT_EQ(3.0, *double_member);
// Test string
StringPrefMember string;
@@ -142,14 +142,14 @@ TEST(PrefMemberTest, BasicGetAndSet) {
}
TEST(PrefMemberTest, TwoPrefs) {
- // Make sure two RealPrefMembers stay in sync.
+ // Make sure two DoublePrefMembers stay in sync.
TestingPrefService prefs;
RegisterTestPrefs(&prefs);
- RealPrefMember pref1;
- pref1.Init(kRealPref, &prefs, NULL);
- RealPrefMember pref2;
- pref2.Init(kRealPref, &prefs, NULL);
+ DoublePrefMember pref1;
+ pref1.Init(kDoublePref, &prefs, NULL);
+ DoublePrefMember pref2;
+ pref2.Init(kDoublePref, &prefs, NULL);
pref1.SetValue(2.3);
EXPECT_EQ(2.3, *pref2);
@@ -157,7 +157,7 @@ TEST(PrefMemberTest, TwoPrefs) {
pref2.SetValue(3.5);
EXPECT_EQ(3.5, *pref1);
- prefs.SetReal(kRealPref, 4.2);
+ prefs.SetDouble(kDoublePref, 4.2);
EXPECT_EQ(4.2, *pref1);
EXPECT_EQ(4.2, *pref2);
}
diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
index 23ca06a..cbfa4bb 100644
--- a/chrome/browser/prefs/pref_service.cc
+++ b/chrome/browser/prefs/pref_service.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,8 +7,11 @@
#include <algorithm>
#include <string>
+<<<<<<< HEAD
#include "app/l10n_util.h"
#ifndef ANDROID
+=======
+>>>>>>> chromium.org at r11.0.672.0
#include "base/command_line.h"
#endif
#include "base/file_path.h"
@@ -23,9 +26,11 @@
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/extensions/extension_pref_store.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/overlay_persistent_pref_store.h"
#include "chrome/browser/prefs/pref_notifier_impl.h"
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/common/json_pref_store.h"
@@ -35,7 +40,11 @@
#include "chrome/common/notification_service.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
+<<<<<<< HEAD
#endif
+=======
+#include "ui/base/l10n/l10n_util.h"
+>>>>>>> chromium.org at r11.0.672.0
namespace {
@@ -61,10 +70,10 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) {
return Value::CreateIntegerValue(val);
}
- case Value::TYPE_REAL: {
+ case Value::TYPE_DOUBLE: {
double val;
base::StringToDouble(resource_string, &val);
- return Value::CreateRealValue(val);
+ return Value::CreateDoubleValue(val);
}
case Value::TYPE_STRING: {
@@ -112,32 +121,51 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename,
}
#endif
+<<<<<<< HEAD
#ifdef ANDROID
return new PrefService(NULL, NULL, NULL, NULL, NULL, NULL);
#else
ConfigurationPolicyPrefStore* managed =
+=======
+ ConfigurationPolicyPrefStore* managed_platform =
+>>>>>>> chromium.org at r11.0.672.0
ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore();
- ConfigurationPolicyPrefStore* device_management =
- ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore(
- profile);
+ ConfigurationPolicyPrefStore* managed_cloud =
+ ConfigurationPolicyPrefStore::CreateManagedCloudPolicyPrefStore(profile);
CommandLinePrefStore* command_line =
new CommandLinePrefStore(CommandLine::ForCurrentProcess());
JsonPrefStore* user = new JsonPrefStore(
pref_filename,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
- ConfigurationPolicyPrefStore* recommended =
- ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
+ ConfigurationPolicyPrefStore* recommended_platform =
+ ConfigurationPolicyPrefStore::CreateRecommendedPlatformPolicyPrefStore();
+ ConfigurationPolicyPrefStore* recommended_cloud =
+ ConfigurationPolicyPrefStore::CreateRecommendedCloudPolicyPrefStore(
+ profile);
+ DefaultPrefStore* default_pref_store = new DefaultPrefStore();
+
+ return new PrefService(managed_platform, managed_cloud, extension_prefs,
+ command_line, user, recommended_platform,
+ recommended_cloud, default_pref_store);
+}
+<<<<<<< HEAD
return new PrefService(managed, device_management, extension_prefs,
command_line, user, recommended);
#endif
+=======
+PrefService* PrefService::CreateIncognitoPrefService(
+ PrefStore* incognito_extension_prefs) {
+ return new PrefService(*this, incognito_extension_prefs);
+>>>>>>> chromium.org at r11.0.672.0
}
PrefService::PrefService(PrefStore* managed_platform_prefs,
- PrefStore* device_management_prefs,
+ PrefStore* managed_cloud_prefs,
PrefStore* extension_prefs,
PrefStore* command_line_prefs,
PersistentPrefStore* user_prefs,
+<<<<<<< HEAD
PrefStore* recommended_prefs)
: user_pref_store_(user_prefs) {
#ifndef ANDROID
@@ -145,11 +173,21 @@ PrefService::PrefService(PrefStore* managed_platform_prefs,
#endif
default_store_ = new DefaultPrefStore();
pref_value_store_ =
+=======
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
+ DefaultPrefStore* default_store)
+ : user_pref_store_(user_prefs),
+ default_store_(default_store) {
+ pref_notifier_.reset(new PrefNotifierImpl(this));
+ pref_value_store_.reset(
+>>>>>>> chromium.org at r11.0.672.0
new PrefValueStore(managed_platform_prefs,
- device_management_prefs,
+ managed_cloud_prefs,
extension_prefs,
command_line_prefs,
user_pref_store_,
+<<<<<<< HEAD
recommended_prefs,
default_store_,
#ifdef ANDROID
@@ -157,6 +195,31 @@ PrefService::PrefService(PrefStore* managed_platform_prefs,
#else
pref_notifier_.get());
#endif
+=======
+ recommended_platform_prefs,
+ recommended_cloud_prefs,
+ default_store,
+ pref_notifier_.get()));
+ InitFromStorage();
+}
+
+PrefService::PrefService(const PrefService& original,
+ PrefStore* incognito_extension_prefs)
+ : user_pref_store_(
+ new OverlayPersistentPrefStore(original.user_pref_store_.get())),
+ default_store_(original.default_store_.get()){
+ pref_notifier_.reset(new PrefNotifierImpl(this));
+ pref_value_store_.reset(original.pref_value_store_->CloneAndSpecialize(
+ NULL, // managed_platform_prefs
+ NULL, // managed_cloud_prefs
+ incognito_extension_prefs,
+ NULL, // command_line_prefs
+ user_pref_store_.get(),
+ NULL, // recommended_platform_prefs
+ NULL, // recommended_cloud_prefs
+ default_store_.get(),
+ pref_notifier_.get()));
+>>>>>>> chromium.org at r11.0.672.0
InitFromStorage();
}
@@ -164,6 +227,11 @@ PrefService::~PrefService() {
DCHECK(CalledOnValidThread());
STLDeleteContainerPointers(prefs_.begin(), prefs_.end());
prefs_.clear();
+
+ // Reset pointers so accesses after destruction reliably crash.
+ pref_value_store_.reset();
+ user_pref_store_ = NULL;
+ default_store_ = NULL;
}
void PrefService::InitFromStorage() {
@@ -217,8 +285,8 @@ void PrefService::RegisterIntegerPref(const char* path, int default_value) {
RegisterPreference(path, Value::CreateIntegerValue(default_value));
}
-void PrefService::RegisterRealPref(const char* path, double default_value) {
- RegisterPreference(path, Value::CreateRealValue(default_value));
+void PrefService::RegisterDoublePref(const char* path, double default_value) {
+ RegisterPreference(path, Value::CreateDoubleValue(default_value));
}
void PrefService::RegisterStringPref(const char* path,
@@ -235,10 +303,19 @@ void PrefService::RegisterListPref(const char* path) {
RegisterPreference(path, new ListValue());
}
+void PrefService::RegisterListPref(const char* path, ListValue* default_value) {
+ RegisterPreference(path, default_value);
+}
+
void PrefService::RegisterDictionaryPref(const char* path) {
RegisterPreference(path, new DictionaryValue());
}
+void PrefService::RegisterDictionaryPref(const char* path,
+ DictionaryValue* default_value) {
+ RegisterPreference(path, default_value);
+}
+
void PrefService::RegisterLocalizedBooleanPref(const char* path,
int locale_default_message_id) {
RegisterPreference(
@@ -253,11 +330,11 @@ void PrefService::RegisterLocalizedIntegerPref(const char* path,
CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id));
}
-void PrefService::RegisterLocalizedRealPref(const char* path,
- int locale_default_message_id) {
+void PrefService::RegisterLocalizedDoublePref(const char* path,
+ int locale_default_message_id) {
RegisterPreference(
path,
- CreateLocaleDefaultValue(Value::TYPE_REAL, locale_default_message_id));
+ CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id));
}
void PrefService::RegisterLocalizedStringPref(const char* path,
@@ -297,7 +374,7 @@ int PrefService::GetInteger(const char* path) const {
return result;
}
-double PrefService::GetReal(const char* path) const {
+double PrefService::GetDouble(const char* path) const {
DCHECK(CalledOnValidThread());
double result = 0.0;
@@ -307,7 +384,7 @@ double PrefService::GetReal(const char* path) const {
NOTREACHED() << "Trying to read an unregistered pref: " << path;
return result;
}
- bool rv = pref->GetValue()->GetAsReal(&result);
+ bool rv = pref->GetValue()->GetAsDouble(&result);
DCHECK(rv);
return result;
}
@@ -347,15 +424,34 @@ FilePath PrefService::GetFilePath(const char* path) const {
}
bool PrefService::HasPrefPath(const char* path) const {
- return pref_value_store_->HasPrefPath(path);
+ const Preference* pref = FindPreference(path);
+ return pref && !pref->IsDefaultValue();
+}
+
+DictionaryValue* PrefService::GetPreferenceValues() const {
+ DCHECK(CalledOnValidThread());
+ DictionaryValue* out = new DictionaryValue;
+ DefaultPrefStore::const_iterator i = default_store_->begin();
+ for (; i != default_store_->end(); ++i) {
+ const Value* value = FindPreference(i->first.c_str())->GetValue();
+ out->Set(i->first, value->DeepCopy());
+ }
+ return out;
}
const PrefService::Preference* PrefService::FindPreference(
const char* pref_name) const {
DCHECK(CalledOnValidThread());
- Preference p(this, pref_name);
+ Preference p(this, pref_name, Value::TYPE_NULL);
PreferenceSet::const_iterator it = prefs_.find(&p);
- return it == prefs_.end() ? NULL : *it;
+ if (it != prefs_.end())
+ return *it;
+ const Value::ValueType type = default_store_->GetType(pref_name);
+ if (type == Value::TYPE_NULL)
+ return NULL;
+ Preference* new_pref = new Preference(this, pref_name, type);
+ prefs_.insert(new_pref);
+ return new_pref;
}
bool PrefService::ReadOnly() const {
@@ -372,10 +468,7 @@ PrefNotifier* PrefService::pref_notifier() const {
bool PrefService::IsManagedPreference(const char* pref_name) const {
const Preference* pref = FindPreference(pref_name);
- if (pref && pref->IsManaged()) {
- return true;
- }
- return false;
+ return pref && pref->IsManaged();
}
const DictionaryValue* PrefService::GetDictionary(const char* path) const {
@@ -387,8 +480,10 @@ const DictionaryValue* PrefService::GetDictionary(const char* path) const {
return NULL;
}
const Value* value = pref->GetValue();
- if (value->GetType() == Value::TYPE_NULL)
+ if (value->GetType() != Value::TYPE_DICTIONARY) {
+ NOTREACHED();
return NULL;
+ }
return static_cast<const DictionaryValue*>(value);
}
@@ -401,8 +496,10 @@ const ListValue* PrefService::GetList(const char* path) const {
return NULL;
}
const Value* value = pref->GetValue();
- if (value->GetType() == Value::TYPE_NULL)
+ if (value->GetType() != Value::TYPE_LIST) {
+ NOTREACHED();
return NULL;
+ }
return static_cast<const ListValue*>(value);
}
@@ -433,18 +530,8 @@ void PrefService::RegisterPreference(const char* path, Value* default_value) {
DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) <<
"invalid preference type: " << orig_type;
- // We set the default value of dictionaries and lists to be null so it's
- // easier for callers to check for empty dict/list prefs. The PrefValueStore
- // accepts ownership of the value (null or default_value).
- if (Value::TYPE_LIST == orig_type || Value::TYPE_DICTIONARY == orig_type) {
- default_store_->SetDefaultValue(path, Value::CreateNullValue());
- } else {
- // Hand off ownership.
- default_store_->SetDefaultValue(path, scoped_value.release());
- }
-
- pref_value_store_->RegisterPreferenceType(path, orig_type);
- prefs_.insert(new Preference(this, path));
+ // Hand off ownership.
+ default_store_->SetDefaultValue(path, scoped_value.release());
}
void PrefService::ClearPref(const char* path) {
@@ -469,13 +556,7 @@ void PrefService::Set(const char* path, const Value& value) {
return;
}
- // Allow dictionary and list types to be set to null, which removes their
- // user values.
- if (value.GetType() == Value::TYPE_NULL &&
- (pref->GetType() == Value::TYPE_DICTIONARY ||
- pref->GetType() == Value::TYPE_LIST)) {
- user_pref_store_->RemoveValue(path);
- } else if (pref->GetType() != value.GetType()) {
+ if (pref->GetType() != value.GetType()) {
NOTREACHED() << "Trying to set pref " << path
<< " of type " << pref->GetType()
<< " to value of type " << value.GetType();
@@ -492,8 +573,8 @@ void PrefService::SetInteger(const char* path, int value) {
SetUserPrefValue(path, Value::CreateIntegerValue(value));
}
-void PrefService::SetReal(const char* path, double value) {
- SetUserPrefValue(path, Value::CreateRealValue(value));
+void PrefService::SetDouble(const char* path, double value) {
+ SetUserPrefValue(path, Value::CreateDoubleValue(value));
}
void PrefService::SetString(const char* path, const std::string& value) {
@@ -541,6 +622,8 @@ void PrefService::RegisterInt64Pref(const char* path, int64 default_value) {
DictionaryValue* PrefService::GetMutableDictionary(const char* path) {
DCHECK(CalledOnValidThread());
+ DLOG_IF(WARNING, IsManagedPreference(path)) <<
+ "Attempt to change managed preference " << path;
const Preference* pref = FindPreference(path);
if (!pref) {
@@ -569,6 +652,8 @@ DictionaryValue* PrefService::GetMutableDictionary(const char* path) {
ListValue* PrefService::GetMutableList(const char* path) {
DCHECK(CalledOnValidThread());
+ DLOG_IF(WARNING, IsManagedPreference(path)) <<
+ "Attempt to change managed preference " << path;
const Preference* pref = FindPreference(path);
if (!pref) {
@@ -597,6 +682,8 @@ ListValue* PrefService::GetMutableList(const char* path) {
void PrefService::SetUserPrefValue(const char* path, Value* new_value) {
DCHECK(CalledOnValidThread());
+ DLOG_IF(WARNING, IsManagedPreference(path)) <<
+ "Attempt to change managed preference " << path;
const Preference* pref = FindPreference(path);
if (!pref) {
@@ -619,15 +706,17 @@ void PrefService::SetUserPrefValue(const char* path, Value* new_value) {
// PrefService::Preference
PrefService::Preference::Preference(const PrefService* service,
- const char* name)
+ const char* name,
+ Value::ValueType type)
: name_(name),
+ type_(type),
pref_service_(service) {
DCHECK(name);
DCHECK(service);
}
Value::ValueType PrefService::Preference::GetType() const {
- return pref_service_->pref_value_store_->GetRegisteredType(name_);
+ return type_;
}
const Value* PrefService::Preference::GetValue() const {
@@ -635,8 +724,10 @@ const Value* PrefService::Preference::GetValue() const {
"Must register pref before getting its value";
Value* found_value = NULL;
- if (pref_service_->pref_value_store_->GetValue(name_, &found_value))
+ if (pref_value_store()->GetValue(name_, type_, &found_value)) {
+ DCHECK(found_value->IsType(type_));
return found_value;
+ }
// Every registered preference has at least a default value.
NOTREACHED() << "no valid value found for registered pref " << name_;
@@ -644,37 +735,29 @@ const Value* PrefService::Preference::GetValue() const {
}
bool PrefService::Preference::IsManaged() const {
- PrefValueStore* pref_value_store = pref_service_->pref_value_store_;
- return pref_value_store->PrefValueInManagedPlatformStore(name_.c_str()) ||
- pref_value_store->PrefValueInDeviceManagementStore(name_.c_str());
+ return pref_value_store()->PrefValueInManagedStore(name_.c_str());
}
bool PrefService::Preference::HasExtensionSetting() const {
- return pref_service_->pref_value_store_->
- PrefValueInExtensionStore(name_.c_str());
+ return pref_value_store()->PrefValueInExtensionStore(name_.c_str());
}
bool PrefService::Preference::HasUserSetting() const {
- return pref_service_->pref_value_store_->
- PrefValueInUserStore(name_.c_str());
+ return pref_value_store()->PrefValueInUserStore(name_.c_str());
}
bool PrefService::Preference::IsExtensionControlled() const {
- return pref_service_->pref_value_store_->
- PrefValueFromExtensionStore(name_.c_str());
+ return pref_value_store()->PrefValueFromExtensionStore(name_.c_str());
}
bool PrefService::Preference::IsUserControlled() const {
- return pref_service_->pref_value_store_->
- PrefValueFromUserStore(name_.c_str());
+ return pref_value_store()->PrefValueFromUserStore(name_.c_str());
}
bool PrefService::Preference::IsDefaultValue() const {
- return pref_service_->pref_value_store_->
- PrefValueFromDefaultStore(name_.c_str());
+ return pref_value_store()->PrefValueFromDefaultStore(name_.c_str());
}
bool PrefService::Preference::IsUserModifiable() const {
- return pref_service_->pref_value_store_->
- PrefValueUserModifiable(name_.c_str());
+ return pref_value_store()->PrefValueUserModifiable(name_.c_str());
}
diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h
index 9e1bd33..2c28d6a 100644
--- a/chrome/browser/prefs/pref_service.h
+++ b/chrome/browser/prefs/pref_service.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -38,11 +38,12 @@ class PrefService : public base::NonThreadSafe {
public:
// The type of the preference is determined by the type with which it is
- // registered. This type needs to be a boolean, integer, real, string,
+ // registered. This type needs to be a boolean, integer, double, string,
// dictionary (a branch), or list. You shouldn't need to construct this on
// your own; use the PrefService::Register*Pref methods instead.
Preference(const PrefService* service,
- const char* name);
+ const char* name,
+ Value::ValueType type);
~Preference() {}
// Returns the name of the Preference (i.e., the key, e.g.,
@@ -90,8 +91,14 @@ class PrefService : public base::NonThreadSafe {
private:
friend class PrefService;
+ PrefValueStore* pref_value_store() const {
+ return pref_service_->pref_value_store_.get();
+ }
+
std::string name_;
+ Value::ValueType type_;
+
// Reference to the PrefService in which this pref was created.
const PrefService* pref_service_;
@@ -109,6 +116,12 @@ class PrefService : public base::NonThreadSafe {
PrefStore* extension_pref_store,
Profile* profile);
+ // Creates an incognito copy of the pref service that shares most pref stores
+ // but uses a fresh non-persistent overlay for the user pref store and an
+ // individual extension pref store (to cache the effective extension prefs for
+ // incognito windows).
+ PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs);
+
virtual ~PrefService();
// Reloads the data from file. This should only be called when the importer
@@ -133,19 +146,22 @@ class PrefService : public base::NonThreadSafe {
// Make the PrefService aware of a pref.
void RegisterBooleanPref(const char* path, bool default_value);
void RegisterIntegerPref(const char* path, int default_value);
- void RegisterRealPref(const char* path, double default_value);
+ void RegisterDoublePref(const char* path, double default_value);
void RegisterStringPref(const char* path, const std::string& default_value);
void RegisterFilePathPref(const char* path, const FilePath& default_value);
void RegisterListPref(const char* path);
void RegisterDictionaryPref(const char* path);
+ // These take ownership of the default_value:
+ void RegisterListPref(const char* path, ListValue* default_value);
+ void RegisterDictionaryPref(const char* path, DictionaryValue* default_value);
// These variants use a default value from the locale dll instead.
void RegisterLocalizedBooleanPref(const char* path,
int locale_default_message_id);
void RegisterLocalizedIntegerPref(const char* path,
int locale_default_message_id);
- void RegisterLocalizedRealPref(const char* path,
- int locale_default_message_id);
+ void RegisterLocalizedDoublePref(const char* path,
+ int locale_default_message_id);
void RegisterLocalizedStringPref(const char* path,
int locale_default_message_id);
@@ -154,12 +170,13 @@ class PrefService : public base::NonThreadSafe {
// value (set when the pref was registered) will be returned.
bool GetBoolean(const char* path) const;
int GetInteger(const char* path) const;
- double GetReal(const char* path) const;
+ double GetDouble(const char* path) const;
std::string GetString(const char* path) const;
FilePath GetFilePath(const char* path) const;
- // Returns the branch if it exists. If it's not a branch or the branch does
- // not exist, returns NULL.
+ // Returns the branch if it exists, or the registered default value otherwise.
+ // Note that |path| must point to a registered preference. In that case, these
+ // functions will never return NULL.
const DictionaryValue* GetDictionary(const char* path) const;
const ListValue* GetList(const char* path) const;
@@ -173,7 +190,7 @@ class PrefService : public base::NonThreadSafe {
void Set(const char* path, const Value& value);
void SetBoolean(const char* path, bool value);
void SetInteger(const char* path, int value);
- void SetReal(const char* path, double value);
+ void SetDouble(const char* path, double value);
void SetString(const char* path, const std::string& value);
void SetFilePath(const char* path, const FilePath& value);
@@ -202,14 +219,9 @@ class PrefService : public base::NonThreadSafe {
// this checks if a value exists for the path.
bool HasPrefPath(const char* path) const;
- class PreferencePathComparator {
- public:
- bool operator() (Preference* lhs, Preference* rhs) const {
- return lhs->name() < rhs->name();
- }
- };
- typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
- const PreferenceSet& preference_set() const { return prefs_; }
+ // Returns a dictionary with effective preference values. The ownership
+ // is passed to the caller.
+ DictionaryValue* GetPreferenceValues() const;
// A helper method to quickly look up a preference. Returns NULL if the
// preference is not registered.
@@ -230,11 +242,13 @@ class PrefService : public base::NonThreadSafe {
// PrefStore pointers. This constructor is what CreatePrefService() ends up
// calling. It's also used for unit tests.
PrefService(PrefStore* managed_platform_prefs,
- PrefStore* device_management_prefs,
+ PrefStore* managed_cloud_prefs,
PrefStore* extension_prefs,
PrefStore* command_line_prefs,
PersistentPrefStore* user_prefs,
- PrefStore* recommended_prefs);
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
+ DefaultPrefStore* default_store);
#ifndef ANDROID
// The PrefNotifier handles registering and notifying preference observers.
@@ -244,6 +258,14 @@ class PrefService : public base::NonThreadSafe {
#endif
private:
+ class PreferencePathComparator {
+ public:
+ bool operator() (Preference* lhs, Preference* rhs) const {
+ return lhs->name() < rhs->name();
+ }
+ };
+ typedef std::set<Preference*, PreferencePathComparator> PreferenceSet;
+
friend class PrefServiceMockBuilder;
// Registration of pref change observers must be done using the
@@ -255,7 +277,15 @@ class PrefService : public base::NonThreadSafe {
friend class PrefChangeRegistrar;
friend class subtle::PrefMemberBase;
+<<<<<<< HEAD
#ifndef ANDROID
+=======
+ // Construct an incognito version of the pref service. Use
+ // CreateIncognitoPrefService() instead of calling this constructor directly.
+ PrefService(const PrefService& original,
+ PrefStore* incognito_extension_prefs);
+
+>>>>>>> chromium.org at r11.0.672.0
// If the pref at the given path changes, we call the observer's Observe
// method with PREF_CHANGED. Note that observers should not call these methods
// directly but rather use a PrefChangeRegistrar to make sure the observer
@@ -264,8 +294,10 @@ class PrefService : public base::NonThreadSafe {
virtual void RemovePrefObserver(const char* path, NotificationObserver* obs);
#endif
- // Add a preference to the PreferenceMap. If the pref already exists, return
- // false. This method takes ownership of |default_value|.
+ // Registers a new preference at |path|. The |default_value| must not be
+ // NULL as it determines the preference value's type.
+ // RegisterPreference must not be called twice for the same path.
+ // This method takes ownership of |default_value|.
void RegisterPreference(const char* path, Value* default_value);
// Sets the value for this pref path in the user pref store and informs the
@@ -278,16 +310,16 @@ class PrefService : public base::NonThreadSafe {
// The PrefValueStore provides prioritized preference values. It is created
// and owned by this PrefService. Subclasses may access it for unit testing.
- scoped_refptr<PrefValueStore> pref_value_store_;
-
- // The persistent pref store used for actual user data.
- PersistentPrefStore* user_pref_store_;
+ scoped_ptr<PrefValueStore> pref_value_store_;
- // Points to the default pref store we passed to the PrefValueStore.
- DefaultPrefStore* default_store_;
+ // Pref Stores and profile that we passed to the PrefValueStore.
+ scoped_refptr<PersistentPrefStore> user_pref_store_;
+ scoped_refptr<DefaultPrefStore> default_store_;
- // A set of all the registered Preference objects.
- PreferenceSet prefs_;
+ // Local cache of registered Preference objects. The default_store_
+ // is authoritative with respect to what the types and default values
+ // of registered preferences are.
+ mutable PreferenceSet prefs_;
DISALLOW_COPY_AND_ASSIGN(PrefService);
};
diff --git a/chrome/browser/prefs/pref_service_mock_builder.cc b/chrome/browser/prefs/pref_service_mock_builder.cc
index b02a334..e714451 100644
--- a/chrome/browser/prefs/pref_service_mock_builder.cc
+++ b/chrome/browser/prefs/pref_service_mock_builder.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/browser_thread.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_service.h"
#include "chrome/browser/prefs/testing_pref_store.h"
#include "chrome/common/json_pref_store.h"
@@ -19,87 +20,107 @@ PrefServiceMockBuilder::~PrefServiceMockBuilder() {}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithManagedPlatformPrefs(PrefStore* store) {
- managed_platform_prefs_.reset(store);
+ managed_platform_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
-PrefServiceMockBuilder::WithDeviceManagementPrefs(PrefStore* store) {
- device_management_prefs_.reset(store);
+PrefServiceMockBuilder::WithManagedCloudPrefs(PrefStore* store) {
+ managed_cloud_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithExtensionPrefs(PrefStore* store) {
- extension_prefs_.reset(store);
+ extension_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithCommandLinePrefs(PrefStore* store) {
- command_line_prefs_.reset(store);
+ command_line_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithUserPrefs(PersistentPrefStore* store) {
- user_prefs_.reset(store);
+ user_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
-PrefServiceMockBuilder::WithRecommendedPrefs(PrefStore* store) {
- recommended_prefs_.reset(store);
+PrefServiceMockBuilder::WithRecommendedPlatformPrefs(PrefStore* store) {
+ recommended_platform_prefs_ = store;
+ return *this;
+}
+
+PrefServiceMockBuilder&
+PrefServiceMockBuilder::WithRecommendedCloudPrefs(PrefStore* store) {
+ recommended_cloud_prefs_ = store;
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithManagedPlatformProvider(
policy::ConfigurationPolicyProvider* provider) {
- managed_platform_prefs_.reset(
- new policy::ConfigurationPolicyPrefStore(provider));
+ managed_platform_prefs_ = new policy::ConfigurationPolicyPrefStore(provider);
+ return *this;
+}
+
+PrefServiceMockBuilder&
+PrefServiceMockBuilder::WithManagedCloudProvider(
+ policy::ConfigurationPolicyProvider* provider) {
+ managed_cloud_prefs_ = new policy::ConfigurationPolicyPrefStore(provider);
return *this;
}
PrefServiceMockBuilder&
-PrefServiceMockBuilder::WithDeviceManagementProvider(
+PrefServiceMockBuilder::WithRecommendedPlatformProvider(
policy::ConfigurationPolicyProvider* provider) {
- device_management_prefs_.reset(
- new policy::ConfigurationPolicyPrefStore(provider));
+ recommended_platform_prefs_ =
+ new policy::ConfigurationPolicyPrefStore(provider);
return *this;
}
PrefServiceMockBuilder&
-PrefServiceMockBuilder::WithRecommendedProvider(
+PrefServiceMockBuilder::WithRecommendedCloudProvider(
policy::ConfigurationPolicyProvider* provider) {
- recommended_prefs_.reset(
- new policy::ConfigurationPolicyPrefStore(provider));
+ recommended_cloud_prefs_ = new policy::ConfigurationPolicyPrefStore(provider);
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithCommandLine(CommandLine* command_line) {
- command_line_prefs_.reset(new CommandLinePrefStore(command_line));
+ command_line_prefs_ = new CommandLinePrefStore(command_line);
return *this;
}
PrefServiceMockBuilder&
PrefServiceMockBuilder::WithUserFilePrefs(const FilePath& prefs_file) {
- user_prefs_.reset(
+ user_prefs_ =
new JsonPrefStore(prefs_file,
BrowserThread::GetMessageLoopProxyForThread(
- BrowserThread::FILE)));
+ BrowserThread::FILE));
return *this;
}
PrefService* PrefServiceMockBuilder::Create() {
PrefService* pref_service =
- new PrefService(managed_platform_prefs_.release(),
- device_management_prefs_.release(),
- extension_prefs_.release(),
- command_line_prefs_.release(),
- user_prefs_.release(),
- recommended_prefs_.release());
- user_prefs_.reset(new TestingPrefStore);
+ new PrefService(managed_platform_prefs_.get(),
+ managed_cloud_prefs_.get(),
+ extension_prefs_.get(),
+ command_line_prefs_.get(),
+ user_prefs_.get(),
+ recommended_platform_prefs_.get(),
+ recommended_cloud_prefs_.get(),
+ new DefaultPrefStore());
+ managed_platform_prefs_ = NULL;
+ managed_cloud_prefs_ = NULL;
+ extension_prefs_ = NULL;
+ command_line_prefs_ = NULL;
+ user_prefs_ = NULL;
+ recommended_platform_prefs_ = NULL;
+ recommended_cloud_prefs_ = NULL;
+ user_prefs_ = new TestingPrefStore;
return pref_service;
}
diff --git a/chrome/browser/prefs/pref_service_mock_builder.h b/chrome/browser/prefs/pref_service_mock_builder.h
index 9cc4fcc..3e4d1e0 100644
--- a/chrome/browser/prefs/pref_service_mock_builder.h
+++ b/chrome/browser/prefs/pref_service_mock_builder.h
@@ -7,7 +7,7 @@
#pragma once
#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
+#include "base/ref_counted.h"
#include "chrome/common/persistent_pref_store.h"
#include "chrome/common/pref_store.h"
@@ -29,18 +29,21 @@ class PrefServiceMockBuilder {
// Functions for setting the various parameters of the PrefService to build.
// These take ownership of the |store| parameter.
PrefServiceMockBuilder& WithManagedPlatformPrefs(PrefStore* store);
- PrefServiceMockBuilder& WithDeviceManagementPrefs(PrefStore* store);
+ PrefServiceMockBuilder& WithManagedCloudPrefs(PrefStore* store);
PrefServiceMockBuilder& WithExtensionPrefs(PrefStore* store);
PrefServiceMockBuilder& WithCommandLinePrefs(PrefStore* store);
PrefServiceMockBuilder& WithUserPrefs(PersistentPrefStore* store);
- PrefServiceMockBuilder& WithRecommendedPrefs(PrefStore* store);
+ PrefServiceMockBuilder& WithRecommendedPlatformPrefs(PrefStore* store);
+ PrefServiceMockBuilder& WithRecommendedCloudPrefs(PrefStore* store);
// Set up policy pref stores using the given policy provider.
PrefServiceMockBuilder& WithManagedPlatformProvider(
policy::ConfigurationPolicyProvider* provider);
- PrefServiceMockBuilder& WithDeviceManagementProvider(
+ PrefServiceMockBuilder& WithManagedCloudProvider(
policy::ConfigurationPolicyProvider* provider);
- PrefServiceMockBuilder& WithRecommendedProvider(
+ PrefServiceMockBuilder& WithRecommendedPlatformProvider(
+ policy::ConfigurationPolicyProvider* provider);
+ PrefServiceMockBuilder& WithRecommendedCloudProvider(
policy::ConfigurationPolicyProvider* provider);
// Specifies to use an actual command-line backed command-line pref store.
@@ -49,19 +52,17 @@ class PrefServiceMockBuilder {
// Specifies to use an actual file-backed user pref store.
PrefServiceMockBuilder& WithUserFilePrefs(const FilePath& prefs_file);
- // Sets the profile to pass to the PrefService.
- PrefServiceMockBuilder& WithRecommendedPrefs(Profile* profile);
-
// Creates the PrefService, invalidating the entire builder configuration.
PrefService* Create();
private:
- scoped_ptr<PrefStore> managed_platform_prefs_;
- scoped_ptr<PrefStore> device_management_prefs_;
- scoped_ptr<PrefStore> extension_prefs_;
- scoped_ptr<PrefStore> command_line_prefs_;
- scoped_ptr<PersistentPrefStore> user_prefs_;
- scoped_ptr<PrefStore> recommended_prefs_;
+ scoped_refptr<PrefStore> managed_platform_prefs_;
+ scoped_refptr<PrefStore> managed_cloud_prefs_;
+ scoped_refptr<PrefStore> extension_prefs_;
+ scoped_refptr<PrefStore> command_line_prefs_;
+ scoped_refptr<PersistentPrefStore> user_prefs_;
+ scoped_refptr<PrefStore> recommended_platform_prefs_;
+ scoped_refptr<PrefStore> recommended_cloud_prefs_;
DISALLOW_COPY_AND_ASSIGN(PrefServiceMockBuilder);
};
diff --git a/chrome/browser/prefs/pref_service_uitest.cc b/chrome/browser/prefs/pref_service_uitest.cc
index 9712481..fe2a79a 100644
--- a/chrome/browser/prefs/pref_service_uitest.cc
+++ b/chrome/browser/prefs/pref_service_uitest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,7 +17,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
-#include "gfx/rect.h"
+#include "ui/gfx/rect.h"
class PreferenceServiceTest : public UITest {
public:
@@ -29,17 +29,27 @@ class PreferenceServiceTest : public UITest {
file_util::Delete(tmp_profile_, true);
file_util::CreateDirectory(tmp_profile_);
- FilePath reference_pref_file =
- test_data_directory_
+ FilePath reference_pref_file;
+ if (new_profile_) {
+ reference_pref_file = test_data_directory_
+ .AppendASCII("profiles")
+ .AppendASCII("window_placement")
+ .AppendASCII("Default")
+ .Append(chrome::kPreferencesFilename);
+ tmp_pref_file_ = tmp_profile_.AppendASCII("Default");
+ ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_));
+ tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename);
+ } else {
+ reference_pref_file = test_data_directory_
.AppendASCII("profiles")
.AppendASCII("window_placement")
.Append(chrome::kLocalStateFilename);
-
- tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename);
+ tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename);
+ }
ASSERT_TRUE(file_util::PathExists(reference_pref_file));
-
- // Copy only the Local State file, the rest will be automatically created
+ // Copy only the Preferences file if |new_profile_|, or Local State if not,
+ // and the rest will be automatically created.
ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_));
#if defined(OS_WIN)
@@ -66,20 +76,21 @@ class PreferenceServiceTest : public UITest {
}
public:
+ bool new_profile_;
FilePath tmp_pref_file_;
FilePath tmp_profile_;
};
-#if defined(OS_WIN)
+#if !defined(OS_LINUX)
// This test verifies that the window position from the prefs file is restored
// when the app restores. This doesn't really make sense on Linux, where
// the window manager might fight with you over positioning. However, we
// might be able to make this work on buildbots.
-// Also, not sure what should happen on the mac. In any case, the code below
-// (minus the Windows bits) compiles fine on my Linux box now.
// TODO(port): revisit this.
TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) {
- // The window should open with the reference profile
+ // The window should open with the new reference profile, with window
+ // placement values stored in the user data directory.
+ new_profile_ = true;
ASSERT_TRUE(LaunchAppWithProfile());
ASSERT_TRUE(file_util::PathExists(tmp_pref_file_));
@@ -132,3 +143,66 @@ TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) {
EXPECT_EQ(is_maximized, is_window_maximized);
}
#endif
+
+#if !defined(OS_LINUX)
+TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsMigrated) {
+ // The window should open with the old reference profile, with window
+ // placement values stored in Local State.
+ new_profile_ = false;
+ ASSERT_TRUE(LaunchAppWithProfile());
+
+ ASSERT_TRUE(file_util::PathExists(tmp_pref_file_));
+
+ JSONFileValueSerializer deserializer(tmp_pref_file_);
+ scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL));
+
+ ASSERT_TRUE(root.get());
+ ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
+
+ // Retrieve the screen rect for the launched window
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+ scoped_refptr<WindowProxy> window(browser->GetWindow());
+ ASSERT_TRUE(window.get());
+
+ gfx::Rect bounds;
+ ASSERT_TRUE(window->GetBounds(&bounds));
+
+ // Values from old reference profile in Local State should have been
+ // correctly migrated to the user's Preferences -- if so, the window
+ // should be set to values taken from the user's Local State.
+ DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get());
+
+ // Retrieve the expected rect values from User Preferences, where they
+ // should have been migrated from Local State.
+ int bottom = 0;
+ std::string kBrowserWindowPlacement(prefs::kBrowserWindowPlacement);
+ EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".bottom",
+ &bottom));
+ EXPECT_EQ(bottom, bounds.y() + bounds.height());
+
+ int top = 0;
+ EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".top",
+ &top));
+ EXPECT_EQ(top, bounds.y());
+
+ int left = 0;
+ EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".left",
+ &left));
+ EXPECT_EQ(left, bounds.x());
+
+ int right = 0;
+ EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".right",
+ &right));
+ EXPECT_EQ(right, bounds.x() + bounds.width());
+
+ // Find if launched window is maximized.
+ bool is_window_maximized = false;
+ ASSERT_TRUE(window->IsMaximized(&is_window_maximized));
+ bool is_maximized = false;
+ EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized",
+ &is_maximized));
+ EXPECT_EQ(is_maximized, is_window_maximized);
+}
+#endif
+
diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc
index 1a79708..90a1882 100644
--- a/chrome/browser/prefs/pref_service_unittest.cc
+++ b/chrome/browser/prefs/pref_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,7 +16,7 @@
#include "chrome/browser/prefs/pref_observer_mock.h"
#include "chrome/browser/prefs/pref_service_mock_builder.h"
#include "chrome/browser/prefs/pref_value_store.h"
-#include "chrome/browser/prefs/proxy_prefs.h"
+#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/browser/prefs/testing_pref_store.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -148,15 +148,84 @@ TEST(PrefServiceTest, Observers) {
Mock::VerifyAndClearExpectations(&obs2);
}
+// Make sure that if a preference changes type, so the wrong type is stored in
+// the user pref file, it uses the correct fallback value instead.
+TEST(PrefServiceTest, GetValueChangedType) {
+ const int kTestValue = 10;
+ TestingPrefService prefs;
+ prefs.RegisterIntegerPref(prefs::kStabilityLaunchCount, kTestValue);
+
+ // Check falling back to a recommended value.
+ prefs.SetUserPref(prefs::kStabilityLaunchCount,
+ Value::CreateStringValue("not an integer"));
+ const PrefService::Preference* pref =
+ prefs.FindPreference(prefs::kStabilityLaunchCount);
+ ASSERT_TRUE(pref);
+ const Value* value = pref->GetValue();
+ ASSERT_TRUE(value);
+ EXPECT_EQ(Value::TYPE_INTEGER, value->GetType());
+ int actual_int_value = -1;
+ EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
+ EXPECT_EQ(kTestValue, actual_int_value);
+}
+
+void assertProxyMode(const ProxyConfigDictionary& dict,
+ ProxyPrefs::ProxyMode expected_mode) {
+ ProxyPrefs::ProxyMode actual_mode;
+ ASSERT_TRUE(dict.GetMode(&actual_mode));
+ EXPECT_EQ(expected_mode, actual_mode);
+}
+
+void assertProxyServer(const ProxyConfigDictionary& dict,
+ const std::string& expected) {
+ std::string actual;
+ if (!expected.empty()) {
+ ASSERT_TRUE(dict.GetProxyServer(&actual));
+ EXPECT_EQ(expected, actual);
+ } else {
+ EXPECT_FALSE(dict.GetProxyServer(&actual));
+ }
+}
+
+void assertPacUrl(const ProxyConfigDictionary& dict,
+ const std::string& expected) {
+ std::string actual;
+ if (!expected.empty()) {
+ ASSERT_TRUE(dict.GetPacUrl(&actual));
+ EXPECT_EQ(expected, actual);
+ } else {
+ EXPECT_FALSE(dict.GetPacUrl(&actual));
+ }
+}
+
+void assertBypassList(const ProxyConfigDictionary& dict,
+ const std::string& expected) {
+ std::string actual;
+ if (!expected.empty()) {
+ ASSERT_TRUE(dict.GetBypassList(&actual));
+ EXPECT_EQ(expected, actual);
+ } else {
+ EXPECT_FALSE(dict.GetBypassList(&actual));
+ }
+}
+
+void assertProxyModeWithoutParams(const ProxyConfigDictionary& dict,
+ ProxyPrefs::ProxyMode proxy_mode) {
+ assertProxyMode(dict, proxy_mode);
+ assertProxyServer(dict, "");
+ assertPacUrl(dict, "");
+ assertBypassList(dict, "");
+}
+
TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
CommandLine command_line(CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
command_line.AppendSwitchASCII(switches::kProxyServer, "789");
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyManuallyConfiguredProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kFixedServersProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
provider->AddPolicy(policy::kPolicyProxyBypassList,
Value::CreateStringValue("abc"));
provider->AddPolicy(policy::kPolicyProxyServer,
@@ -168,11 +237,11 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
builder.WithCommandLine(&command_line);
scoped_ptr<PrefService> prefs(builder.Create());
browser::RegisterUserPrefs(prefs.get());
- EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS,
- prefs->GetInteger(prefs::kProxyMode));
- EXPECT_EQ("789", prefs->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ("123", prefs->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
+ assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
+ assertProxyServer(dict, "789");
+ assertPacUrl(dict, "");
+ assertBypassList(dict, "123");
// Try a second time time with the managed PrefStore in place, the
// manual proxy policy should have removed all traces of the command
@@ -181,11 +250,11 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
builder.WithManagedPlatformProvider(provider.get());
scoped_ptr<PrefService> prefs2(builder.Create());
browser::RegisterUserPrefs(prefs2.get());
- EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS,
- prefs2->GetInteger(prefs::kProxyMode));
- EXPECT_EQ("ghi", prefs2->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ("abc", prefs2->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
+ assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
+ assertProxyServer(dict2, "ghi");
+ assertPacUrl(dict2, "");
+ assertBypassList(dict2, "abc");
}
TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
@@ -194,9 +263,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
command_line.AppendSwitchASCII(switches::kProxyServer, "789");
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyAutoDetectProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kAutoDetectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that command-line options are set correctly when
// there is no policy in effect.
@@ -204,10 +273,11 @@ TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
builder.WithCommandLine(&command_line);
scoped_ptr<PrefService> prefs(builder.Create());
browser::RegisterUserPrefs(prefs.get());
- EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS,
- prefs->GetInteger(prefs::kProxyMode));
- EXPECT_EQ("789", prefs->GetString(prefs::kProxyServer));
- EXPECT_EQ("123", prefs->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
+ assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
+ assertProxyServer(dict, "789");
+ assertPacUrl(dict, "");
+ assertBypassList(dict, "123");
// Try a second time time with the managed PrefStore in place, the
// no proxy policy should have removed all traces of the command
@@ -217,11 +287,8 @@ TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
builder.WithManagedPlatformProvider(provider.get());
scoped_ptr<PrefService> prefs2(builder.Create());
browser::RegisterUserPrefs(prefs2.get());
- EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT,
- prefs2->GetInteger(prefs::kProxyMode));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
+ assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
}
TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
@@ -229,9 +296,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
command_line.AppendSwitch(switches::kNoProxyServer);
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyAutoDetectProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kAutoDetectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that command-line options are set correctly when
// there is no policy in effect.
@@ -239,10 +306,8 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
builder.WithCommandLine(&command_line);
scoped_ptr<PrefService> prefs(builder.Create());
browser::RegisterUserPrefs(prefs.get());
- EXPECT_EQ(ProxyPrefs::MODE_DIRECT, prefs->GetInteger(prefs::kProxyMode));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
+ assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
// Try a second time time with the managed PrefStore in place, the
// auto-detect should be overridden. The default pref store must be
@@ -251,11 +316,8 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
builder.WithManagedPlatformProvider(provider.get());
scoped_ptr<PrefService> prefs2(builder.Create());
browser::RegisterUserPrefs(prefs2.get());
- EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT,
- prefs2->GetInteger(prefs::kProxyMode));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
+ assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
}
TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
@@ -263,9 +325,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
command_line.AppendSwitch(switches::kProxyAutoDetect);
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyNoProxyServerMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kDirectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that the auto-detect is set if there is no managed
// PrefStore.
@@ -273,10 +335,8 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
builder.WithCommandLine(&command_line);
scoped_ptr<PrefService> prefs(builder.Create());
browser::RegisterUserPrefs(prefs.get());
- EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, prefs->GetInteger(prefs::kProxyMode));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ(std::string(), prefs->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
+ assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
// Try a second time time with the managed PrefStore in place, the
// auto-detect should be overridden. The default pref store must be
@@ -285,10 +345,8 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
builder.WithManagedPlatformProvider(provider.get());
scoped_ptr<PrefService> prefs2(builder.Create());
browser::RegisterUserPrefs(prefs2.get());
- EXPECT_EQ(ProxyPrefs::MODE_DIRECT, prefs2->GetInteger(prefs::kProxyMode));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyServer));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyPacUrl));
- EXPECT_EQ(std::string(), prefs2->GetString(prefs::kProxyBypassList));
+ ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
+ assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
}
class PrefServiceSetValueTest : public testing::Test {
@@ -296,11 +354,7 @@ class PrefServiceSetValueTest : public testing::Test {
static const char kName[];
static const char kValue[];
- PrefServiceSetValueTest()
- : null_value_(Value::CreateNullValue()) {}
-
TestingPrefService prefs_;
- scoped_ptr<Value> null_value_;
PrefObserverMock observer_;
};
@@ -337,10 +391,8 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {
registrar.Init(&prefs_);
registrar.Add(kName, &observer_);
- // Dictionary values are special: setting one to NULL is the same as clearing
- // the user value, allowing the NULL default to take (or keep) control.
EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
- prefs_.Set(kName, *null_value_);
+ prefs_.RemoveUserPref(kName);
Mock::VerifyAndClearExpectations(&observer_);
DictionaryValue new_value;
@@ -353,8 +405,9 @@ TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {
prefs_.Set(kName, new_value);
Mock::VerifyAndClearExpectations(&observer_);
- observer_.Expect(&prefs_, kName, null_value_.get());
- prefs_.Set(kName, *null_value_);
+ DictionaryValue empty;
+ observer_.Expect(&prefs_, kName, &empty);
+ prefs_.Set(kName, empty);
Mock::VerifyAndClearExpectations(&observer_);
}
@@ -364,10 +417,8 @@ TEST_F(PrefServiceSetValueTest, SetListValue) {
registrar.Init(&prefs_);
registrar.Add(kName, &observer_);
- // List values are special: setting one to NULL is the same as clearing the
- // user value, allowing the NULL default to take (or keep) control.
EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
- prefs_.Set(kName, *null_value_);
+ prefs_.RemoveUserPref(kName);
Mock::VerifyAndClearExpectations(&observer_);
ListValue new_value;
@@ -380,7 +431,8 @@ TEST_F(PrefServiceSetValueTest, SetListValue) {
prefs_.Set(kName, new_value);
Mock::VerifyAndClearExpectations(&observer_);
- observer_.Expect(&prefs_, kName, null_value_.get());
- prefs_.Set(kName, *null_value_);
+ ListValue empty;
+ observer_.Expect(&prefs_, kName, &empty);
+ prefs_.Set(kName, empty);
Mock::VerifyAndClearExpectations(&observer_);
}
diff --git a/chrome/browser/prefs/pref_set_observer.cc b/chrome/browser/prefs/pref_set_observer.cc
index 133b219..117937e 100644
--- a/chrome/browser/prefs/pref_set_observer.cc
+++ b/chrome/browser/prefs/pref_set_observer.cc
@@ -47,10 +47,7 @@ PrefSetObserver* PrefSetObserver::CreateProxyPrefSetObserver(
PrefService* pref_service,
NotificationObserver* observer) {
PrefSetObserver* pref_set = new PrefSetObserver(pref_service, observer);
- pref_set->AddPref(prefs::kProxyMode);
- pref_set->AddPref(prefs::kProxyServer);
- pref_set->AddPref(prefs::kProxyPacUrl);
- pref_set->AddPref(prefs::kProxyBypassList);
+ pref_set->AddPref(prefs::kProxy);
return pref_set;
}
@@ -66,6 +63,7 @@ PrefSetObserver* PrefSetObserver::CreateDefaultSearchPrefSetObserver(
pref_set->AddPref(prefs::kDefaultSearchProviderSearchURL);
pref_set->AddPref(prefs::kDefaultSearchProviderSuggestURL);
pref_set->AddPref(prefs::kDefaultSearchProviderIconURL);
+ pref_set->AddPref(prefs::kDefaultSearchProviderInstantURL);
pref_set->AddPref(prefs::kDefaultSearchProviderEncodings);
return pref_set;
diff --git a/chrome/browser/prefs/pref_value_map.cc b/chrome/browser/prefs/pref_value_map.cc
index 6e7bf79..0857f6d 100644
--- a/chrome/browser/prefs/pref_value_map.cc
+++ b/chrome/browser/prefs/pref_value_map.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -58,6 +58,22 @@ void PrefValueMap::Clear() {
prefs_.clear();
}
+PrefValueMap::iterator PrefValueMap::begin() {
+ return prefs_.begin();
+}
+
+PrefValueMap::iterator PrefValueMap::end() {
+ return prefs_.end();
+}
+
+PrefValueMap::const_iterator PrefValueMap::begin() const {
+ return prefs_.begin();
+}
+
+PrefValueMap::const_iterator PrefValueMap::end() const {
+ return prefs_.end();
+}
+
bool PrefValueMap::GetBoolean(const std::string& key,
bool* value) const {
Value* stored_value = NULL;
diff --git a/chrome/browser/prefs/pref_value_map.h b/chrome/browser/prefs/pref_value_map.h
index 0e99920..19aeb05 100644
--- a/chrome/browser/prefs/pref_value_map.h
+++ b/chrome/browser/prefs/pref_value_map.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,6 +17,9 @@ class Value;
// A generic string to value map used by the PrefStore implementations.
class PrefValueMap {
public:
+ typedef std::map<std::string, Value*>::iterator iterator;
+ typedef std::map<std::string, Value*>::const_iterator const_iterator;
+
PrefValueMap();
virtual ~PrefValueMap();
@@ -36,6 +39,11 @@ class PrefValueMap {
// Clears the map.
void Clear();
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
// Gets a boolean value for |key| and stores it in |value|. Returns true if
// the value was found and of the proper type.
bool GetBoolean(const std::string& key, bool* value) const;
diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc
index bfe00b4..d3cf044 100644
--- a/chrome/browser/prefs/pref_value_store.cc
+++ b/chrome/browser/prefs/pref_value_store.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,8 +13,11 @@ PrefValueStore::PrefStoreKeeper::PrefStoreKeeper()
}
PrefValueStore::PrefStoreKeeper::~PrefStoreKeeper() {
- if (pref_store_.get())
+ if (pref_store_.get()) {
pref_store_->RemoveObserver(this);
+ pref_store_ = NULL;
+ }
+ pref_value_store_ = NULL;
}
void PrefValueStore::PrefStoreKeeper::Initialize(
@@ -25,7 +28,7 @@ void PrefValueStore::PrefStoreKeeper::Initialize(
pref_store_->RemoveObserver(this);
type_ = type;
pref_value_store_ = store;
- pref_store_.reset(pref_store);
+ pref_store_ = pref_store;
if (pref_store_.get())
pref_store_->AddObserver(this);
}
@@ -40,20 +43,22 @@ void PrefValueStore::PrefStoreKeeper::OnInitializationCompleted() {
}
PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
- PrefStore* device_management_prefs,
+ PrefStore* managed_cloud_prefs,
PrefStore* extension_prefs,
PrefStore* command_line_prefs,
PrefStore* user_prefs,
- PrefStore* recommended_prefs,
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
PrefStore* default_prefs,
PrefNotifier* pref_notifier)
: pref_notifier_(pref_notifier) {
InitPrefStore(MANAGED_PLATFORM_STORE, managed_platform_prefs);
- InitPrefStore(DEVICE_MANAGEMENT_STORE, device_management_prefs);
+ InitPrefStore(MANAGED_CLOUD_STORE, managed_cloud_prefs);
InitPrefStore(EXTENSION_STORE, extension_prefs);
InitPrefStore(COMMAND_LINE_STORE, command_line_prefs);
InitPrefStore(USER_STORE, user_prefs);
- InitPrefStore(RECOMMENDED_STORE, recommended_prefs);
+ InitPrefStore(RECOMMENDED_PLATFORM_STORE, recommended_platform_prefs);
+ InitPrefStore(RECOMMENDED_CLOUD_STORE, recommended_cloud_prefs);
InitPrefStore(DEFAULT_STORE, default_prefs);
CheckInitializationCompleted();
@@ -61,45 +66,68 @@ PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs,
PrefValueStore::~PrefValueStore() {}
+PrefValueStore* PrefValueStore::CloneAndSpecialize(
+ PrefStore* managed_platform_prefs,
+ PrefStore* managed_cloud_prefs,
+ PrefStore* extension_prefs,
+ PrefStore* command_line_prefs,
+ PrefStore* user_prefs,
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
+ PrefStore* default_prefs,
+ PrefNotifier* pref_notifier) {
+ DCHECK(pref_notifier);
+ if (!managed_platform_prefs)
+ managed_platform_prefs = GetPrefStore(MANAGED_PLATFORM_STORE);
+ if (!managed_cloud_prefs)
+ managed_cloud_prefs = GetPrefStore(MANAGED_CLOUD_STORE);
+ if (!extension_prefs)
+ extension_prefs = GetPrefStore(EXTENSION_STORE);
+ if (!command_line_prefs)
+ command_line_prefs = GetPrefStore(COMMAND_LINE_STORE);
+ if (!user_prefs)
+ user_prefs = GetPrefStore(USER_STORE);
+ if (!recommended_platform_prefs)
+ recommended_platform_prefs = GetPrefStore(RECOMMENDED_PLATFORM_STORE);
+ if (!recommended_cloud_prefs)
+ recommended_cloud_prefs = GetPrefStore(RECOMMENDED_CLOUD_STORE);
+ if (!default_prefs)
+ default_prefs = GetPrefStore(DEFAULT_STORE);
+
+ return new PrefValueStore(
+ managed_platform_prefs, managed_cloud_prefs, extension_prefs,
+ command_line_prefs, user_prefs, recommended_platform_prefs,
+ recommended_cloud_prefs, default_prefs,
+ pref_notifier);
+}
+
bool PrefValueStore::GetValue(const std::string& name,
+ Value::ValueType type,
Value** out_value) const {
+ *out_value = NULL;
// Check the |PrefStore|s in order of their priority from highest to lowest
// to find the value of the preference described by the given preference name.
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i),
- out_value))
+ out_value)) {
+ if (!(*out_value)->IsType(type)) {
+ LOG(WARNING) << "Expected type for " << name << " is " << type
+ << " but got " << (*out_value)->GetType()
+ << " in store " << i;
+ continue;
+ }
return true;
+ }
}
return false;
}
-void PrefValueStore::RegisterPreferenceType(const std::string& name,
- Value::ValueType type) {
- pref_types_[name] = type;
-}
-
-Value::ValueType PrefValueStore::GetRegisteredType(
- const std::string& name) const {
- PrefTypeMap::const_iterator found = pref_types_.find(name);
- if (found == pref_types_.end())
- return Value::TYPE_NULL;
- return found->second;
-}
-
-bool PrefValueStore::HasPrefPath(const char* path) const {
- Value* tmp_value = NULL;
- const std::string name(path);
- bool rv = GetValue(name, &tmp_value);
- // Merely registering a pref doesn't count as "having" it: we require a
- // non-default value set.
- return rv && !PrefValueFromDefaultStore(path);
-}
-
void PrefValueStore::NotifyPrefChanged(
const char* path,
PrefValueStore::PrefStoreType new_store) {
DCHECK(new_store != INVALID_STORE);
+<<<<<<< HEAD
// If this pref is not registered, just discard the notification.
if (!pref_types_.count(path))
return;
@@ -120,16 +148,19 @@ void PrefValueStore::NotifyPrefChanged(
#ifndef ANDROID
if (changed)
+=======
+ // If the pref is controlled by a higher-priority store, its effective value
+ // cannot have changed.
+ PrefStoreType controller = ControllingPrefStoreForPref(path);
+ if (controller == INVALID_STORE || controller >= new_store)
+>>>>>>> chromium.org at r11.0.672.0
pref_notifier_->OnPreferenceChanged(path);
#endif
}
-bool PrefValueStore::PrefValueInManagedPlatformStore(const char* name) const {
- return PrefValueInStore(name, MANAGED_PLATFORM_STORE);
-}
-
-bool PrefValueStore::PrefValueInDeviceManagementStore(const char* name) const {
- return PrefValueInStore(name, DEVICE_MANAGEMENT_STORE);
+bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
+ return PrefValueInStore(name, MANAGED_PLATFORM_STORE) ||
+ PrefValueInStore(name, MANAGED_CLOUD_STORE);
}
bool PrefValueStore::PrefValueInExtensionStore(const char* name) const {
@@ -158,24 +189,6 @@ bool PrefValueStore::PrefValueUserModifiable(const char* name) const {
effective_store == INVALID_STORE;
}
-// Returns true if the actual value is a valid type for the expected type when
-// found in the given store.
-bool PrefValueStore::IsValidType(Value::ValueType expected,
- Value::ValueType actual,
- PrefValueStore::PrefStoreType store) {
- if (expected == actual)
- return true;
-
- // Dictionaries and lists are allowed to hold TYPE_NULL values too, but only
- // in the default pref store.
- if (store == DEFAULT_STORE &&
- actual == Value::TYPE_NULL &&
- (expected == Value::TYPE_DICTIONARY || expected == Value::TYPE_LIST)) {
- return true;
- }
- return false;
-}
-
bool PrefValueStore::PrefValueInStore(
const char* name,
PrefValueStore::PrefStoreType store) const {
@@ -227,12 +240,7 @@ bool PrefValueStore::GetValueFromStore(const char* name,
}
// Fall through...
case PrefStore::READ_OK:
- if (IsValidType(GetRegisteredType(name),
- (*out_value)->GetType(),
- store_type)) {
- return true;
- }
- break;
+ return true;
case PrefStore::READ_NO_VALUE:
break;
}
@@ -260,7 +268,8 @@ void PrefValueStore::InitPrefStore(PrefValueStore::PrefStoreType type,
void PrefValueStore::CheckInitializationCompleted() {
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
- PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(i));
+ scoped_refptr<PrefStore> store =
+ GetPrefStore(static_cast<PrefStoreType>(i));
if (store && !store->IsInitializationComplete())
return;
}
diff --git a/chrome/browser/prefs/pref_value_store.h b/chrome/browser/prefs/pref_value_store.h
index 8b6ba0c..0592989 100644
--- a/chrome/browser/prefs/pref_value_store.h
+++ b/chrome/browser/prefs/pref_value_store.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,6 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/ref_counted.h"
-#include "base/scoped_ptr.h"
#include "base/values.h"
#ifndef ANDROID
#include "chrome/browser/browser_thread.h"
@@ -23,7 +22,6 @@
class FilePath;
class PrefNotifier;
class PrefStore;
-class Profile;
// The PrefValueStore manages various sources of values for Preferences
// (e.g., configuration policies, extensions, and user settings). It returns
@@ -32,65 +30,62 @@ class Profile;
//
// Unless otherwise explicitly noted, all of the methods of this class must
// be called on the UI thread.
-class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
+class PrefValueStore {
public:
// In decreasing order of precedence:
// |managed_platform_prefs| contains all managed platform (non-cloud policy)
// preference values.
- // |device_management_prefs| contains all device management (cloud policy)
- // preference values.
+ // |managed_cloud_prefs| contains all managed cloud 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.
+ // |recommended_platform_prefs| contains all recommended platform policy
+ // preference values.
+ // |recommended_cloud_prefs| contains all recommended cloud policy
+ // preference values.
// |default_prefs| contains application-default preference values. It must
// be non-null if any preferences are to be registered.
//
// |pref_notifier| facilitates broadcasting preference change notifications
// to the world.
- //
- // The |profile| parameter is used to construct a replacement device
- // management pref store. This is done after policy refresh when we swap out
- // the policy pref stores for new ones, so the |profile| pointer needs to be
- // kept around for then. It is safe to pass a NULL pointer for local state
- // preferences.
PrefValueStore(PrefStore* managed_platform_prefs,
- PrefStore* device_management_prefs,
+ PrefStore* managed_cloud_prefs,
PrefStore* extension_prefs,
PrefStore* command_line_prefs,
PrefStore* user_prefs,
- PrefStore* recommended_prefs,
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
PrefStore* default_prefs,
PrefNotifier* pref_notifier);
virtual ~PrefValueStore();
- // Gets the value for the given preference name that has a valid value type;
- // that is, the same type the preference was registered with, or NULL for
- // default values of Dictionaries and Lists. Returns true if a valid value
+ // Creates a clone of this PrefValueStore with PrefStores overwritten
+ // by the parameters passed, if unequal NULL.
+ PrefValueStore* CloneAndSpecialize(PrefStore* managed_platform_prefs,
+ PrefStore* managed_cloud_prefs,
+ PrefStore* extension_prefs,
+ PrefStore* command_line_prefs,
+ PrefStore* user_prefs,
+ PrefStore* recommended_platform_prefs,
+ PrefStore* recommended_cloud_prefs,
+ PrefStore* default_prefs,
+ PrefNotifier* pref_notifier);
+
+ // Gets the value for the given preference name that has the specified value
+ // type. Values stored in a PrefStore that have the matching |name| but
+ // a non-matching |type| are silently skipped. Returns true if a valid value
// was found in any of the available PrefStores. Most callers should use
// Preference::GetValue() instead of calling this method directly.
- bool GetValue(const std::string& name, Value** out_value) const;
-
- // Adds a preference to the mapping of names to types.
- void RegisterPreferenceType(const std::string& name, Value::ValueType type);
-
- // Gets the registered value type for the given preference name. Returns
- // Value::TYPE_NULL if the preference has never been registered.
- Value::ValueType GetRegisteredType(const std::string& name) const;
-
- // Returns true if the PrefValueStore contains the given preference (i.e.,
- // it's been registered), and a value with the correct type has been actively
- // set in some pref store. The application default specified when the pref was
- // registered does not count as an "actively set" value, but another pref
- // store setting a value that happens to be equal to the default does.
- bool HasPrefPath(const char* name) const;
+ bool GetValue(const std::string& name,
+ Value::ValueType type,
+ Value** out_value) const;
// These methods return true if a preference with the given name is in the
// indicated pref store, even if that value is currently being overridden by
// a higher-priority source.
- bool PrefValueInManagedPlatformStore(const char* name) const;
- bool PrefValueInDeviceManagementStore(const char* name) const;
+ bool PrefValueInManagedStore(const char* name) const;
bool PrefValueInExtensionStore(const char* name) const;
bool PrefValueInUserStore(const char* name) const;
@@ -122,11 +117,12 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
// an invalid marker, e.g. as a return value.
INVALID_STORE = -1,
MANAGED_PLATFORM_STORE = 0,
- DEVICE_MANAGEMENT_STORE,
+ MANAGED_CLOUD_STORE,
EXTENSION_STORE,
COMMAND_LINE_STORE,
USER_STORE,
- RECOMMENDED_STORE,
+ RECOMMENDED_PLATFORM_STORE,
+ RECOMMENDED_CLOUD_STORE,
DEFAULT_STORE,
PREF_STORE_TYPE_MAX = DEFAULT_STORE
};
@@ -157,7 +153,7 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
PrefValueStore* pref_value_store_;
// The PrefStore managed by this keeper.
- scoped_ptr<PrefStore> pref_store_;
+ scoped_refptr<PrefStore> pref_store_;
// Type of the pref store.
PrefStoreType type_;
@@ -174,12 +170,6 @@ class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> {
FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest,
TestConcurrentPolicyRefresh);
- // Returns true if the actual type is a valid type for the expected type when
- // found in the given store.
- static bool IsValidType(Value::ValueType expected,
- Value::ValueType actual,
- PrefStoreType store);
-
// Returns true if the preference with the given name has a value in the
// given PrefStoreType, of the same value type as the preference was
// registered with.
diff --git a/chrome/browser/prefs/pref_value_store_unittest.cc b/chrome/browser/prefs/pref_value_store_unittest.cc
index 5c0fa53..e67de56 100644
--- a/chrome/browser/prefs/pref_value_store_unittest.cc
+++ b/chrome/browser/prefs/pref_value_store_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -33,58 +33,80 @@ class MockPrefNotifier : public PrefNotifier {
} // namespace
-// Names of the preferences used in this test program.
+// Names of the preferences used in this test.
namespace prefs {
+const char kManagedPlatformPref[] = "this.pref.managed_platform";
+const char kManagedCloudPref[] = "this.pref.managed_cloud";
+const char kCommandLinePref[] = "this.pref.command_line";
+const char kExtensionPref[] = "this.pref.extension";
+const char kUserPref[] = "this.pref.user";
+const char kRecommendedPlatformPref[] = "this.pref.recommended_platform";
+const char kRecommendedCloudPref[] = "this.pref.recommended_cloud";
+const char kDefaultPref[] = "this.pref.default";
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 managed_platform_pref {
-const std::string kHomepageValue = "http://www.topeka.com";
+const char kManagedPlatformValue[] = "managed_platform:managed_platform";
}
-namespace device_management_pref {
-const std::string kSearchProviderNameValue = "Chromium";
-const char kHomepageValue[] = "http://www.wandering-around.org";
+namespace managed_cloud_pref {
+const char kManagedPlatformValue[] = "managed_cloud:managed_platform";
+const char kManagedCloudValue[] = "managed_cloud:managed_cloud";
}
namespace extension_pref {
-const char kCurrentThemeIDValue[] = "set by extension";
-const char kHomepageValue[] = "http://www.chromium.org";
-const std::string kSearchProviderNameValue = "AreYouFeelingALittleLucky";
+const char kManagedPlatformValue[] = "extension:managed_platform";
+const char kManagedCloudValue[] = "extension:managed_cloud";
+const char kExtensionValue[] = "extension:extension";
}
namespace command_line_pref {
-const char kApplicationLocaleValue[] = "hi-MOM";
-const char kCurrentThemeIDValue[] = "zyxwvut";
-const char kHomepageValue[] = "http://www.ferretcentral.org";
-const std::string kSearchProviderNameValue = "AreYouFeelingPrettyLucky";
+const char kManagedPlatformValue[] = "command_line:managed_platform";
+const char kManagedCloudValue[] = "command_line:managed_cloud";
+const char kExtensionValue[] = "command_line:extension";
+const char kCommandLineValue[] = "command_line:command_line";
}
-// The "user" namespace is defined globally in an ARM system header, so we need
-// something different here.
namespace user_pref {
-const int kStabilityLaunchCountValue = 31;
-const bool kDeleteCacheValue = true;
-const char kCurrentThemeIDValue[] = "abcdefg";
-const char kHomepageValue[] = "http://www.google.com";
-const char kApplicationLocaleValue[] = "is-WRONG";
-const std::string kSearchProviderNameValue = "AreYouFeelingVeryLucky";
+const char kManagedPlatformValue[] = "user:managed_platform";
+const char kManagedCloudValue[] = "user:managed_cloud";
+const char kExtensionValue[] = "user:extension";
+const char kCommandLineValue[] = "user:command_line";
+const char kUserValue[] = "user:user";
}
-namespace recommended_pref {
-const int kStabilityLaunchCountValue = 10;
-const bool kRecommendedPrefValue = true;
+namespace recommended_platform_pref {
+const char kManagedPlatformValue[] = "recommended_platform:managed_platform";
+const char kManagedCloudValue[] = "recommended_platform:managed_cloud";
+const char kExtensionValue[] = "recommended_platform:extension";
+const char kCommandLineValue[] = "recommended_platform:command_line";
+const char kUserValue[] = "recommended_platform:user";
+const char kRecommendedPlatformValue[] =
+ "recommended_platform:recommended_platform";
+}
+
+namespace recommended_cloud_pref {
+const char kManagedPlatformValue[] = "recommended_cloud:managed_platform";
+const char kManagedCloudValue[] = "recommended_cloud:managed_cloud";
+const char kExtensionValue[] = "recommended_cloud:extension";
+const char kCommandLineValue[] = "recommended_cloud:command_line";
+const char kUserValue[] = "recommended_cloud:user";
+const char kRecommendedPlatformValue[] =
+ "recommended_cloud:recommended_platform";
+const char kRecommendedCloudValue[] = "recommended_cloud:recommended_cloud";
}
namespace default_pref {
-const int kDefaultValue = 7;
-const char kHomepageValue[] = "default homepage";
-const std::string kSearchProviderNameValue = "AreYouFeelingExtraLucky";
+const char kManagedPlatformValue[] = "default:managed_platform";
+const char kManagedCloudValue[] = "default:managed_cloud";
+const char kExtensionValue[] = "default:extension";
+const char kCommandLineValue[] = "default:command_line";
+const char kUserValue[] = "default:user";
+const char kRecommendedPlatformValue[] = "default:recommended_platform";
+const char kRecommendedCloudValue[] = "default:recommended_cloud";
+const char kDefaultValue[] = "default:default";
}
class PrefValueStoreTest : public testing::Test {
@@ -92,328 +114,350 @@ class PrefValueStoreTest : public testing::Test {
virtual void SetUp() {
// Create TestingPrefStores.
CreateManagedPlatformPrefs();
- CreateDeviceManagementPrefs();
+ CreateManagedCloudPrefs();
CreateExtensionPrefs();
CreateCommandLinePrefs();
CreateUserPrefs();
- CreateRecommendedPrefs();
+ CreateRecommendedPlatformPrefs();
+ CreateRecommendedCloudPrefs();
CreateDefaultPrefs();
// Create a fresh PrefValueStore.
- pref_value_store_ = new PrefValueStore(
+ pref_value_store_.reset(new PrefValueStore(
managed_platform_pref_store_,
- device_management_pref_store_,
+ managed_cloud_pref_store_,
extension_pref_store_,
command_line_pref_store_,
user_pref_store_,
- recommended_pref_store_,
+ recommended_platform_pref_store_,
+ recommended_cloud_pref_store_,
default_pref_store_,
- &pref_notifier_);
-
- // Register prefs with the PrefValueStore.
- pref_value_store_->RegisterPreferenceType(prefs::kApplicationLocale,
- Value::TYPE_STRING);
- pref_value_store_->RegisterPreferenceType(prefs::kCurrentThemeID,
- Value::TYPE_STRING);
- pref_value_store_->RegisterPreferenceType(
- prefs::kDefaultSearchProviderName,
- Value::TYPE_STRING);
- pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache,
- Value::TYPE_BOOLEAN);
- pref_value_store_->RegisterPreferenceType(prefs::kHomePage,
- Value::TYPE_STRING);
- pref_value_store_->RegisterPreferenceType(prefs::kStabilityLaunchCount,
- Value::TYPE_INTEGER);
- pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref,
- Value::TYPE_BOOLEAN);
- pref_value_store_->RegisterPreferenceType(prefs::kSampleDict,
- Value::TYPE_DICTIONARY);
- pref_value_store_->RegisterPreferenceType(prefs::kSampleList,
- Value::TYPE_LIST);
- pref_value_store_->RegisterPreferenceType(prefs::kDefaultPref,
- Value::TYPE_INTEGER);
- pref_value_store_->RegisterPreferenceType(prefs::kProxyMode,
- Value::TYPE_INTEGER);
- }
-
- // Creates a new dictionary and stores some sample user preferences
- // in it.
- void CreateUserPrefs() {
- user_pref_store_ = new TestingPrefStore;
- user_pref_store_->SetBoolean(prefs::kDeleteCache,
- user_pref::kDeleteCacheValue);
- user_pref_store_->SetInteger(prefs::kStabilityLaunchCount,
- user_pref::kStabilityLaunchCountValue);
- user_pref_store_->SetString(prefs::kCurrentThemeID,
- user_pref::kCurrentThemeIDValue);
- user_pref_store_->SetString(prefs::kApplicationLocale,
- user_pref::kApplicationLocaleValue);
- user_pref_store_->SetString(prefs::kDefaultSearchProviderName,
- user_pref::kSearchProviderNameValue);
- user_pref_store_->SetString(prefs::kHomePage,
- user_pref::kHomepageValue);
+ &pref_notifier_));
}
void CreateManagedPlatformPrefs() {
managed_platform_pref_store_ = new TestingPrefStore;
- managed_platform_pref_store_->SetString(prefs::kHomePage,
- managed_platform_pref::kHomepageValue);
+ managed_platform_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ managed_platform_pref::kManagedPlatformValue);
}
- void CreateDeviceManagementPrefs() {
- device_management_pref_store_ = new TestingPrefStore;
- device_management_pref_store_->SetString(prefs::kDefaultSearchProviderName,
- device_management_pref::kSearchProviderNameValue);
- device_management_pref_store_->SetString(prefs::kHomePage,
- device_management_pref::kHomepageValue);
+ void CreateManagedCloudPrefs() {
+ managed_cloud_pref_store_ = new TestingPrefStore;
+ managed_cloud_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ managed_cloud_pref::kManagedPlatformValue);
+ managed_cloud_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ managed_cloud_pref::kManagedCloudValue);
}
void CreateExtensionPrefs() {
extension_pref_store_ = new TestingPrefStore;
- extension_pref_store_->SetString(prefs::kCurrentThemeID,
- extension_pref::kCurrentThemeIDValue);
- extension_pref_store_->SetString(prefs::kHomePage,
- extension_pref::kHomepageValue);
- extension_pref_store_->SetString(prefs::kDefaultSearchProviderName,
- extension_pref::kSearchProviderNameValue);
+ extension_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ extension_pref::kManagedPlatformValue);
+ extension_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ extension_pref::kManagedCloudValue);
+ extension_pref_store_->SetString(
+ prefs::kExtensionPref,
+ extension_pref::kExtensionValue);
}
void CreateCommandLinePrefs() {
command_line_pref_store_ = new TestingPrefStore;
- command_line_pref_store_->SetString(prefs::kCurrentThemeID,
- command_line_pref::kCurrentThemeIDValue);
- command_line_pref_store_->SetString(prefs::kApplicationLocale,
- command_line_pref::kApplicationLocaleValue);
- command_line_pref_store_->SetString(prefs::kHomePage,
- command_line_pref::kHomepageValue);
- command_line_pref_store_->SetString(prefs::kDefaultSearchProviderName,
- command_line_pref::kSearchProviderNameValue);
+ command_line_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ command_line_pref::kManagedPlatformValue);
+ command_line_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ command_line_pref::kManagedCloudValue);
+ command_line_pref_store_->SetString(
+ prefs::kExtensionPref,
+ command_line_pref::kExtensionValue);
+ command_line_pref_store_->SetString(
+ prefs::kCommandLinePref,
+ command_line_pref::kCommandLineValue);
}
- void CreateRecommendedPrefs() {
- recommended_pref_store_ = new TestingPrefStore;
- recommended_pref_store_->SetInteger(prefs::kStabilityLaunchCount,
- recommended_pref::kStabilityLaunchCountValue);
- recommended_pref_store_->SetBoolean(prefs::kRecommendedPref,
- recommended_pref::kRecommendedPrefValue);
+ void CreateUserPrefs() {
+ user_pref_store_ = new TestingPrefStore;
+ user_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ user_pref::kManagedPlatformValue);
+ user_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ user_pref::kManagedCloudValue);
+ user_pref_store_->SetString(
+ prefs::kCommandLinePref,
+ user_pref::kCommandLineValue);
+ user_pref_store_->SetString(
+ prefs::kExtensionPref,
+ user_pref::kExtensionValue);
+ user_pref_store_->SetString(
+ prefs::kUserPref,
+ user_pref::kUserValue);
}
- void CreateDefaultPrefs() {
- default_pref_store_ = new TestingPrefStore;
- default_pref_store_->SetInteger(prefs::kDefaultPref,
- default_pref::kDefaultValue);
+ void CreateRecommendedPlatformPrefs() {
+ recommended_platform_pref_store_ = new TestingPrefStore;
+ recommended_platform_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ recommended_platform_pref::kManagedPlatformValue);
+ recommended_platform_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ recommended_platform_pref::kManagedCloudValue);
+ recommended_platform_pref_store_->SetString(
+ prefs::kCommandLinePref,
+ recommended_platform_pref::kCommandLineValue);
+ recommended_platform_pref_store_->SetString(
+ prefs::kExtensionPref,
+ recommended_platform_pref::kExtensionValue);
+ recommended_platform_pref_store_->SetString(
+ prefs::kUserPref,
+ recommended_platform_pref::kUserValue);
+ recommended_platform_pref_store_->SetString(
+ prefs::kRecommendedPlatformPref,
+ recommended_platform_pref::kRecommendedPlatformValue);
}
- DictionaryValue* CreateSampleDictValue() {
- DictionaryValue* sample_dict = new DictionaryValue();
- sample_dict->SetBoolean("issample", true);
- sample_dict->SetInteger("value", 4);
- sample_dict->SetString("descr", "Sample Test Dictionary");
- return sample_dict;
+ void CreateRecommendedCloudPrefs() {
+ recommended_cloud_pref_store_ = new TestingPrefStore;
+ recommended_cloud_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ recommended_cloud_pref::kManagedPlatformValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ recommended_cloud_pref::kManagedCloudValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kCommandLinePref,
+ recommended_cloud_pref::kCommandLineValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kExtensionPref,
+ recommended_cloud_pref::kExtensionValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kUserPref,
+ recommended_cloud_pref::kUserValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kRecommendedPlatformPref,
+ recommended_cloud_pref::kRecommendedPlatformValue);
+ recommended_cloud_pref_store_->SetString(
+ prefs::kRecommendedCloudPref,
+ recommended_cloud_pref::kRecommendedCloudValue);
}
- ListValue* CreateSampleListValue() {
- ListValue* sample_list = new ListValue();
- sample_list->Set(0, Value::CreateIntegerValue(0));
- sample_list->Set(1, Value::CreateIntegerValue(1));
- sample_list->Set(2, Value::CreateIntegerValue(2));
- sample_list->Set(3, Value::CreateIntegerValue(3));
- return sample_list;
+ void CreateDefaultPrefs() {
+ default_pref_store_ = new TestingPrefStore;
+ default_pref_store_->SetString(
+ prefs::kManagedPlatformPref,
+ default_pref::kManagedPlatformValue);
+ default_pref_store_->SetString(
+ prefs::kManagedCloudPref,
+ default_pref::kManagedCloudValue);
+ default_pref_store_->SetString(
+ prefs::kCommandLinePref,
+ default_pref::kCommandLineValue);
+ default_pref_store_->SetString(
+ prefs::kExtensionPref,
+ default_pref::kExtensionValue);
+ default_pref_store_->SetString(
+ prefs::kUserPref,
+ default_pref::kUserValue);
+ default_pref_store_->SetString(
+ prefs::kRecommendedPlatformPref,
+ default_pref::kRecommendedPlatformValue);
+ default_pref_store_->SetString(
+ prefs::kRecommendedCloudPref,
+ default_pref::kRecommendedCloudValue);
+ default_pref_store_->SetString(
+ prefs::kDefaultPref,
+ default_pref::kDefaultValue);
}
MockPrefNotifier pref_notifier_;
- scoped_refptr<PrefValueStore> pref_value_store_;
-
- // |PrefStore|s are owned by the |PrefValueStore|.
- TestingPrefStore* managed_platform_pref_store_;
- TestingPrefStore* device_management_pref_store_;
- TestingPrefStore* extension_pref_store_;
- TestingPrefStore* command_line_pref_store_;
- TestingPrefStore* user_pref_store_;
- TestingPrefStore* recommended_pref_store_;
- TestingPrefStore* default_pref_store_;
+ scoped_ptr<PrefValueStore> pref_value_store_;
+
+ scoped_refptr<TestingPrefStore> managed_platform_pref_store_;
+ scoped_refptr<TestingPrefStore> managed_cloud_pref_store_;
+ scoped_refptr<TestingPrefStore> extension_pref_store_;
+ scoped_refptr<TestingPrefStore> command_line_pref_store_;
+ scoped_refptr<TestingPrefStore> user_pref_store_;
+ scoped_refptr<TestingPrefStore> recommended_platform_pref_store_;
+ scoped_refptr<TestingPrefStore> recommended_cloud_pref_store_;
+ scoped_refptr<TestingPrefStore> default_pref_store_;
};
TEST_F(PrefValueStoreTest, GetValue) {
Value* value;
- // Test getting a managed platform value overwriting a user-defined and
- // extension-defined value.
+ // The following tests read a value from the PrefService. The preferences are
+ // set in a way such that all lower-priority stores have a value and we can
+ // test whether overrides work correctly.
+
+ // Test getting a managed platform value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPlatformPref,
+ Value::TYPE_STRING, &value));
std::string actual_str_value;
EXPECT_TRUE(value->GetAsString(&actual_str_value));
- EXPECT_EQ(managed_platform_pref::kHomepageValue, actual_str_value);
+ EXPECT_EQ(managed_platform_pref::kManagedPlatformValue, actual_str_value);
- // Test getting a managed platform value overwriting a user-defined value.
+ // Test getting a managed cloud value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultSearchProviderName,
- &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedCloudPref,
+ Value::TYPE_STRING, &value));
EXPECT_TRUE(value->GetAsString(&actual_str_value));
- EXPECT_EQ(device_management_pref::kSearchProviderNameValue,
- actual_str_value);
+ EXPECT_EQ(managed_cloud_pref::kManagedCloudValue, actual_str_value);
- // Test getting an extension value overwriting a user-defined and
- // command-line-defined value.
+ // Test getting an extension value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCurrentThemeID, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref,
+ Value::TYPE_STRING, &value));
EXPECT_TRUE(value->GetAsString(&actual_str_value));
- EXPECT_EQ(extension_pref::kCurrentThemeIDValue, actual_str_value);
+ EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value);
- // Test getting a command-line value overwriting a user-defined value.
+ // Test getting a command-line value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kApplicationLocale, &value));
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref,
+ Value::TYPE_STRING, &value));
EXPECT_TRUE(value->GetAsString(&actual_str_value));
- EXPECT_EQ(command_line_pref::kApplicationLocaleValue, actual_str_value);
+ EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value);
// Test getting a user-set value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDeleteCache, &value));
- bool actual_bool_value = false;
- EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
- EXPECT_EQ(user_pref::kDeleteCacheValue, actual_bool_value);
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref,
+ Value::TYPE_STRING, &value));
+ EXPECT_TRUE(value->GetAsString(&actual_str_value));
+ EXPECT_EQ(user_pref::kUserValue, actual_str_value);
// Test getting a user set value overwriting a recommended value.
value = NULL;
- 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::kStabilityLaunchCountValue, actual_int_value);
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPlatformPref,
+ Value::TYPE_STRING, &value));
+ EXPECT_TRUE(value->GetAsString(&actual_str_value));
+ EXPECT_EQ(recommended_platform_pref::kRecommendedPlatformValue,
+ actual_str_value);
// Test getting a recommended value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref, &value));
- actual_bool_value = false;
- EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
- EXPECT_EQ(recommended_pref::kRecommendedPrefValue, actual_bool_value);
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedCloudPref,
+ Value::TYPE_STRING, &value));
+ EXPECT_TRUE(value->GetAsString(&actual_str_value));
+ EXPECT_EQ(recommended_cloud_pref::kRecommendedCloudValue, actual_str_value);
// Test getting a default value.
value = NULL;
- ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref, &value));
- actual_int_value = -1;
- EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
- EXPECT_EQ(default_pref::kDefaultValue, actual_int_value);
+ ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref,
+ Value::TYPE_STRING, &value));
+ EXPECT_TRUE(value->GetAsString(&actual_str_value));
+ EXPECT_EQ(default_pref::kDefaultValue, actual_str_value);
// Test getting a preference value that the |PrefValueStore|
// does not contain.
FundamentalValue tmp_dummy_value(true);
- Value* v_null = &tmp_dummy_value;
- ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, &v_null));
- ASSERT_TRUE(v_null == NULL);
-}
-
-// Make sure that if a preference changes type, so the wrong type is stored in
-// the user pref file, it uses the correct fallback value instead.
-TEST_F(PrefValueStoreTest, GetValueChangedType) {
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(AnyNumber());
-
- // Check falling back to a recommended value.
- user_pref_store_->SetString(prefs::kStabilityLaunchCount,
- "not an integer");
- Value* value = NULL;
- 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::kStabilityLaunchCountValue, actual_int_value);
-
- // Check falling back multiple times, to a default string.
- default_pref_store_->SetString(prefs::kHomePage,
- default_pref::kHomepageValue);
- managed_platform_pref_store_->SetInteger(prefs::kHomePage, 1);
- device_management_pref_store_->SetInteger(prefs::kHomePage, 1);
- extension_pref_store_->SetInteger(prefs::kHomePage, 1);
- command_line_pref_store_->SetInteger(prefs::kHomePage, 1);
- user_pref_store_->SetInteger(prefs::kHomePage, 1);
- recommended_pref_store_->SetInteger(prefs::kHomePage, 1);
-
- value = NULL;
- 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;
- EXPECT_TRUE(value->GetAsString(&actual_str_value));
- EXPECT_EQ(default_pref::kHomepageValue, actual_str_value);
-}
-
-TEST_F(PrefValueStoreTest, HasPrefPath) {
- // Managed Platform preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
- // Device management preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(
- prefs::kDefaultSearchProviderName));
- // Extension preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
- // User preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache));
- // Recommended preference
- EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
- // Default preference
- EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
- // Unknown preference
- EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
+ value = &tmp_dummy_value;
+ ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref,
+ Value::TYPE_STRING, &value));
+ ASSERT_TRUE(value == NULL);
}
TEST_F(PrefValueStoreTest, PrefChanges) {
- // Setup.
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(AnyNumber());
- const char managed_platform_pref_path[] = "managed_platform_pref";
- pref_value_store_->RegisterPreferenceType(managed_platform_pref_path,
- Value::TYPE_STRING);
- managed_platform_pref_store_->SetString(managed_platform_pref_path,
- "managed value");
- const char user_pref_path[] = "user_pref";
- pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING);
- user_pref_store_->SetString(user_pref_path, "user value");
- const char default_pref_path[] = "default_pref";
- pref_value_store_->RegisterPreferenceType(default_pref_path,
- Value::TYPE_STRING);
- default_pref_store_->SetString(default_pref_path, "default value");
- Mock::VerifyAndClearExpectations(&pref_notifier_);
-
// Check pref controlled by highest-priority store.
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(managed_platform_pref_path));
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kManagedPlatformPref));
managed_platform_pref_store_->NotifyPrefValueChanged(
- managed_platform_pref_path);
+ prefs::kManagedPlatformPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0);
- user_pref_store_->NotifyPrefValueChanged(managed_platform_pref_path);
+ managed_cloud_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ extension_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ command_line_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ user_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ recommended_platform_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ recommended_cloud_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
+ default_pref_store_->NotifyPrefValueChanged(
+ prefs::kManagedPlatformPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
// Check pref controlled by user store.
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(user_pref_path));
- managed_platform_pref_store_->NotifyPrefValueChanged(user_pref_path);
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
+ managed_platform_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
+ managed_cloud_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
+ extension_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
+ command_line_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(user_pref_path));
- user_pref_store_->NotifyPrefValueChanged(user_pref_path);
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kUserPref));
+ user_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0);
- default_pref_store_->NotifyPrefValueChanged(user_pref_path);
+ recommended_platform_pref_store_->NotifyPrefValueChanged(
+ prefs::kUserPref);
+ recommended_cloud_pref_store_->NotifyPrefValueChanged(
+ prefs::kUserPref);
+ default_pref_store_->NotifyPrefValueChanged(
+ prefs::kUserPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
// Check pref controlled by default-pref store.
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(default_pref_path));
- user_pref_store_->NotifyPrefValueChanged(default_pref_path);
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ managed_platform_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ managed_cloud_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ extension_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ command_line_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ user_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ recommended_platform_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
- EXPECT_CALL(pref_notifier_, OnPreferenceChanged(default_pref_path));
- default_pref_store_->NotifyPrefValueChanged(default_pref_path);
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ recommended_cloud_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
+ Mock::VerifyAndClearExpectations(&pref_notifier_);
+
+ EXPECT_CALL(pref_notifier_, OnPreferenceChanged(prefs::kDefaultPref));
+ default_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
Mock::VerifyAndClearExpectations(&pref_notifier_);
}
TEST_F(PrefValueStoreTest, OnInitializationCompleted) {
EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(0);
managed_platform_pref_store_->SetInitializationCompleted();
- device_management_pref_store_->SetInitializationCompleted();
+ managed_cloud_pref_store_->SetInitializationCompleted();
extension_pref_store_->SetInitializationCompleted();
command_line_pref_store_->SetInitializationCompleted();
- recommended_pref_store_->SetInitializationCompleted();
+ recommended_platform_pref_store_->SetInitializationCompleted();
+ recommended_cloud_pref_store_->SetInitializationCompleted();
default_pref_store_->SetInitializationCompleted();
Mock::VerifyAndClearExpectations(&pref_notifier_);
@@ -423,198 +467,149 @@ TEST_F(PrefValueStoreTest, OnInitializationCompleted) {
Mock::VerifyAndClearExpectations(&pref_notifier_);
}
-TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) {
- // Test a managed platform preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
- EXPECT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore(
- prefs::kHomePage));
-
- // Test a device management preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(
- prefs::kDefaultSearchProviderName));
- EXPECT_TRUE(pref_value_store_->PrefValueInDeviceManagementStore(
- prefs::kDefaultSearchProviderName));
-
- // Test an extension preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
- prefs::kCurrentThemeID));
-
- // Test a command-line preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
- prefs::kApplicationLocale));
-
- // Test a user preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
- prefs::kStabilityLaunchCount));
-
- // Test a preference from the recommended pref store.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
- prefs::kRecommendedPref));
-
- // Test a preference from the default pref store.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
+TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
+ EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kManagedPlatformPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kManagedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kExtensionPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kCommandLinePref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kUserPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
+ prefs::kRecommendedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
prefs::kDefaultPref));
-
- // Test a preference for which the PrefValueStore does not contain a value.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
- EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
+ EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
prefs::kMissingPref));
}
TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
- // Test a managed platform preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
- EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomePage));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kHomePage));
-
- // Test a device management preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(
- prefs::kDefaultSearchProviderName));
EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
- prefs::kDefaultSearchProviderName));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kDefaultSearchProviderName));
-
- // Test an extension preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ prefs::kManagedPlatformPref));
EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
- prefs::kCurrentThemeID));
- EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kCurrentThemeID));
-
- // Test a command-line preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ prefs::kManagedCloudPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kExtensionPref));
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::kStabilityLaunchCount));
+ prefs::kCommandLinePref));
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));
+ prefs::kUserPref));
EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
- prefs::kRecommendedPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kRecommendedPref));
-
- // Test a preference from the default pref store.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
+ prefs::kRecommendedCloudPref));
EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
prefs::kDefaultPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kDefaultPref));
-
- // Test a preference for which the PrefValueStore does not contain a value.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
prefs::kMissingPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
- prefs::kMissingPref));
}
TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
- // Test a managed platform preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
- EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage));
-
- // Test a device management preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(
- prefs::kDefaultSearchProviderName));
EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
- prefs::kDefaultSearchProviderName));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
- prefs::kDefaultSearchProviderName));
-
- // Test an extension preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ prefs::kManagedPlatformPref));
EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
- prefs::kCurrentThemeID));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
- prefs::kCurrentThemeID));
-
- // Test a command-line preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ prefs::kManagedCloudPref));
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::kStabilityLaunchCount));
+ prefs::kExtensionPref));
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));
+ prefs::kCommandLinePref));
+ EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
+ prefs::kUserPref));
EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
- prefs::kRecommendedPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
- prefs::kRecommendedPref));
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
+ prefs::kRecommendedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
+ prefs::kDefaultPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
+ prefs::kMissingPref));
+}
- // Test a preference from the default pref store.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
- EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kDefaultPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kDefaultPref));
+TEST_F(PrefValueStoreTest, PrefValueFromExtensionStore) {
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kManagedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kManagedCloudPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kExtensionPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kCommandLinePref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kUserPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kRecommendedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kDefaultPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
+ prefs::kMissingPref));
+}
- // Test a preference for which the PrefValueStore does not contain a value.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
- EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref));
- EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref));
+TEST_F(PrefValueStoreTest, PrefValueFromUserStore) {
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kManagedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kManagedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kExtensionPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kCommandLinePref));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kUserPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kRecommendedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kDefaultPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
+ prefs::kMissingPref));
}
TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
- // Test a managed platform preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
- EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomePage));
-
- // Test a device management preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(
- prefs::kDefaultSearchProviderName));
EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
- prefs::kDefaultSearchProviderName));
-
- // Test an extension preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
+ prefs::kManagedPlatformPref));
EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
- prefs::kCurrentThemeID));
-
- // Test a command-line preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
+ prefs::kManagedCloudPref));
EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
- prefs::kApplicationLocale));
-
- // Test a user preference.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
+ prefs::kExtensionPref));
EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
- prefs::kStabilityLaunchCount));
-
- // Test a preference from the recommended pref store.
- ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
+ prefs::kCommandLinePref));
EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
- prefs::kRecommendedPref));
-
- // Test a preference from the default pref store.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
- EXPECT_TRUE(
- pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref));
+ prefs::kUserPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
+ prefs::kRecommendedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
+ prefs::kRecommendedCloudPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueFromDefaultStore(
+ prefs::kDefaultPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
+ prefs::kMissingPref));
+}
- // Test a preference for which the PrefValueStore does not contain a value.
- ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
- EXPECT_FALSE(
- pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref));
+TEST_F(PrefValueStoreTest, PrefValueUserModifiable) {
+ EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kManagedPlatformPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kManagedCloudPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kExtensionPref));
+ EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kCommandLinePref));
+ EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kUserPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kRecommendedPlatformPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kRecommendedCloudPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kDefaultPref));
+ EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
+ prefs::kMissingPref));
}
diff --git a/chrome/browser/prefs/proxy_config_dictionary.cc b/chrome/browser/prefs/proxy_config_dictionary.cc
new file mode 100644
index 0000000..0c063cd
--- /dev/null
+++ b/chrome/browser/prefs/proxy_config_dictionary.cc
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prefs/proxy_config_dictionary.h"
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/values.h"
+
+namespace {
+
+// Integer to specify the type of proxy settings.
+// See ProxyPrefs for possible values and interactions with the other proxy
+// preferences.
+const char kProxyMode[] = "mode";
+// String specifying the proxy server. For a specification of the expected
+// syntax see net::ProxyConfig::ProxyRules::ParseFromString().
+const char kProxyServer[] = "server";
+// URL to the proxy .pac file.
+const char kProxyPacUrl[] = "pac_url";
+// String containing proxy bypass rules. For a specification of the
+// expected syntax see net::ProxyBypassRules::ParseFromString().
+const char kProxyBypassList[] = "bypass_list";
+
+} // namespace
+
+ProxyConfigDictionary::ProxyConfigDictionary(const DictionaryValue* dict)
+ : dict_(dict->DeepCopy()) {
+}
+
+ProxyConfigDictionary::~ProxyConfigDictionary() {}
+
+bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const {
+ std::string mode_str;
+ return dict_->GetString(kProxyMode, &mode_str)
+ && StringToProxyMode(mode_str, out);
+}
+
+bool ProxyConfigDictionary::GetPacUrl(std::string* out) const {
+ return dict_->GetString(kProxyPacUrl, out);
+}
+
+bool ProxyConfigDictionary::GetProxyServer(std::string* out) const {
+ return dict_->GetString(kProxyServer, out);
+}
+
+bool ProxyConfigDictionary::GetBypassList(std::string* out) const {
+ return dict_->GetString(kProxyBypassList, out);
+}
+
+bool ProxyConfigDictionary::HasBypassList() const {
+ return dict_->HasKey(kProxyBypassList);
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreateDirect() {
+ return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", "", "");
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() {
+ return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", "", "");
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreatePacScript(
+ const std::string& pac_url) {
+ return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, "", "");
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreateFixedServers(
+ const std::string& proxy_server,
+ const std::string& bypass_list) {
+ if (!proxy_server.empty()) {
+ return CreateDictionary(
+ ProxyPrefs::MODE_FIXED_SERVERS, "", proxy_server, bypass_list);
+ } else {
+ return CreateDirect();
+ }
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreateSystem() {
+ return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", "", "");
+}
+
+// static
+DictionaryValue* ProxyConfigDictionary::CreateDictionary(
+ ProxyPrefs::ProxyMode mode,
+ const std::string& pac_url,
+ const std::string& proxy_server,
+ const std::string& bypass_list) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString(kProxyMode, ProxyModeToString(mode));
+ if (!pac_url.empty())
+ dict->SetString(kProxyPacUrl, pac_url);
+ if (!proxy_server.empty())
+ dict->SetString(kProxyServer, proxy_server);
+ if (!bypass_list.empty())
+ dict->SetString(kProxyBypassList, bypass_list);
+ return dict;
+}
diff --git a/chrome/browser/prefs/proxy_config_dictionary.h b/chrome/browser/prefs/proxy_config_dictionary.h
new file mode 100644
index 0000000..7af2e27
--- /dev/null
+++ b/chrome/browser/prefs/proxy_config_dictionary.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PREFS_PROXY_CONFIG_DICTIONARY_H_
+#define CHROME_BROWSER_PREFS_PROXY_CONFIG_DICTIONARY_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/prefs/proxy_prefs.h"
+
+class DictionaryValue;
+
+// Factory and wrapper for proxy config dictionaries that are stored
+// in the user preferences. The dictionary has the following structure:
+// {
+// mode: string,
+// server: string,
+// pac_url: string,
+// bypass_list: string
+// }
+// See proxy_config_dictionary.cc for the structure of the respective strings.
+class ProxyConfigDictionary {
+ public:
+ // Creates a deep copy of |dict| and leaves ownership to caller.
+ explicit ProxyConfigDictionary(const DictionaryValue* dict);
+ ~ProxyConfigDictionary();
+
+ bool GetMode(ProxyPrefs::ProxyMode* out) const;
+ bool GetPacUrl(std::string* out) const;
+ bool GetProxyServer(std::string* out) const;
+ bool GetBypassList(std::string* out) const;
+ bool HasBypassList() const;
+
+ static DictionaryValue* CreateDirect();
+ static DictionaryValue* CreateAutoDetect();
+ static DictionaryValue* CreatePacScript(const std::string& pac_url);
+ static DictionaryValue* CreateFixedServers(
+ const std::string& proxy_server,
+ const std::string& bypass_list);
+ static DictionaryValue* CreateSystem();
+ private:
+ static DictionaryValue* CreateDictionary(ProxyPrefs::ProxyMode mode,
+ const std::string& pac_url,
+ const std::string& proxy_server,
+ const std::string& bypass_list);
+
+ scoped_ptr<DictionaryValue> dict_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProxyConfigDictionary);
+};
+
+#endif // CHROME_BROWSER_PREFS_PROXY_CONFIG_DICTIONARY_H_
diff --git a/chrome/browser/prefs/proxy_config_dictionary_unittest.cc b/chrome/browser/prefs/proxy_config_dictionary_unittest.cc
new file mode 100644
index 0000000..07c6743
--- /dev/null
+++ b/chrome/browser/prefs/proxy_config_dictionary_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/prefs/proxy_config_dictionary.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+struct ProxyConfigHolder {
+ ProxyPrefs::ProxyMode mode;
+ std::string pac_url;
+ std::string proxy_server;
+ std::string bypass_list;
+};
+
+TEST(ProxyConfigDictionaryTest, CreateDirect) {
+ scoped_ptr<DictionaryValue> dict_value(ProxyConfigDictionary::CreateDirect());
+ ProxyConfigDictionary dict(dict_value.get());
+ ProxyConfigHolder h;
+
+ ASSERT_TRUE(dict.GetMode(&h.mode));
+ EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode);
+ ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
+ ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
+ ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
+}
+
+TEST(ProxyConfigDictionaryTest, CreateAutoDetect) {
+ scoped_ptr<DictionaryValue> dict_value(
+ ProxyConfigDictionary::CreateAutoDetect());
+ ProxyConfigDictionary dict(dict_value.get());
+ ProxyConfigHolder h;
+
+ ASSERT_TRUE(dict.GetMode(&h.mode));
+ EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode);
+ ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
+ ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
+ ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
+}
+
+TEST(ProxyConfigDictionaryTest, CreatePacScript) {
+ scoped_ptr<DictionaryValue> dict_value(
+ ProxyConfigDictionary::CreatePacScript("pac"));
+ ProxyConfigDictionary dict(dict_value.get());
+ ProxyConfigHolder h;
+
+ ASSERT_TRUE(dict.GetMode(&h.mode));
+ EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode);
+ ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list));
+ EXPECT_EQ("pac", h.bypass_list);
+ ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
+ ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
+}
+
+TEST(ProxyConfigDictionaryTest, CreateFixedServers) {
+ scoped_ptr<DictionaryValue> dict_value(
+ ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4",
+ "http://foo"));
+ ProxyConfigDictionary dict(dict_value.get());
+ ProxyConfigHolder h;
+
+ ASSERT_TRUE(dict.GetMode(&h.mode));
+ EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode);
+ ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
+ ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server));
+ EXPECT_EQ("http://1.2.3.4", h.proxy_server);
+ ASSERT_TRUE(dict.GetBypassList(&h.bypass_list));
+ EXPECT_EQ("http://foo", h.bypass_list);
+}
+
+TEST(ProxyConfigDictionaryTest, CreateSystem) {
+ scoped_ptr<DictionaryValue> dict_value(ProxyConfigDictionary::CreateSystem());
+ ProxyConfigDictionary dict(dict_value.get());
+ ProxyConfigHolder h;
+
+ ASSERT_TRUE(dict.GetMode(&h.mode));
+ EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode);
+ ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
+ ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
+ ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
+}
diff --git a/chrome/browser/prefs/proxy_prefs.cc b/chrome/browser/prefs/proxy_prefs.cc
index 7eb504c..4d7b550 100644
--- a/chrome/browser/prefs/proxy_prefs.cc
+++ b/chrome/browser/prefs/proxy_prefs.cc
@@ -7,15 +7,25 @@
#include "base/basictypes.h"
#include "base/logging.h"
+namespace ProxyPrefs {
+
+const char kDirectProxyModeName[] = "direct";
+const char kAutoDetectProxyModeName[] = "auto_detect";
+const char kPacScriptProxyModeName[] = "pac_script";
+const char kFixedServersProxyModeName[] = "fixed_servers";
+const char kSystemProxyModeName[] = "system";
+
+}
+
namespace {
// These names are exposed to the proxy extension API. They must be in sync
// with the constants of ProxyPrefs.
-const char* kProxyModeNames[] = { "direct",
- "auto_detect",
- "pac_script",
- "fixed_servers",
- "system" };
+const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName,
+ ProxyPrefs::kAutoDetectProxyModeName,
+ ProxyPrefs::kPacScriptProxyModeName,
+ ProxyPrefs::kFixedServersProxyModeName,
+ ProxyPrefs::kSystemProxyModeName };
} // namespace
@@ -42,4 +52,8 @@ bool StringToProxyMode(const std::string& in_value, ProxyMode* out_value) {
return false;
}
+const char* ProxyModeToString(ProxyMode mode) {
+ return kProxyModeNames[mode];
+}
+
} // namespace
diff --git a/chrome/browser/prefs/proxy_prefs.h b/chrome/browser/prefs/proxy_prefs.h
index bbeb44d..46be759 100644
--- a/chrome/browser/prefs/proxy_prefs.h
+++ b/chrome/browser/prefs/proxy_prefs.h
@@ -36,9 +36,19 @@ enum ProxyMode {
kModeCount
};
+// Constants for string values used to specify the proxy mode through externally
+// visible APIs, e.g. through policy or the proxy extension API.
+extern const char kDirectProxyModeName[];
+extern const char kAutoDetectProxyModeName[];
+extern const char kPacScriptProxyModeName[];
+extern const char kFixedServersProxyModeName[];
+extern const char kSystemProxyModeName[];
+
bool IntToProxyMode(int in_value, ProxyMode* out_value);
bool StringToProxyMode(const std::string& in_value,
ProxyMode* out_value);
+// Ownership of the return value is NOT passed to the caller.
+const char* ProxyModeToString(ProxyMode mode);
} // namespace ProxyPrefs
diff --git a/chrome/browser/prefs/proxy_prefs_unittest.cc b/chrome/browser/prefs/proxy_prefs_unittest.cc
index 72aa0f1..63b8ea3 100644
--- a/chrome/browser/prefs/proxy_prefs_unittest.cc
+++ b/chrome/browser/prefs/proxy_prefs_unittest.cc
@@ -1,12 +1,10 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
-#include "base/logging.h"
#include "base/values.h"
-#include "base/version.h"
#include "chrome/browser/prefs/proxy_prefs.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/prefs/testing_pref_store.cc b/chrome/browser/prefs/testing_pref_store.cc
index 39c20f2..89394bd 100644
--- a/chrome/browser/prefs/testing_pref_store.cc
+++ b/chrome/browser/prefs/testing_pref_store.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,9 @@
TestingPrefStore::TestingPrefStore()
: read_only_(true),
prefs_written_(false),
- init_complete_(false) { }
+ init_complete_(false) {}
+
+TestingPrefStore::~TestingPrefStore() {}
PrefStore::ReadResult TestingPrefStore::GetValue(const std::string& key,
Value** value) const {
@@ -24,6 +26,10 @@ void TestingPrefStore::RemoveObserver(PrefStore::Observer* observer) {
observers_.RemoveObserver(observer);
}
+bool TestingPrefStore::IsInitializationComplete() const {
+ return init_complete_;
+}
+
void TestingPrefStore::SetValue(const std::string& key, Value* value) {
if (prefs_.SetValue(key, value))
NotifyPrefValueChanged(key);
@@ -38,6 +44,10 @@ void TestingPrefStore::RemoveValue(const std::string& key) {
NotifyPrefValueChanged(key);
}
+bool TestingPrefStore::ReadOnly() const {
+ return read_only_;
+}
+
PersistentPrefStore::PrefReadError TestingPrefStore::ReadPrefs() {
prefs_.Clear();
return PersistentPrefStore::PREF_READ_ERROR_NONE;
@@ -98,3 +108,15 @@ bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const {
return stored_value->GetAsBoolean(value);
}
+
+void TestingPrefStore::set_read_only(bool read_only) {
+ read_only_ = read_only;
+}
+
+void TestingPrefStore::set_prefs_written(bool status) {
+ prefs_written_ = status;
+}
+
+bool TestingPrefStore::get_prefs_written() {
+ return prefs_written_;
+}
diff --git a/chrome/browser/prefs/testing_pref_store.h b/chrome/browser/prefs/testing_pref_store.h
index 555ee69..5502ad2 100644
--- a/chrome/browser/prefs/testing_pref_store.h
+++ b/chrome/browser/prefs/testing_pref_store.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,19 +20,19 @@ class DictionaryValue;
class TestingPrefStore : public PersistentPrefStore {
public:
TestingPrefStore();
- virtual ~TestingPrefStore() {}
+ virtual ~TestingPrefStore();
// Overriden from PrefStore.
virtual ReadResult GetValue(const std::string& key, Value** result) const;
virtual void AddObserver(PrefStore::Observer* observer);
virtual void RemoveObserver(PrefStore::Observer* observer);
- virtual bool IsInitializationComplete() const { return init_complete_; }
+ virtual bool IsInitializationComplete() const;
// PersistentPrefStore overrides:
virtual void SetValue(const std::string& key, Value* value);
virtual void SetValueSilently(const std::string& key, Value* value);
virtual void RemoveValue(const std::string& key);
- virtual bool ReadOnly() const { return read_only_; }
+ virtual bool ReadOnly() const;
virtual PersistentPrefStore::PrefReadError ReadPrefs();
virtual bool WritePrefs();
virtual void ScheduleWritePrefs() {}
@@ -55,9 +55,9 @@ class TestingPrefStore : public PersistentPrefStore {
// Getter and Setter methods for setting and getting the state of the
// |TestingPrefStore|.
- virtual void set_read_only(bool read_only) { read_only_ = read_only; }
- virtual void set_prefs_written(bool status) { prefs_written_ = status; }
- virtual bool get_prefs_written() { return prefs_written_; }
+ virtual void set_read_only(bool read_only);
+ virtual void set_prefs_written(bool status);
+ virtual bool get_prefs_written();
private:
// Stores the preference values.
diff --git a/chrome/browser/prefs/value_map_pref_store.cc b/chrome/browser/prefs/value_map_pref_store.cc
index 705c958..58c4016 100644
--- a/chrome/browser/prefs/value_map_pref_store.cc
+++ b/chrome/browser/prefs/value_map_pref_store.cc
@@ -39,3 +39,19 @@ void ValueMapPrefStore::RemoveValue(const std::string& key) {
void ValueMapPrefStore::NotifyInitializationCompleted() {
FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted());
}
+
+ValueMapPrefStore::iterator ValueMapPrefStore::begin() {
+ return prefs_.begin();
+}
+
+ValueMapPrefStore::iterator ValueMapPrefStore::end() {
+ return prefs_.end();
+}
+
+ValueMapPrefStore::const_iterator ValueMapPrefStore::begin() const {
+ return prefs_.begin();
+}
+
+ValueMapPrefStore::const_iterator ValueMapPrefStore::end() const {
+ return prefs_.end();
+}
diff --git a/chrome/browser/prefs/value_map_pref_store.h b/chrome/browser/prefs/value_map_pref_store.h
index 20bf290..a8b66c4 100644
--- a/chrome/browser/prefs/value_map_pref_store.h
+++ b/chrome/browser/prefs/value_map_pref_store.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,8 +6,6 @@
#define CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_
#pragma once
-#include <map>
-
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "chrome/browser/prefs/pref_value_map.h"
@@ -17,6 +15,9 @@
// storing the preference values.
class ValueMapPrefStore : public PrefStore {
public:
+ typedef std::map<std::string, Value*>::iterator iterator;
+ typedef std::map<std::string, Value*>::const_iterator const_iterator;
+
ValueMapPrefStore();
virtual ~ValueMapPrefStore();
@@ -25,6 +26,11 @@ class ValueMapPrefStore : public PrefStore {
virtual void AddObserver(PrefStore::Observer* observer);
virtual void RemoveObserver(PrefStore::Observer* observer);
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
protected:
// Store a |value| for |key| in the store. Also generates an notification if
// the value changed. Assumes ownership of |value|, which must be non-NULL.