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

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: Converted incognito pref functions to a class. 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;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 prefs::kPluginsDisabledPlugins}, 196 prefs::kPluginsDisabledPlugins},
186 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions, 197 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions,
187 prefs::kPluginsDisabledPluginsExceptions}, 198 prefs::kPluginsDisabledPluginsExceptions},
188 { Value::TYPE_LIST, kPolicyEnabledPlugins, 199 { Value::TYPE_LIST, kPolicyEnabledPlugins,
189 prefs::kPluginsEnabledPlugins}, 200 prefs::kPluginsEnabledPlugins},
190 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, 201 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton,
191 prefs::kShowHomeButton }, 202 prefs::kShowHomeButton },
192 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, 203 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled,
193 prefs::kWebKitJavascriptEnabled }, 204 prefs::kWebKitJavascriptEnabled },
194 { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled, 205 { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled,
195 prefs::kIncognitoEnabled }, 206 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
196 { Value::TYPE_BOOLEAN, kPolicyIncognitoForced,
197 prefs::kIncognitoForced },
198 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, 207 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled,
199 prefs::kSavingBrowserHistoryDisabled }, 208 prefs::kSavingBrowserHistoryDisabled },
200 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, 209 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit,
201 prefs::kClearSiteDataOnExit }, 210 prefs::kClearSiteDataOnExit },
202 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, 211 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled,
203 prefs::kDevToolsDisabled }, 212 prefs::kDevToolsDisabled },
204 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, 213 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies,
205 prefs::kBlockThirdPartyCookies }, 214 prefs::kBlockThirdPartyCookies },
206 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting, 215 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting,
207 prefs::kManagedDefaultCookiesSetting }, 216 prefs::kManagedDefaultCookiesSetting },
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings, 319 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings,
311 prefs::kDefaultSearchProviderEncodings }, 320 prefs::kDefaultSearchProviderEncodings },
312 }; 321 };
313 322
314 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( 323 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper(
315 ConfigurationPolicyProvider* provider) { 324 ConfigurationPolicyProvider* provider) {
316 if (!provider->Provide(this)) 325 if (!provider->Provide(this))
317 LOG(WARNING) << "Failed to get policy from provider."; 326 LOG(WARNING) << "Failed to get policy from provider.";
318 FinalizeProxyPolicySettings(); 327 FinalizeProxyPolicySettings();
319 FinalizeDefaultSearchPolicySettings(); 328 FinalizeDefaultSearchPolicySettings();
329 FinalizeIncognitoModeSettings();
320 } 330 }
321 331
322 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { 332 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() {
323 DCHECK(proxy_policies_.empty()); 333 DCHECK(proxy_policies_.empty());
324 } 334 }
325 335
326 PrefStore::ReadResult 336 PrefStore::ReadResult
327 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, 337 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key,
328 const Value** result) const { 338 const Value** result) const {
329 const Value* stored_value = NULL; 339 const Value* stored_value = NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 372
363 if (ApplyDiskCacheDirPolicy(policy, value)) 373 if (ApplyDiskCacheDirPolicy(policy, value))
364 return; 374 return;
365 375
366 if (ApplyFileSelectionDialogsPolicy(policy, value)) 376 if (ApplyFileSelectionDialogsPolicy(policy, value))
367 return; 377 return;
368 378
369 if (ApplyDefaultSearchPolicy(policy, value)) 379 if (ApplyDefaultSearchPolicy(policy, value))
370 return; 380 return;
371 381
382 if (ApplyIncognitoModePolicy(policy, value))
383 return;
384
372 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, 385 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
373 arraysize(kSimplePolicyMap))) 386 arraysize(kSimplePolicyMap)))
374 return; 387 return;
375 388
376 // Other policy implementations go here. 389 // Other policy implementations go here.
377 NOTIMPLEMENTED(); 390 NOTIMPLEMENTED();
378 delete value; 391 delete value;
379 } 392 }
380 393
381 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( 394 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap(
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return true; 562 return true;
550 } 563 }
551 564
552 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, 565 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
553 arraysize(kDefaultSearchPolicyMap))) { 566 arraysize(kDefaultSearchPolicyMap))) {
554 return true; 567 return true;
555 } 568 }
556 return false; 569 return false;
557 } 570 }
558 571
572 bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy(
573 ConfigurationPolicyType policy,
574 Value* value) {
575 if (policy == kPolicyIncognitoModeAvailability) {
576 int availability = IncognitoModePrefs::ENABLED;
577 bool result = value->GetAsInteger(&availability);
578 DCHECK(result);
579 delete value;
580 IncognitoModePrefs::Availability availability_enum_value;
581 result = IncognitoModePrefs::IntToAvailability(availability,
582 &availability_enum_value);
583 DCHECK(result);
584 prefs_.SetValue(prefs::kIncognitoModeAvailability,
585 Value::CreateIntegerValue(availability_enum_value));
586 return true;
587 }
588 // The policy is not relevant to incognito.
589 return false;
590 }
591
559 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( 592 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
560 const std::string& path) { 593 const std::string& path) {
561 std::string value; 594 std::string value;
562 if (!prefs_.GetString(path, &value)) 595 if (!prefs_.GetString(path, &value))
563 prefs_.SetString(path, value); 596 prefs_.SetString(path, value);
564 } 597 }
565 598
566 namespace { 599 namespace {
567 600
568 // Implementation of SearchTermsData just for validation. 601 // Implementation of SearchTermsData just for validation.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID, 663 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID,
631 std::string()); 664 std::string());
632 return; 665 return;
633 } 666 }
634 } 667 }
635 // Required entries are not there. Remove any related entries. 668 // Required entries are not there. Remove any related entries.
636 RemovePreferencesOfMap(kDefaultSearchPolicyMap, 669 RemovePreferencesOfMap(kDefaultSearchPolicyMap,
637 arraysize(kDefaultSearchPolicyMap)); 670 arraysize(kDefaultSearchPolicyMap));
638 } 671 }
639 672
673 void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() {
674 int int_value;
675 if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) {
676 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete
677 // kPolicyIncognitoEnabled.
678 bool obsolete_incognito_enabled;
679 if (prefs_.GetBoolean(prefs::kIncognitoEnabled,
680 &obsolete_incognito_enabled)) {
681 if (!obsolete_incognito_enabled) {
682 // If the obsolete policy says that incognito is disabled,
683 prefs_.SetInteger(prefs::kIncognitoModeAvailability,
684 IncognitoModePrefs::DISABLED);
685 }
686 }
687 }
688 }
689
640 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { 690 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
641 if (CheckProxySettings()) 691 if (CheckProxySettings())
642 ApplyProxySettings(); 692 ApplyProxySettings();
643 693
644 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), 694 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(),
645 proxy_policies_.end()); 695 proxy_policies_.end());
646 proxy_policies_.clear(); 696 proxy_policies_.clear();
647 } 697 }
648 698
649 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { 699 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST, 1042 { kPolicyExtensionInstallWhitelist, Value::TYPE_LIST,
993 key::kExtensionInstallWhitelist }, 1043 key::kExtensionInstallWhitelist },
994 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST, 1044 { kPolicyExtensionInstallBlacklist, Value::TYPE_LIST,
995 key::kExtensionInstallBlacklist }, 1045 key::kExtensionInstallBlacklist },
996 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST, 1046 { kPolicyExtensionInstallForcelist, Value::TYPE_LIST,
997 key::kExtensionInstallForcelist }, 1047 key::kExtensionInstallForcelist },
998 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, 1048 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton },
999 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, 1049 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled },
1000 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, 1050 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled },
1001 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, 1051 { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled },
1002 { kPolicyIncognitoForced, Value::TYPE_BOOLEAN, key::kIncognitoForced }, 1052 { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER,
1053 key::kIncognitoModeAvailability },
1003 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, 1054 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN,
1004 key::kSavingBrowserHistoryDisabled }, 1055 key::kSavingBrowserHistoryDisabled },
1005 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN, 1056 { kPolicyClearSiteDataOnExit, Value::TYPE_BOOLEAN,
1006 key::kClearSiteDataOnExit }, 1057 key::kClearSiteDataOnExit },
1007 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, 1058 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN,
1008 key::kDeveloperToolsDisabled }, 1059 key::kDeveloperToolsDisabled },
1009 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, 1060 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN,
1010 key::kBlockThirdPartyCookies }, 1061 key::kBlockThirdPartyCookies },
1011 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, 1062 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER,
1012 key::kDefaultCookiesSetting }, 1063 key::kDefaultCookiesSetting },
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 // Update the initialization flag. 1189 // Update the initialization flag.
1139 if (!initialization_complete_ && 1190 if (!initialization_complete_ &&
1140 provider_->IsInitializationComplete()) { 1191 provider_->IsInitializationComplete()) {
1141 initialization_complete_ = true; 1192 initialization_complete_ = true;
1142 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1193 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1143 OnInitializationCompleted(true)); 1194 OnInitializationCompleted(true));
1144 } 1195 }
1145 } 1196 }
1146 1197
1147 } // namespace policy 1198 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698