| 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 COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ |
| 6 #define COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 6 #define COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // subclassed to handle a single policy (not a combination of policies). | 75 // subclassed to handle a single policy (not a combination of policies). |
| 76 class POLICY_EXPORT TypeCheckingPolicyHandler | 76 class POLICY_EXPORT TypeCheckingPolicyHandler |
| 77 : public ConfigurationPolicyHandler { | 77 : public ConfigurationPolicyHandler { |
| 78 public: | 78 public: |
| 79 TypeCheckingPolicyHandler(const char* policy_name, | 79 TypeCheckingPolicyHandler(const char* policy_name, |
| 80 base::Value::Type value_type); | 80 base::Value::Type value_type); |
| 81 virtual ~TypeCheckingPolicyHandler(); | 81 virtual ~TypeCheckingPolicyHandler(); |
| 82 | 82 |
| 83 // ConfigurationPolicyHandler methods: | 83 // ConfigurationPolicyHandler methods: |
| 84 virtual bool CheckPolicySettings(const PolicyMap& policies, | 84 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 85 PolicyErrorMap* errors) OVERRIDE; | 85 PolicyErrorMap* errors) override; |
| 86 | 86 |
| 87 const char* policy_name() const; | 87 const char* policy_name() const; |
| 88 | 88 |
| 89 protected: | 89 protected: |
| 90 // Runs policy checks and returns the policy value if successful. | 90 // Runs policy checks and returns the policy value if successful. |
| 91 bool CheckAndGetValue(const PolicyMap& policies, | 91 bool CheckAndGetValue(const PolicyMap& policies, |
| 92 PolicyErrorMap* errors, | 92 PolicyErrorMap* errors, |
| 93 const base::Value** value); | 93 const base::Value** value); |
| 94 | 94 |
| 95 private: | 95 private: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 class POLICY_EXPORT IntRangePolicyHandlerBase | 108 class POLICY_EXPORT IntRangePolicyHandlerBase |
| 109 : public TypeCheckingPolicyHandler { | 109 : public TypeCheckingPolicyHandler { |
| 110 public: | 110 public: |
| 111 IntRangePolicyHandlerBase(const char* policy_name, | 111 IntRangePolicyHandlerBase(const char* policy_name, |
| 112 int min, | 112 int min, |
| 113 int max, | 113 int max, |
| 114 bool clamp); | 114 bool clamp); |
| 115 | 115 |
| 116 // ConfigurationPolicyHandler: | 116 // ConfigurationPolicyHandler: |
| 117 virtual bool CheckPolicySettings(const PolicyMap& policies, | 117 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 118 PolicyErrorMap* errors) OVERRIDE; | 118 PolicyErrorMap* errors) override; |
| 119 | 119 |
| 120 protected: | 120 protected: |
| 121 virtual ~IntRangePolicyHandlerBase(); | 121 virtual ~IntRangePolicyHandlerBase(); |
| 122 | 122 |
| 123 // Ensures that the value is in the allowed range. Returns false if the value | 123 // Ensures that the value is in the allowed range. Returns false if the value |
| 124 // cannot be parsed or lies outside the allowed range and clamping is | 124 // cannot be parsed or lies outside the allowed range and clamping is |
| 125 // disabled. | 125 // disabled. |
| 126 bool EnsureInRange(const base::Value* input, | 126 bool EnsureInRange(const base::Value* input, |
| 127 int* output, | 127 int* output, |
| 128 PolicyErrorMap* errors); | 128 PolicyErrorMap* errors); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 // ConfigurationPolicyHandler for policies that map directly to a preference. | 144 // ConfigurationPolicyHandler for policies that map directly to a preference. |
| 145 class POLICY_EXPORT SimplePolicyHandler : public TypeCheckingPolicyHandler { | 145 class POLICY_EXPORT SimplePolicyHandler : public TypeCheckingPolicyHandler { |
| 146 public: | 146 public: |
| 147 SimplePolicyHandler(const char* policy_name, | 147 SimplePolicyHandler(const char* policy_name, |
| 148 const char* pref_path, | 148 const char* pref_path, |
| 149 base::Value::Type value_type); | 149 base::Value::Type value_type); |
| 150 virtual ~SimplePolicyHandler(); | 150 virtual ~SimplePolicyHandler(); |
| 151 | 151 |
| 152 // ConfigurationPolicyHandler methods: | 152 // ConfigurationPolicyHandler methods: |
| 153 virtual void ApplyPolicySettings(const PolicyMap& policies, | 153 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 154 PrefValueMap* prefs) OVERRIDE; | 154 PrefValueMap* prefs) override; |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 // The DictionaryValue path of the preference the policy maps to. | 157 // The DictionaryValue path of the preference the policy maps to. |
| 158 const char* pref_path_; | 158 const char* pref_path_; |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | 160 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Base class that encapsulates logic for mapping from a string enum list | 163 // Base class that encapsulates logic for mapping from a string enum list |
| 164 // to a separate matching type value. | 164 // to a separate matching type value. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 179 // Callback that generates the map for this instance. | 179 // Callback that generates the map for this instance. |
| 180 typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback; | 180 typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback; |
| 181 | 181 |
| 182 StringMappingListPolicyHandler(const char* policy_name, | 182 StringMappingListPolicyHandler(const char* policy_name, |
| 183 const char* pref_path, | 183 const char* pref_path, |
| 184 const GenerateMapCallback& map_generator); | 184 const GenerateMapCallback& map_generator); |
| 185 virtual ~StringMappingListPolicyHandler(); | 185 virtual ~StringMappingListPolicyHandler(); |
| 186 | 186 |
| 187 // ConfigurationPolicyHandler methods: | 187 // ConfigurationPolicyHandler methods: |
| 188 virtual bool CheckPolicySettings(const PolicyMap& policies, | 188 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 189 PolicyErrorMap* errors) OVERRIDE; | 189 PolicyErrorMap* errors) override; |
| 190 virtual void ApplyPolicySettings(const PolicyMap& policies, | 190 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 191 PrefValueMap* prefs) OVERRIDE; | 191 PrefValueMap* prefs) override; |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 // Attempts to convert the list in |input| to |output| according to the table, | 194 // Attempts to convert the list in |input| to |output| according to the table, |
| 195 // returns false on errors. | 195 // returns false on errors. |
| 196 bool Convert(const base::Value* input, | 196 bool Convert(const base::Value* input, |
| 197 base::ListValue* output, | 197 base::ListValue* output, |
| 198 PolicyErrorMap* errors); | 198 PolicyErrorMap* errors); |
| 199 | 199 |
| 200 // Helper method that converts from a policy value string to the associated | 200 // Helper method that converts from a policy value string to the associated |
| 201 // pref value. | 201 // pref value. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 220 public: | 220 public: |
| 221 IntRangePolicyHandler(const char* policy_name, | 221 IntRangePolicyHandler(const char* policy_name, |
| 222 const char* pref_path, | 222 const char* pref_path, |
| 223 int min, | 223 int min, |
| 224 int max, | 224 int max, |
| 225 bool clamp); | 225 bool clamp); |
| 226 virtual ~IntRangePolicyHandler(); | 226 virtual ~IntRangePolicyHandler(); |
| 227 | 227 |
| 228 // ConfigurationPolicyHandler: | 228 // ConfigurationPolicyHandler: |
| 229 virtual void ApplyPolicySettings(const PolicyMap& policies, | 229 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 230 PrefValueMap* prefs) OVERRIDE; | 230 PrefValueMap* prefs) override; |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 // Name of the pref to write. | 233 // Name of the pref to write. |
| 234 const char* pref_path_; | 234 const char* pref_path_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler); | 236 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 // A policy handler implementation that maps an int percentage value to a | 239 // A policy handler implementation that maps an int percentage value to a |
| 240 // double. | 240 // double. |
| 241 class POLICY_EXPORT IntPercentageToDoublePolicyHandler | 241 class POLICY_EXPORT IntPercentageToDoublePolicyHandler |
| 242 : public IntRangePolicyHandlerBase { | 242 : public IntRangePolicyHandlerBase { |
| 243 public: | 243 public: |
| 244 IntPercentageToDoublePolicyHandler(const char* policy_name, | 244 IntPercentageToDoublePolicyHandler(const char* policy_name, |
| 245 const char* pref_path, | 245 const char* pref_path, |
| 246 int min, | 246 int min, |
| 247 int max, | 247 int max, |
| 248 bool clamp); | 248 bool clamp); |
| 249 virtual ~IntPercentageToDoublePolicyHandler(); | 249 virtual ~IntPercentageToDoublePolicyHandler(); |
| 250 | 250 |
| 251 // ConfigurationPolicyHandler: | 251 // ConfigurationPolicyHandler: |
| 252 virtual void ApplyPolicySettings(const PolicyMap& policies, | 252 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 253 PrefValueMap* prefs) OVERRIDE; | 253 PrefValueMap* prefs) override; |
| 254 | 254 |
| 255 private: | 255 private: |
| 256 // Name of the pref to write. | 256 // Name of the pref to write. |
| 257 const char* pref_path_; | 257 const char* pref_path_; |
| 258 | 258 |
| 259 DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler); | 259 DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler); |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 // Like TypeCheckingPolicyHandler, but validates against a schema instead of a | 262 // Like TypeCheckingPolicyHandler, but validates against a schema instead of a |
| 263 // single type. |schema| is the schema used for this policy, and |strategy| is | 263 // single type. |schema| is the schema used for this policy, and |strategy| is |
| 264 // the strategy used for schema validation errors. | 264 // the strategy used for schema validation errors. |
| 265 class POLICY_EXPORT SchemaValidatingPolicyHandler | 265 class POLICY_EXPORT SchemaValidatingPolicyHandler |
| 266 : public ConfigurationPolicyHandler { | 266 : public ConfigurationPolicyHandler { |
| 267 public: | 267 public: |
| 268 SchemaValidatingPolicyHandler(const char* policy_name, | 268 SchemaValidatingPolicyHandler(const char* policy_name, |
| 269 Schema schema, | 269 Schema schema, |
| 270 SchemaOnErrorStrategy strategy); | 270 SchemaOnErrorStrategy strategy); |
| 271 virtual ~SchemaValidatingPolicyHandler(); | 271 virtual ~SchemaValidatingPolicyHandler(); |
| 272 | 272 |
| 273 // ConfigurationPolicyHandler: | 273 // ConfigurationPolicyHandler: |
| 274 virtual bool CheckPolicySettings(const PolicyMap& policies, | 274 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 275 PolicyErrorMap* errors) OVERRIDE; | 275 PolicyErrorMap* errors) override; |
| 276 | 276 |
| 277 const char* policy_name() const; | 277 const char* policy_name() const; |
| 278 | 278 |
| 279 protected: | 279 protected: |
| 280 // Runs policy checks and returns the policy value if successful. | 280 // Runs policy checks and returns the policy value if successful. |
| 281 bool CheckAndGetValue(const PolicyMap& policies, | 281 bool CheckAndGetValue(const PolicyMap& policies, |
| 282 PolicyErrorMap* errors, | 282 PolicyErrorMap* errors, |
| 283 scoped_ptr<base::Value>* output); | 283 scoped_ptr<base::Value>* output); |
| 284 | 284 |
| 285 private: | 285 private: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 306 const char* policy_name, | 306 const char* policy_name, |
| 307 const char* pref_path, | 307 const char* pref_path, |
| 308 Schema schema, | 308 Schema schema, |
| 309 SchemaOnErrorStrategy strategy, | 309 SchemaOnErrorStrategy strategy, |
| 310 RecommendedPermission recommended_permission, | 310 RecommendedPermission recommended_permission, |
| 311 MandatoryPermission mandatory_permission); | 311 MandatoryPermission mandatory_permission); |
| 312 virtual ~SimpleSchemaValidatingPolicyHandler(); | 312 virtual ~SimpleSchemaValidatingPolicyHandler(); |
| 313 | 313 |
| 314 // ConfigurationPolicyHandler: | 314 // ConfigurationPolicyHandler: |
| 315 virtual bool CheckPolicySettings(const PolicyMap& policies, | 315 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 316 PolicyErrorMap* errors) OVERRIDE; | 316 PolicyErrorMap* errors) override; |
| 317 virtual void ApplyPolicySettings(const PolicyMap& policies, | 317 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 318 PrefValueMap* prefs) OVERRIDE; | 318 PrefValueMap* prefs) override; |
| 319 | 319 |
| 320 private: | 320 private: |
| 321 const char* pref_path_; | 321 const char* pref_path_; |
| 322 const bool allow_recommended_; | 322 const bool allow_recommended_; |
| 323 const bool allow_mandatory_; | 323 const bool allow_mandatory_; |
| 324 | 324 |
| 325 DISALLOW_COPY_AND_ASSIGN(SimpleSchemaValidatingPolicyHandler); | 325 DISALLOW_COPY_AND_ASSIGN(SimpleSchemaValidatingPolicyHandler); |
| 326 }; | 326 }; |
| 327 | 327 |
| 328 // A policy handler to deprecate multiple legacy policies with a new one. | 328 // A policy handler to deprecate multiple legacy policies with a new one. |
| 329 // This handler will completely ignore any of legacy policy values if the new | 329 // This handler will completely ignore any of legacy policy values if the new |
| 330 // one is set. | 330 // one is set. |
| 331 class POLICY_EXPORT LegacyPoliciesDeprecatingPolicyHandler | 331 class POLICY_EXPORT LegacyPoliciesDeprecatingPolicyHandler |
| 332 : public ConfigurationPolicyHandler { | 332 : public ConfigurationPolicyHandler { |
| 333 public: | 333 public: |
| 334 LegacyPoliciesDeprecatingPolicyHandler( | 334 LegacyPoliciesDeprecatingPolicyHandler( |
| 335 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, | 335 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, |
| 336 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler); | 336 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler); |
| 337 virtual ~LegacyPoliciesDeprecatingPolicyHandler(); | 337 virtual ~LegacyPoliciesDeprecatingPolicyHandler(); |
| 338 | 338 |
| 339 // ConfigurationPolicyHandler: | 339 // ConfigurationPolicyHandler: |
| 340 virtual bool CheckPolicySettings(const PolicyMap& policies, | 340 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 341 PolicyErrorMap* errors) OVERRIDE; | 341 PolicyErrorMap* errors) override; |
| 342 virtual void ApplyPolicySettings(const PolicyMap& policies, | 342 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 343 PrefValueMap* prefs) OVERRIDE; | 343 PrefValueMap* prefs) override; |
| 344 | 344 |
| 345 private: | 345 private: |
| 346 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; | 346 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; |
| 347 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; | 347 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; |
| 348 | 348 |
| 349 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); | 349 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 } // namespace policy | 352 } // namespace policy |
| 353 | 353 |
| 354 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 354 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ |
| OLD | NEW |