| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 scoped_refptr<net::X509Certificate> matching_cert = | 104 scoped_refptr<net::X509Certificate> matching_cert = |
| 105 certificate_pattern::GetCertificateMatch( | 105 certificate_pattern::GetCertificateMatch( |
| 106 ui_data->certificate_pattern()); | 106 ui_data->certificate_pattern()); |
| 107 if (!matching_cert.get()) | 107 if (!matching_cert.get()) |
| 108 return false; | 108 return false; |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 static NetworkConnectionHandler* g_connection_handler_instance = NULL; | |
| 115 | |
| 116 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; | 114 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; |
| 117 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; | 115 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; |
| 118 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; | 116 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; |
| 119 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; | 117 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; |
| 120 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = | 118 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = |
| 121 "passphrase-required"; | 119 "passphrase-required"; |
| 122 const char NetworkConnectionHandler::kErrorActivationRequired[] = | 120 const char NetworkConnectionHandler::kErrorActivationRequired[] = |
| 123 "activation-required"; | 121 "activation-required"; |
| 124 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 122 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
| 125 "certificate-required"; | 123 "certificate-required"; |
| 126 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 124 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
| 127 "configuration-required"; | 125 "configuration-required"; |
| 128 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; | 126 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; |
| 129 | 127 |
| 130 // static | 128 NetworkConnectionHandler::NetworkConnectionHandler() |
| 131 void NetworkConnectionHandler::Initialize() { | 129 : network_state_handler_(NULL), |
| 132 CHECK(!g_connection_handler_instance); | 130 network_configuration_handler_(NULL) { |
| 133 g_connection_handler_instance = new NetworkConnectionHandler; | |
| 134 } | |
| 135 | |
| 136 // static | |
| 137 void NetworkConnectionHandler::Shutdown() { | |
| 138 CHECK(g_connection_handler_instance); | |
| 139 delete g_connection_handler_instance; | |
| 140 g_connection_handler_instance = NULL; | |
| 141 } | |
| 142 | |
| 143 // static | |
| 144 NetworkConnectionHandler* NetworkConnectionHandler::Get() { | |
| 145 CHECK(g_connection_handler_instance) | |
| 146 << "NetworkConnectionHandler::Get() called before Initialize()"; | |
| 147 return g_connection_handler_instance; | |
| 148 } | |
| 149 | |
| 150 NetworkConnectionHandler::NetworkConnectionHandler() { | |
| 151 const char* new_handlers_enabled = | 131 const char* new_handlers_enabled = |
| 152 CommandLine::ForCurrentProcess()->HasSwitch( | 132 CommandLine::ForCurrentProcess()->HasSwitch( |
| 153 chromeos::switches::kUseNewNetworkConfigurationHandlers) ? | 133 chromeos::switches::kUseNewNetworkConfigurationHandlers) ? |
| 154 "enabled" : "disabled"; | 134 "enabled" : "disabled"; |
| 155 NET_LOG_EVENT("NewNetworkConfigurationHandlers", new_handlers_enabled); | 135 NET_LOG_EVENT("NewNetworkConfigurationHandlers", new_handlers_enabled); |
| 156 } | 136 } |
| 157 | 137 |
| 158 NetworkConnectionHandler::~NetworkConnectionHandler() { | 138 NetworkConnectionHandler::~NetworkConnectionHandler() { |
| 159 } | 139 } |
| 160 | 140 |
| 141 void NetworkConnectionHandler::Init( |
| 142 NetworkStateHandler* network_state_handler, |
| 143 NetworkConfigurationHandler* network_configuration_handler) { |
| 144 network_state_handler_ = network_state_handler; |
| 145 network_configuration_handler_ = network_configuration_handler; |
| 146 } |
| 147 |
| 161 void NetworkConnectionHandler::ConnectToNetwork( | 148 void NetworkConnectionHandler::ConnectToNetwork( |
| 162 const std::string& service_path, | 149 const std::string& service_path, |
| 163 const base::Closure& success_callback, | 150 const base::Closure& success_callback, |
| 164 const network_handler::ErrorCallback& error_callback, | 151 const network_handler::ErrorCallback& error_callback, |
| 165 bool ignore_error_state) { | 152 bool ignore_error_state) { |
| 166 const NetworkState* network = | 153 const NetworkState* network = |
| 167 NetworkStateHandler::Get()->GetNetworkState(service_path); | 154 network_state_handler_->GetNetworkState(service_path); |
| 168 if (!network) { | 155 if (!network) { |
| 169 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 156 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); |
| 170 return; | 157 return; |
| 171 } | 158 } |
| 172 if (network->IsConnectedState()) { | 159 if (network->IsConnectedState()) { |
| 173 InvokeErrorCallback(service_path, error_callback, kErrorConnected); | 160 InvokeErrorCallback(service_path, error_callback, kErrorConnected); |
| 174 return; | 161 return; |
| 175 } | 162 } |
| 176 if (network->IsConnectingState() || | 163 if (network->IsConnectingState() || |
| 177 pending_requests_.find(service_path) != pending_requests_.end()) { | 164 pending_requests_.find(service_path) != pending_requests_.end()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 203 kErrorConfigurationRequired); | 190 kErrorConfigurationRequired); |
| 204 return; | 191 return; |
| 205 } | 192 } |
| 206 } | 193 } |
| 207 | 194 |
| 208 // All synchronous checks passed, add |service_path| to connecting list. | 195 // All synchronous checks passed, add |service_path| to connecting list. |
| 209 pending_requests_.insert(service_path); | 196 pending_requests_.insert(service_path); |
| 210 | 197 |
| 211 if (!network->connectable() && NetworkMayNeedCredentials(network)) { | 198 if (!network->connectable() && NetworkMayNeedCredentials(network)) { |
| 212 // Request additional properties to check. | 199 // Request additional properties to check. |
| 213 NetworkConfigurationHandler::Get()->GetProperties( | 200 network_configuration_handler_->GetProperties( |
| 214 network->path(), | 201 network->path(), |
| 215 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 202 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
| 216 AsWeakPtr(), success_callback, error_callback), | 203 AsWeakPtr(), success_callback, error_callback), |
| 217 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 204 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 218 AsWeakPtr(), network->path(), error_callback)); | 205 AsWeakPtr(), network->path(), error_callback)); |
| 219 return; | 206 return; |
| 220 } | 207 } |
| 221 // All checks passed, send connect request. | 208 // All checks passed, send connect request. |
| 222 CallShillConnect(service_path, success_callback, error_callback); | 209 CallShillConnect(service_path, success_callback, error_callback); |
| 223 } | 210 } |
| 224 | 211 |
| 225 void NetworkConnectionHandler::DisconnectNetwork( | 212 void NetworkConnectionHandler::DisconnectNetwork( |
| 226 const std::string& service_path, | 213 const std::string& service_path, |
| 227 const base::Closure& success_callback, | 214 const base::Closure& success_callback, |
| 228 const network_handler::ErrorCallback& error_callback) { | 215 const network_handler::ErrorCallback& error_callback) { |
| 229 const NetworkState* network = | 216 const NetworkState* network = |
| 230 NetworkStateHandler::Get()->GetNetworkState(service_path); | 217 network_state_handler_->GetNetworkState(service_path); |
| 231 if (!network) { | 218 if (!network) { |
| 232 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 219 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); |
| 233 return; | 220 return; |
| 234 } | 221 } |
| 235 if (!network->IsConnectedState()) { | 222 if (!network->IsConnectedState()) { |
| 236 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); | 223 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); |
| 237 return; | 224 return; |
| 238 } | 225 } |
| 239 CallShillDisconnect(service_path, success_callback, error_callback); | 226 CallShillDisconnect(service_path, success_callback, error_callback); |
| 240 } | 227 } |
| 241 | 228 |
| 242 void NetworkConnectionHandler::CallShillConnect( | 229 void NetworkConnectionHandler::CallShillConnect( |
| 243 const std::string& service_path, | 230 const std::string& service_path, |
| 244 const base::Closure& success_callback, | 231 const base::Closure& success_callback, |
| 245 const network_handler::ErrorCallback& error_callback) { | 232 const network_handler::ErrorCallback& error_callback) { |
| 246 // TODO(stevenjb): Remove SetConnectingNetwork and use this class to maintain | 233 // TODO(stevenjb): Remove SetConnectingNetwork and use this class to maintain |
| 247 // the connecting network(s) once NetworkLibrary path is eliminated. | 234 // the connecting network(s) once NetworkLibrary path is eliminated. |
| 248 NetworkStateHandler::Get()->SetConnectingNetwork(service_path); | 235 network_state_handler_->SetConnectingNetwork(service_path); |
| 249 NET_LOG_EVENT("Connect Request", service_path); | 236 NET_LOG_EVENT("Connect Request", service_path); |
| 250 DBusThreadManager::Get()->GetShillServiceClient()->Connect( | 237 DBusThreadManager::Get()->GetShillServiceClient()->Connect( |
| 251 dbus::ObjectPath(service_path), | 238 dbus::ObjectPath(service_path), |
| 252 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, | 239 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, |
| 253 AsWeakPtr(), service_path, success_callback), | 240 AsWeakPtr(), service_path, success_callback), |
| 254 base::Bind(&NetworkConnectionHandler::HandleShillFailure, | 241 base::Bind(&NetworkConnectionHandler::HandleShillFailure, |
| 255 AsWeakPtr(), service_path, error_callback)); | 242 AsWeakPtr(), service_path, error_callback)); |
| 256 } | 243 } |
| 257 | 244 |
| 258 void NetworkConnectionHandler::CallShillDisconnect( | 245 void NetworkConnectionHandler::CallShillDisconnect( |
| 259 const std::string& service_path, | 246 const std::string& service_path, |
| 260 const base::Closure& success_callback, | 247 const base::Closure& success_callback, |
| 261 const network_handler::ErrorCallback& error_callback) { | 248 const network_handler::ErrorCallback& error_callback) { |
| 262 NET_LOG_EVENT("Disconnect Request", service_path); | 249 NET_LOG_EVENT("Disconnect Request", service_path); |
| 263 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 250 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
| 264 dbus::ObjectPath(service_path), | 251 dbus::ObjectPath(service_path), |
| 265 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, | 252 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, |
| 266 AsWeakPtr(), service_path, success_callback), | 253 AsWeakPtr(), service_path, success_callback), |
| 267 base::Bind(&NetworkConnectionHandler::HandleShillFailure, | 254 base::Bind(&NetworkConnectionHandler::HandleShillFailure, |
| 268 AsWeakPtr(), service_path, error_callback)); | 255 AsWeakPtr(), service_path, error_callback)); |
| 269 } | 256 } |
| 270 | 257 |
| 271 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 258 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
| 272 const base::Closure& success_callback, | 259 const base::Closure& success_callback, |
| 273 const network_handler::ErrorCallback& error_callback, | 260 const network_handler::ErrorCallback& error_callback, |
| 274 const std::string& service_path, | 261 const std::string& service_path, |
| 275 const base::DictionaryValue& properties) { | 262 const base::DictionaryValue& properties) { |
| 276 const NetworkState* network = | 263 const NetworkState* network = |
| 277 NetworkStateHandler::Get()->GetNetworkState(service_path); | 264 network_state_handler_->GetNetworkState(service_path); |
| 278 if (!network) { | 265 if (!network) { |
| 279 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 266 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); |
| 280 return; | 267 return; |
| 281 } | 268 } |
| 282 | 269 |
| 283 // VPN requires a host and username to be set. | 270 // VPN requires a host and username to be set. |
| 284 if (network->type() == flimflam::kTypeVPN && | 271 if (network->type() == flimflam::kTypeVPN && |
| 285 !VPNIsConfigured(properties)) { | 272 !VPNIsConfigured(properties)) { |
| 286 InvokeErrorCallback(service_path, error_callback, | 273 InvokeErrorCallback(service_path, error_callback, |
| 287 kErrorConfigurationRequired); | 274 kErrorConfigurationRequired); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 const network_handler::ErrorCallback& error_callback, | 315 const network_handler::ErrorCallback& error_callback, |
| 329 const std::string& error_name, | 316 const std::string& error_name, |
| 330 const std::string& error_message) { | 317 const std::string& error_message) { |
| 331 pending_requests_.erase(service_path); | 318 pending_requests_.erase(service_path); |
| 332 std::string error = "Connect Failure: " + error_name + ": " + error_message; | 319 std::string error = "Connect Failure: " + error_name + ": " + error_message; |
| 333 network_handler::ShillErrorCallbackFunction( | 320 network_handler::ShillErrorCallbackFunction( |
| 334 service_path, error_callback, error_name, error_message); | 321 service_path, error_callback, error_name, error_message); |
| 335 } | 322 } |
| 336 | 323 |
| 337 } // namespace chromeos | 324 } // namespace chromeos |
| OLD | NEW |