Chromium Code Reviews| Index: chrome/browser/policy/configuration_policy_handler.h |
| diff --git a/chrome/browser/policy/configuration_policy_handler.h b/chrome/browser/policy/configuration_policy_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3833cb233883e213ed740d268f3ba36005e078d8 |
| --- /dev/null |
| +++ b/chrome/browser/policy/configuration_policy_handler.h |
| @@ -0,0 +1,271 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| +#define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/policy/configuration_policy_handler_interface.h" |
| +#include "chrome/browser/policy/policy_error_map.h" |
| +#include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/prefs/incognito_mode_prefs.h" |
| +#include "chrome/browser/prefs/pref_value_map.h" |
| +#include "policy/configuration_policy_type.h" |
| + |
| +namespace policy { |
| + |
| +// Abstract class derived from ConfigurationPolicyHandlerInterface that should |
| +// be subclassed to handle a single policy (not a combination of policies). |
| +class TypeCheckingPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| + public: |
| + TypeCheckingPolicyHandler(ConfigurationPolicyType policy, |
| + base::Value::Type value_type); |
| + |
| + // ConfigurationPolicyHandlerInterface method. Returns true if the value of |
| + // the policy is of the correct type and false otherwise. |
| + virtual bool CheckPolicySettings(const PolicyMap* policies, |
| + PolicyErrorMap* errors) OVERRIDE; |
|
Mattias Nissler (ping if slow)
2011/09/30 13:33:35
Hm, why did the simpler Apply disappear from here?
|
| + |
| + protected: |
| + virtual ~TypeCheckingPolicyHandler(); |
| + |
| + ConfigurationPolicyType policy_type() const; |
| + |
| + private: |
| + // The ConfigurationPolicyType of the policy. |
| + ConfigurationPolicyType policy_type_; |
| + |
| + // The type the value of the policy should have. |
| + base::Value::Type value_type_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler ); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for policies that map |
| +// directly to a preference. |
| +class SimplePolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + SimplePolicyHandler(ConfigurationPolicyType policy, |
| + base::Value::Type value_type, |
| + const char* pref_path); |
| + virtual ~SimplePolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + // The DictionaryValue path of the preference the policy maps to. |
| + const char* pref_path_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the SyncDisabled |
| +// policy. |
| +class SyncPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + SyncPolicyHandler(); |
| + virtual ~SyncPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the AutofillEnabled |
| +// policy. |
| +class AutofillPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + AutofillPolicyHandler(); |
| + virtual ~AutofillPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the DownloadDirectory |
| +// policy. |
| +class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + DownloadDirPolicyHandler(); |
| + virtual ~DownloadDirPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the DiskCacheDir |
| +// policy. |
| +class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + explicit DiskCacheDirPolicyHandler(); |
| + virtual ~DiskCacheDirPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the |
| +// FileSelectionDialogsHandler policy. |
| +class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + FileSelectionDialogsHandler(); |
| + virtual ~FileSelectionDialogsHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the BookmarkBarEnabled |
| +// policy. |
| +class BookmarksPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + BookmarksPolicyHandler(); |
| + virtual ~BookmarksPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BookmarksPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the incognito mode |
| +// policies. |
| +class IncognitoModePolicyHandler : public ConfigurationPolicyHandlerInterface { |
| + public: |
| + IncognitoModePolicyHandler(); |
| + virtual ~IncognitoModePolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual bool CheckPolicySettings(const PolicyMap* policies, |
| + PolicyErrorMap* errors) OVERRIDE; |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + IncognitoModePrefs::Availability GetAvailabilityValueAsEnum( |
| + const Value* availability); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the |
| +// DefaultSearchEncodings policy. |
| +class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler { |
| + public: |
| + DefaultSearchEncodingsPolicyHandler(); |
| + virtual ~DefaultSearchEncodingsPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the default search |
| +// policies. |
| +class DefaultSearchPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| + public: |
| + DefaultSearchPolicyHandler(); |
| + virtual ~DefaultSearchPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual bool CheckPolicySettings(const PolicyMap* policies, |
| + PolicyErrorMap* errors) OVERRIDE; |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + typedef std::vector<ConfigurationPolicyHandlerInterface*> HandlerList; |
| + |
| + // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| |
| + // and returns true if all of the calls return true and false otherwise. |
| + bool CheckIndividualPolicies(const PolicyMap* policies, |
| + PolicyErrorMap* errors); |
| + |
| + // Returns true if there is a value for |policy_type| in |policies| and false |
| + // otherwise. |
| + bool HasDefaultSearchPolicy(const PolicyMap* policies, |
| + ConfigurationPolicyType policy_type); |
| + |
| + // Returns true if any default search policies are specified in |policies| and |
| + // false otherwise. |
| + bool AnyDefaultSearchPoliciesSpecified(const PolicyMap* policies); |
| + |
| + // Returns true if the default search provider is disabled and false |
| + // otherwise. |
| + bool DefaultSearchProviderIsDisabled(const PolicyMap* policies); |
| + |
| + // Returns true if the default search URL was set and is valid and false |
| + // otherwise. |
| + bool DefaultSearchURLIsValid(const PolicyMap* policies); |
| + |
| + // Make sure that the |path| if present in |prefs_|. If not, set it to |
| + // a blank string. |
| + void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); |
| + |
| + // The ConfigurationPolicyHandlerInterface handlers for each of default search |
| + // policies. |
| + HandlerList handlers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); |
| +}; |
| + |
| +// ConfigurationPolicyHandlerInterface implementation for the proxy policies. |
| +class ProxyPolicyHandler : public ConfigurationPolicyHandlerInterface { |
| + public: |
| + ProxyPolicyHandler(); |
| + virtual ~ProxyPolicyHandler(); |
| + |
| + // ConfigurationPolicyHandlerInterface methods: |
| + virtual bool CheckPolicySettings(const PolicyMap* policies, |
| + PolicyErrorMap* errors) OVERRIDE; |
| + virtual void ApplyPolicySettings(const PolicyMap* policies, |
| + PrefValueMap* prefs) OVERRIDE; |
| + |
| + private: |
| + const Value* GetProxyPolicyValue(const PolicyMap* policies, |
| + ConfigurationPolicyType policy); |
| + |
| + // Converts the deprecated ProxyServerMode policy value to a ProxyMode value |
| + // and places the result in |mode_value|. Returns true if the conversion |
| + // succeeded and false otherwise. |
| + bool CheckProxyModeAndServerMode(const PolicyMap* policies, |
| + PolicyErrorMap* errors, |
| + std::string* mode_value); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); |
| +}; |
| + |
| +} // namespace policy |
| + |
| +#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |