| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "components/policy/core/common/schema.h" | 17 #include "components/policy/core/common/schema.h" |
| 17 #include "components/policy/policy_export.h" | 18 #include "components/policy/policy_export.h" |
| 18 | 19 |
| 19 class PrefValueMap; | 20 class PrefValueMap; |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 virtual void ApplyPolicySettings(const PolicyMap& policies, | 153 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 153 PrefValueMap* prefs) OVERRIDE; | 154 PrefValueMap* prefs) OVERRIDE; |
| 154 | 155 |
| 155 private: | 156 private: |
| 156 // The DictionaryValue path of the preference the policy maps to. | 157 // The DictionaryValue path of the preference the policy maps to. |
| 157 const char* pref_path_; | 158 const char* pref_path_; |
| 158 | 159 |
| 159 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | 160 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 // A policy handler implementation that maps a string enum list to an int enum | 163 // Base class that encapsulates logic for mapping from a string enum list |
| 163 // list as specified by a mapping table. | 164 // to a separate matching type value. |
| 164 class POLICY_EXPORT StringToIntEnumListPolicyHandler | 165 class POLICY_EXPORT StringMappingListPolicyHandler |
| 165 : public TypeCheckingPolicyHandler { | 166 : public TypeCheckingPolicyHandler { |
| 166 public: | 167 public: |
| 167 struct POLICY_EXPORT MappingEntry { | 168 // Data structure representing the map between policy strings and |
| 169 // matching pref values. |
| 170 class POLICY_EXPORT MappingEntry { |
| 171 public: |
| 172 MappingEntry(const char* policy_value, scoped_ptr<base::Value> map); |
| 173 ~MappingEntry(); |
| 174 |
| 168 const char* enum_value; | 175 const char* enum_value; |
| 169 int int_value; | 176 scoped_ptr<base::Value> mapped_value; |
| 170 }; | 177 }; |
| 171 | 178 |
| 172 StringToIntEnumListPolicyHandler(const char* policy_name, | 179 // Callback that generates the map for this instance. |
| 173 const char* pref_path, | 180 typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback; |
| 174 const MappingEntry* mapping_begin, | 181 |
| 175 const MappingEntry* mapping_end); | 182 StringMappingListPolicyHandler(const char* policy_name, |
| 183 const char* pref_path, |
| 184 const GenerateMapCallback& map_generator); |
| 185 virtual ~StringMappingListPolicyHandler(); |
| 176 | 186 |
| 177 // ConfigurationPolicyHandler methods: | 187 // ConfigurationPolicyHandler methods: |
| 178 virtual bool CheckPolicySettings(const PolicyMap& policies, | 188 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 179 PolicyErrorMap* errors) OVERRIDE; | 189 PolicyErrorMap* errors) OVERRIDE; |
| 180 virtual void ApplyPolicySettings(const PolicyMap& policies, | 190 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 181 PrefValueMap* prefs) OVERRIDE; | 191 PrefValueMap* prefs) OVERRIDE; |
| 182 | 192 |
| 183 private: | 193 private: |
| 184 // 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, |
| 185 // returns false on errors. | 195 // returns false on errors. |
| 186 bool Convert(const base::Value* input, | 196 bool Convert(const base::Value* input, |
| 187 base::ListValue* output, | 197 base::ListValue* output, |
| 188 PolicyErrorMap* errors); | 198 PolicyErrorMap* errors); |
| 189 | 199 |
| 200 // Helper method that converts from a policy value string to the associated |
| 201 // pref value. |
| 202 scoped_ptr<base::Value> Map(const std::string& entry_value); |
| 203 |
| 190 // Name of the pref to write. | 204 // Name of the pref to write. |
| 191 const char* pref_path_; | 205 const char* pref_path_; |
| 192 | 206 |
| 193 // The mapping table. | 207 // The callback invoked to generate the map for this instance. |
| 194 const MappingEntry* mapping_begin_; | 208 GenerateMapCallback map_getter_; |
| 195 const MappingEntry* mapping_end_; | |
| 196 | 209 |
| 197 DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler); | 210 // Map of string policy values to local pref values. This is generated lazily |
| 211 // so the generation does not have to happen if no policy is present. |
| 212 ScopedVector<MappingEntry> map_; |
| 213 |
| 214 DISALLOW_COPY_AND_ASSIGN(StringMappingListPolicyHandler); |
| 198 }; | 215 }; |
| 199 | 216 |
| 200 // A policy handler implementation that ensures an int policy's value lies in an | 217 // A policy handler implementation that ensures an int policy's value lies in an |
| 201 // allowed range. | 218 // allowed range. |
| 202 class POLICY_EXPORT IntRangePolicyHandler : public IntRangePolicyHandlerBase { | 219 class POLICY_EXPORT IntRangePolicyHandler : public IntRangePolicyHandlerBase { |
| 203 public: | 220 public: |
| 204 IntRangePolicyHandler(const char* policy_name, | 221 IntRangePolicyHandler(const char* policy_name, |
| 205 const char* pref_path, | 222 const char* pref_path, |
| 206 int min, | 223 int min, |
| 207 int max, | 224 int max, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 private: | 345 private: |
| 329 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; | 346 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers_; |
| 330 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; | 347 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler_; |
| 331 | 348 |
| 332 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); | 349 DISALLOW_COPY_AND_ASSIGN(LegacyPoliciesDeprecatingPolicyHandler); |
| 333 }; | 350 }; |
| 334 | 351 |
| 335 } // namespace policy | 352 } // namespace policy |
| 336 | 353 |
| 337 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 354 #endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ |
| OLD | NEW |