network_configuration_updater.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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_NETWORK_CONFIGURATION_UPDATER_H_
6#define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/memory/scoped_ptr.h"
13#include "chrome/browser/policy/policy_service.h"
14#include "components/onc/onc_constants.h"
15
16namespace base {
17class Value;
18}
19
20namespace chromeos {
21class ManagedNetworkConfigurationHandler;
22
23namespace onc {
24class CertificateImporter;
25}
26}
27
28namespace policy {
29
30class PolicyMap;
31
32// Implements the common part of tracking a OpenNetworkConfiguration device or
33// user policy. Pushes the network configs to the
34// ManagedNetworkConfigurationHandler, which in turn writes configurations to
35// Shill. Certificates are imported with the chromeos::onc::CertificateImporter.
36// For user policies the subclass UserNetworkConfigurationUpdater must be used.
37// Does not handle proxy settings.
38class NetworkConfigurationUpdater : public PolicyService::Observer {
39 public:
40  virtual ~NetworkConfigurationUpdater();
41
42  // Creates an updater that applies the ONC device policy from |policy_service|
43  // once the policy service is completely initialized and on each policy
44  // change.
45  static scoped_ptr<NetworkConfigurationUpdater> CreateForDevicePolicy(
46      scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
47      PolicyService* policy_service,
48      chromeos::ManagedNetworkConfigurationHandler* network_config_handler);
49
50  // PolicyService::Observer overrides
51  virtual void OnPolicyUpdated(const PolicyNamespace& ns,
52                               const PolicyMap& previous,
53                               const PolicyMap& current) OVERRIDE;
54  virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE;
55
56 protected:
57  NetworkConfigurationUpdater(
58      onc::ONCSource onc_source,
59      std::string policy_key,
60      scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
61      PolicyService* policy_service,
62      chromeos::ManagedNetworkConfigurationHandler* network_config_handler);
63
64  void Init();
65
66  // Imports the certificates part of the policy.
67  virtual void ImportCertificates(const base::ListValue& certificates_onc);
68
69  // Pushes the network part of the policy to the
70  // ManagedNetworkConfigurationHandler. This can be overridden by subclasses to
71  // modify |network_configs_onc| before the actual application.
72  virtual void ApplyNetworkPolicy(base::ListValue* network_configs_onc);
73
74  onc::ONCSource onc_source_;
75
76  // Pointer to the global singleton or a test instance.
77  chromeos::ManagedNetworkConfigurationHandler* network_config_handler_;
78
79  scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_;
80
81 private:
82  // Called if the ONC policy changed.
83  void OnPolicyChanged(const base::Value* previous, const base::Value* current);
84
85  // Apply the observed policy, i.e. both networks and certificates.
86  void ApplyPolicy();
87
88  std::string LogHeader() const;
89
90  std::string policy_key_;
91
92  // Used to register for notifications from the |policy_service_|.
93  PolicyChangeRegistrar policy_change_registrar_;
94
95  // Used to retrieve the policies.
96  PolicyService* policy_service_;
97
98  DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater);
99};
100
101}  // namespace policy
102
103#endif  // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
104