Chromium Code Reviews| 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..b85b931155cde984d3aa0c8bfd531bdcc42ded18 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. |
| @@ -193,8 +204,6 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry |
| prefs::kWebKitJavascriptEnabled }, |
| { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled, |
| prefs::kIncognitoEnabled }, |
|
Mattias Nissler (ping if slow)
2011/07/29 10:33:23
This should go away. In fact, the entire prefs::kI
rustema
2011/07/30 06:17:37
Yep, the code has become much cleaner this way. Th
|
| - { Value::TYPE_BOOLEAN, kPolicyIncognitoForced, |
| - prefs::kIncognitoForced }, |
| { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, |
| prefs::kSavingBrowserHistoryDisabled }, |
| { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, |
| @@ -317,6 +326,7 @@ ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( |
| LOG(WARNING) << "Failed to get policy from provider."; |
| FinalizeProxyPolicySettings(); |
| FinalizeDefaultSearchPolicySettings(); |
| + FinalizeIncognitoModeSettings(); |
| } |
| ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { |
| @@ -369,6 +379,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 +569,26 @@ bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy( |
| return false; |
| } |
| +bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy( |
| + ConfigurationPolicyType policy, |
| + Value* value) { |
| + if (policy == kPolicyIncognitoModeAvailability) { |
| + int availability = IncognitoModePrefs::ENABLED; |
| + bool result = value->GetAsInteger(&availability); |
| + DCHECK(result); |
| + delete value; |
| + IncognitoModePrefs::Availability availability_enum_value; |
| + result = IncognitoModePrefs::IntToAvailability(availability, |
| + &availability_enum_value); |
| + DCHECK(result); |
| + prefs_.SetValue(prefs::kIncognitoModeAvailability, |
| + Value::CreateIntegerValue(availability_enum_value)); |
| + return true; |
| + } |
| + // The policy is not relevant to incognito. |
| + return false; |
| +} |
| + |
| void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( |
| const std::string& path) { |
| std::string value; |
| @@ -637,6 +670,23 @@ 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. |
| + bool obsolete_incognito_enabled; |
| + if (prefs_.GetBoolean(prefs::kIncognitoEnabled, |
| + &obsolete_incognito_enabled)) { |
| + if (!obsolete_incognito_enabled) { |
| + // If the obsolete policy says that incognito is disabled, |
| + prefs_.SetInteger(prefs::kIncognitoModeAvailability, |
| + IncognitoModePrefs::DISABLED); |
| + } |
| + } |
| + } |
| +} |
| + |
| void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { |
| if (CheckProxySettings()) |
| ApplyProxySettings(); |
| @@ -999,7 +1049,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, |