summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs
diff options
context:
space:
mode:
authorrustema@google.com <rustema@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-05 05:28:27 +0000
committerrustema@google.com <rustema@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-05 05:28:27 +0000
commit4e94ab3d72e4fd1cf76be4014721985dde1b724b (patch)
treec13ad27f4de1f44ee054929ead4960ca90039b90 /chrome/browser/prefs
parent85acecb3f21d0905acae3fbbb27f904f15a6b878 (diff)
downloadchromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.zip
chromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.tar.gz
chromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.tar.bz2
Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy.
Enum may take 3 values: * ENABLED (default) - both normal and incognito modes are allowed. * DISABLED - incognito mode cannot be used. * FORCED - browsing is only possible in incognito mode. Mapped IncognitoEnabled::false to IncognitoModeAvailability::DISABLED when IncognitoModeAvailability policy/pref is not set. Removed IncognitoEnabled pref (no longer used). BUG=69580 TEST= Review URL: http://codereview.chromium.org/7520023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs')
-rw-r--r--chrome/browser/prefs/browser_prefs.cc2
-rw-r--r--chrome/browser/prefs/command_line_pref_store.cc1
-rw-r--r--chrome/browser/prefs/incognito_mode_prefs.cc45
-rw-r--r--chrome/browser/prefs/incognito_mode_prefs.h53
-rw-r--r--chrome/browser/prefs/incognito_mode_prefs_unittest.cc66
-rw-r--r--chrome/browser/prefs/pref_value_map.cc9
-rw-r--r--chrome/browser/prefs/pref_value_map.h7
-rw-r--r--chrome/browser/prefs/pref_value_map_unittest.cc13
8 files changed, 195 insertions, 1 deletions
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 952317d..9b0db6e 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -38,6 +38,7 @@
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/plugin_updater.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h"
+#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/profiles/profile_impl.h"
@@ -155,6 +156,7 @@ void RegisterUserPrefs(PrefService* user_prefs) {
TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs);
ExtensionWebUI::RegisterUserPrefs(user_prefs);
ExtensionsUI::RegisterUserPrefs(user_prefs);
+ IncognitoModePrefs::RegisterUserPrefs(user_prefs);
NewTabUI::RegisterUserPrefs(user_prefs);
PluginsUI::RegisterUserPrefs(user_prefs);
PluginUpdater::RegisterPrefs(user_prefs);
diff --git a/chrome/browser/prefs/command_line_pref_store.cc b/chrome/browser/prefs/command_line_pref_store.cc
index a0e94dc..021be74 100644
--- a/chrome/browser/prefs/command_line_pref_store.cc
+++ b/chrome/browser/prefs/command_line_pref_store.cc
@@ -42,7 +42,6 @@ const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
prefs::kWebKitAllowDisplayingInsecureContent, false },
{ switches::kAllowCrossOriginAuthPrompt,
prefs::kAllowCrossOriginAuthPrompt, true },
- { switches::kIncognito, prefs::kIncognitoForced, true },
};
CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line)
diff --git a/chrome/browser/prefs/incognito_mode_prefs.cc b/chrome/browser/prefs/incognito_mode_prefs.cc
new file mode 100644
index 0000000..067edc2
--- /dev/null
+++ b/chrome/browser/prefs/incognito_mode_prefs.cc
@@ -0,0 +1,45 @@
+// 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/incognito_mode_prefs.h"
+
+#include "base/logging.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/pref_names.h"
+
+// static
+bool IncognitoModePrefs::IntToAvailability(int in_value,
+ Availability* out_value) {
+ if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
+ *out_value = ENABLED;
+ return false;
+ }
+ *out_value = static_cast<Availability>(in_value);
+ return true;
+}
+
+// static
+IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
+ const PrefService* pref_service) {
+ DCHECK(pref_service);
+ int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
+ Availability result = IncognitoModePrefs::ENABLED;
+ bool valid = IntToAvailability(pref_value, &result);
+ DCHECK(valid);
+ return result;
+}
+
+// static
+void IncognitoModePrefs::SetAvailability(PrefService* prefs,
+ const Availability availability) {
+ prefs->SetInteger(prefs::kIncognitoModeAvailability, availability);
+}
+
+// static
+void IncognitoModePrefs::RegisterUserPrefs(PrefService* pref_service) {
+ DCHECK(pref_service);
+ pref_service->RegisterIntegerPref(prefs::kIncognitoModeAvailability,
+ IncognitoModePrefs::ENABLED,
+ PrefService::UNSYNCABLE_PREF);
+}
diff --git a/chrome/browser/prefs/incognito_mode_prefs.h b/chrome/browser/prefs/incognito_mode_prefs.h
new file mode 100644
index 0000000..907ac96
--- /dev/null
+++ b/chrome/browser/prefs/incognito_mode_prefs.h
@@ -0,0 +1,53 @@
+// 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_INCOGNITO_MODE_PREFS_H_
+#define CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+class PrefService;
+
+// Specifies Incognito mode availability preferences.
+class IncognitoModePrefs {
+ public:
+ // Possible values for Incognito mode availability. Please, do not change
+ // the order of entries since numeric values are exposed to users.
+ enum Availability {
+ // Incognito mode enabled. Users may open pages in both Incognito mode and
+ // normal mode (the default behaviour).
+ ENABLED = 0,
+ // Incognito mode disabled. Users may not open pages in Incognito mode.
+ // Only normal mode is available for browsing.
+ DISABLED,
+ // Incognito mode forced. Users may open pages *ONLY* in Incognito mode.
+ // Normal mode is not available for browsing.
+ FORCED,
+
+ AVAILABILITY_NUM_TYPES
+ };
+
+ // Register incognito related preferences.
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ // Returns kIncognitoModeAvailability preference value stored
+ // in the given pref service.
+ static Availability GetAvailability(const PrefService* prefs);
+
+ // Sets kIncognitoModeAvailability preference to the specified availability
+ // value.
+ static void SetAvailability(PrefService* prefs,
+ const Availability availability);
+
+ // Converts in_value into the corresponding Availability value. Returns true
+ // if conversion is successful (in_value is valid). Otherwise, returns false
+ // and *out_value is set to ENABLED.
+ static bool IntToAvailability(int in_value, Availability* out_value);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(IncognitoModePrefs);
+};
+
+#endif // CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_
diff --git a/chrome/browser/prefs/incognito_mode_prefs_unittest.cc b/chrome/browser/prefs/incognito_mode_prefs_unittest.cc
new file mode 100644
index 0000000..053f0bf
--- /dev/null
+++ b/chrome/browser/prefs/incognito_mode_prefs_unittest.cc
@@ -0,0 +1,66 @@
+// 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/incognito_mode_prefs.h"
+
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class IncognitoModePrefsTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ IncognitoModePrefs::RegisterUserPrefs(&prefs_);
+ }
+
+ TestingPrefService prefs_;
+};
+
+TEST_F(IncognitoModePrefsTest, IntToAvailability) {
+ ASSERT_EQ(0, IncognitoModePrefs::ENABLED);
+ ASSERT_EQ(1, IncognitoModePrefs::DISABLED);
+ ASSERT_EQ(2, IncognitoModePrefs::FORCED);
+
+ IncognitoModePrefs::Availability incognito;
+ EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(0, &incognito));
+ EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
+ EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(1, &incognito));
+ EXPECT_EQ(IncognitoModePrefs::DISABLED, incognito);
+ EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito));
+ EXPECT_EQ(IncognitoModePrefs::FORCED, incognito);
+
+ EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito));
+ EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
+ EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito));
+ EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
+}
+
+TEST_F(IncognitoModePrefsTest, GetAvailability) {
+ prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
+ Value::CreateIntegerValue(IncognitoModePrefs::ENABLED));
+ EXPECT_EQ(IncognitoModePrefs::ENABLED,
+ IncognitoModePrefs::GetAvailability(&prefs_));
+
+ prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
+ Value::CreateIntegerValue(IncognitoModePrefs::DISABLED));
+ EXPECT_EQ(IncognitoModePrefs::DISABLED,
+ IncognitoModePrefs::GetAvailability(&prefs_));
+
+ prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
+ Value::CreateIntegerValue(IncognitoModePrefs::FORCED));
+ EXPECT_EQ(IncognitoModePrefs::FORCED,
+ IncognitoModePrefs::GetAvailability(&prefs_));
+}
+
+typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest;
+
+TEST_F(IncognitoModePrefsDeathTest, GetAvailabilityBadValue) {
+ prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
+ Value::CreateIntegerValue(-1));
+ EXPECT_DEBUG_DEATH({
+ IncognitoModePrefs::Availability availability =
+ IncognitoModePrefs::GetAvailability(&prefs_);
+ EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
+ }, "");
+}
diff --git a/chrome/browser/prefs/pref_value_map.cc b/chrome/browser/prefs/pref_value_map.cc
index b810519..3d69cf1 100644
--- a/chrome/browser/prefs/pref_value_map.cc
+++ b/chrome/browser/prefs/pref_value_map.cc
@@ -102,6 +102,15 @@ void PrefValueMap::SetString(const std::string& key,
SetValue(key, Value::CreateStringValue(value));
}
+bool PrefValueMap::GetInteger(const std::string& key, int* value) const {
+ const Value* stored_value = NULL;
+ return GetValue(key, &stored_value) && stored_value->GetAsInteger(value);
+}
+
+void PrefValueMap::SetInteger(const std::string& key, const int value) {
+ SetValue(key, Value::CreateIntegerValue(value));
+}
+
void PrefValueMap::GetDifferingKeys(
const PrefValueMap* other,
std::vector<std::string>* differing_keys) const {
diff --git a/chrome/browser/prefs/pref_value_map.h b/chrome/browser/prefs/pref_value_map.h
index 100aa34..f8995ce 100644
--- a/chrome/browser/prefs/pref_value_map.h
+++ b/chrome/browser/prefs/pref_value_map.h
@@ -58,6 +58,13 @@ class PrefValueMap {
// Sets the value for |key| to the string |value|.
void SetString(const std::string& key, const std::string& value);
+ // Gets an int value for |key| and stores it in |value|. Returns true if
+ // the value was found and of the proper type.
+ bool GetInteger(const std::string& key, int* value) const;
+
+ // Sets the value for |key| to the int |value|.
+ void SetInteger(const std::string& key, const int value);
+
// Compares this value map against |other| and stores all key names that have
// different values in |differing_keys|. This includes keys that are present
// only in one of the maps.
diff --git a/chrome/browser/prefs/pref_value_map_unittest.cc b/chrome/browser/prefs/pref_value_map_unittest.cc
index cc47a85..08aa578 100644
--- a/chrome/browser/prefs/pref_value_map_unittest.cc
+++ b/chrome/browser/prefs/pref_value_map_unittest.cc
@@ -23,6 +23,19 @@ TEST_F(PrefValueMapTest, SetValue) {
EXPECT_TRUE(StringValue("hi mom!").Equals(result));
}
+TEST_F(PrefValueMapTest, GetAndSetIntegerValue) {
+ PrefValueMap map;
+ ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5)));
+
+ int int_value = 0;
+ EXPECT_TRUE(map.GetInteger("key", &int_value));
+ EXPECT_EQ(5, int_value);
+
+ map.SetInteger("key", -14);
+ EXPECT_TRUE(map.GetInteger("key", &int_value));
+ EXPECT_EQ(-14, int_value);
+}
+
TEST_F(PrefValueMapTest, RemoveValue) {
PrefValueMap map;
EXPECT_FALSE(map.RemoveValue("key"));