network_configuration_updater.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include <string> 9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/basictypes.h" 11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/compiler_specific.h" 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 13424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "chrome/browser/policy/policy_service.h" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "components/onc/onc_constants.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace base { 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class DictionaryValue; 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class ListValue; 19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class Value; 203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace chromeos { 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class ManagedNetworkConfigurationHandler; 24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace onc { 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class CertificateImporter; 27424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace policy { 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class PolicyMap; 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Implements the common part of tracking a OpenNetworkConfiguration device or 35424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// user policy. Pushes the network configs to the 36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// ManagedNetworkConfigurationHandler, which in turn writes configurations to 37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Shill. Certificates are imported with the chromeos::onc::CertificateImporter. 38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// For user policies the subclass UserNetworkConfigurationUpdater must be used. 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Does not handle proxy settings. 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class NetworkConfigurationUpdater : public PolicyService::Observer { 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NetworkConfigurationUpdater(); 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Creates an updater that applies the ONC device policy from |policy_service| 45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // once the policy service is completely initialized and on each policy 46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // change. 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) static scoped_ptr<NetworkConfigurationUpdater> CreateForDevicePolicy( 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, 49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PolicyService* policy_service, 50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // PolicyService::Observer overrides 53424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void OnPolicyUpdated(const PolicyNamespace& ns, 54424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const PolicyMap& previous, 55424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const PolicyMap& current) OVERRIDE; 56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected: 59424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) NetworkConfigurationUpdater( 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) onc::ONCSource onc_source, 61424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::string policy_key, 62424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, 63424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PolicyService* policy_service, 64424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chromeos::ManagedNetworkConfigurationHandler* network_config_handler); 65424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 66424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void Init(); 67424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 68424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Imports the certificates part of the policy. 69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void ImportCertificates(const base::ListValue& certificates_onc); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 71424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Pushes the network part of the policy to the 72424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // ManagedNetworkConfigurationHandler. This can be overridden by subclasses to 73424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // modify |network_configs_onc| before the actual application. 748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void ApplyNetworkPolicy(base::ListValue* network_configs_onc, 758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::DictionaryValue* global_network_config); 76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) onc::ONCSource onc_source_; 78424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 79424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Pointer to the global singleton or a test instance. 80424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) chromeos::ManagedNetworkConfigurationHandler* network_config_handler_; 81424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 82424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer_; 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 85424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Called if the ONC policy changed. 86424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void OnPolicyChanged(const base::Value* previous, const base::Value* current); 87424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 88424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Apply the observed policy, i.e. both networks and certificates. 89424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void ApplyPolicy(); 90424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 91424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::string LogHeader() const; 92424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 93424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::string policy_key_; 94424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 95424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Used to register for notifications from the |policy_service_|. 96424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PolicyChangeRegistrar policy_change_registrar_; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 98424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Used to retrieve the policies. 99424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) PolicyService* policy_service_; 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationUpdater); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace policy 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_CHROMEOS_POLICY_NETWORK_CONFIGURATION_UPDATER_H_ 107