Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1357)

Unified Diff: chrome/browser/policy/configuration_policy_handler.h

Issue 7972013: ConfigurationPolicyPrefStore refactoring to surface error messages. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4e91ad51977987136eb98b382bab27ae1b5a5948
--- /dev/null
+++ b/chrome/browser/policy/configuration_policy_handler.h
@@ -0,0 +1,274 @@
+// 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 "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/policy/configuration_policy_handler_interface.h"
+#include "chrome/browser/prefs/incognito_mode_prefs.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 CheckPolicyValueType : public ConfigurationPolicyHandlerInterface {
Mattias Nissler (ping if slow) 2011/09/20 13:12:25 Maybe rename to TypeCheckingPolicyHandler?
simo 2011/09/22 11:43:26 Done.
+ public:
+ CheckPolicyValueType(ConfigurationPolicyType policy,
+ base::Value::Type value_type,
+ const char* pref_path);
Mattias Nissler (ping if slow) 2011/09/20 13:12:25 Why do you have the pref_path as a constructor arg
simo 2011/09/22 11:43:26 I've removed it and I'm using PolicyStatus::GetPol
+
+ // ConfigurationPolicyHandlerInterface method. Returns true if the value of
+ // the policy is of the correct type and false otherwise.
+ virtual bool CheckPolicySettings(PolicyMap* policies,
+ PolicyErrorMap* errors) OVERRIDE;
+
+ protected:
+ virtual ~CheckPolicyValueType();
+
+ // Returns a weak reference to the value pointed to by policy_value_.get().
Mattias Nissler (ping if slow) 2011/09/20 13:12:25 Comment doesn't apply?
simo 2011/09/22 11:43:26 Done.
+ ConfigurationPolicyType policy_type() const;
+ const char* pref_path() const;
+
+ private:
+ static std::string ValueTypeToString(Value::Type type);
+
+ // The ConfigurationPolicyType of the policy.
+ ConfigurationPolicyType policy_type_;
+
+ // The type the value of the policy should have.
+ base::Value::Type value_type_;
+
+ // The DictionaryValue path of the preference the policy maps to.
+ const char* pref_path_;
+
+ DISALLOW_COPY_AND_ASSIGN(CheckPolicyValueType);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for policies that map
+// directly to a preference.
+class SimplePolicyHandler : public CheckPolicyValueType {
+ public:
+ // SimplePolicyHandler takes ownership of |value|.|value| must be non-NULL.
+ SimplePolicyHandler(ConfigurationPolicyType policy,
+ base::Value::Type value_type,
+ const char* pref_path);
+
+ virtual ~SimplePolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the SyncDisabled
+// policy.
+class SyncPolicyHandler : public CheckPolicyValueType {
+ public:
+ // SyncPolicyHandler takes ownership of |value|. |value| must be non-NULL.
+ SyncPolicyHandler();
+ virtual ~SyncPolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the AutofillEnabled
+// policy.
+class AutofillPolicyHandler : public CheckPolicyValueType {
+ public:
+ // AutofillPolicyHandler takes ownership of |value|. |value| must be non-NULL.
+ AutofillPolicyHandler();
+ virtual ~AutofillPolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the DownloadDirectory
+// policy.
+class DownloadDirPolicyHandler : public CheckPolicyValueType {
+ public:
+ // DownloadDirPolicyHandler takes ownership of |value|. |value| must be
+ // non-NULL.
+ DownloadDirPolicyHandler();
+ virtual ~DownloadDirPolicyHandler();
+
+ // CheckPolicyValueType method:
+ virtual bool CheckPolicySettings(PolicyMap* map,
+ PolicyErrorMap* errors) OVERRIDE;
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the DiskCacheDir
+// policy.
+class DiskCacheDirPolicyHandler : public CheckPolicyValueType {
+ public:
+ // DiskCacheDirPolicyHandler takes ownership of |value|. |value| must be
+ // non-NULL.
+ explicit DiskCacheDirPolicyHandler();
+ virtual ~DiskCacheDirPolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the
+// FileSelectionDialogsHandler policy.
+class FileSelectionDialogsHandler : public CheckPolicyValueType {
+ public:
+ // FileSelectionDialogsHandler takes ownership of |value|. |value| must be
+ // non-NULL.
+ FileSelectionDialogsHandler();
+ virtual ~FileSelectionDialogsHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the BookmarkBarEnabled
+// policy.
+class BookmarksPolicyHandler : public CheckPolicyValueType {
+ public:
+ // BookmarksPolicyHandler takes ownership of |value|. |value| must be
+ // non-NULL.
+ BookmarksPolicyHandler();
+ virtual ~BookmarksPolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BookmarksPolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the incognito mode
+// policies.
+class IncognitoModePolicyHandler : public ConfigurationPolicyHandlerInterface {
+ public:
+ // IncognitoModePolicyHandler takes ownership of |incognito_mode_availability|
+ // and |incognito_enabled_value|.Set |incognito_mode_availability| or
+ // |incognito_enabled_value| to NULL if there is no value for the
+ // corresponding policy.
+ IncognitoModePolicyHandler();
+ virtual ~IncognitoModePolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface methods:
+ virtual bool CheckPolicySettings(PolicyMap* policies,
+ PolicyErrorMap* errors) OVERRIDE;
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ // The value of kPolicyIncognitoModeAvailability as an enum.
+ IncognitoModePrefs::Availability availability_enum_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler);
+};
+
+// ConfigurationPolicyHandlerInterface implementation for the
+// DefaultSearchEncodings policy.
+class DefaultSearchEncodingsPolicyHandler : public CheckPolicyValueType {
+ public:
+ DefaultSearchEncodingsPolicyHandler();
+ virtual ~DefaultSearchEncodingsPolicyHandler();
+
+ // ConfigurationPolicyHandlerInterface method:
+ virtual void ApplyPolicySettings(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(PolicyMap* policies,
+ PolicyErrorMap* errors) OVERRIDE;
+ virtual void ApplyPolicySettings(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(PolicyMap* policies, PolicyErrorMap* errors);
+
+ // Returns true if the default search provider is disabled and false
+ // otherwise.
+ bool DefaultSearchProviderIsDisabled(PolicyMap* policies);
+
+ // Returns true if the default search URL was set and is valid and false
+ // otherwise.
+ bool DefaultSearchURLIsPresentAndValid(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);
+
+ // Clears all default search preferences in |prefs|.
+ void ClearDefaultSearchPreferences(PrefValueMap* prefs);
+
+ // 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(PolicyMap* map,
+ PolicyErrorMap* errors) OVERRIDE;
+ virtual void ApplyPolicySettings(PolicyMap* policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698