network_configuration_updater.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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 DictionaryValue; 18class ListValue; 19class Value; 20} 21 22namespace chromeos { 23class ManagedNetworkConfigurationHandler; 24 25namespace onc { 26class CertificateImporter; 27} 28} 29 30namespace policy { 31 32class PolicyMap; 33 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. 40class NetworkConfigurationUpdater : public PolicyService::Observer { 41 public: 42 virtual ~NetworkConfigurationUpdater(); 43 44 // Creates an updater that applies the ONC device policy from |policy_service| 45 // once the policy service is completely initialized and on each policy 46 // change. 47 static scoped_ptr<NetworkConfigurationUpdater> CreateForDevicePolicy( 48 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, 49 PolicyService* policy_service, 50 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 51 52 // PolicyService::Observer overrides 53 virtual void OnPolicyUpdated(const PolicyNamespace& ns, 54 const PolicyMap& previous, 55 const PolicyMap& current) OVERRIDE; 56 virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; 57 58 protected: 59 NetworkConfigurationUpdater( 60 onc::ONCSource onc_source, 61 std::string policy_key, 62 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, 63 PolicyService* policy_service, 64 chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 65 66 void Init(); 67 68 // Imports the certificates part of the policy. 69 virtual void ImportCertificates(const base::ListValue& certificates_onc); 70 71 // Pushes the network part of the policy to the 72 // ManagedNetworkConfigurationHandler. This can be overridden by subclasses to 73 // modify |network_configs_onc| before the actual application. 74 virtual void ApplyNetworkPolicy(base::ListValue* network_configs_onc, 75 base::DictionaryValue* global_network_config); 76 77 onc::ONCSource onc_source_; 78 79 // Pointer to the global singleton or a test instance. 80 chromeos::ManagedNetworkConfigurationHandler* network_config_handler_; 81 82 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_; 83 84 private: 85 // Called if the ONC policy changed. 86 void OnPolicyChanged(const base::Value* previous, const base::Value* current); 87 88 // Apply the observed policy, i.e. both networks and certificates. 89 void ApplyPolicy(); 90 91 std::string LogHeader() const; 92 93 std::string policy_key_; 94 95 // Used to register for notifications from the |policy_service_|. 96 PolicyChangeRegistrar policy_change_registrar_; 97 98 // Used to retrieve the policies. 99 PolicyService* policy_service_; 100 101 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater); 102}; 103 104} // namespace policy 105 106#endif // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_ 107