Chromium Code Reviews| 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 CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 14 #include "policy/configuration_policy_type.h" | |
| 15 | 14 |
| 16 class PrefValueMap; | 15 class PrefValueMap; |
| 17 | 16 |
| 18 namespace policy { | 17 namespace policy { |
| 19 | 18 |
| 20 class PolicyErrorMap; | 19 class PolicyErrorMap; |
| 21 class PolicyMap; | 20 class PolicyMap; |
| 22 | 21 |
| 23 // An abstract super class that subclasses should implement to map policies to | 22 // An abstract super class that subclasses should implement to map policies to |
| 24 // their corresponding preferences, and to check whether the policies are valid. | 23 // their corresponding preferences, and to check whether the policies are valid. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 47 virtual void PrepareForDisplaying(PolicyMap* policies) const; | 46 virtual void PrepareForDisplaying(PolicyMap* policies) const; |
| 48 | 47 |
| 49 private: | 48 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler); | 49 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler); |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 // Abstract class derived from ConfigurationPolicyHandler that should be | 52 // Abstract class derived from ConfigurationPolicyHandler that should be |
| 54 // subclassed to handle a single policy (not a combination of policies). | 53 // subclassed to handle a single policy (not a combination of policies). |
| 55 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler { | 54 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler { |
| 56 public: | 55 public: |
| 57 TypeCheckingPolicyHandler(ConfigurationPolicyType policy_type, | 56 TypeCheckingPolicyHandler(const char* policy_name, |
| 58 base::Value::Type value_type); | 57 base::Value::Type value_type); |
| 59 | 58 |
| 60 // ConfigurationPolicyHandler methods: | 59 // ConfigurationPolicyHandler methods: |
| 61 virtual bool CheckPolicySettings(const PolicyMap& policies, | 60 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 62 PolicyErrorMap* errors) OVERRIDE; | 61 PolicyErrorMap* errors) OVERRIDE; |
| 63 | 62 |
| 64 protected: | 63 protected: |
| 65 virtual ~TypeCheckingPolicyHandler(); | 64 virtual ~TypeCheckingPolicyHandler(); |
| 66 | 65 |
| 67 // Runs policy checks and returns the policy value if successful. | 66 // Runs policy checks and returns the policy value if successful. |
| 68 bool CheckAndGetValue(const PolicyMap& policies, | 67 bool CheckAndGetValue(const PolicyMap& policies, |
| 69 PolicyErrorMap* errors, | 68 PolicyErrorMap* errors, |
| 70 const Value** value); | 69 const Value** value); |
| 71 | 70 |
| 72 ConfigurationPolicyType policy_type() const; | 71 const char* policy_name() const; |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 // The ConfigurationPolicyType of the policy. | 74 // The name of the policy. |
| 76 ConfigurationPolicyType policy_type_; | 75 const char* policy_name_; |
| 77 | 76 |
| 78 // The type the value of the policy should have. | 77 // The type the value of the policy should have. |
| 79 base::Value::Type value_type_; | 78 base::Value::Type value_type_; |
| 80 | 79 |
| 81 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); | 80 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 // ConfigurationPolicyHandler for policies that map directly to a preference. | 83 // ConfigurationPolicyHandler for policies that map directly to a preference. |
| 85 class SimplePolicyHandler : public TypeCheckingPolicyHandler { | 84 class SimplePolicyHandler : public TypeCheckingPolicyHandler { |
| 86 public: | 85 public: |
| 87 SimplePolicyHandler(ConfigurationPolicyType policy_type, | 86 SimplePolicyHandler(const char* policy_name, |
| 88 base::Value::Type value_type, | 87 const char* pref_path, |
| 89 const char* pref_path); | 88 base::Value::Type value_type); |
| 90 virtual ~SimplePolicyHandler(); | 89 virtual ~SimplePolicyHandler(); |
| 91 | 90 |
| 92 // ConfigurationPolicyHandler methods: | 91 // ConfigurationPolicyHandler methods: |
| 93 virtual void ApplyPolicySettings(const PolicyMap& policies, | 92 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 94 PrefValueMap* prefs) OVERRIDE; | 93 PrefValueMap* prefs) OVERRIDE; |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 // The DictionaryValue path of the preference the policy maps to. | 96 // The DictionaryValue path of the preference the policy maps to. |
| 98 const char* pref_path_; | 97 const char* pref_path_; |
| 99 | 98 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 PolicyErrorMap* errors) OVERRIDE; | 213 PolicyErrorMap* errors) OVERRIDE; |
| 215 virtual void ApplyPolicySettings(const PolicyMap& policies, | 214 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 216 PrefValueMap* prefs) OVERRIDE; | 215 PrefValueMap* prefs) OVERRIDE; |
| 217 | 216 |
| 218 private: | 217 private: |
| 219 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| | 218 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| |
| 220 // and returns true if all of the calls return true and false otherwise. | 219 // and returns true if all of the calls return true and false otherwise. |
| 221 bool CheckIndividualPolicies(const PolicyMap& policies, | 220 bool CheckIndividualPolicies(const PolicyMap& policies, |
| 222 PolicyErrorMap* errors); | 221 PolicyErrorMap* errors); |
| 223 | 222 |
| 224 // Returns true if there is a value for |policy_type| in |policies| and false | 223 // Returns true if there is a value for |policy_name| in |policies| and false |
| 225 // otherwise. | 224 // otherwise. |
| 226 bool HasDefaultSearchPolicy(const PolicyMap& policies, | 225 bool HasDefaultSearchPolicy(const PolicyMap& policies, |
| 227 ConfigurationPolicyType policy_type); | 226 const char* policy_name); |
| 228 | 227 |
| 229 // Returns true if any default search policies are specified in |policies| and | 228 // Returns true if any default search policies are specified in |policies| and |
| 230 // false otherwise. | 229 // false otherwise. |
| 231 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies); | 230 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies); |
| 232 | 231 |
| 233 // Returns true if the default search provider is disabled and false | 232 // Returns true if the default search provider is disabled and false |
| 234 // otherwise. | 233 // otherwise. |
| 235 bool DefaultSearchProviderIsDisabled(const PolicyMap& policies); | 234 bool DefaultSearchProviderIsDisabled(const PolicyMap& policies); |
| 236 | 235 |
| 237 // Returns true if the default search URL was set and is valid and false | 236 // Returns true if the default search URL was set and is valid and false |
| 238 // otherwise. | 237 // otherwise. |
| 239 bool DefaultSearchURLIsValid(const PolicyMap& policies); | 238 bool DefaultSearchURLIsValid(const PolicyMap& policies); |
| 240 | 239 |
| 241 // Make sure that the |path| if present in |prefs_|. If not, set it to | 240 // Make sure that the |path| if present in |prefs_|. If not, set it to |
| 242 // a blank string. | 241 // a blank string. |
| 243 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); | 242 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); |
| 244 | 243 |
| 245 // The ConfigurationPolicyHandler handlers for each default search policy. | 244 // The ConfigurationPolicyHandler handlers for each default search policy. |
| 246 std::vector<ConfigurationPolicyHandler*> handlers_; | 245 std::vector<ConfigurationPolicyHandler*> handlers_; |
| 247 | 246 |
| 248 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); | 247 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); |
| 249 }; | 248 }; |
| 250 | 249 |
| 251 // ConfigurationPolicyHandler for the proxy policies. | 250 // ConfigurationPolicyHandler for the proxy policies. |
| 252 class ProxyPolicyHandler : public ConfigurationPolicyHandler { | 251 class ProxyPolicyHandler : public ConfigurationPolicyHandler { |
| 253 public: | 252 public: |
| 253 // Constants for the "Proxy Server Mode" defined in the policies. | |
| 254 // Note that these diverge from internal presentation defined in | |
| 255 // ProxyPrefs::ProxyMode for legacy reasons. The following four | |
| 256 // PolicyProxyModeType types were not very precise and had overlapping use | |
| 257 // cases. | |
| 258 enum ProxyModeType { | |
| 259 // Disable Proxy, connect directly. | |
| 260 kNoProxyServerMode = 0, | |
|
Mattias Nissler (ping if slow)
2012/01/16 18:23:33
If you touch the enum, you might as well make the
Joao da Silva
2012/01/17 13:09:29
Done.
| |
| 261 // Auto detect proxy or use specific PAC script if given. | |
| 262 kAutoDetectProxyServerMode = 1, | |
| 263 // Use manually configured proxy servers (fixed servers). | |
| 264 kManuallyConfiguredProxyServerMode = 2, | |
| 265 // Use system proxy server. | |
| 266 kUseSystemProxyServerMode = 3, | |
| 267 | |
| 268 MODE_COUNT | |
| 269 }; | |
| 270 | |
| 254 ProxyPolicyHandler(); | 271 ProxyPolicyHandler(); |
| 255 virtual ~ProxyPolicyHandler(); | 272 virtual ~ProxyPolicyHandler(); |
| 256 | 273 |
| 257 // ConfigurationPolicyHandler methods: | 274 // ConfigurationPolicyHandler methods: |
| 258 virtual bool CheckPolicySettings(const PolicyMap& policies, | 275 virtual bool CheckPolicySettings(const PolicyMap& policies, |
| 259 PolicyErrorMap* errors) OVERRIDE; | 276 PolicyErrorMap* errors) OVERRIDE; |
| 260 virtual void ApplyPolicySettings(const PolicyMap& policies, | 277 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 261 PrefValueMap* prefs) OVERRIDE; | 278 PrefValueMap* prefs) OVERRIDE; |
| 262 | 279 |
| 263 private: | 280 private: |
| 264 const Value* GetProxyPolicyValue(const PolicyMap& policies, | 281 const Value* GetProxyPolicyValue(const PolicyMap& policies, |
| 265 ConfigurationPolicyType policy); | 282 const char* policy_name); |
| 266 | 283 |
| 267 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value | 284 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value |
| 268 // and places the result in |mode_value|. Returns true if the conversion | 285 // and places the result in |mode_value|. Returns true if the conversion |
| 269 // succeeded and false otherwise. | 286 // succeeded and false otherwise. |
| 270 bool CheckProxyModeAndServerMode(const PolicyMap& policies, | 287 bool CheckProxyModeAndServerMode(const PolicyMap& policies, |
| 271 PolicyErrorMap* errors, | 288 PolicyErrorMap* errors, |
| 272 std::string* mode_value); | 289 std::string* mode_value); |
| 273 | 290 |
| 274 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); | 291 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); |
| 275 }; | 292 }; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 286 virtual void ApplyPolicySettings(const PolicyMap& policies, | 303 virtual void ApplyPolicySettings(const PolicyMap& policies, |
| 287 PrefValueMap* prefs) OVERRIDE; | 304 PrefValueMap* prefs) OVERRIDE; |
| 288 | 305 |
| 289 private: | 306 private: |
| 290 DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler); | 307 DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler); |
| 291 }; | 308 }; |
| 292 | 309 |
| 293 } // namespace policy | 310 } // namespace policy |
| 294 | 311 |
| 295 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | 312 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| OLD | NEW |