OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/policy/configuration_policy_handler_interface.h" |
| 14 #include "chrome/browser/policy/policy_error_map.h" |
| 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 17 #include "chrome/browser/prefs/pref_value_map.h" |
| 18 #include "policy/configuration_policy_type.h" |
| 19 |
| 20 namespace policy { |
| 21 |
| 22 // Abstract class derived from ConfigurationPolicyHandlerInterface that should |
| 23 // be subclassed to handle a single policy (not a combination of policies). |
| 24 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| 25 public: |
| 26 TypeCheckingPolicyHandler(ConfigurationPolicyType policy, |
| 27 base::Value::Type value_type); |
| 28 |
| 29 // ConfigurationPolicyHandlerInterface method. Returns true if the value of |
| 30 // the policy is of the correct type and false otherwise. |
| 31 virtual bool CheckPolicySettings(const PolicyMap* policies, |
| 32 PolicyErrorMap* errors) OVERRIDE; |
| 33 virtual void ApplyPolicySettings(const PolicyMap* policies, |
| 34 PrefValueMap* prefs) OVERRIDE; |
| 35 |
| 36 // Uses the given |value| to apply the policy given by |policy_type_| to the |
| 37 // PrefValueMap pointed to by |prefs|. |
| 38 virtual void ApplyPolicyValue(PrefValueMap* prefs, const Value* value) = 0; |
| 39 |
| 40 protected: |
| 41 virtual ~TypeCheckingPolicyHandler(); |
| 42 |
| 43 ConfigurationPolicyType policy_type() const; |
| 44 |
| 45 private: |
| 46 // The ConfigurationPolicyType of the policy. |
| 47 ConfigurationPolicyType policy_type_; |
| 48 |
| 49 // The type the value of the policy should have. |
| 50 base::Value::Type value_type_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler ); |
| 53 }; |
| 54 |
| 55 // ConfigurationPolicyHandlerInterface implementation for policies that map |
| 56 // directly to a preference. |
| 57 class SimplePolicyHandler : public TypeCheckingPolicyHandler { |
| 58 public: |
| 59 SimplePolicyHandler(ConfigurationPolicyType policy, |
| 60 base::Value::Type value_type, |
| 61 const char* pref_path); |
| 62 virtual ~SimplePolicyHandler(); |
| 63 |
| 64 // TypeCheckingPolicyHandler method: |
| 65 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 66 const Value* value) OVERRIDE; |
| 67 |
| 68 private: |
| 69 // The DictionaryValue path of the preference the policy maps to. |
| 70 const char* pref_path_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); |
| 73 }; |
| 74 |
| 75 // ConfigurationPolicyHandlerInterface implementation for the SyncDisabled |
| 76 // policy. |
| 77 class SyncPolicyHandler : public TypeCheckingPolicyHandler { |
| 78 public: |
| 79 SyncPolicyHandler(); |
| 80 virtual ~SyncPolicyHandler(); |
| 81 |
| 82 // TypeCheckingPolicyHandler method: |
| 83 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 84 const Value* value) OVERRIDE; |
| 85 |
| 86 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler); |
| 88 }; |
| 89 |
| 90 // ConfigurationPolicyHandlerInterface implementation for the AutofillEnabled |
| 91 // policy. |
| 92 class AutofillPolicyHandler : public TypeCheckingPolicyHandler { |
| 93 public: |
| 94 AutofillPolicyHandler(); |
| 95 virtual ~AutofillPolicyHandler(); |
| 96 |
| 97 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 98 const Value* value) OVERRIDE; |
| 99 |
| 100 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler); |
| 102 }; |
| 103 |
| 104 // ConfigurationPolicyHandlerInterface implementation for the DownloadDirectory |
| 105 // policy. |
| 106 class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler { |
| 107 public: |
| 108 DownloadDirPolicyHandler(); |
| 109 virtual ~DownloadDirPolicyHandler(); |
| 110 |
| 111 // TypeCheckingPolicyHandler methods: |
| 112 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 113 const Value* value) OVERRIDE; |
| 114 |
| 115 private: |
| 116 DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler); |
| 117 }; |
| 118 |
| 119 // ConfigurationPolicyHandlerInterface implementation for the DiskCacheDir |
| 120 // policy. |
| 121 class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler { |
| 122 public: |
| 123 explicit DiskCacheDirPolicyHandler(); |
| 124 virtual ~DiskCacheDirPolicyHandler(); |
| 125 |
| 126 // TypeCheckingPolicyHandler method: |
| 127 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 128 const Value* value) OVERRIDE; |
| 129 |
| 130 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler); |
| 132 }; |
| 133 |
| 134 // ConfigurationPolicyHandlerInterface implementation for the |
| 135 // FileSelectionDialogsHandler policy. |
| 136 class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler { |
| 137 public: |
| 138 FileSelectionDialogsHandler(); |
| 139 virtual ~FileSelectionDialogsHandler(); |
| 140 |
| 141 // TypeCheckingPolicyHandler method: |
| 142 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 143 const Value* value) OVERRIDE; |
| 144 |
| 145 private: |
| 146 DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler); |
| 147 }; |
| 148 |
| 149 // ConfigurationPolicyHandlerInterface implementation for the BookmarkBarEnabled |
| 150 // policy. |
| 151 class BookmarksPolicyHandler : public TypeCheckingPolicyHandler { |
| 152 public: |
| 153 BookmarksPolicyHandler(); |
| 154 virtual ~BookmarksPolicyHandler(); |
| 155 |
| 156 // TypeCheckingPolicyHandler method: |
| 157 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 158 const Value* value) OVERRIDE; |
| 159 |
| 160 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(BookmarksPolicyHandler); |
| 162 }; |
| 163 |
| 164 // ConfigurationPolicyHandlerInterface implementation for the incognito mode |
| 165 // policies. |
| 166 class IncognitoModePolicyHandler : public ConfigurationPolicyHandlerInterface { |
| 167 public: |
| 168 IncognitoModePolicyHandler(); |
| 169 virtual ~IncognitoModePolicyHandler(); |
| 170 |
| 171 // TypeCheckingPolicyHandler methods: |
| 172 virtual bool CheckPolicySettings(const PolicyMap* policies, |
| 173 PolicyErrorMap* errors) OVERRIDE; |
| 174 virtual void ApplyPolicySettings(const PolicyMap* policies, |
| 175 PrefValueMap* prefs) OVERRIDE; |
| 176 |
| 177 private: |
| 178 IncognitoModePrefs::Availability GetAvailabilityValueAsEnum( |
| 179 const Value* availability); |
| 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler); |
| 182 }; |
| 183 |
| 184 // ConfigurationPolicyHandlerInterface implementation for the |
| 185 // DefaultSearchEncodings policy. |
| 186 class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler { |
| 187 public: |
| 188 DefaultSearchEncodingsPolicyHandler(); |
| 189 virtual ~DefaultSearchEncodingsPolicyHandler(); |
| 190 |
| 191 // TypeCheckingPolicyHandler method: |
| 192 virtual void ApplyPolicyValue(PrefValueMap* prefs, |
| 193 const Value* value) OVERRIDE; |
| 194 |
| 195 private: |
| 196 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); |
| 197 }; |
| 198 |
| 199 // ConfigurationPolicyHandlerInterface implementation for the default search |
| 200 // policies. |
| 201 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| 202 public: |
| 203 DefaultSearchPolicyHandler(); |
| 204 virtual ~DefaultSearchPolicyHandler(); |
| 205 |
| 206 // ConfigurationPolicyHandlerInterface methods: |
| 207 virtual bool CheckPolicySettings(const PolicyMap* policies, |
| 208 PolicyErrorMap* errors) OVERRIDE; |
| 209 virtual void ApplyPolicySettings(const PolicyMap* policies, |
| 210 PrefValueMap* prefs) OVERRIDE; |
| 211 |
| 212 private: |
| 213 typedef std::vector<ConfigurationPolicyHandlerInterface*> HandlerList; |
| 214 |
| 215 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| |
| 216 // and returns true if all of the calls return true and false otherwise. |
| 217 bool CheckIndividualPolicies(const PolicyMap* policies, |
| 218 PolicyErrorMap* errors); |
| 219 |
| 220 // Returns true if there is a value for |policy_type| in |policies| and false |
| 221 // otherwise. |
| 222 bool HasDefaultSearchPolicy(const PolicyMap* policies, |
| 223 ConfigurationPolicyType policy_type); |
| 224 |
| 225 // Returns true if any default search policies are specified in |policies| and |
| 226 // false otherwise. |
| 227 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap* policies); |
| 228 |
| 229 // Returns true if the default search provider is disabled and false |
| 230 // otherwise. |
| 231 bool DefaultSearchProviderIsDisabled(const PolicyMap* policies); |
| 232 |
| 233 // Returns true if the default search URL was set and is valid and false |
| 234 // otherwise. |
| 235 bool DefaultSearchURLIsValid(const PolicyMap* policies); |
| 236 |
| 237 // Make sure that the |path| if present in |prefs_|. If not, set it to |
| 238 // a blank string. |
| 239 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); |
| 240 |
| 241 // Copies all default search preferences in |tmp_prefs| to |prefs|. |
| 242 void CopyTempPrefsToRealPrefs(PrefValueMap* tmp_prefs, PrefValueMap* prefs); |
| 243 |
| 244 // The ConfigurationPolicyHandlerInterface handlers for each of default search |
| 245 // policies. |
| 246 HandlerList handlers_; |
| 247 |
| 248 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); |
| 249 }; |
| 250 |
| 251 // ConfigurationPolicyHandlerInterface implementation for the proxy policies. |
| 252 class ProxyPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| 253 public: |
| 254 ProxyPolicyHandler(); |
| 255 virtual ~ProxyPolicyHandler(); |
| 256 |
| 257 // ConfigurationPolicyHandlerInterface methods: |
| 258 virtual bool CheckPolicySettings(const PolicyMap* policies, |
| 259 PolicyErrorMap* errors) OVERRIDE; |
| 260 virtual void ApplyPolicySettings(const PolicyMap* policies, |
| 261 PrefValueMap* prefs) OVERRIDE; |
| 262 |
| 263 private: |
| 264 const Value* GetProxyPolicyValue(const PolicyMap* policies, |
| 265 ConfigurationPolicyType policy); |
| 266 |
| 267 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value |
| 268 // and places the result in |mode_value|. Returns true if the conversion |
| 269 // succeeded and false otherwise. |
| 270 bool CheckProxyModeAndServerMode(const PolicyMap* policies, |
| 271 PolicyErrorMap* errors, |
| 272 std::string* mode_value); |
| 273 |
| 274 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); |
| 275 }; |
| 276 |
| 277 } // namespace policy |
| 278 |
| 279 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
OLD | NEW |