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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/onc/onc_constants.h"
14 #include "components/policy/core/common/policy_service.h"
17 class DictionaryValue
;
23 class ManagedNetworkConfigurationHandler
;
26 class CertificateImporter
;
34 // Implements the common part of tracking a OpenNetworkConfiguration device or
35 // user policy. Pushes the network configs to the
36 // ManagedNetworkConfigurationHandler, which in turn writes configurations to
37 // Shill. Certificates are imported with the chromeos::onc::CertificateImporter.
38 // For user policies the subclass UserNetworkConfigurationUpdater must be used.
39 // Does not handle proxy settings.
40 class NetworkConfigurationUpdater
: public PolicyService::Observer
{
42 virtual ~NetworkConfigurationUpdater();
44 // PolicyService::Observer overrides
45 virtual void OnPolicyUpdated(const PolicyNamespace
& ns
,
46 const PolicyMap
& previous
,
47 const PolicyMap
& current
) OVERRIDE
;
48 virtual void OnPolicyServiceInitialized(PolicyDomain domain
) OVERRIDE
;
51 NetworkConfigurationUpdater(
52 onc::ONCSource onc_source
,
53 std::string policy_key
,
54 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
55 PolicyService
* policy_service
,
56 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
);
60 // Imports the certificates part of the policy.
61 virtual void ImportCertificates(const base::ListValue
& certificates_onc
) = 0;
63 // Pushes the network part of the policy to the
64 // ManagedNetworkConfigurationHandler. This can be overridden by subclasses to
65 // modify |network_configs_onc| before the actual application.
66 virtual void ApplyNetworkPolicy(
67 base::ListValue
* network_configs_onc
,
68 base::DictionaryValue
* global_network_config
) = 0;
70 onc::ONCSource onc_source_
;
72 // Pointer to the global singleton or a test instance.
73 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler_
;
75 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer_
;
78 // Called if the ONC policy changed.
79 void OnPolicyChanged(const base::Value
* previous
, const base::Value
* current
);
81 // Apply the observed policy, i.e. both networks and certificates.
84 std::string
LogHeader() const;
86 std::string policy_key_
;
88 // Used to register for notifications from the |policy_service_|.
89 PolicyChangeRegistrar policy_change_registrar_
;
91 // Used to retrieve the policies.
92 PolicyService
* policy_service_
;
94 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater
);
99 #endif // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_