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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 bool passphrase_required = false; | 93 bool passphrase_required = false; |
94 properties->GetBooleanWithoutPathExpansion( | 94 properties->GetBooleanWithoutPathExpansion( |
95 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 95 flimflam::kPassphraseRequiredProperty, &passphrase_required); |
96 std::string passphrase; | 96 std::string passphrase; |
97 properties->GetStringWithoutPathExpansion( | 97 properties->GetStringWithoutPathExpansion( |
98 flimflam::kOpenVPNPasswordProperty, &passphrase); | 98 flimflam::kOpenVPNPasswordProperty, &passphrase); |
99 if (passphrase_required && passphrase.empty()) { | 99 if (passphrase_required && passphrase.empty()) { |
100 NET_LOG_EVENT("OpenVPN: No passphrase", service_path); | 100 NET_LOG_EVENT("OpenVPN: No passphrase", service_path); |
101 return false; | 101 return false; |
102 } | 102 } |
103 std::string client_cert_id; | |
104 properties->GetStringWithoutPathExpansion( | |
105 flimflam::kOpenVPNClientCertIdProperty, &client_cert_id); | |
106 if (client_cert_id.empty()) { | |
107 NET_LOG_EVENT("OpenVPN: No cert id", service_path); | |
108 return false; | |
109 } | |
110 NET_LOG_EVENT("OpenVPN Is Configured", service_path); | 103 NET_LOG_EVENT("OpenVPN Is Configured", service_path); |
111 } else { | 104 } else { |
112 bool passphrase_required = false; | 105 bool passphrase_required = false; |
113 std::string passphrase; | 106 std::string passphrase; |
114 properties->GetBooleanWithoutPathExpansion( | 107 properties->GetBooleanWithoutPathExpansion( |
115 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); | 108 flimflam::kL2tpIpsecPskRequiredProperty, &passphrase_required); |
116 properties->GetStringWithoutPathExpansion( | 109 properties->GetStringWithoutPathExpansion( |
117 flimflam::kL2tpIpsecPskProperty, &passphrase); | 110 flimflam::kL2tpIpsecPskProperty, &passphrase); |
118 if (passphrase_required && passphrase.empty()) | 111 if (passphrase_required && passphrase.empty()) |
119 return false; | 112 return false; |
120 NET_LOG_EVENT("VPN Is Configured", service_path); | 113 NET_LOG_EVENT("VPN Is Configured", service_path); |
121 } | 114 } |
122 return true; | 115 return true; |
123 } | 116 } |
124 | 117 |
125 bool CertificateIsConfigured(NetworkUIData* ui_data) { | |
126 if (ui_data->certificate_type() != CLIENT_CERT_TYPE_PATTERN) | |
127 return true; // No certificate or a reference. | |
128 if (ui_data->onc_source() == onc::ONC_SOURCE_DEVICE_POLICY) { | |
129 // We skip checking certificate patterns for device policy ONC so that an | |
130 // unmanaged user can't get to the place where a cert is presented for them | |
131 // involuntarily. | |
132 return true; | |
133 } | |
134 if (ui_data->certificate_pattern().Empty()) | |
135 return false; | |
136 | |
137 // Find the matching certificate. | |
138 scoped_refptr<net::X509Certificate> matching_cert = | |
139 certificate_pattern::GetCertificateMatch( | |
140 ui_data->certificate_pattern()); | |
141 if (!matching_cert.get()) | |
142 return false; | |
143 return true; | |
144 } | |
145 | |
146 } // namespace | 118 } // namespace |
147 | 119 |
148 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; | 120 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; |
149 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; | 121 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; |
150 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; | 122 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; |
151 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; | 123 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; |
152 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = | 124 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = |
153 "passphrase-required"; | 125 "passphrase-required"; |
154 const char NetworkConnectionHandler::kErrorActivationRequired[] = | 126 const char NetworkConnectionHandler::kErrorActivationRequired[] = |
155 "activation-required"; | 127 "activation-required"; |
156 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 128 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
157 "certificate-required"; | 129 "certificate-required"; |
158 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 130 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
159 "configuration-required"; | 131 "configuration-required"; |
160 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; | 132 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; |
161 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; | 133 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; |
162 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; | 134 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; |
163 | 135 |
164 struct NetworkConnectionHandler::ConnectRequest { | 136 struct NetworkConnectionHandler::ConnectRequest { |
165 ConnectRequest(const base::Closure& success, | 137 ConnectRequest(const std::string& service_path, |
| 138 const base::Closure& success, |
166 const network_handler::ErrorCallback& error) | 139 const network_handler::ErrorCallback& error) |
167 : connect_state(CONNECT_REQUESTED), | 140 : service_path(service_path), |
| 141 connect_state(CONNECT_REQUESTED), |
168 success_callback(success), | 142 success_callback(success), |
169 error_callback(error) { | 143 error_callback(error) { |
170 } | 144 } |
171 enum ConnectState { | 145 enum ConnectState { |
172 CONNECT_REQUESTED = 0, | 146 CONNECT_REQUESTED = 0, |
173 CONNECT_STARTED = 1, | 147 CONNECT_STARTED = 1, |
174 CONNECT_CONNECTING = 2 | 148 CONNECT_CONNECTING = 2 |
175 }; | 149 }; |
| 150 std::string service_path; |
176 ConnectState connect_state; | 151 ConnectState connect_state; |
177 base::Closure success_callback; | 152 base::Closure success_callback; |
178 network_handler::ErrorCallback error_callback; | 153 network_handler::ErrorCallback error_callback; |
179 }; | 154 }; |
180 | 155 |
181 NetworkConnectionHandler::NetworkConnectionHandler() | 156 NetworkConnectionHandler::NetworkConnectionHandler() |
182 : network_state_handler_(NULL), | 157 : cert_loader_(NULL), |
183 network_configuration_handler_(NULL) { | 158 network_state_handler_(NULL), |
184 const char* new_handler_enabled = | 159 network_configuration_handler_(NULL), |
185 CommandLine::ForCurrentProcess()->HasSwitch( | 160 logged_in_(false), |
186 chromeos::switches::kUseNewNetworkConnectionHandler) ? | 161 certificates_loaded_(false) { |
187 "enabled" : "disabled"; | |
188 NET_LOG_EVENT("NewNetworkConnectionHandler", new_handler_enabled); | |
189 } | 162 } |
190 | 163 |
191 NetworkConnectionHandler::~NetworkConnectionHandler() { | 164 NetworkConnectionHandler::~NetworkConnectionHandler() { |
192 if (network_state_handler_) | 165 if (network_state_handler_) |
193 network_state_handler_->RemoveObserver(this); | 166 network_state_handler_->RemoveObserver(this); |
| 167 if (cert_loader_) |
| 168 cert_loader_->RemoveObserver(this); |
| 169 if (LoginState::IsInitialized()) |
| 170 LoginState::Get()->RemoveObserver(this); |
194 } | 171 } |
195 | 172 |
196 void NetworkConnectionHandler::Init( | 173 void NetworkConnectionHandler::Init( |
| 174 CertLoader* cert_loader, |
197 NetworkStateHandler* network_state_handler, | 175 NetworkStateHandler* network_state_handler, |
198 NetworkConfigurationHandler* network_configuration_handler) { | 176 NetworkConfigurationHandler* network_configuration_handler) { |
| 177 LoginState::Get()->AddObserver(this); |
| 178 logged_in_ = |
| 179 LoginState::Get()->GetLoggedInState() == LoginState::LOGGED_IN_ACTIVE; |
| 180 if (cert_loader) { |
| 181 cert_loader_ = cert_loader; |
| 182 cert_loader_->AddObserver(this); |
| 183 certificates_loaded_ = cert_loader->certificates_loaded(); |
| 184 } else { |
| 185 // TODO(stevenjb): Require a mock or stub cert_loader in tests. |
| 186 certificates_loaded_ = true; |
| 187 } |
199 if (network_state_handler) { | 188 if (network_state_handler) { |
200 network_state_handler_ = network_state_handler; | 189 network_state_handler_ = network_state_handler; |
201 network_state_handler_->AddObserver(this); | 190 network_state_handler_->AddObserver(this); |
202 } | 191 } |
203 network_configuration_handler_ = network_configuration_handler; | 192 network_configuration_handler_ = network_configuration_handler; |
204 } | 193 } |
205 | 194 |
| 195 void NetworkConnectionHandler::LoggedInStateChanged( |
| 196 LoginState::LoggedInState state) { |
| 197 NET_LOG_EVENT("NewNetworkConnectionHandler", |
| 198 CommandLine::ForCurrentProcess()->HasSwitch( |
| 199 chromeos::switches::kUseNewNetworkConnectionHandler) ? |
| 200 "enabled" : "disabled"); |
| 201 if (state == LoginState::LOGGED_IN_ACTIVE) { |
| 202 logged_in_ = true; |
| 203 NET_LOG_EVENT("Logged In", ""); |
| 204 } |
| 205 } |
| 206 |
| 207 void NetworkConnectionHandler::OnCertificatesLoaded( |
| 208 const net::CertificateList& cert_list, |
| 209 bool initial_load) { |
| 210 certificates_loaded_ = true; |
| 211 NET_LOG_EVENT("Certificates Loaded", ""); |
| 212 if (queued_connect_) { |
| 213 NET_LOG_EVENT("Connecting to Queued Network", |
| 214 queued_connect_->service_path); |
| 215 ConnectToNetwork(queued_connect_->service_path, |
| 216 queued_connect_->success_callback, |
| 217 queued_connect_->error_callback, |
| 218 true /* ignore_error_state */); |
| 219 } else if (initial_load) { |
| 220 // Once certificates have loaded, connect to the "best" available network. |
| 221 NetworkHandler::Get()->network_state_handler()->ConnectToBestWifiNetwork(); |
| 222 } |
| 223 } |
| 224 |
206 void NetworkConnectionHandler::ConnectToNetwork( | 225 void NetworkConnectionHandler::ConnectToNetwork( |
207 const std::string& service_path, | 226 const std::string& service_path, |
208 const base::Closure& success_callback, | 227 const base::Closure& success_callback, |
209 const network_handler::ErrorCallback& error_callback, | 228 const network_handler::ErrorCallback& error_callback, |
210 bool ignore_error_state) { | 229 bool ignore_error_state) { |
211 NET_LOG_USER("ConnectToNetwork", service_path); | 230 NET_LOG_USER("ConnectToNetwork", service_path); |
| 231 // Clear any existing queued connect request. |
| 232 queued_connect_.reset(); |
212 const NetworkState* network = | 233 const NetworkState* network = |
213 network_state_handler_->GetNetworkState(service_path); | 234 network_state_handler_->GetNetworkState(service_path); |
214 if (!network) { | 235 if (!network) { |
215 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 236 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); |
216 return; | 237 return; |
217 } | 238 } |
218 if (HasConnectingNetwork(service_path)) { | 239 if (HasConnectingNetwork(service_path)) { |
219 NET_LOG_USER("Connect Request While Pending", service_path); | 240 NET_LOG_USER("Connect Request While Pending", service_path); |
220 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 241 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
221 return; | 242 return; |
(...skipping 28 matching lines...) Expand all Loading... |
250 } | 271 } |
251 if (network->HasAuthenticationError()) { | 272 if (network->HasAuthenticationError()) { |
252 InvokeErrorCallback(service_path, error_callback, | 273 InvokeErrorCallback(service_path, error_callback, |
253 kErrorConfigurationRequired); | 274 kErrorConfigurationRequired); |
254 return; | 275 return; |
255 } | 276 } |
256 } | 277 } |
257 | 278 |
258 // All synchronous checks passed, add |service_path| to connecting list. | 279 // All synchronous checks passed, add |service_path| to connecting list. |
259 pending_requests_.insert(std::make_pair( | 280 pending_requests_.insert(std::make_pair( |
260 service_path, ConnectRequest(success_callback, error_callback))); | 281 service_path, |
| 282 ConnectRequest(service_path, success_callback, error_callback))); |
261 | 283 |
262 if (!NetworkConnectable(network) && NetworkMayNeedCredentials(network)) { | 284 if (!NetworkConnectable(network) && |
| 285 NetworkMayNeedCredentials(network)) { |
263 // Request additional properties to check. | 286 // Request additional properties to check. |
264 network_configuration_handler_->GetProperties( | 287 network_configuration_handler_->GetProperties( |
265 network->path(), | 288 network->path(), |
266 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 289 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
267 AsWeakPtr()), | 290 AsWeakPtr()), |
268 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 291 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
269 AsWeakPtr(), network->path())); | 292 AsWeakPtr(), network->path())); |
270 return; | 293 return; |
271 } | 294 } |
272 // All checks passed, send connect request. | 295 // All checks passed, send connect request. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 pending_requests_.find(service_path); | 336 pending_requests_.find(service_path); |
314 return iter != pending_requests_.end() ? &(iter->second) : NULL; | 337 return iter != pending_requests_.end() ? &(iter->second) : NULL; |
315 } | 338 } |
316 | 339 |
317 // ConnectToNetwork implementation | 340 // ConnectToNetwork implementation |
318 | 341 |
319 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 342 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
320 const std::string& service_path, | 343 const std::string& service_path, |
321 const base::DictionaryValue& properties) { | 344 const base::DictionaryValue& properties) { |
322 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 345 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
323 ConnectRequest* request = pending_request(service_path); | |
324 DCHECK(request); | |
325 network_handler::ErrorCallback error_callback = request->error_callback; | |
326 | 346 |
327 const NetworkState* network = | 347 const NetworkState* network = |
328 network_state_handler_->GetNetworkState(service_path); | 348 network_state_handler_->GetNetworkState(service_path); |
329 if (!network) { | 349 if (!network) { |
330 pending_requests_.erase(service_path); | 350 ErrorCallbackForPendingRequest(service_path, kErrorNotFound); |
331 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
332 return; | 351 return; |
333 } | 352 } |
334 | 353 |
335 // VPN requires a host and username to be set. | 354 // VPN requires a host and username to be set. |
336 if (network->type() == flimflam::kTypeVPN && | 355 if (network->type() == flimflam::kTypeVPN && |
337 !VPNIsConfigured(service_path, properties)) { | 356 !VPNIsConfigured(service_path, properties)) { |
338 pending_requests_.erase(service_path); | 357 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
339 InvokeErrorCallback(service_path, error_callback, | |
340 kErrorConfigurationRequired); | |
341 return; | 358 return; |
342 } | 359 } |
343 | 360 |
344 // Check certificate properties in kUIDataProperty. | 361 // Check certificate properties in kUIDataProperty. |
345 scoped_ptr<NetworkUIData> ui_data = | 362 scoped_ptr<NetworkUIData> ui_data = |
346 ManagedNetworkConfigurationHandler::GetUIData(properties); | 363 ManagedNetworkConfigurationHandler::GetUIData(properties); |
347 if (ui_data && !CertificateIsConfigured(ui_data.get())) { | 364 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { |
348 pending_requests_.erase(service_path); | 365 // User must be logged in to connect to a network requiring a certificate. |
349 InvokeErrorCallback(service_path, error_callback, | 366 if (!logged_in_ || !cert_loader_) { |
350 kErrorCertificateRequired); | 367 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
351 return; | 368 return; |
| 369 } |
| 370 // If certificates have not been loaded yet, queue the connect request. |
| 371 if (!certificates_loaded_) { |
| 372 ConnectRequest* request = pending_request(service_path); |
| 373 DCHECK(request); |
| 374 NET_LOG_EVENT("Connect Request Queued", service_path); |
| 375 queued_connect_.reset(new ConnectRequest( |
| 376 service_path, request->success_callback, request->error_callback)); |
| 377 pending_requests_.erase(service_path); |
| 378 return; |
| 379 } |
| 380 |
| 381 // Ensure the certificate is available. |
| 382 std::string pkcs11_id; |
| 383 if (!CertificateIsConfigured(ui_data.get(), &pkcs11_id)) { |
| 384 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 385 return; |
| 386 } |
| 387 |
| 388 // The network may not be 'Connectable' because the certificate data is |
| 389 // not set up, so configure tpm slot/pin and pkcs11_id before connecting. |
| 390 // TODO(stevenjb): Remove this code once NetworkConfigurationHandler |
| 391 // handles this. |
| 392 NET_LOG_EVENT("Configuring Network", service_path); |
| 393 const std::string& tpm_slot = cert_loader_->tpm_token_slot(); |
| 394 const std::string& tpm_pin = cert_loader_->tpm_user_pin(); |
| 395 base::DictionaryValue config_properties; |
| 396 network->GetConfigProperties(&config_properties); |
| 397 |
| 398 if (network->type() == flimflam::kTypeVPN) { |
| 399 std::string provider_type; |
| 400 properties.GetString(flimflam::kTypeProperty, &provider_type); |
| 401 if (provider_type == flimflam::kProviderOpenVpn) { |
| 402 config_properties.SetStringWithoutPathExpansion( |
| 403 flimflam::kOpenVPNClientCertSlotProperty, tpm_slot); |
| 404 config_properties.SetStringWithoutPathExpansion( |
| 405 flimflam::kOpenVPNPinProperty, tpm_pin); |
| 406 config_properties.SetStringWithoutPathExpansion( |
| 407 flimflam::kOpenVPNClientCertIdProperty, pkcs11_id); |
| 408 } else { |
| 409 config_properties.SetStringWithoutPathExpansion( |
| 410 flimflam::kL2tpIpsecClientCertSlotProperty, tpm_slot); |
| 411 config_properties.SetStringWithoutPathExpansion( |
| 412 flimflam::kL2tpIpsecPinProperty, tpm_pin); |
| 413 config_properties.SetStringWithoutPathExpansion( |
| 414 flimflam::kL2tpIpsecClientCertIdProperty, pkcs11_id); |
| 415 } |
| 416 } else if (network->type() == flimflam::kTypeWifi) { |
| 417 config_properties.SetStringWithoutPathExpansion( |
| 418 flimflam::kEapPinProperty, cert_loader_->tpm_user_pin()); |
| 419 config_properties.SetStringWithoutPathExpansion( |
| 420 flimflam::kEapCertIdProperty, pkcs11_id); |
| 421 config_properties.SetStringWithoutPathExpansion( |
| 422 flimflam::kEapKeyIdProperty, pkcs11_id); |
| 423 } |
| 424 network_configuration_handler_->SetProperties( |
| 425 service_path, |
| 426 config_properties, |
| 427 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
| 428 AsWeakPtr(), service_path), |
| 429 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 430 AsWeakPtr(), service_path)); |
| 431 return; |
352 } | 432 } |
353 | 433 |
354 CallShillConnect(service_path); | 434 // Otherwise, we need to configure the network. |
| 435 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
355 } | 436 } |
356 | 437 |
357 void NetworkConnectionHandler::CallShillConnect( | 438 void NetworkConnectionHandler::CallShillConnect( |
358 const std::string& service_path) { | 439 const std::string& service_path) { |
359 NET_LOG_EVENT("Connect Request", service_path); | 440 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); |
360 DBusThreadManager::Get()->GetShillServiceClient()->Connect( | 441 DBusThreadManager::Get()->GetShillServiceClient()->Connect( |
361 dbus::ObjectPath(service_path), | 442 dbus::ObjectPath(service_path), |
362 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, | 443 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, |
363 AsWeakPtr(), service_path), | 444 AsWeakPtr(), service_path), |
364 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, | 445 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, |
365 AsWeakPtr(), service_path)); | 446 AsWeakPtr(), service_path)); |
366 } | 447 } |
367 | 448 |
368 void NetworkConnectionHandler::HandleConfigurationFailure( | 449 void NetworkConnectionHandler::HandleConfigurationFailure( |
369 const std::string& service_path, | 450 const std::string& service_path, |
370 const std::string& error_name, | 451 const std::string& error_name, |
371 scoped_ptr<base::DictionaryValue> error_data) { | 452 scoped_ptr<base::DictionaryValue> error_data) { |
372 ConnectRequest* request = pending_request(service_path); | 453 ConnectRequest* request = pending_request(service_path); |
373 DCHECK(request); | 454 DCHECK(request); |
374 network_handler::ErrorCallback error_callback = request->error_callback; | 455 network_handler::ErrorCallback error_callback = request->error_callback; |
375 pending_requests_.erase(service_path); | 456 pending_requests_.erase(service_path); |
376 if (!error_callback.is_null()) | 457 if (!error_callback.is_null()) |
377 error_callback.Run(error_name, error_data.Pass()); | 458 error_callback.Run(error_name, error_data.Pass()); |
378 } | 459 } |
379 | 460 |
380 void NetworkConnectionHandler::HandleShillConnectSuccess( | 461 void NetworkConnectionHandler::HandleShillConnectSuccess( |
381 const std::string& service_path) { | 462 const std::string& service_path) { |
382 ConnectRequest* request = pending_request(service_path); | 463 ConnectRequest* request = pending_request(service_path); |
383 DCHECK(request); | 464 DCHECK(request); |
384 request->connect_state = ConnectRequest::CONNECT_STARTED; | 465 request->connect_state = ConnectRequest::CONNECT_STARTED; |
385 NET_LOG_EVENT("Connect Request Sent", service_path); | 466 NET_LOG_EVENT("Connect Request Acknowledged", service_path); |
386 // Do not call success_callback here, wait for one of the following | 467 // Do not call success_callback here, wait for one of the following |
387 // conditions: | 468 // conditions: |
388 // * State transitions to a non connecting state indicating succes or failure | 469 // * State transitions to a non connecting state indicating succes or failure |
389 // * Network is no longer in the visible list, indicating failure | 470 // * Network is no longer in the visible list, indicating failure |
390 CheckPendingRequest(service_path); | 471 CheckPendingRequest(service_path); |
391 } | 472 } |
392 | 473 |
393 void NetworkConnectionHandler::HandleShillConnectFailure( | 474 void NetworkConnectionHandler::HandleShillConnectFailure( |
394 const std::string& service_path, | 475 const std::string& service_path, |
395 const std::string& error_name, | 476 const std::string& error_name, |
396 const std::string& error_message) { | 477 const std::string& error_message) { |
397 ConnectRequest* request = pending_request(service_path); | 478 ConnectRequest* request = pending_request(service_path); |
398 DCHECK(request); | 479 DCHECK(request); |
399 network_handler::ErrorCallback error_callback = request->error_callback; | 480 network_handler::ErrorCallback error_callback = request->error_callback; |
400 pending_requests_.erase(service_path); | 481 pending_requests_.erase(service_path); |
401 std::string error = "Connect Failure: " + error_name + ": " + error_message; | 482 std::string error = "Connect Failure: " + error_name + ": " + error_message; |
402 network_handler::ShillErrorCallbackFunction( | 483 network_handler::ShillErrorCallbackFunction( |
403 service_path, error_callback, error_name, error_message); | 484 service_path, error_callback, error_name, error_message); |
404 } | 485 } |
405 | 486 |
406 void NetworkConnectionHandler::CheckPendingRequest( | 487 void NetworkConnectionHandler::CheckPendingRequest( |
407 const std::string service_path) { | 488 const std::string service_path) { |
408 ConnectRequest* request = pending_request(service_path); | 489 ConnectRequest* request = pending_request(service_path); |
409 DCHECK(request); | 490 DCHECK(request); |
410 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 491 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
411 return; // Request has not started, ignore update | 492 return; // Request has not started, ignore update |
412 const NetworkState* network = | 493 const NetworkState* network = |
413 network_state_handler_->GetNetworkState(service_path); | 494 network_state_handler_->GetNetworkState(service_path); |
414 if (!network) { | 495 if (!network) { |
415 network_handler::ErrorCallback error_callback = request->error_callback; | 496 ErrorCallbackForPendingRequest(service_path, kErrorNotFound); |
416 pending_requests_.erase(service_path); | |
417 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
418 return; | 497 return; |
419 } | 498 } |
420 if (network->IsConnectingState()) { | 499 if (network->IsConnectingState()) { |
421 request->connect_state = ConnectRequest::CONNECT_CONNECTING; | 500 request->connect_state = ConnectRequest::CONNECT_CONNECTING; |
422 return; | 501 return; |
423 } | 502 } |
424 if (network->IsConnectedState()) { | 503 if (network->IsConnectedState()) { |
425 NET_LOG_EVENT("Connect Request Succeeded", service_path); | 504 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
426 if (!request->success_callback.is_null()) | 505 if (!request->success_callback.is_null()) |
427 request->success_callback.Run(); | 506 request->success_callback.Run(); |
(...skipping 27 matching lines...) Expand all Loading... |
455 error_callback.Run(error_name, error_data.Pass()); | 534 error_callback.Run(error_name, error_data.Pass()); |
456 } | 535 } |
457 | 536 |
458 void NetworkConnectionHandler::CheckAllPendingRequests() { | 537 void NetworkConnectionHandler::CheckAllPendingRequests() { |
459 for (std::map<std::string, ConnectRequest>::iterator iter = | 538 for (std::map<std::string, ConnectRequest>::iterator iter = |
460 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { | 539 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { |
461 CheckPendingRequest(iter->first); | 540 CheckPendingRequest(iter->first); |
462 } | 541 } |
463 } | 542 } |
464 | 543 |
| 544 bool NetworkConnectionHandler::CertificateIsConfigured(NetworkUIData* ui_data, |
| 545 std::string* pkcs11_id) { |
| 546 if (ui_data->certificate_pattern().Empty()) |
| 547 return false; |
| 548 |
| 549 // Find the matching certificate. |
| 550 scoped_refptr<net::X509Certificate> matching_cert = |
| 551 certificate_pattern::GetCertificateMatch(ui_data->certificate_pattern()); |
| 552 if (!matching_cert.get()) |
| 553 return false; |
| 554 *pkcs11_id = cert_loader_->GetPkcs11IdForCert(*matching_cert.get()); |
| 555 return true; |
| 556 } |
| 557 |
| 558 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 559 const std::string& service_path, |
| 560 const std::string& error_name) { |
| 561 ConnectRequest* request = pending_request(service_path); |
| 562 DCHECK(request); |
| 563 // Remove the entry before invoking the callback in case it triggers a retry. |
| 564 network_handler::ErrorCallback error_callback = request->error_callback; |
| 565 pending_requests_.erase(service_path); |
| 566 InvokeErrorCallback(service_path, error_callback, error_name); |
| 567 } |
| 568 |
465 // Disconnect | 569 // Disconnect |
466 | 570 |
467 void NetworkConnectionHandler::CallShillDisconnect( | 571 void NetworkConnectionHandler::CallShillDisconnect( |
468 const std::string& service_path, | 572 const std::string& service_path, |
469 const base::Closure& success_callback, | 573 const base::Closure& success_callback, |
470 const network_handler::ErrorCallback& error_callback) { | 574 const network_handler::ErrorCallback& error_callback) { |
471 NET_LOG_USER("Disconnect Request", service_path); | 575 NET_LOG_USER("Disconnect Request", service_path); |
472 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 576 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
473 dbus::ObjectPath(service_path), | 577 dbus::ObjectPath(service_path), |
474 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, | 578 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, |
(...skipping 14 matching lines...) Expand all Loading... |
489 const network_handler::ErrorCallback& error_callback, | 593 const network_handler::ErrorCallback& error_callback, |
490 const std::string& error_name, | 594 const std::string& error_name, |
491 const std::string& error_message) { | 595 const std::string& error_message) { |
492 std::string error = | 596 std::string error = |
493 "Disconnect Failure: " + error_name + ": " + error_message; | 597 "Disconnect Failure: " + error_name + ": " + error_message; |
494 network_handler::ShillErrorCallbackFunction( | 598 network_handler::ShillErrorCallbackFunction( |
495 service_path, error_callback, error_name, error_message); | 599 service_path, error_callback, error_name, error_message); |
496 } | 600 } |
497 | 601 |
498 } // namespace chromeos | 602 } // namespace chromeos |
OLD | NEW |