1 // Copyright 2013 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 #include "chromeos/network/network_handler.h" 6 7 #include "base/threading/worker_pool.h" 8 #include "chromeos/dbus/dbus_thread_manager.h" 9 #include "chromeos/network/client_cert_resolver.h" 10 #include "chromeos/network/geolocation_handler.h" 11 #include "chromeos/network/managed_network_configuration_handler_impl.h" 12 #include "chromeos/network/network_activation_handler.h" 13 #include "chromeos/network/network_cert_migrator.h" 14 #include "chromeos/network/network_configuration_handler.h" 15 #include "chromeos/network/network_connection_handler.h" 16 #include "chromeos/network/network_device_handler.h" 17 #include "chromeos/network/network_event_log.h" 18 #include "chromeos/network/network_profile_handler.h" 19 #include "chromeos/network/network_profile_observer.h" 20 #include "chromeos/network/network_sms_handler.h" 21 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler_observer.h" 23 24 namespace chromeos { 25 26 static NetworkHandler* g_network_handler = NULL; 27 28 NetworkHandler::NetworkHandler() 29 : message_loop_(base::MessageLoopProxy::current()) { 30 CHECK(DBusThreadManager::IsInitialized()); 31 32 network_event_log::Initialize(); 33 34 network_state_handler_.reset(new NetworkStateHandler()); 35 network_device_handler_.reset(new NetworkDeviceHandler()); 36 network_profile_handler_.reset(new NetworkProfileHandler()); 37 network_configuration_handler_.reset(new NetworkConfigurationHandler()); 38 managed_network_configuration_handler_.reset( 39 new ManagedNetworkConfigurationHandlerImpl()); 40 if (CertLoader::IsInitialized()) { 41 network_cert_migrator_.reset(new NetworkCertMigrator()); 42 client_cert_resolver_.reset(new ClientCertResolver()); 43 } 44 network_activation_handler_.reset(new NetworkActivationHandler()); 45 network_connection_handler_.reset(new NetworkConnectionHandler()); 46 network_sms_handler_.reset(new NetworkSmsHandler()); 47 geolocation_handler_.reset(new GeolocationHandler()); 48 } 49 50 NetworkHandler::~NetworkHandler() { 51 network_event_log::Shutdown(); 52 } 53 54 void NetworkHandler::Init() { 55 network_state_handler_->InitShillPropertyHandler(); 56 network_profile_handler_->Init(network_state_handler_.get()); 57 network_configuration_handler_->Init(network_state_handler_.get()); 58 managed_network_configuration_handler_->Init( 59 network_state_handler_.get(), 60 network_profile_handler_.get(), 61 network_configuration_handler_.get()); 62 network_connection_handler_->Init(network_state_handler_.get(), 63 network_configuration_handler_.get()); 64 if (network_cert_migrator_) 65 network_cert_migrator_->Init(network_state_handler_.get()); 66 if (client_cert_resolver_) { 67 client_cert_resolver_->Init(network_state_handler_.get(), 68 managed_network_configuration_handler_.get()); 69 } 70 network_sms_handler_->Init(); 71 geolocation_handler_->Init(); 72 } 73 74 // static 75 void NetworkHandler::Initialize() { 76 CHECK(!g_network_handler); 77 g_network_handler = new NetworkHandler(); 78 g_network_handler->Init(); 79 } 80 81 // static 82 void NetworkHandler::Shutdown() { 83 CHECK(g_network_handler); 84 delete g_network_handler; 85 g_network_handler = NULL; 86 } 87 88 // static 89 NetworkHandler* NetworkHandler::Get() { 90 CHECK(g_network_handler) 91 << "NetworkHandler::Get() called before Initialize()"; 92 return g_network_handler; 93 } 94 95 // static 96 bool NetworkHandler::IsInitialized() { 97 return g_network_handler; 98 } 99 100 NetworkStateHandler* NetworkHandler::network_state_handler() { 101 return network_state_handler_.get(); 102 } 103 104 NetworkDeviceHandler* NetworkHandler::network_device_handler() { 105 return network_device_handler_.get(); 106 } 107 108 NetworkProfileHandler* NetworkHandler::network_profile_handler() { 109 return network_profile_handler_.get(); 110 } 111 112 NetworkConfigurationHandler* NetworkHandler::network_configuration_handler() { 113 return network_configuration_handler_.get(); 114 } 115 116 ManagedNetworkConfigurationHandler* 117 NetworkHandler::managed_network_configuration_handler() { 118 return managed_network_configuration_handler_.get(); 119 } 120 121 NetworkActivationHandler* NetworkHandler::network_activation_handler() { 122 return network_activation_handler_.get(); 123 } 124 125 NetworkConnectionHandler* NetworkHandler::network_connection_handler() { 126 return network_connection_handler_.get(); 127 } 128 129 NetworkSmsHandler* NetworkHandler::network_sms_handler() { 130 return network_sms_handler_.get(); 131 } 132 133 GeolocationHandler* NetworkHandler::geolocation_handler() { 134 return geolocation_handler_.get(); 135 } 136 137 } // namespace chromeos 138