| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 private: | 74 private: |
| 75 // The name of the policy. | 75 // The name of the policy. |
| 76 const char* policy_name_; | 76 const char* policy_name_; |
| 77 | 77 |
| 78 // The type the value of the policy should have. | 78 // The type the value of the policy should have. |
| 79 base::Value::Type value_type_; | 79 base::Value::Type value_type_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); | 81 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 // Abstract class derived from TypeCheckingPolicyHandler that ensures an int |
| 85 // policy's value lies in an allowed range. Either clamps or rejects values |
| 86 // outside the range. |
| 87 class IntRangePolicyHandlerBase : public TypeCheckingPolicyHandler { |
| 88 public: |
| 89 IntRangePolicyHandlerBase(const char* policy_name, |
| 90 int min, |
| 91 int max, |
| 92 bool clamp); |
| 93 |
| 94 // ConfigurationPolicyHandler: |
| 95 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 96 PolicyErrorMap* errors) OVERRIDE; |
| 97 |
| 98 protected: |
| 99 virtual ~IntRangePolicyHandlerBase(); |
| 100 |
| 101 // Ensures that the value is in the allowed range. Returns false if the value |
| 102 // cannot be parsed or lies outside the allowed range and clamping is |
| 103 // disabled. |
| 104 bool EnsureInRange(const base::Value* input, |
| 105 int* output, |
| 106 PolicyErrorMap* errors); |
| 107 |
| 108 private: |
| 109 // The minimum value allowed. |
| 110 int min_; |
| 111 |
| 112 // The maximum value allowed. |
| 113 int max_; |
| 114 |
| 115 // Whether to clamp values lying outside the allowed range instead of |
| 116 // rejecting them. |
| 117 bool clamp_; |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandlerBase); |
| 120 }; |
| 121 |
| 84 // ConfigurationPolicyHandler for policies that map directly to a preference. | 122 // ConfigurationPolicyHandler for policies that map directly to a preference. |
| 85 class SimplePolicyHandler : public TypeCheckingPolicyHandler { | 123 class SimplePolicyHandler : public TypeCheckingPolicyHandler { |
| 86 public: | 124 public: |
| 87 SimplePolicyHandler(const char* policy_name, | 125 SimplePolicyHandler(const char* policy_name, |
| 88 const char* pref_path, | 126 const char* pref_path, |
| 89 base::Value::Type value_type); | 127 base::Value::Type value_type); |
| 90 virtual ~SimplePolicyHandler(); | 128 virtual ~SimplePolicyHandler(); |
| 91 | 129 |
| 92 // ConfigurationPolicyHandler methods: | 130 // ConfigurationPolicyHandler methods: |
| 93 virtual void ApplyPolicySettings(const PolicyMap& policies, | 131 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Name of the pref to write. | 168 // Name of the pref to write. |
| 131 const char* pref_path_; | 169 const char* pref_path_; |
| 132 | 170 |
| 133 // The mapping table. | 171 // The mapping table. |
| 134 const MappingEntry* mapping_begin_; | 172 const MappingEntry* mapping_begin_; |
| 135 const MappingEntry* mapping_end_; | 173 const MappingEntry* mapping_end_; |
| 136 | 174 |
| 137 DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler); | 175 DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler); |
| 138 }; | 176 }; |
| 139 | 177 |
| 178 // A policy handler implementation that ensures an int policy's value lies in an |
| 179 // allowed range. |
| 180 class IntRangePolicyHandler : public IntRangePolicyHandlerBase { |
| 181 public: |
| 182 IntRangePolicyHandler(const char* policy_name, |
| 183 const char* pref_path, |
| 184 int min, |
| 185 int max, |
| 186 bool clamp); |
| 187 virtual ~IntRangePolicyHandler(); |
| 188 |
| 189 // ConfigurationPolicyHandler: |
| 190 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 191 PrefValueMap* prefs) OVERRIDE; |
| 192 |
| 193 private: |
| 194 // Name of the pref to write. |
| 195 const char* pref_path_; |
| 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler); |
| 198 }; |
| 199 |
| 200 // A policy handler implementation that maps an int percentage value to a |
| 201 // double. |
| 202 class IntPercentageToDoublePolicyHandler : public IntRangePolicyHandlerBase { |
| 203 public: |
| 204 IntPercentageToDoublePolicyHandler(const char* policy_name, |
| 205 const char* pref_path, |
| 206 int min, |
| 207 int max, |
| 208 bool clamp); |
| 209 virtual ~IntPercentageToDoublePolicyHandler(); |
| 210 |
| 211 // ConfigurationPolicyHandler: |
| 212 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 213 PrefValueMap* prefs) OVERRIDE; |
| 214 |
| 215 private: |
| 216 // Name of the pref to write. |
| 217 const char* pref_path_; |
| 218 |
| 219 DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler); |
| 220 }; |
| 221 |
| 140 // Implements additional checks for policies that are lists of extension IDs. | 222 // Implements additional checks for policies that are lists of extension IDs. |
| 141 class ExtensionListPolicyHandler : public TypeCheckingPolicyHandler { | 223 class ExtensionListPolicyHandler : public TypeCheckingPolicyHandler { |
| 142 public: | 224 public: |
| 143 ExtensionListPolicyHandler(const char* policy_name, | 225 ExtensionListPolicyHandler(const char* policy_name, |
| 144 const char* pref_path, | 226 const char* pref_path, |
| 145 bool allow_wildcards); | 227 bool allow_wildcards); |
| 146 virtual ~ExtensionListPolicyHandler(); | 228 virtual ~ExtensionListPolicyHandler(); |
| 147 | 229 |
| 148 // ConfigurationPolicyHandler methods: | 230 // ConfigurationPolicyHandler methods: |
| 149 virtual bool CheckPolicySettings(const PolicyMap& policies, | 231 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 private: | 540 private: |
| 459 void ApplyPolicySettingsFromHomePage(const PolicyMap& policies, | 541 void ApplyPolicySettingsFromHomePage(const PolicyMap& policies, |
| 460 PrefValueMap* prefs); | 542 PrefValueMap* prefs); |
| 461 | 543 |
| 462 DISALLOW_COPY_AND_ASSIGN(RestoreOnStartupPolicyHandler); | 544 DISALLOW_COPY_AND_ASSIGN(RestoreOnStartupPolicyHandler); |
| 463 }; | 545 }; |
| 464 | 546 |
| 465 } // namespace policy | 547 } // namespace policy |
| 466 | 548 |
| 467 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 549 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| OLD | NEW |