| 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 <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/policy/core/common/schema.h" | 17 #include "components/policy/core/common/schema.h" |
| 18 #include "components/policy/policy_export.h" | 18 #include "components/policy/policy_export.h" |
| 19 | 19 |
| 20 class PrefValueMap; | 20 class PrefValueMap; |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 | 23 |
| 24 class PolicyErrorMap; | 24 class PolicyErrorMap; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 // Base class that encapsulates logic for mapping from a string enum list | 166 // Base class that encapsulates logic for mapping from a string enum list |
| 167 // to a separate matching type value. | 167 // to a separate matching type value. |
| 168 class POLICY_EXPORT StringMappingListPolicyHandler | 168 class POLICY_EXPORT StringMappingListPolicyHandler |
| 169 : public TypeCheckingPolicyHandler { | 169 : public TypeCheckingPolicyHandler { |
| 170 public: | 170 public: |
| 171 // Data structure representing the map between policy strings and | 171 // Data structure representing the map between policy strings and |
| 172 // matching pref values. | 172 // matching pref values. |
| 173 class POLICY_EXPORT MappingEntry { | 173 class POLICY_EXPORT MappingEntry { |
| 174 public: | 174 public: |
| 175 MappingEntry(const char* policy_value, scoped_ptr<base::Value> map); | 175 MappingEntry(const char* policy_value, std::unique_ptr<base::Value> map); |
| 176 ~MappingEntry(); | 176 ~MappingEntry(); |
| 177 | 177 |
| 178 const char* enum_value; | 178 const char* enum_value; |
| 179 scoped_ptr<base::Value> mapped_value; | 179 std::unique_ptr<base::Value> mapped_value; |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 // Callback that generates the map for this instance. | 182 // Callback that generates the map for this instance. |
| 183 typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback; | 183 typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback; |
| 184 | 184 |
| 185 StringMappingListPolicyHandler(const char* policy_name, | 185 StringMappingListPolicyHandler(const char* policy_name, |
| 186 const char* pref_path, | 186 const char* pref_path, |
| 187 const GenerateMapCallback& map_generator); | 187 const GenerateMapCallback& map_generator); |
| 188 ~StringMappingListPolicyHandler() override; | 188 ~StringMappingListPolicyHandler() override; |
| 189 | 189 |
| 190 // ConfigurationPolicyHandler methods: | 190 // ConfigurationPolicyHandler methods: |
| 191 bool CheckPolicySettings(const PolicyMap& policies, | 191 bool CheckPolicySettings(const PolicyMap& policies, |
| 192 PolicyErrorMap* errors) override; | 192 PolicyErrorMap* errors) override; |
| 193 void ApplyPolicySettings(const PolicyMap& policies, | 193 void ApplyPolicySettings(const PolicyMap& policies, |
| 194 PrefValueMap* prefs) override; | 194 PrefValueMap* prefs) override; |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 // Attempts to convert the list in |input| to |output| according to the table, | 197 // Attempts to convert the list in |input| to |output| according to the table, |
| 198 // returns false on errors. | 198 // returns false on errors. |
| 199 bool Convert(const base::Value* input, | 199 bool Convert(const base::Value* input, |
| 200 base::ListValue* output, | 200 base::ListValue* output, |
| 201 PolicyErrorMap* errors); | 201 PolicyErrorMap* errors); |
| 202 | 202 |
| 203 // Helper method that converts from a policy value string to the associated | 203 // Helper method that converts from a policy value string to the associated |
| 204 // pref value. | 204 // pref value. |
| 205 scoped_ptr<base::Value> Map(const std::string& entry_value); | 205 std::unique_ptr<base::Value> Map(const std::string& entry_value); |
| 206 | 206 |
| 207 // Name of the pref to write. | 207 // Name of the pref to write. |
| 208 const char* pref_path_; | 208 const char* pref_path_; |
| 209 | 209 |
| 210 // The callback invoked to generate the map for this instance. | 210 // The callback invoked to generate the map for this instance. |
| 211 GenerateMapCallback map_getter_; | 211 GenerateMapCallback map_getter_; |
| 212 | 212 |
| 213 // Map of string policy values to local pref values. This is generated lazily | 213 // Map of string policy values to local pref values. This is generated lazily |
| 214 // so the generation does not have to happen if no policy is present. | 214 // so the generation does not have to happen if no policy is present. |
| 215 ScopedVector<MappingEntry> map_; | 215 ScopedVector<MappingEntry> map_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // ConfigurationPolicyHandler: | 276 // ConfigurationPolicyHandler: |
| 277 bool CheckPolicySettings(const PolicyMap& policies, | 277 bool CheckPolicySettings(const PolicyMap& policies, |
| 278 PolicyErrorMap* errors) override; | 278 PolicyErrorMap* errors) override; |
| 279 | 279 |
| 280 const char* policy_name() const; | 280 const char* policy_name() const; |
| 281 | 281 |
| 282 protected: | 282 protected: |
| 283 // Runs policy checks and returns the policy value if successful. | 283 // Runs policy checks and returns the policy value if successful. |
| 284 bool CheckAndGetValue(const PolicyMap& policies, | 284 bool CheckAndGetValue(const PolicyMap& policies, |
| 285 PolicyErrorMap* errors, | 285 PolicyErrorMap* errors, |
| 286 scoped_ptr<base::Value>* output); | 286 std::unique_ptr<base::Value>* output); |
| 287 | 287 |
| 288 private: | 288 private: |
| 289 const char* policy_name_; | 289 const char* policy_name_; |
| 290 Schema schema_; | 290 Schema schema_; |
| 291 SchemaOnErrorStrategy strategy_; | 291 SchemaOnErrorStrategy strategy_; |
| 292 | 292 |
| 293 DISALLOW_COPY_AND_ASSIGN(SchemaValidatingPolicyHandler); | 293 DISALLOW_COPY_AND_ASSIGN(SchemaValidatingPolicyHandler); |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 // Maps policy to pref like SimplePolicyHandler while ensuring that the value | 296 // Maps policy to pref like SimplePolicyHandler while ensuring that the value |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 // A policy handler to deprecate multiple legacy policies with a new one. | 331 // A policy handler to deprecate multiple legacy policies with a new one. |
| 332 // This handler will completely ignore any of legacy policy values if the new | 332 // This handler will completely ignore any of legacy policy values if the new |
| 333 // one is set. | 333 // one is set. |
| 334 class POLICY_EXPORT LegacyPoliciesDeprecatingPolicyHandler | 334 class POLICY_EXPORT LegacyPoliciesDeprecatingPolicyHandler |
| 335 : public ConfigurationPolicyHandler { | 335 : public ConfigurationPolicyHandler { |
| 336 public: | 336 public: |
| 337 LegacyPoliciesDeprecatingPolicyHandler( | 337 LegacyPoliciesDeprecatingPolicyHandler( |
| 338 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, | 338 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, |
| 339 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler); | 339 std::unique_ptr<SchemaValidatingPolicyHandler> new_policy_handler); |
| 340 ~LegacyPoliciesDeprecatingPolicyHandler() override; | 340 ~LegacyPoliciesDeprecatingPolicyHandler() override; |
| 341 | 341 |
| 342 // ConfigurationPolicyHandler: | 342 // ConfigurationPolicyHandler: |
| 343 bool CheckPolicySettings(const PolicyMap& policies, | 343 bool CheckPolicySettings(const PolicyMap& policies, |
| 344 PolicyErrorMap* errors) override; | 344 PolicyErrorMap* errors) override; |
| 345 void ApplyPolicySettingsWithParameters( | 345 void ApplyPolicySettingsWithParameters( |
| 346 const policy::PolicyMap& policies, | 346 const policy::PolicyMap& policies, |
| 347 const policy::PolicyHandlerParameters& parameters, | 347 const policy::PolicyHandlerParameters& parameters, |
| 348 PrefValueMap* prefs) override; | 348 PrefValueMap* prefs) override; |
| 349 | 349 |
| 350 protected: | 350 protected: |
| 351 void ApplyPolicySettings(const PolicyMap& policies, | 351 void ApplyPolicySettings(const PolicyMap& policies, |
| 352 PrefValueMap* prefs) override; | 352 PrefValueMap* prefs) override; |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; | 355 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; |
| 356 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; | 356 std::unique_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; |
| 357 | 357 |
| 358 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); | 358 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 } // namespace policy | 361 } // namespace policy |
| 362 | 362 |
| 363 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 363 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ |
| OLD | NEW |