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

Side by Side 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: Removed IncognitoEnabled pref. Fixed style issues. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/configuration_policy_pref_store.h" 5 #include "chrome/browser/policy/configuration_policy_pref_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/policy/browser_policy_connector.h" 21 #include "chrome/browser/policy/browser_policy_connector.h"
22 #include "chrome/browser/policy/configuration_policy_provider.h" 22 #include "chrome/browser/policy/configuration_policy_provider.h"
23 #include "chrome/browser/policy/policy_path_parser.h" 23 #include "chrome/browser/policy/policy_path_parser.h"
24 #include "chrome/browser/prefs/incognito_mode_prefs.h"
24 #include "chrome/browser/prefs/pref_value_map.h" 25 #include "chrome/browser/prefs/pref_value_map.h"
25 #include "chrome/browser/prefs/proxy_config_dictionary.h" 26 #include "chrome/browser/prefs/proxy_config_dictionary.h"
26 #include "chrome/browser/search_engines/search_terms_data.h" 27 #include "chrome/browser/search_engines/search_terms_data.h"
27 #include "chrome/browser/search_engines/template_url.h" 28 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "content/common/notification_service.h" 30 #include "content/common/notification_service.h"
30 #include "policy/policy_constants.h" 31 #include "policy/policy_constants.h"
31 32
32 namespace policy { 33 namespace policy {
33 34
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the 100 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the
100 // case that the policy is recognized. 101 // case that the policy is recognized.
101 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy, 102 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy,
102 Value* value); 103 Value* value);
103 104
104 // Processes default search provider policies. Returns true if the specified 105 // Processes default search provider policies. Returns true if the specified
105 // policy is a default search provider related policy. In that case, 106 // policy is a default search provider related policy. In that case,
106 // ApplyDefaultSearchPolicy takes ownership of |value|. 107 // ApplyDefaultSearchPolicy takes ownership of |value|.
107 bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value); 108 bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value);
108 109
110 // Processes incognito mode availability related policies. Returns true if the
111 // specified policy is pertinent to incognito mode availability. In that case,
112 // the function takes ownership of |value|.
113 bool ApplyIncognitoModePolicy(ConfigurationPolicyType policy, Value* value);
114
109 // Make sure that the |path| if present in |prefs_|. If not, set it to 115 // Make sure that the |path| if present in |prefs_|. If not, set it to
110 // a blank string. 116 // a blank string.
111 void EnsureStringPrefExists(const std::string& path); 117 void EnsureStringPrefExists(const std::string& path);
112 118
113 // If the required entries for default search are specified and valid, 119 // If the required entries for default search are specified and valid,
114 // finalizes the policy-specified configuration by initializing the 120 // finalizes the policy-specified configuration by initializing the
115 // unspecified map entries. Otherwise wipes all default search related 121 // unspecified map entries. Otherwise wipes all default search related
116 // map entries from |prefs_|. 122 // map entries from |prefs_|.
117 void FinalizeDefaultSearchPolicySettings(); 123 void FinalizeDefaultSearchPolicySettings();
118 124
119 // If the required entries for the proxy settings are specified and valid, 125 // If the required entries for the proxy settings are specified and valid,
120 // finalizes the policy-specified configuration by initializing the 126 // finalizes the policy-specified configuration by initializing the
121 // respective values in |prefs_|. 127 // respective values in |prefs_|.
122 void FinalizeProxyPolicySettings(); 128 void FinalizeProxyPolicySettings();
123 129
130 // If the required entries for the Incognito mode availability settings
131 // are specified and valid, finalizes the policy-specified configuration
132 // by initializing the respective values in |prefs_|.
133 void FinalizeIncognitoModeSettings();
134
124 // Returns true if the policy values stored in proxy_* represent a valid proxy 135 // Returns true if the policy values stored in proxy_* represent a valid proxy
125 // configuration, including the case in which there is no configuration at 136 // configuration, including the case in which there is no configuration at
126 // all. 137 // all.
127 bool CheckProxySettings(); 138 bool CheckProxySettings();
128 139
129 // Assumes CheckProxySettings returns true and applies the values stored 140 // Assumes CheckProxySettings returns true and applies the values stored
130 // in proxy_*. 141 // in proxy_*.
131 void ApplyProxySettings(); 142 void ApplyProxySettings();
132 143
133 bool HasProxyPolicy(ConfigurationPolicyType policy) const; 144 bool HasProxyPolicy(ConfigurationPolicyType policy) const;
134 145
135 // Temporary cache that stores values until FinalizeProxyPolicySettings() 146 // Temporary cache that stores values until FinalizeProxyPolicySettings()
136 // is called. 147 // is called.
137 std::map<ConfigurationPolicyType, Value*> proxy_policies_; 148 std::map<ConfigurationPolicyType, Value*> proxy_policies_;
138 149
150 // Saved state of the deprecated kPolicyIncognitoEnabled. If is still used for
Mattias Nissler (ping if slow) 2011/08/01 11:13:40 s/If/It/
rustema 2011/08/01 23:55:33 Done.
151 // backward compatibility to set the new kIncognitoAvailabilityMode pref in
152 // case the corresponding policy for the latter is not specified.
153 bool deprecated_incognito_enabled_;
154
139 PrefValueMap prefs_; 155 PrefValueMap prefs_;
140 156
141 static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; 157 static const PolicyToPreferenceMapEntry kSimplePolicyMap[];
142 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[]; 158 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[];
143 159
144 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper); 160 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper);
145 }; 161 };
146 162
147 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry 163 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
148 ConfigurationPolicyPrefKeeper::kSimplePolicyMap[] = { 164 ConfigurationPolicyPrefKeeper::kSimplePolicyMap[] = {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 { Value::TYPE_LIST, kPolicyDisabledPlugins, 200 { Value::TYPE_LIST, kPolicyDisabledPlugins,
185 prefs::kPluginsDisabledPlugins}, 201 prefs::kPluginsDisabledPlugins},
186 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions, 202 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions,
187 prefs::kPluginsDisabledPluginsExceptions}, 203 prefs::kPluginsDisabledPluginsExceptions},
188 { Value::TYPE_LIST, kPolicyEnabledPlugins, 204 { Value::TYPE_LIST, kPolicyEnabledPlugins,
189 prefs::kPluginsEnabledPlugins}, 205 prefs::kPluginsEnabledPlugins},
190 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, 206 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton,
191 prefs::kShowHomeButton }, 207 prefs::kShowHomeButton },
192 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, 208 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled,
193 prefs::kWebKitJavascriptEnabled }, 209 prefs::kWebKitJavascriptEnabled },
194 { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled,
195 prefs::kIncognitoEnabled },
196 { Value::TYPE_BOOLEAN, kPolicyIncognitoForced,
197 prefs::kIncognitoForced },
198 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, 210 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled,
199 prefs::kSavingBrowserHistoryDisabled }, 211 prefs::kSavingBrowserHistoryDisabled },
200 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, 212 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit,
201 prefs::kClearSiteDataOnExit }, 213 prefs::kClearSiteDataOnExit },
202 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, 214 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled,
203 prefs::kDevToolsDisabled }, 215 prefs::kDevToolsDisabled },
204 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, 216 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies,
205 prefs::kBlockThirdPartyCookies }, 217 prefs::kBlockThirdPartyCookies },
206 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting, 218 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting,
207 prefs::kManagedDefaultCookiesSetting }, 219 prefs::kManagedDefaultCookiesSetting },
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL, 318 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL,
307 prefs::kDefaultSearchProviderInstantURL }, 319 prefs::kDefaultSearchProviderInstantURL },
308 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, 320 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL,
309 prefs::kDefaultSearchProviderIconURL }, 321 prefs::kDefaultSearchProviderIconURL },
310 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings, 322 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings,
311 prefs::kDefaultSearchProviderEncodings }, 323 prefs::kDefaultSearchProviderEncodings },
312 }; 324 };
313 325
314 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( 326 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper(
315 ConfigurationPolicyProvider* provider) { 327 ConfigurationPolicyProvider* provider) {
328 deprecated_incognito_enabled_ = true;
316 if (!provider->Provide(this)) 329 if (!provider->Provide(this))
317 LOG(WARNING) << "Failed to get policy from provider."; 330 LOG(WARNING) << "Failed to get policy from provider.";
318 FinalizeProxyPolicySettings(); 331 FinalizeProxyPolicySettings();
319 FinalizeDefaultSearchPolicySettings(); 332 FinalizeDefaultSearchPolicySettings();
333 FinalizeIncognitoModeSettings();
320 } 334 }
321 335
322 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { 336 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() {
323 DCHECK(proxy_policies_.empty()); 337 DCHECK(proxy_policies_.empty());
324 } 338 }
325 339
326 PrefStore::ReadResult 340 PrefStore::ReadResult
327 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, 341 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key,
328 const Value** result) const { 342 const Value** result) const {
329 const Value* stored_value = NULL; 343 const Value* stored_value = NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 376
363 if (ApplyDiskCacheDirPolicy(policy, value)) 377 if (ApplyDiskCacheDirPolicy(policy, value))
364 return; 378 return;
365 379
366 if (ApplyFileSelectionDialogsPolicy(policy, value)) 380 if (ApplyFileSelectionDialogsPolicy(policy, value))
367 return; 381 return;
368 382
369 if (ApplyDefaultSearchPolicy(policy, value)) 383 if (ApplyDefaultSearchPolicy(policy, value))
370 return; 384 return;
371 385
386 if (ApplyIncognitoModePolicy(policy, value))
387 return;
388
372 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, 389 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
373 arraysize(kSimplePolicyMap))) 390 arraysize(kSimplePolicyMap)))
374 return; 391 return;
375 392
376 // Other policy implementations go here. 393 // Other policy implementations go here.
377 NOTIMPLEMENTED(); 394 NOTIMPLEMENTED();
378 delete value; 395 delete value;
379 } 396 }
380 397
381 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( 398 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap(
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return true; 566 return true;
550 } 567 }
551 568
552 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, 569 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
553 arraysize(kDefaultSearchPolicyMap))) { 570 arraysize(kDefaultSearchPolicyMap))) {
554 return true; 571 return true;
555 } 572 }
556 return false; 573 return false;
557 } 574 }
558 575
576 bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy(
577 ConfigurationPolicyType policy,
578 Value* value) {
579 if (policy == kPolicyIncognitoModeAvailability) {
580 int availability = IncognitoModePrefs::ENABLED;
581 bool result = value->GetAsInteger(&availability);
582 DCHECK(result);
583 delete value;
584 IncognitoModePrefs::Availability availability_enum_value;
585 result = IncognitoModePrefs::IntToAvailability(availability,
586 &availability_enum_value);
587 DCHECK(result);
588 prefs_.SetValue(prefs::kIncognitoModeAvailability,
589 Value::CreateIntegerValue(availability_enum_value));
590 return true;
591 }
592 if (policy == kPolicyIncognitoEnabled) {
Mattias Nissler (ping if slow) 2011/08/01 11:13:40 else if
rustema 2011/08/01 23:55:33 But there's a return statement in the previous if
Mattias Nissler (ping if slow) 2011/08/03 09:16:08 Yes, right, sorry for the noise.
593 bool result = value->GetAsBoolean(&deprecated_incognito_enabled_);
594 DCHECK(result);
595 delete value;
596 return true;
597 }
598 // The policy is not relevant to incognito.
599 return false;
600 }
601
559 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( 602 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
560 const std::string& path) { 603 const std::string& path) {
561 std::string value; 604 std::string value;
562 if (!prefs_.GetString(path, &value)) 605 if (!prefs_.GetString(path, &value))
563 prefs_.SetString(path, value); 606 prefs_.SetString(path, value);
564 } 607 }
565 608
566 namespace { 609 namespace {
567 610
568 // Implementation of SearchTermsData just for validation. 611 // Implementation of SearchTermsData just for validation.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID, 673 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID,
631 std::string()); 674 std::string());
632 return; 675 return;
633 } 676 }
634 } 677 }
635 // Required entries are not there. Remove any related entries. 678 // Required entries are not there. Remove any related entries.
636 RemovePreferencesOfMap(kDefaultSearchPolicyMap, 679 RemovePreferencesOfMap(kDefaultSearchPolicyMap,
637 arraysize(kDefaultSearchPolicyMap)); 680 arraysize(kDefaultSearchPolicyMap));
638 } 681 }
639 682
683 void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() {
684 int int_value;
685 if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) {
686 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete
687 // kPolicyIncognitoEnabled.
688 if (!deprecated_incognito_enabled_) {
Mattias Nissler (ping if slow) 2011/08/01 11:13:40 It's not correct to treat the cases "not set" and
rustema 2011/08/01 23:55:33 Done.
689 // If the obsolete policy says that incognito is disabled,
690 prefs_.SetInteger(prefs::kIncognitoModeAvailability,
691 IncognitoModePrefs::DISABLED);
692 }
693 }
694 }
695
640 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { 696 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
641 if (CheckProxySettings()) 697 if (CheckProxySettings())
642 ApplyProxySettings(); 698 ApplyProxySettings();
643 699
644 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), 700 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(),
645 proxy_policies_.end()); 701 proxy_policies_.end());
646 proxy_policies_.clear(); 702 proxy_policies_.clear();
647 } 703 }
648 704
649 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { 705 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST, 1048 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST,
993 key::kExtensionInstallWhitelist }, 1049 key::kExtensionInstallWhitelist },
994 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST, 1050 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST,
995 key::kExtensionInstallBlacklist }, 1051 key::kExtensionInstallBlacklist },
996 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST, 1052 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST,
997 key::kExtensionInstallForcelist }, 1053 key::kExtensionInstallForcelist },
998 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, 1054 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton },
999 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, 1055 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled },
1000 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, 1056 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled },
1001 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, 1057 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled },
1002 { kPolicyIncognitoForced, Value::TYPE_BOOLEAN, key::kIncognitoForced }, 1058 { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER,
1059 key::kIncognitoModeAvailability },
1003 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, 1060 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN,
1004 key::kSavingBrowserHistoryDisabled }, 1061 key::kSavingBrowserHistoryDisabled },
1005 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN, 1062 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN,
1006 key::kClearSiteDataOnExit }, 1063 key::kClearSiteDataOnExit },
1007 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, 1064 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN,
1008 key::kDeveloperToolsDisabled }, 1065 key::kDeveloperToolsDisabled },
1009 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, 1066 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN,
1010 key::kBlockThirdPartyCookies }, 1067 key::kBlockThirdPartyCookies },
1011 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, 1068 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER,
1012 key::kDefaultCookiesSetting }, 1069 key::kDefaultCookiesSetting },
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 // Update the initialization flag. 1195 // Update the initialization flag.
1139 if (!initialization_complete_ && 1196 if (!initialization_complete_ &&
1140 provider_->IsInitializationComplete()) { 1197 provider_->IsInitializationComplete()) {
1141 initialization_complete_ = true; 1198 initialization_complete_ = true;
1142 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1199 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1143 OnInitializationCompleted(true)); 1200 OnInitializationCompleted(true));
1144 } 1201 }
1145 } 1202 }
1146 1203
1147 } // namespace policy 1204 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698