Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2850)

Unified Diff: chrome/browser/policy/configuration_policy_pref_store.cc

Issue 7520023: Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Ignore incognito policies if values cannot be parsed. Address comments. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/configuration_policy_pref_store.cc
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index 3f74a0137462f5aa2b69d064884410bdb46f64ba..c11615dbda61d33c3a636b4811446d7958b8931f 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/policy_path_parser.h"
+#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/pref_value_map.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/browser/search_engines/search_terms_data.h"
@@ -106,6 +107,11 @@ class ConfigurationPolicyPrefKeeper
// ApplyDefaultSearchPolicy takes ownership of |value|.
bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value);
+ // Processes incognito mode availability related policies. Returns true if the
+ // specified policy is pertinent to incognito mode availability. In that case,
+ // the function takes ownership of |value|.
+ bool ApplyIncognitoModePolicy(ConfigurationPolicyType policy, Value* value);
+
// Make sure that the |path| if present in |prefs_|. If not, set it to
// a blank string.
void EnsureStringPrefExists(const std::string& path);
@@ -121,6 +127,11 @@ class ConfigurationPolicyPrefKeeper
// respective values in |prefs_|.
void FinalizeProxyPolicySettings();
+ // If the required entries for the Incognito mode availability settings
+ // are specified and valid, finalizes the policy-specified configuration
+ // by initializing the respective values in |prefs_|.
+ void FinalizeIncognitoModeSettings();
+
// Returns true if the policy values stored in proxy_* represent a valid proxy
// configuration, including the case in which there is no configuration at
// all.
@@ -136,6 +147,11 @@ class ConfigurationPolicyPrefKeeper
// is called.
std::map<ConfigurationPolicyType, Value*> proxy_policies_;
+ // Saved state of the deprecated kPolicyIncognitoEnabled. It is still used for
+ // backward compatibility to set the new kIncognitoAvailabilityMode pref in
+ // case the corresponding policy for the latter is not specified.
+ scoped_ptr<Value> deprecated_incognito_enabled_;
+
PrefValueMap prefs_;
static const PolicyToPreferenceMapEntry kSimplePolicyMap[];
@@ -191,10 +207,6 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
prefs::kShowHomeButton },
{ Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled,
prefs::kWebKitJavascriptEnabled },
- { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled,
- prefs::kIncognitoEnabled },
- { Value::TYPE_BOOLEAN, kPolicyIncognitoForced,
- prefs::kIncognitoForced },
{ Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled,
prefs::kSavingBrowserHistoryDisabled },
{ Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit,
@@ -317,6 +329,7 @@ ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper(
LOG(WARNING) << "Failed to get policy from provider.";
FinalizeProxyPolicySettings();
FinalizeDefaultSearchPolicySettings();
+ FinalizeIncognitoModeSettings();
}
ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() {
@@ -369,6 +382,9 @@ void ConfigurationPolicyPrefKeeper::Apply(ConfigurationPolicyType policy,
if (ApplyDefaultSearchPolicy(policy, value))
return;
+ if (ApplyIncognitoModePolicy(policy, value))
+ return;
+
if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
arraysize(kSimplePolicyMap)))
return;
@@ -556,6 +572,37 @@ bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy(
return false;
}
+bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy(
+ ConfigurationPolicyType policy,
+ Value* value) {
+ if (policy == kPolicyIncognitoModeAvailability) {
+ int availability = IncognitoModePrefs::ENABLED;
+ bool result = value->GetAsInteger(&availability);
+ delete value;
+ if (result) {
+ IncognitoModePrefs::Availability availability_enum_value;
+ if (IncognitoModePrefs::IntToAvailability(availability,
+ &availability_enum_value)) {
+ prefs_.SetValue(prefs::kIncognitoModeAvailability,
+ Value::CreateIntegerValue(availability_enum_value));
+ } else {
+ LOG(WARNING) << "IncognitoModeAvailability policy value is "
+ << "out of range " << availability;
+ }
+ } else {
+ LOG(WARNING) << "IncognitoModeAvailability policy value could not be "
+ << "parsed";
+ }
+ return true;
+ }
+ if (policy == kPolicyIncognitoEnabled) {
+ deprecated_incognito_enabled_.reset(value);
+ return true;
+ }
+ // The policy is not relevant to incognito.
+ return false;
+}
+
void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
const std::string& path) {
std::string value;
@@ -637,6 +684,26 @@ void ConfigurationPolicyPrefKeeper::FinalizeDefaultSearchPolicySettings() {
arraysize(kDefaultSearchPolicyMap));
}
+void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() {
+ int int_value;
+ if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) {
+ // If kPolicyIncognitoModeAvailability is not specified, check the obsolete
+ // kPolicyIncognitoEnabled.
+ if (deprecated_incognito_enabled_.get()) {
+ bool enabled = true;
+ if (deprecated_incognito_enabled_->GetAsBoolean(&enabled)) {
+ // If the obsolete policy says that incognito is disabled,
Mattias Nissler (ping if slow) 2011/08/04 09:03:53 nit: Seems this comment fell through the cracks. J
rustema 2011/08/04 17:58:07 Done.
+ prefs_.SetInteger(
+ prefs::kIncognitoModeAvailability,
+ enabled ? IncognitoModePrefs::ENABLED :
+ IncognitoModePrefs::DISABLED);
+ } else {
+ LOG(WARNING) << "IncognitoEnabled policy value could not be parsed";
+ }
+ }
+ }
+}
+
void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
if (CheckProxySettings())
ApplyProxySettings();
@@ -999,7 +1066,8 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
{ kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled },
{ kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled },
{ kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled },
- { kPolicyIncognitoForced, Value::TYPE_BOOLEAN, key::kIncognitoForced },
+ { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER,
+ key::kIncognitoModeAvailability },
{ kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN,
key::kSavingBrowserHistoryDisabled },
{ kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN,

Powered by Google App Engine
This is Rietveld 408576698