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

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: 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 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. It is still used for
151 // backward compatibility to set the new kIncognitoAvailabilityMode pref in
152 // case the corresponding policy for the latter is not specified.
153 scoped_ptr<Value> 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
316 if (!provider->Provide(this)) 328 if (!provider->Provide(this))
317 LOG(WARNING) << "Failed to get policy from provider."; 329 LOG(WARNING) << "Failed to get policy from provider.";
318 FinalizeProxyPolicySettings(); 330 FinalizeProxyPolicySettings();
319 FinalizeDefaultSearchPolicySettings(); 331 FinalizeDefaultSearchPolicySettings();
332 FinalizeIncognitoModeSettings();
320 } 333 }
321 334
322 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { 335 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() {
323 DCHECK(proxy_policies_.empty()); 336 DCHECK(proxy_policies_.empty());
324 } 337 }
325 338
326 PrefStore::ReadResult 339 PrefStore::ReadResult
327 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, 340 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key,
328 const Value** result) const { 341 const Value** result) const {
329 const Value* stored_value = NULL; 342 const Value* stored_value = NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 375
363 if (ApplyDiskCacheDirPolicy(policy, value)) 376 if (ApplyDiskCacheDirPolicy(policy, value))
364 return; 377 return;
365 378
366 if (ApplyFileSelectionDialogsPolicy(policy, value)) 379 if (ApplyFileSelectionDialogsPolicy(policy, value))
367 return; 380 return;
368 381
369 if (ApplyDefaultSearchPolicy(policy, value)) 382 if (ApplyDefaultSearchPolicy(policy, value))
370 return; 383 return;
371 384
385 if (ApplyIncognitoModePolicy(policy, value))
386 return;
387
372 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, 388 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
373 arraysize(kSimplePolicyMap))) 389 arraysize(kSimplePolicyMap)))
374 return; 390 return;
375 391
376 // Other policy implementations go here. 392 // Other policy implementations go here.
377 NOTIMPLEMENTED(); 393 NOTIMPLEMENTED();
378 delete value; 394 delete value;
379 } 395 }
380 396
381 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( 397 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap(
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return true; 565 return true;
550 } 566 }
551 567
552 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, 568 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
553 arraysize(kDefaultSearchPolicyMap))) { 569 arraysize(kDefaultSearchPolicyMap))) {
554 return true; 570 return true;
555 } 571 }
556 return false; 572 return false;
557 } 573 }
558 574
575 bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy(
576 ConfigurationPolicyType policy,
577 Value* value) {
578 if (policy == kPolicyIncognitoModeAvailability) {
579 int availability = IncognitoModePrefs::ENABLED;
580 bool result = value->GetAsInteger(&availability);
581 delete value;
582 if (result) {
583 IncognitoModePrefs::Availability availability_enum_value;
584 if (IncognitoModePrefs::IntToAvailability(availability,
585 &availability_enum_value)) {
586 prefs_.SetValue(prefs::kIncognitoModeAvailability,
587 Value::CreateIntegerValue(availability_enum_value));
588 } else {
589 LOG(WARNING) << "IncognitoModeAvailability policy value is "
590 << "out of range " << availability;
591 }
592 } else {
593 LOG(WARNING) << "IncognitoModeAvailability policy value could not be "
594 << "parsed";
595 }
596 return true;
597 }
598 if (policy == kPolicyIncognitoEnabled) {
599 deprecated_incognito_enabled_.reset(value);
600 return true;
601 }
602 // The policy is not relevant to incognito.
603 return false;
604 }
605
559 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( 606 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
560 const std::string& path) { 607 const std::string& path) {
561 std::string value; 608 std::string value;
562 if (!prefs_.GetString(path, &value)) 609 if (!prefs_.GetString(path, &value))
563 prefs_.SetString(path, value); 610 prefs_.SetString(path, value);
564 } 611 }
565 612
566 namespace { 613 namespace {
567 614
568 // Implementation of SearchTermsData just for validation. 615 // Implementation of SearchTermsData just for validation.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID, 677 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID,
631 std::string()); 678 std::string());
632 return; 679 return;
633 } 680 }
634 } 681 }
635 // Required entries are not there. Remove any related entries. 682 // Required entries are not there. Remove any related entries.
636 RemovePreferencesOfMap(kDefaultSearchPolicyMap, 683 RemovePreferencesOfMap(kDefaultSearchPolicyMap,
637 arraysize(kDefaultSearchPolicyMap)); 684 arraysize(kDefaultSearchPolicyMap));
638 } 685 }
639 686
687 void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() {
688 int int_value;
689 if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) {
690 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete
691 // kPolicyIncognitoEnabled.
692 if (deprecated_incognito_enabled_.get()) {
693 bool enabled = true;
694 if (deprecated_incognito_enabled_->GetAsBoolean(&enabled)) {
695 // 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.
696 prefs_.SetInteger(
697 prefs::kIncognitoModeAvailability,
698 enabled ? IncognitoModePrefs::ENABLED :
699 IncognitoModePrefs::DISABLED);
700 } else {
701 LOG(WARNING) << "IncognitoEnabled policy value could not be parsed";
702 }
703 }
704 }
705 }
706
640 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { 707 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
641 if (CheckProxySettings()) 708 if (CheckProxySettings())
642 ApplyProxySettings(); 709 ApplyProxySettings();
643 710
644 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), 711 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(),
645 proxy_policies_.end()); 712 proxy_policies_.end());
646 proxy_policies_.clear(); 713 proxy_policies_.clear();
647 } 714 }
648 715
649 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { 716 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST, 1059 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST,
993 key::kExtensionInstallWhitelist }, 1060 key::kExtensionInstallWhitelist },
994 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST, 1061 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST,
995 key::kExtensionInstallBlacklist }, 1062 key::kExtensionInstallBlacklist },
996 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST, 1063 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST,
997 key::kExtensionInstallForcelist }, 1064 key::kExtensionInstallForcelist },
998 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, 1065 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton },
999 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, 1066 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled },
1000 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, 1067 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled },
1001 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, 1068 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled },
1002 { kPolicyIncognitoForced, Value::TYPE_BOOLEAN, key::kIncognitoForced }, 1069 { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER,
1070 key::kIncognitoModeAvailability },
1003 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, 1071 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN,
1004 key::kSavingBrowserHistoryDisabled }, 1072 key::kSavingBrowserHistoryDisabled },
1005 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN, 1073 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN,
1006 key::kClearSiteDataOnExit }, 1074 key::kClearSiteDataOnExit },
1007 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, 1075 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN,
1008 key::kDeveloperToolsDisabled }, 1076 key::kDeveloperToolsDisabled },
1009 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, 1077 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN,
1010 key::kBlockThirdPartyCookies }, 1078 key::kBlockThirdPartyCookies },
1011 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, 1079 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER,
1012 key::kDefaultCookiesSetting }, 1080 key::kDefaultCookiesSetting },
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 // Update the initialization flag. 1206 // Update the initialization flag.
1139 if (!initialization_complete_ && 1207 if (!initialization_complete_ &&
1140 provider_->IsInitializationComplete()) { 1208 provider_->IsInitializationComplete()) {
1141 initialization_complete_ = true; 1209 initialization_complete_ = true;
1142 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1210 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1143 OnInitializationCompleted(true)); 1211 OnInitializationCompleted(true));
1144 } 1212 }
1145 } 1213 }
1146 1214
1147 } // namespace policy 1215 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698