OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/profiles/incognito_mode_policy_handler.h" | 5 #include "chrome/browser/profiles/incognito_mode_policy_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "components/policy/core/browser/policy_error_map.h" | 12 #include "components/policy/core/browser/policy_error_map.h" |
13 #include "components/policy/core/common/policy_map.h" | 13 #include "components/policy/core/common/policy_map.h" |
14 #include "components/prefs/pref_value_map.h" | 14 #include "components/prefs/pref_value_map.h" |
15 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
16 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
17 | 17 |
18 namespace policy { | 18 namespace policy { |
19 | 19 |
20 IncognitoModePolicyHandler::IncognitoModePolicyHandler() {} | 20 IncognitoModePolicyHandler::IncognitoModePolicyHandler() {} |
21 | 21 |
22 IncognitoModePolicyHandler::~IncognitoModePolicyHandler() {} | 22 IncognitoModePolicyHandler::~IncognitoModePolicyHandler() {} |
23 | 23 |
24 bool IncognitoModePolicyHandler::CheckPolicySettings(const PolicyMap& policies, | 24 bool IncognitoModePolicyHandler::CheckPolicySettings(const PolicyMap& policies, |
25 PolicyErrorMap* errors) { | 25 PolicyErrorMap* errors) { |
26 int int_value = IncognitoModePrefs::ENABLED; | |
27 const base::Value* availability = | 26 const base::Value* availability = |
28 policies.GetValue(key::kIncognitoModeAvailability); | 27 policies.GetValue(key::kIncognitoModeAvailability); |
29 | |
30 if (availability) { | 28 if (availability) { |
31 if (availability->GetAsInteger(&int_value)) { | 29 int int_value = IncognitoModePrefs::ENABLED; |
32 IncognitoModePrefs::Availability availability_enum_value; | 30 if (!availability->GetAsInteger(&int_value)) { |
33 if (!IncognitoModePrefs::IntToAvailability(int_value, | 31 errors->AddError(key::kIncognitoModeAvailability, IDS_POLICY_TYPE_ERROR, |
34 &availability_enum_value)) { | 32 base::Value::GetTypeName(base::Value::TYPE_INTEGER)); |
35 errors->AddError(key::kIncognitoModeAvailability, | |
36 IDS_POLICY_OUT_OF_RANGE_ERROR, | |
37 base::IntToString(int_value)); | |
38 return false; | |
39 } | |
40 } else { | |
41 errors->AddError(key::kIncognitoModeAvailability, | |
42 IDS_POLICY_TYPE_ERROR, | |
43 ValueTypeToString(base::Value::TYPE_INTEGER)); | |
44 return false; | 33 return false; |
45 } | 34 } |
46 } else { | 35 IncognitoModePrefs::Availability availability_enum_value; |
47 const base::Value* deprecated_enabled = | 36 if (!IncognitoModePrefs::IntToAvailability(int_value, |
48 policies.GetValue(key::kIncognitoEnabled); | 37 &availability_enum_value)) { |
49 if (deprecated_enabled && | 38 errors->AddError(key::kIncognitoModeAvailability, |
50 !deprecated_enabled->IsType(base::Value::TYPE_BOOLEAN)) { | 39 IDS_POLICY_OUT_OF_RANGE_ERROR, |
51 errors->AddError(key::kIncognitoEnabled, | 40 base::IntToString(int_value)); |
52 IDS_POLICY_TYPE_ERROR, | |
53 ValueTypeToString(base::Value::TYPE_BOOLEAN)); | |
54 return false; | 41 return false; |
55 } | 42 } |
| 43 return true; |
| 44 } |
| 45 |
| 46 const base::Value* deprecated_enabled = |
| 47 policies.GetValue(key::kIncognitoEnabled); |
| 48 if (deprecated_enabled && |
| 49 !deprecated_enabled->IsType(base::Value::TYPE_BOOLEAN)) { |
| 50 errors->AddError(key::kIncognitoEnabled, IDS_POLICY_TYPE_ERROR, |
| 51 base::Value::GetTypeName(base::Value::TYPE_BOOLEAN)); |
| 52 return false; |
56 } | 53 } |
57 return true; | 54 return true; |
58 } | 55 } |
59 | 56 |
60 void IncognitoModePolicyHandler::ApplyPolicySettings(const PolicyMap& policies, | 57 void IncognitoModePolicyHandler::ApplyPolicySettings(const PolicyMap& policies, |
61 PrefValueMap* prefs) { | 58 PrefValueMap* prefs) { |
62 const base::Value* availability = | 59 const base::Value* availability = |
63 policies.GetValue(key::kIncognitoModeAvailability); | 60 policies.GetValue(key::kIncognitoModeAvailability); |
64 const base::Value* deprecated_enabled = | 61 const base::Value* deprecated_enabled = |
65 policies.GetValue(key::kIncognitoEnabled); | 62 policies.GetValue(key::kIncognitoEnabled); |
(...skipping 16 matching lines...) Expand all Loading... |
82 prefs->SetInteger( | 79 prefs->SetInteger( |
83 prefs::kIncognitoModeAvailability, | 80 prefs::kIncognitoModeAvailability, |
84 enabled ? IncognitoModePrefs::ENABLED : IncognitoModePrefs::DISABLED); | 81 enabled ? IncognitoModePrefs::ENABLED : IncognitoModePrefs::DISABLED); |
85 } else { | 82 } else { |
86 NOTREACHED(); | 83 NOTREACHED(); |
87 } | 84 } |
88 } | 85 } |
89 } | 86 } |
90 | 87 |
91 } // namespace policy | 88 } // namespace policy |
OLD | NEW |