managed_network_configuration_handler_impl.h revision 010d83a9304c5a91596085d917d248abff47903a
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_ 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_ 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <map> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string> 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/compiler_specific.h" 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/linked_ptr.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/weak_ptr.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/chromeos_export.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/managed_network_configuration_handler.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_handler_callbacks.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_profile_observer.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/policy_applicator.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base { 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class DictionaryValue; 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace chromeos { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NetworkConfigurationHandler; 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct NetworkProfile; 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NetworkProfileHandler; 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NetworkStateHandler; 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CHROMEOS_EXPORT ManagedNetworkConfigurationHandlerImpl 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : public ManagedNetworkConfigurationHandler, 34c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch public NetworkProfileObserver, 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public PolicyApplicator::ConfigurationHandler { 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~ManagedNetworkConfigurationHandlerImpl(); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // ManagedNetworkConfigurationHandler overrides 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void AddObserver(NetworkPolicyObserver* observer) OVERRIDE; 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void RemoveObserver(NetworkPolicyObserver* observer) OVERRIDE; 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void GetProperties( 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& service_path, 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::DictionaryResultCallback& callback, 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) OVERRIDE; 471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void GetManagedProperties( 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& userhash, 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& service_path, 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::DictionaryResultCallback& callback, 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) OVERRIDE; 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void SetProperties( 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& service_path, 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const base::DictionaryValue& user_settings, 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const base::Closure& callback, 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const network_handler::ErrorCallback& error_callback) const OVERRIDE; 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void CreateConfiguration( 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& userhash, 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::DictionaryValue& properties, 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const network_handler::StringResultCallback& callback, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) const OVERRIDE; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void RemoveConfiguration( 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& service_path, 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const network_handler::ErrorCallback& error_callback) const OVERRIDE; 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void SetPolicy( 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci onc::ONCSource onc_source, 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& userhash, 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::ListValue& network_configs_onc, 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::DictionaryValue& global_network_config) OVERRIDE; 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual const base::DictionaryValue* FindPolicyByGUID( 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string userhash, 791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const std::string& guid, 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) onc::ONCSource* onc_source) const OVERRIDE; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const base::DictionaryValue* GetGlobalConfigFromPolicy( 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const std::string userhash) const OVERRIDE; 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual const base::DictionaryValue* FindPolicyByGuidAndProfile( 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& guid, 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& profile_path) const OVERRIDE; 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // NetworkProfileObserver overrides 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnProfileAdded(const NetworkProfile& profile) OVERRIDE; 911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnProfileRemoved(const NetworkProfile& profile) OVERRIDE; 921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // PolicyApplicator::ConfigurationHandler overrides 940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void CreateConfigurationFromPolicy( 951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const base::DictionaryValue& shill_properties) OVERRIDE; 961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void UpdateExistingConfigurationWithPropertiesFromPolicy( 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::DictionaryValue& existing_properties, 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::DictionaryValue& new_properties) OVERRIDE; 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 101 virtual void OnPoliciesApplied() OVERRIDE; 102 103 private: 104 friend class ClientCertResolverTest; 105 friend class NetworkHandler; 106 friend class ManagedNetworkConfigurationHandlerTest; 107 108 struct Policies; 109 typedef std::map<std::string, linked_ptr<Policies> > UserToPoliciesMap; 110 111 ManagedNetworkConfigurationHandlerImpl(); 112 113 void Init(NetworkStateHandler* network_state_handler, 114 NetworkProfileHandler* network_profile_handler, 115 NetworkConfigurationHandler* network_configuration_handler); 116 117 void GetManagedPropertiesCallback( 118 const network_handler::DictionaryResultCallback& callback, 119 const network_handler::ErrorCallback& error_callback, 120 const std::string& service_path, 121 const base::DictionaryValue& shill_properties); 122 123 void GetPropertiesCallback( 124 const network_handler::DictionaryResultCallback& callback, 125 const std::string& service_path, 126 const base::DictionaryValue& shill_properties); 127 128 const Policies* GetPoliciesForUser(const std::string& userhash) const; 129 const Policies* GetPoliciesForProfile(const NetworkProfile& profile) const; 130 131 void OnPolicyAppliedToNetwork(const std::string& service_path); 132 133 // Helper method to append "IPConfigs" property to |properties| by extracting 134 // them from the associated DeviceState. 135 void GetIPConfigs(const std::string& service_path, 136 base::DictionaryValue* properties); 137 138 // If present, the empty string maps to the device policy. 139 UserToPoliciesMap policies_by_user_; 140 141 // Local references to the associated handler instances. 142 NetworkStateHandler* network_state_handler_; 143 NetworkProfileHandler* network_profile_handler_; 144 NetworkConfigurationHandler* network_configuration_handler_; 145 146 ObserverList<NetworkPolicyObserver> observers_; 147 148 // For Shill client callbacks 149 base::WeakPtrFactory<ManagedNetworkConfigurationHandlerImpl> 150 weak_ptr_factory_; 151 152 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerImpl); 153}; 154 155} // namespace chromeos 156 157#endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_ 158