| 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 COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 
| 6 #define CHROME_BROWSER_POLICY_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/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" | 
| 13 #include "base/values.h" | 13 #include "base/values.h" | 
|  | 14 #include "components/policy/policy_export.h" | 
| 14 | 15 | 
| 15 class PrefValueMap; | 16 class PrefValueMap; | 
| 16 | 17 | 
| 17 namespace policy { | 18 namespace policy { | 
| 18 | 19 | 
| 19 class PolicyErrorMap; | 20 class PolicyErrorMap; | 
| 20 class PolicyMap; | 21 class PolicyMap; | 
| 21 | 22 | 
| 22 // Maps a policy type to a preference path, and to the expected value type. | 23 // Maps a policy type to a preference path, and to the expected value type. | 
| 23 struct PolicyToPreferenceMapEntry { | 24 struct POLICY_EXPORT PolicyToPreferenceMapEntry { | 
| 24   const char* const policy_name; | 25   const char* const policy_name; | 
| 25   const char* const preference_path; | 26   const char* const preference_path; | 
| 26   const base::Value::Type value_type; | 27   const base::Value::Type value_type; | 
| 27 }; | 28 }; | 
| 28 | 29 | 
| 29 // An abstract super class that subclasses should implement to map policies to | 30 // An abstract super class that subclasses should implement to map policies to | 
| 30 // their corresponding preferences, and to check whether the policies are valid. | 31 // their corresponding preferences, and to check whether the policies are valid. | 
| 31 class ConfigurationPolicyHandler { | 32 class POLICY_EXPORT ConfigurationPolicyHandler { | 
| 32  public: | 33  public: | 
| 33   static std::string ValueTypeToString(Value::Type type); | 34   static std::string ValueTypeToString(Value::Type type); | 
| 34 | 35 | 
| 35   ConfigurationPolicyHandler(); | 36   ConfigurationPolicyHandler(); | 
| 36   virtual ~ConfigurationPolicyHandler(); | 37   virtual ~ConfigurationPolicyHandler(); | 
| 37 | 38 | 
| 38   // Returns whether the policy settings handled by this | 39   // Returns whether the policy settings handled by this | 
| 39   // ConfigurationPolicyHandler can be applied.  Fills |errors| with error | 40   // ConfigurationPolicyHandler can be applied.  Fills |errors| with error | 
| 40   // messages or warnings.  |errors| may contain error messages even when | 41   // messages or warnings.  |errors| may contain error messages even when | 
| 41   // |CheckPolicySettings()| returns true. | 42   // |CheckPolicySettings()| returns true. | 
| 42   virtual bool CheckPolicySettings(const PolicyMap& policies, | 43   virtual bool CheckPolicySettings(const PolicyMap& policies, | 
| 43                                    PolicyErrorMap* errors) = 0; | 44                                    PolicyErrorMap* errors) = 0; | 
| 44 | 45 | 
| 45   // Processes the policies handled by this ConfigurationPolicyHandler and sets | 46   // Processes the policies handled by this ConfigurationPolicyHandler and sets | 
| 46   // the appropriate preferences in |prefs|. | 47   // the appropriate preferences in |prefs|. | 
| 47   virtual void ApplyPolicySettings(const PolicyMap& policies, | 48   virtual void ApplyPolicySettings(const PolicyMap& policies, | 
| 48                                    PrefValueMap* prefs) = 0; | 49                                    PrefValueMap* prefs) = 0; | 
| 49 | 50 | 
| 50   // Modifies the values of some of the policies in |policies| so that they | 51   // Modifies the values of some of the policies in |policies| so that they | 
| 51   // are more suitable to display to the user. This can be used to remove | 52   // are more suitable to display to the user. This can be used to remove | 
| 52   // sensitive values such as passwords, or to pretty-print values. | 53   // sensitive values such as passwords, or to pretty-print values. | 
| 53   virtual void PrepareForDisplaying(PolicyMap* policies) const; | 54   virtual void PrepareForDisplaying(PolicyMap* policies) const; | 
| 54 | 55 | 
| 55  private: | 56  private: | 
| 56   DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler); | 57   DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler); | 
| 57 }; | 58 }; | 
| 58 | 59 | 
| 59 // Abstract class derived from ConfigurationPolicyHandler that should be | 60 // Abstract class derived from ConfigurationPolicyHandler that should be | 
| 60 // subclassed to handle a single policy (not a combination of policies). | 61 // subclassed to handle a single policy (not a combination of policies). | 
| 61 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler { | 62 class POLICY_EXPORT TypeCheckingPolicyHandler | 
|  | 63     : public ConfigurationPolicyHandler { | 
| 62  public: | 64  public: | 
| 63   TypeCheckingPolicyHandler(const char* policy_name, | 65   TypeCheckingPolicyHandler(const char* policy_name, | 
| 64                             base::Value::Type value_type); | 66                             base::Value::Type value_type); | 
| 65   virtual ~TypeCheckingPolicyHandler(); | 67   virtual ~TypeCheckingPolicyHandler(); | 
| 66 | 68 | 
| 67   // ConfigurationPolicyHandler methods: | 69   // ConfigurationPolicyHandler methods: | 
| 68   virtual bool CheckPolicySettings(const PolicyMap& policies, | 70   virtual bool CheckPolicySettings(const PolicyMap& policies, | 
| 69                                    PolicyErrorMap* errors) OVERRIDE; | 71                                    PolicyErrorMap* errors) OVERRIDE; | 
| 70 | 72 | 
| 71   const char* policy_name() const; | 73   const char* policy_name() const; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 82 | 84 | 
| 83   // The type the value of the policy should have. | 85   // The type the value of the policy should have. | 
| 84   base::Value::Type value_type_; | 86   base::Value::Type value_type_; | 
| 85 | 87 | 
| 86   DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); | 88   DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); | 
| 87 }; | 89 }; | 
| 88 | 90 | 
| 89 // Abstract class derived from TypeCheckingPolicyHandler that ensures an int | 91 // Abstract class derived from TypeCheckingPolicyHandler that ensures an int | 
| 90 // policy's value lies in an allowed range. Either clamps or rejects values | 92 // policy's value lies in an allowed range. Either clamps or rejects values | 
| 91 // outside the range. | 93 // outside the range. | 
| 92 class IntRangePolicyHandlerBase : public TypeCheckingPolicyHandler { | 94 class POLICY_EXPORT IntRangePolicyHandlerBase | 
|  | 95     : public TypeCheckingPolicyHandler { | 
| 93  public: | 96  public: | 
| 94   IntRangePolicyHandlerBase(const char* policy_name, | 97   IntRangePolicyHandlerBase(const char* policy_name, | 
| 95                             int min, | 98                             int min, | 
| 96                             int max, | 99                             int max, | 
| 97                             bool clamp); | 100                             bool clamp); | 
| 98 | 101 | 
| 99   // ConfigurationPolicyHandler: | 102   // ConfigurationPolicyHandler: | 
| 100   virtual bool CheckPolicySettings(const PolicyMap& policies, | 103   virtual bool CheckPolicySettings(const PolicyMap& policies, | 
| 101                                    PolicyErrorMap* errors) OVERRIDE; | 104                                    PolicyErrorMap* errors) OVERRIDE; | 
| 102 | 105 | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 118   int max_; | 121   int max_; | 
| 119 | 122 | 
| 120   // Whether to clamp values lying outside the allowed range instead of | 123   // Whether to clamp values lying outside the allowed range instead of | 
| 121   // rejecting them. | 124   // rejecting them. | 
| 122   bool clamp_; | 125   bool clamp_; | 
| 123 | 126 | 
| 124   DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandlerBase); | 127   DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandlerBase); | 
| 125 }; | 128 }; | 
| 126 | 129 | 
| 127 // ConfigurationPolicyHandler for policies that map directly to a preference. | 130 // ConfigurationPolicyHandler for policies that map directly to a preference. | 
| 128 class SimplePolicyHandler : public TypeCheckingPolicyHandler { | 131 class POLICY_EXPORT SimplePolicyHandler : public TypeCheckingPolicyHandler { | 
| 129  public: | 132  public: | 
| 130   SimplePolicyHandler(const char* policy_name, | 133   SimplePolicyHandler(const char* policy_name, | 
| 131                       const char* pref_path, | 134                       const char* pref_path, | 
| 132                       base::Value::Type value_type); | 135                       base::Value::Type value_type); | 
| 133   virtual ~SimplePolicyHandler(); | 136   virtual ~SimplePolicyHandler(); | 
| 134 | 137 | 
| 135   // ConfigurationPolicyHandler methods: | 138   // ConfigurationPolicyHandler methods: | 
| 136   virtual void ApplyPolicySettings(const PolicyMap& policies, | 139   virtual void ApplyPolicySettings(const PolicyMap& policies, | 
| 137                                    PrefValueMap* prefs) OVERRIDE; | 140                                    PrefValueMap* prefs) OVERRIDE; | 
| 138 | 141 | 
| 139  private: | 142  private: | 
| 140   // The DictionaryValue path of the preference the policy maps to. | 143   // The DictionaryValue path of the preference the policy maps to. | 
| 141   const char* pref_path_; | 144   const char* pref_path_; | 
| 142 | 145 | 
| 143   DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | 146   DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | 
| 144 }; | 147 }; | 
| 145 | 148 | 
| 146 // A policy handler implementation that maps a string enum list to an int enum | 149 // A policy handler implementation that maps a string enum list to an int enum | 
| 147 // list as specified by a mapping table. | 150 // list as specified by a mapping table. | 
| 148 class StringToIntEnumListPolicyHandler : public TypeCheckingPolicyHandler { | 151 class POLICY_EXPORT StringToIntEnumListPolicyHandler | 
|  | 152     : public TypeCheckingPolicyHandler { | 
| 149  public: | 153  public: | 
| 150   struct MappingEntry { | 154   struct POLICY_EXPORT MappingEntry { | 
| 151     const char* enum_value; | 155     const char* enum_value; | 
| 152     int int_value; | 156     int int_value; | 
| 153   }; | 157   }; | 
| 154 | 158 | 
| 155   StringToIntEnumListPolicyHandler(const char* policy_name, | 159   StringToIntEnumListPolicyHandler(const char* policy_name, | 
| 156                                    const char* pref_path, | 160                                    const char* pref_path, | 
| 157                                    const MappingEntry* mapping_begin, | 161                                    const MappingEntry* mapping_begin, | 
| 158                                    const MappingEntry* mapping_end); | 162                                    const MappingEntry* mapping_end); | 
| 159 | 163 | 
| 160   // ConfigurationPolicyHandler methods: | 164   // ConfigurationPolicyHandler methods: | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 175 | 179 | 
| 176   // The mapping table. | 180   // The mapping table. | 
| 177   const MappingEntry* mapping_begin_; | 181   const MappingEntry* mapping_begin_; | 
| 178   const MappingEntry* mapping_end_; | 182   const MappingEntry* mapping_end_; | 
| 179 | 183 | 
| 180   DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler); | 184   DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler); | 
| 181 }; | 185 }; | 
| 182 | 186 | 
| 183 // A policy handler implementation that ensures an int policy's value lies in an | 187 // A policy handler implementation that ensures an int policy's value lies in an | 
| 184 // allowed range. | 188 // allowed range. | 
| 185 class IntRangePolicyHandler : public IntRangePolicyHandlerBase { | 189 class POLICY_EXPORT IntRangePolicyHandler : public IntRangePolicyHandlerBase { | 
| 186  public: | 190  public: | 
| 187   IntRangePolicyHandler(const char* policy_name, | 191   IntRangePolicyHandler(const char* policy_name, | 
| 188                         const char* pref_path, | 192                         const char* pref_path, | 
| 189                         int min, | 193                         int min, | 
| 190                         int max, | 194                         int max, | 
| 191                         bool clamp); | 195                         bool clamp); | 
| 192   virtual ~IntRangePolicyHandler(); | 196   virtual ~IntRangePolicyHandler(); | 
| 193 | 197 | 
| 194   // ConfigurationPolicyHandler: | 198   // ConfigurationPolicyHandler: | 
| 195   virtual void ApplyPolicySettings(const PolicyMap& policies, | 199   virtual void ApplyPolicySettings(const PolicyMap& policies, | 
| 196                                    PrefValueMap* prefs) OVERRIDE; | 200                                    PrefValueMap* prefs) OVERRIDE; | 
| 197 | 201 | 
| 198  private: | 202  private: | 
| 199   // Name of the pref to write. | 203   // Name of the pref to write. | 
| 200   const char* pref_path_; | 204   const char* pref_path_; | 
| 201 | 205 | 
| 202   DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler); | 206   DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler); | 
| 203 }; | 207 }; | 
| 204 | 208 | 
| 205 // A policy handler implementation that maps an int percentage value to a | 209 // A policy handler implementation that maps an int percentage value to a | 
| 206 // double. | 210 // double. | 
| 207 class IntPercentageToDoublePolicyHandler : public IntRangePolicyHandlerBase { | 211 class POLICY_EXPORT IntPercentageToDoublePolicyHandler | 
|  | 212     : public IntRangePolicyHandlerBase { | 
| 208  public: | 213  public: | 
| 209   IntPercentageToDoublePolicyHandler(const char* policy_name, | 214   IntPercentageToDoublePolicyHandler(const char* policy_name, | 
| 210                                      const char* pref_path, | 215                                      const char* pref_path, | 
| 211                                      int min, | 216                                      int min, | 
| 212                                      int max, | 217                                      int max, | 
| 213                                      bool clamp); | 218                                      bool clamp); | 
| 214   virtual ~IntPercentageToDoublePolicyHandler(); | 219   virtual ~IntPercentageToDoublePolicyHandler(); | 
| 215 | 220 | 
| 216   // ConfigurationPolicyHandler: | 221   // ConfigurationPolicyHandler: | 
| 217   virtual void ApplyPolicySettings(const PolicyMap& policies, | 222   virtual void ApplyPolicySettings(const PolicyMap& policies, | 
| 218                                    PrefValueMap* prefs) OVERRIDE; | 223                                    PrefValueMap* prefs) OVERRIDE; | 
| 219 | 224 | 
| 220  private: | 225  private: | 
| 221   // Name of the pref to write. | 226   // Name of the pref to write. | 
| 222   const char* pref_path_; | 227   const char* pref_path_; | 
| 223 | 228 | 
| 224   DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler); | 229   DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler); | 
| 225 }; | 230 }; | 
| 226 | 231 | 
| 227 }  // namespace policy | 232 }  // namespace policy | 
| 228 | 233 | 
| 229 #endif  // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 234 #endif  // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_H_ | 
| OLD | NEW | 
|---|