Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / profiles / incognito_mode_policy_handler.cc
blobdf387fe0720b7d9294d79a9140d02330f985aaa0
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/incognito_mode_policy_handler.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_value_map.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/policy/core/browser/policy_error_map.h"
14 #include "components/policy/core/common/policy_map.h"
15 #include "grit/components_strings.h"
16 #include "policy/policy_constants.h"
18 namespace policy {
20 IncognitoModePolicyHandler::IncognitoModePolicyHandler() {}
22 IncognitoModePolicyHandler::~IncognitoModePolicyHandler() {}
24 bool IncognitoModePolicyHandler::CheckPolicySettings(const PolicyMap& policies,
25 PolicyErrorMap* errors) {
26 int int_value = IncognitoModePrefs::ENABLED;
27 const base::Value* availability =
28 policies.GetValue(key::kIncognitoModeAvailability);
30 if (availability) {
31 if (availability->GetAsInteger(&int_value)) {
32 IncognitoModePrefs::Availability availability_enum_value;
33 if (!IncognitoModePrefs::IntToAvailability(int_value,
34 &availability_enum_value)) {
35 errors->AddError(key::kIncognitoModeAvailability,
36 IDS_POLICY_OUT_OF_RANGE_ERROR,
37 base::IntToString(int_value));
38 return false;
40 } else {
41 errors->AddError(key::kIncognitoModeAvailability,
42 IDS_POLICY_TYPE_ERROR,
43 ValueTypeToString(base::Value::TYPE_INTEGER));
44 return false;
46 } else {
47 const base::Value* deprecated_enabled =
48 policies.GetValue(key::kIncognitoEnabled);
49 if (deprecated_enabled &&
50 !deprecated_enabled->IsType(base::Value::TYPE_BOOLEAN)) {
51 errors->AddError(key::kIncognitoEnabled,
52 IDS_POLICY_TYPE_ERROR,
53 ValueTypeToString(base::Value::TYPE_BOOLEAN));
54 return false;
57 return true;
60 void IncognitoModePolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
61 PrefValueMap* prefs) {
62 const base::Value* availability =
63 policies.GetValue(key::kIncognitoModeAvailability);
64 const base::Value* deprecated_enabled =
65 policies.GetValue(key::kIncognitoEnabled);
66 if (availability) {
67 int int_value = IncognitoModePrefs::ENABLED;
68 IncognitoModePrefs::Availability availability_enum_value;
69 if (availability->GetAsInteger(&int_value) &&
70 IncognitoModePrefs::IntToAvailability(int_value,
71 &availability_enum_value)) {
72 prefs->SetInteger(prefs::kIncognitoModeAvailability,
73 availability_enum_value);
74 } else {
75 NOTREACHED();
77 } else if (deprecated_enabled) {
78 // If kIncognitoModeAvailability is not specified, check the obsolete
79 // kIncognitoEnabled.
80 bool enabled = true;
81 if (deprecated_enabled->GetAsBoolean(&enabled)) {
82 prefs->SetInteger(
83 prefs::kIncognitoModeAvailability,
84 enabled ? IncognitoModePrefs::ENABLED : IncognitoModePrefs::DISABLED);
85 } else {
86 NOTREACHED();
91 } // namespace policy