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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONFIGURATION_POLICY_HANDLER_CHROMEOS_H_
6#define CHROME_BROWSER_CHROMEOS_POLICY_CONFIGURATION_POLICY_HANDLER_CHROMEOS_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "chrome/browser/extensions/policy_handlers.h"
11#include "chromeos/network/network_ui_data.h"
12#include "components/onc/onc_constants.h"
13#include "components/policy/core/browser/configuration_policy_handler.h"
14
15namespace base {
16class DictionaryValue;
17class Value;
18}
19
20namespace policy {
21
22class Schema;
23
24// ConfigurationPolicyHandler for policies referencing external data.
25class ExternalDataPolicyHandler : public TypeCheckingPolicyHandler {
26 public:
27  explicit ExternalDataPolicyHandler(const char* policy_name);
28  virtual ~ExternalDataPolicyHandler();
29
30  // TypeCheckingPolicyHandler:
31  virtual bool CheckPolicySettings(const PolicyMap& policies,
32                                   PolicyErrorMap* errors) OVERRIDE;
33
34  virtual void ApplyPolicySettings(const PolicyMap& policies,
35                                   PrefValueMap* prefs) OVERRIDE;
36
37 private:
38  DISALLOW_COPY_AND_ASSIGN(ExternalDataPolicyHandler);
39};
40
41// ConfigurationPolicyHandler for validation of the network configuration
42// policies. These actually don't set any preferences, but the handler just
43// generates error messages.
44class NetworkConfigurationPolicyHandler : public TypeCheckingPolicyHandler {
45 public:
46  static NetworkConfigurationPolicyHandler* CreateForUserPolicy();
47  static NetworkConfigurationPolicyHandler* CreateForDevicePolicy();
48
49  virtual ~NetworkConfigurationPolicyHandler();
50
51  // ConfigurationPolicyHandler methods:
52  virtual bool CheckPolicySettings(const PolicyMap& policies,
53                                   PolicyErrorMap* errors) OVERRIDE;
54  virtual void ApplyPolicySettings(const PolicyMap& policies,
55                                   PrefValueMap* prefs) OVERRIDE;
56  virtual void PrepareForDisplaying(PolicyMap* policies) const OVERRIDE;
57
58 private:
59  explicit NetworkConfigurationPolicyHandler(
60      const char* policy_name,
61      ::onc::ONCSource onc_source,
62      const char* pref_path);
63
64  // Takes network policy in Value representation and produces an output Value
65  // that contains a pretty-printed and sanitized version. In particular, we
66  // remove any Passphrases that may be contained in the JSON. Ownership of the
67  // return value is transferred to the caller.
68  static base::Value* SanitizeNetworkConfig(const base::Value* config);
69
70  // The kind of ONC source that this handler represents. ONCSource
71  // distinguishes between user and device policy.
72  const ::onc::ONCSource onc_source_;
73
74  // The name of the pref to apply the policy to.
75  const char* pref_path_;
76
77  DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationPolicyHandler);
78};
79
80// Maps the PinnedLauncherApps policy to the corresponding pref.
81class PinnedLauncherAppsPolicyHandler
82    : public extensions::ExtensionListPolicyHandler {
83 public:
84  PinnedLauncherAppsPolicyHandler();
85  virtual ~PinnedLauncherAppsPolicyHandler();
86
87  // ExtensionListPolicyHandler methods:
88  virtual void ApplyPolicySettings(const PolicyMap& policies,
89                                   PrefValueMap* prefs) OVERRIDE;
90
91 private:
92  DISALLOW_COPY_AND_ASSIGN(PinnedLauncherAppsPolicyHandler);
93};
94
95class ScreenMagnifierPolicyHandler : public IntRangePolicyHandlerBase {
96 public:
97  ScreenMagnifierPolicyHandler();
98  virtual ~ScreenMagnifierPolicyHandler();
99
100  // IntRangePolicyHandlerBase:
101  virtual void ApplyPolicySettings(const PolicyMap& policies,
102                                   PrefValueMap* prefs) OVERRIDE;
103
104 private:
105  DISALLOW_COPY_AND_ASSIGN(ScreenMagnifierPolicyHandler);
106};
107
108// Policy handler for login screen power management settings. This does not
109// actually set any prefs, it just checks whether the settings are valid and
110// generates errors if appropriate.
111class LoginScreenPowerManagementPolicyHandler
112    : public SchemaValidatingPolicyHandler {
113 public:
114  explicit LoginScreenPowerManagementPolicyHandler(const Schema& chrome_schema);
115  virtual ~LoginScreenPowerManagementPolicyHandler();
116
117  // SchemaValidatingPolicyHandler:
118  virtual void ApplyPolicySettings(const PolicyMap& policies,
119                                   PrefValueMap* prefs) OVERRIDE;
120
121 private:
122  DISALLOW_COPY_AND_ASSIGN(LoginScreenPowerManagementPolicyHandler);
123};
124
125// Handles the deprecated IdleAction policy, so both kIdleActionBattery and
126// kIdleActionAC fall back to the deprecated action.
127class DeprecatedIdleActionHandler : public IntRangePolicyHandlerBase {
128 public:
129  DeprecatedIdleActionHandler();
130  virtual ~DeprecatedIdleActionHandler();
131
132  // ConfigurationPolicyHandler methods:
133  virtual void ApplyPolicySettings(const PolicyMap& policies,
134                                   PrefValueMap* prefs) OVERRIDE;
135
136 private:
137  DISALLOW_COPY_AND_ASSIGN(DeprecatedIdleActionHandler);
138};
139
140class PowerManagementIdleSettingsPolicyHandler
141    : public SchemaValidatingPolicyHandler {
142 public:
143  explicit PowerManagementIdleSettingsPolicyHandler(
144      const Schema& chrome_schema);
145  virtual ~PowerManagementIdleSettingsPolicyHandler();
146
147  // SchemaValidatingPolicyHandler:
148  virtual void ApplyPolicySettings(const PolicyMap& policies,
149                                   PrefValueMap* prefs) OVERRIDE;
150
151 private:
152  DISALLOW_COPY_AND_ASSIGN(PowerManagementIdleSettingsPolicyHandler);
153};
154
155class ScreenLockDelayPolicyHandler : public SchemaValidatingPolicyHandler {
156 public:
157  explicit ScreenLockDelayPolicyHandler(const Schema& chrome_schema);
158  virtual ~ScreenLockDelayPolicyHandler();
159
160  // SchemaValidatingPolicyHandler:
161  virtual void ApplyPolicySettings(const PolicyMap& policies,
162                                   PrefValueMap* prefs) OVERRIDE;
163
164 private:
165  DISALLOW_COPY_AND_ASSIGN(ScreenLockDelayPolicyHandler);
166};
167
168}  // namespace policy
169
170#endif  // CHROME_BROWSER_CHROMEOS_POLICY_CONFIGURATION_POLICY_HANDLER_CHROMEOS_H_
171