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 COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_LIST_H_
6#define COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_LIST_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "components/policy/core/common/policy_details.h"
14#include "components/policy/policy_export.h"
15
16class PrefValueMap;
17
18namespace policy {
19
20class ConfigurationPolicyHandler;
21class PolicyErrorMap;
22struct PolicyHandlerParameters;
23class PolicyMap;
24struct PolicyToPreferenceMapEntry;
25class Schema;
26
27// Converts policies to their corresponding preferences by applying a list of
28// ConfigurationPolicyHandler objects. This includes error checking and
29// cleaning up policy values for displaying.
30class POLICY_EXPORT ConfigurationPolicyHandlerList {
31 public:
32  typedef base::Callback<void(PolicyHandlerParameters*)>
33      PopulatePolicyHandlerParametersCallback;
34
35  explicit ConfigurationPolicyHandlerList(
36      const PopulatePolicyHandlerParametersCallback& parameters_callback,
37      const GetChromePolicyDetailsCallback& details_callback);
38  ~ConfigurationPolicyHandlerList();
39
40  // Adds a policy handler to the list.
41  void AddHandler(scoped_ptr<ConfigurationPolicyHandler> handler);
42
43  // Translates |policies| to their corresponding preferences in |prefs|.
44  // Any errors found while processing the policies are stored in |errors|.
45  // |prefs| or |errors| can be NULL, and won't be filled in that case.
46  void ApplyPolicySettings(const PolicyMap& policies,
47                           PrefValueMap* prefs,
48                           PolicyErrorMap* errors) const;
49
50  // Converts sensitive policy values to others more appropriate for displaying.
51  void PrepareForDisplaying(PolicyMap* policies) const;
52
53 private:
54  std::vector<ConfigurationPolicyHandler*> handlers_;
55  const PopulatePolicyHandlerParametersCallback parameters_callback_;
56  const GetChromePolicyDetailsCallback details_callback_;
57
58  DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandlerList);
59};
60
61// Callback with signature of BuildHandlerList(), to be used in constructor of
62// BrowserPolicyConnector.
63typedef base::Callback<scoped_ptr<ConfigurationPolicyHandlerList>(
64    const Schema&)> HandlerListFactory;
65
66}  // namespace policy
67
68#endif  // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_LIST_H_
69