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