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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "base/time/time.h" | |
13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
14 #include "chromeos/dbus/shill_manager_client.h" | 15 #include "chromeos/dbus/shill_manager_client.h" |
15 #include "chromeos/dbus/shill_service_client.h" | 16 #include "chromeos/dbus/shill_service_client.h" |
16 #include "chromeos/network/certificate_pattern.h" | 17 #include "chromeos/network/certificate_pattern.h" |
17 #include "chromeos/network/client_cert_resolver.h" | 18 #include "chromeos/network/client_cert_resolver.h" |
18 #include "chromeos/network/client_cert_util.h" | 19 #include "chromeos/network/client_cert_util.h" |
19 #include "chromeos/network/managed_network_configuration_handler.h" | 20 #include "chromeos/network/managed_network_configuration_handler.h" |
20 #include "chromeos/network/network_configuration_handler.h" | 21 #include "chromeos/network/network_configuration_handler.h" |
21 #include "chromeos/network/network_event_log.h" | 22 #include "chromeos/network/network_event_log.h" |
22 #include "chromeos/network/network_profile_handler.h" | 23 #include "chromeos/network/network_profile_handler.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 return NetworkProfileHandler::GetSharedProfilePath(); | 87 return NetworkProfileHandler::GetSharedProfilePath(); |
87 } | 88 } |
88 const NetworkProfile* profile = | 89 const NetworkProfile* profile = |
89 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); | 90 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); |
90 return profile ? profile->path | 91 return profile ? profile->path |
91 : NetworkProfileHandler::GetSharedProfilePath(); | 92 : NetworkProfileHandler::GetSharedProfilePath(); |
92 } | 93 } |
93 | 94 |
94 } // namespace | 95 } // namespace |
95 | 96 |
97 // Static constants. | |
96 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; | 98 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; |
97 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; | 99 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; |
98 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; | 100 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; |
99 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; | 101 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; |
100 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = | 102 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = |
101 "passphrase-required"; | 103 "passphrase-required"; |
102 const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase"; | 104 const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase"; |
103 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 105 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
104 "certificate-required"; | 106 "certificate-required"; |
105 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 107 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
(...skipping 11 matching lines...) Expand all Loading... | |
117 "cert-load-timeout"; | 119 "cert-load-timeout"; |
118 const char NetworkConnectionHandler::kErrorUnmanagedNetwork[] = | 120 const char NetworkConnectionHandler::kErrorUnmanagedNetwork[] = |
119 "unmanaged-network"; | 121 "unmanaged-network"; |
120 const char NetworkConnectionHandler::kErrorActivateFailed[] = "activate-failed"; | 122 const char NetworkConnectionHandler::kErrorActivateFailed[] = "activate-failed"; |
121 const char NetworkConnectionHandler::kErrorEnabledOrDisabledWhenNotAvailable[] = | 123 const char NetworkConnectionHandler::kErrorEnabledOrDisabledWhenNotAvailable[] = |
122 "not-available"; | 124 "not-available"; |
123 const char | 125 const char |
124 NetworkConnectionHandler::kErrorTetherConnectionAttemptWithNoDelegate[] = | 126 NetworkConnectionHandler::kErrorTetherConnectionAttemptWithNoDelegate[] = |
125 "tether-with-no-delegate"; | 127 "tether-with-no-delegate"; |
126 | 128 |
127 struct NetworkConnectionHandler::ConnectRequest { | 129 // Implementation. |
stevenjb
2017/05/03 22:05:38
Move this to a separate file.
Kyle Horimoto
2017/05/03 22:38:29
Done.
| |
128 ConnectRequest(const std::string& service_path, | 130 class CHROMEOS_EXPORT NetworkConnectionHandlerImpl |
129 const std::string& profile_path, | 131 : public NetworkConnectionHandler, |
130 const base::Closure& success, | 132 public base::SupportsWeakPtr<NetworkConnectionHandlerImpl> { |
131 const network_handler::ErrorCallback& error) | 133 public: |
132 : service_path(service_path), | 134 NetworkConnectionHandlerImpl(); |
133 profile_path(profile_path), | 135 ~NetworkConnectionHandlerImpl() override; |
134 connect_state(CONNECT_REQUESTED), | 136 |
135 success_callback(success), | 137 // NetworkConnectionHandler: |
136 error_callback(error) { | 138 void ConnectToNetwork(const std::string& service_path, |
137 } | 139 const base::Closure& success_callback, |
138 enum ConnectState { | 140 const network_handler::ErrorCallback& error_callback, |
139 CONNECT_REQUESTED = 0, | 141 bool check_error_state) override; |
140 CONNECT_STARTED = 1, | 142 void DisconnectNetwork( |
141 CONNECT_CONNECTING = 2 | 143 const std::string& service_path, |
144 const base::Closure& success_callback, | |
145 const network_handler::ErrorCallback& error_callback) override; | |
146 bool HasConnectingNetwork(const std::string& service_path) override; | |
147 bool HasPendingConnectRequest() override; | |
148 | |
149 // NetworkStateHandlerObserver | |
150 void NetworkListChanged() override; | |
151 void NetworkPropertiesUpdated(const NetworkState* network) override; | |
152 | |
153 // LoginState::Observer | |
154 void LoggedInStateChanged() override; | |
155 | |
156 // CertLoader::Observer | |
157 void OnCertificatesLoaded(const net::CertificateList& cert_list, | |
158 bool initial_load) override; | |
159 | |
160 protected: | |
161 void Init(NetworkStateHandler* network_state_handler, | |
162 NetworkConfigurationHandler* network_configuration_handler, | |
163 ManagedNetworkConfigurationHandler* | |
164 managed_network_configuration_handler) override; | |
165 | |
166 private: | |
167 ////////////////////////////////////////////////////////////////////////////// | |
168 friend class NetworkHandler; | |
169 friend class NetworkConnectionHandlerTest; | |
170 | |
171 struct ConnectRequest { | |
172 ConnectRequest(const std::string& service_path, | |
173 const std::string& profile_path, | |
174 const base::Closure& success, | |
175 const network_handler::ErrorCallback& error) | |
176 : service_path(service_path), | |
177 profile_path(profile_path), | |
178 connect_state(CONNECT_REQUESTED), | |
179 success_callback(success), | |
180 error_callback(error) {} | |
181 enum ConnectState { | |
182 CONNECT_REQUESTED = 0, | |
183 CONNECT_STARTED = 1, | |
184 CONNECT_CONNECTING = 2 | |
185 }; | |
186 std::string service_path; | |
187 std::string profile_path; | |
188 ConnectState connect_state; | |
189 base::Closure success_callback; | |
190 network_handler::ErrorCallback error_callback; | |
142 }; | 191 }; |
143 std::string service_path; | 192 |
144 std::string profile_path; | 193 ConnectRequest* GetPendingRequest(const std::string& service_path); |
145 ConnectState connect_state; | 194 |
146 base::Closure success_callback; | 195 // Callback from Shill.Service.GetProperties. Parses |properties| to verify |
147 network_handler::ErrorCallback error_callback; | 196 // whether or not the network appears to be configured. If configured, |
197 // attempts a connection, otherwise invokes error_callback from | |
198 // pending_requests_[service_path]. |check_error_state| is passed from | |
199 // ConnectToNetwork(), see comment for info. | |
200 void VerifyConfiguredAndConnect(bool check_error_state, | |
201 const std::string& service_path, | |
202 const base::DictionaryValue& properties); | |
203 | |
204 bool IsNetworkProhibitedByPolicy(const std::string& type, | |
205 const std::string& guid, | |
206 const std::string& profile_path); | |
207 | |
208 // Queues a connect request until certificates have loaded. | |
209 void QueueConnectRequest(const std::string& service_path); | |
210 | |
211 // Checks to see if certificates have loaded and if not, cancels any queued | |
212 // connect request and notifies the user. | |
213 void CheckCertificatesLoaded(); | |
214 | |
215 // Handles connecting to a queued network after certificates are loaded or | |
216 // handle cert load timeout. | |
217 void ConnectToQueuedNetwork(); | |
218 | |
219 // Calls Shill.Manager.Connect asynchronously. | |
220 void CallShillConnect(const std::string& service_path); | |
221 | |
222 // Handles failure from ConfigurationHandler calls. | |
223 void HandleConfigurationFailure( | |
224 const std::string& service_path, | |
225 const std::string& error_name, | |
226 std::unique_ptr<base::DictionaryValue> error_data); | |
227 | |
228 // Handles success or failure from Shill.Service.Connect. | |
229 void HandleShillConnectSuccess(const std::string& service_path); | |
230 void HandleShillConnectFailure(const std::string& service_path, | |
231 const std::string& error_name, | |
232 const std::string& error_message); | |
233 | |
234 // Note: |service_path| is passed by value here, because in some cases | |
235 // the value may be located in the map and then it can be deleted, producing | |
236 // a reference to invalid memory. | |
237 void CheckPendingRequest(const std::string service_path); | |
238 | |
239 void CheckAllPendingRequests(); | |
240 | |
241 // Look up the ConnectRequest for |service_path| and call | |
242 // InvokeConnectErrorCallback. | |
243 void ErrorCallbackForPendingRequest(const std::string& service_path, | |
244 const std::string& error_name); | |
245 | |
246 // Calls Shill.Manager.Disconnect asynchronously. | |
247 void CallShillDisconnect( | |
248 const std::string& service_path, | |
249 const base::Closure& success_callback, | |
250 const network_handler::ErrorCallback& error_callback); | |
251 | |
252 // Handle success from Shill.Service.Disconnect. | |
253 void HandleShillDisconnectSuccess(const std::string& service_path, | |
254 const base::Closure& success_callback); | |
255 | |
256 // Local references to the associated handler instances. | |
257 CertLoader* cert_loader_; | |
258 NetworkStateHandler* network_state_handler_; | |
259 NetworkConfigurationHandler* configuration_handler_; | |
260 ManagedNetworkConfigurationHandler* managed_configuration_handler_; | |
261 | |
262 // Map of pending connect requests, used to prevent repeated attempts while | |
263 // waiting for Shill and to trigger callbacks on eventual success or failure. | |
264 std::map<std::string, ConnectRequest> pending_requests_; | |
265 std::unique_ptr<ConnectRequest> queued_connect_; | |
266 | |
267 // Track certificate loading state. | |
268 bool logged_in_; | |
269 bool certificates_loaded_; | |
270 base::TimeTicks logged_in_time_; | |
271 | |
272 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerImpl); | |
148 }; | 273 }; |
149 | 274 |
275 // NetworkConnectionHandler implementation. | |
276 | |
277 // static | |
278 std::unique_ptr<NetworkConnectionHandler> NetworkConnectionHandler::Create() { | |
279 return base::MakeUnique<NetworkConnectionHandlerImpl>(); | |
280 } | |
281 | |
150 NetworkConnectionHandler::NetworkConnectionHandler() | 282 NetworkConnectionHandler::NetworkConnectionHandler() |
283 : tether_delegate_(nullptr), weak_ptr_factory_(this) {} | |
284 | |
285 NetworkConnectionHandler::~NetworkConnectionHandler() {} | |
286 | |
287 void NetworkConnectionHandler::AddObserver( | |
288 NetworkConnectionObserver* observer) { | |
289 observers_.AddObserver(observer); | |
290 } | |
291 | |
292 void NetworkConnectionHandler::RemoveObserver( | |
293 NetworkConnectionObserver* observer) { | |
294 observers_.RemoveObserver(observer); | |
295 } | |
296 | |
297 void NetworkConnectionHandler::SetTetherDelegate( | |
298 TetherDelegate* tether_delegate) { | |
299 tether_delegate_ = tether_delegate; | |
300 } | |
301 | |
302 void NetworkConnectionHandler::InvokeConnectSuccessCallback( | |
303 const std::string& service_path, | |
304 const base::Closure& success_callback) { | |
305 NET_LOG_EVENT("Connect Request Succeeded", service_path); | |
306 if (!success_callback.is_null()) | |
307 success_callback.Run(); | |
308 for (auto& observer : observers_) | |
309 observer.ConnectSucceeded(service_path); | |
310 } | |
311 | |
312 void NetworkConnectionHandler::InvokeConnectErrorCallback( | |
313 const std::string& service_path, | |
314 const network_handler::ErrorCallback& error_callback, | |
315 const std::string& error_name) { | |
316 NET_LOG_ERROR("Connect Failure: " + error_name, service_path); | |
317 network_handler::RunErrorCallback(error_callback, service_path, error_name, | |
318 ""); | |
319 for (auto& observer : observers_) | |
320 observer.ConnectFailed(service_path, error_name); | |
321 } | |
322 | |
323 void NetworkConnectionHandler::InitiateTetherNetworkConnection( | |
324 const std::string& tether_network_guid, | |
325 const base::Closure& success_callback, | |
326 const network_handler::ErrorCallback& error_callback) { | |
327 DCHECK(tether_delegate_); | |
328 tether_delegate_->ConnectToNetwork( | |
329 tether_network_guid, | |
330 base::Bind(&NetworkConnectionHandlerImpl::InvokeConnectSuccessCallback, | |
331 weak_ptr_factory_.GetWeakPtr(), tether_network_guid, | |
332 success_callback), | |
333 base::Bind(&NetworkConnectionHandlerImpl::InvokeConnectErrorCallback, | |
334 weak_ptr_factory_.GetWeakPtr(), tether_network_guid, | |
335 error_callback)); | |
336 } | |
337 | |
338 // NetworkConnectionHandlerImpl implementation. | |
339 | |
340 NetworkConnectionHandlerImpl::NetworkConnectionHandlerImpl() | |
151 : cert_loader_(NULL), | 341 : cert_loader_(NULL), |
152 network_state_handler_(NULL), | 342 network_state_handler_(NULL), |
153 configuration_handler_(NULL), | 343 configuration_handler_(NULL), |
154 logged_in_(false), | 344 logged_in_(false), |
155 certificates_loaded_(false), | 345 certificates_loaded_(false) {} |
156 tether_delegate_(nullptr) {} | 346 |
157 | 347 NetworkConnectionHandlerImpl::~NetworkConnectionHandlerImpl() { |
158 NetworkConnectionHandler::~NetworkConnectionHandler() { | |
159 if (network_state_handler_) | 348 if (network_state_handler_) |
160 network_state_handler_->RemoveObserver(this, FROM_HERE); | 349 network_state_handler_->RemoveObserver(this, FROM_HERE); |
161 if (cert_loader_) | 350 if (cert_loader_) |
162 cert_loader_->RemoveObserver(this); | 351 cert_loader_->RemoveObserver(this); |
163 if (LoginState::IsInitialized()) | 352 if (LoginState::IsInitialized()) |
164 LoginState::Get()->RemoveObserver(this); | 353 LoginState::Get()->RemoveObserver(this); |
165 } | 354 } |
166 | 355 |
167 void NetworkConnectionHandler::Init( | 356 void NetworkConnectionHandlerImpl::Init( |
168 NetworkStateHandler* network_state_handler, | 357 NetworkStateHandler* network_state_handler, |
169 NetworkConfigurationHandler* network_configuration_handler, | 358 NetworkConfigurationHandler* network_configuration_handler, |
170 ManagedNetworkConfigurationHandler* managed_network_configuration_handler) { | 359 ManagedNetworkConfigurationHandler* managed_network_configuration_handler) { |
171 if (LoginState::IsInitialized()) | 360 if (LoginState::IsInitialized()) |
172 LoginState::Get()->AddObserver(this); | 361 LoginState::Get()->AddObserver(this); |
173 | 362 |
174 if (CertLoader::IsInitialized()) { | 363 if (CertLoader::IsInitialized()) { |
175 cert_loader_ = CertLoader::Get(); | 364 cert_loader_ = CertLoader::Get(); |
176 cert_loader_->AddObserver(this); | 365 cert_loader_->AddObserver(this); |
177 if (cert_loader_->certificates_loaded()) { | 366 if (cert_loader_->certificates_loaded()) { |
178 NET_LOG_EVENT("Certificates Loaded", ""); | 367 NET_LOG_EVENT("Certificates Loaded", ""); |
179 certificates_loaded_ = true; | 368 certificates_loaded_ = true; |
180 } | 369 } |
181 } else { | 370 } else { |
182 // TODO(tbarzic): Require a mock or stub cert_loader in tests. | 371 // TODO(tbarzic): Require a mock or stub cert_loader in tests. |
183 NET_LOG_EVENT("Certificate Loader not initialized", ""); | 372 NET_LOG_EVENT("Certificate Loader not initialized", ""); |
184 certificates_loaded_ = true; | 373 certificates_loaded_ = true; |
185 } | 374 } |
186 | 375 |
187 if (network_state_handler) { | 376 if (network_state_handler) { |
188 network_state_handler_ = network_state_handler; | 377 network_state_handler_ = network_state_handler; |
189 network_state_handler_->AddObserver(this, FROM_HERE); | 378 network_state_handler_->AddObserver(this, FROM_HERE); |
190 } | 379 } |
191 configuration_handler_ = network_configuration_handler; | 380 configuration_handler_ = network_configuration_handler; |
192 managed_configuration_handler_ = managed_network_configuration_handler; | 381 managed_configuration_handler_ = managed_network_configuration_handler; |
193 | 382 |
194 // After this point, the NetworkConnectionHandler is fully initialized (all | 383 // After this point, the NetworkConnectionHandlerImpl is fully initialized |
195 // handler references set, observers registered, ...). | 384 // (all handler references set, observers registered, ...). |
196 | 385 |
197 if (LoginState::IsInitialized()) | 386 if (LoginState::IsInitialized()) |
198 LoggedInStateChanged(); | 387 LoggedInStateChanged(); |
199 } | 388 } |
200 | 389 |
201 void NetworkConnectionHandler::AddObserver( | 390 void NetworkConnectionHandlerImpl::LoggedInStateChanged() { |
202 NetworkConnectionObserver* observer) { | |
203 observers_.AddObserver(observer); | |
204 } | |
205 | |
206 void NetworkConnectionHandler::RemoveObserver( | |
207 NetworkConnectionObserver* observer) { | |
208 observers_.RemoveObserver(observer); | |
209 } | |
210 | |
211 void NetworkConnectionHandler::LoggedInStateChanged() { | |
212 LoginState* login_state = LoginState::Get(); | 391 LoginState* login_state = LoginState::Get(); |
213 if (logged_in_ || !login_state->IsUserLoggedIn()) | 392 if (logged_in_ || !login_state->IsUserLoggedIn()) |
214 return; | 393 return; |
215 | 394 |
216 logged_in_ = true; | 395 logged_in_ = true; |
217 logged_in_time_ = base::TimeTicks::Now(); | 396 logged_in_time_ = base::TimeTicks::Now(); |
218 } | 397 } |
219 | 398 |
220 void NetworkConnectionHandler::OnCertificatesLoaded( | 399 void NetworkConnectionHandlerImpl::OnCertificatesLoaded( |
221 const net::CertificateList& cert_list, | 400 const net::CertificateList& cert_list, |
222 bool initial_load) { | 401 bool initial_load) { |
223 certificates_loaded_ = true; | 402 certificates_loaded_ = true; |
224 NET_LOG_EVENT("Certificates Loaded", ""); | 403 NET_LOG_EVENT("Certificates Loaded", ""); |
225 if (queued_connect_) | 404 if (queued_connect_) |
226 ConnectToQueuedNetwork(); | 405 ConnectToQueuedNetwork(); |
227 } | 406 } |
228 | 407 |
229 void NetworkConnectionHandler::InitiateTetherNetworkConnection( | 408 void NetworkConnectionHandlerImpl::ConnectToNetwork( |
230 const std::string& tether_network_guid, | |
231 const base::Closure& success_callback, | |
232 const network_handler::ErrorCallback& error_callback) { | |
233 DCHECK(tether_delegate_); | |
234 tether_delegate_->ConnectToNetwork( | |
235 tether_network_guid, | |
236 base::Bind(&NetworkConnectionHandler::InvokeConnectSuccessCallback, | |
237 AsWeakPtr(), tether_network_guid, success_callback), | |
238 base::Bind(&NetworkConnectionHandler::InvokeConnectErrorCallback, | |
239 AsWeakPtr(), tether_network_guid, error_callback)); | |
240 } | |
241 | |
242 void NetworkConnectionHandler::ConnectToNetwork( | |
243 const std::string& service_path, | 409 const std::string& service_path, |
244 const base::Closure& success_callback, | 410 const base::Closure& success_callback, |
245 const network_handler::ErrorCallback& error_callback, | 411 const network_handler::ErrorCallback& error_callback, |
246 bool check_error_state) { | 412 bool check_error_state) { |
247 NET_LOG_USER("ConnectToNetwork", service_path); | 413 NET_LOG_USER("ConnectToNetwork", service_path); |
248 for (auto& observer : observers_) | 414 for (auto& observer : observers_) |
249 observer.ConnectToNetworkRequested(service_path); | 415 observer.ConnectToNetworkRequested(service_path); |
250 | 416 |
251 // Clear any existing queued connect request. | 417 // Clear any existing queued connect request. |
252 queued_connect_.reset(); | 418 queued_connect_.reset(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 | 493 |
328 CallShillConnect(service_path); | 494 CallShillConnect(service_path); |
329 return; | 495 return; |
330 } | 496 } |
331 | 497 |
332 // Request additional properties to check. VerifyConfiguredAndConnect will | 498 // Request additional properties to check. VerifyConfiguredAndConnect will |
333 // use only these properties, not cached properties, to ensure that they | 499 // use only these properties, not cached properties, to ensure that they |
334 // are up to date after any recent configuration. | 500 // are up to date after any recent configuration. |
335 configuration_handler_->GetShillProperties( | 501 configuration_handler_->GetShillProperties( |
336 service_path, | 502 service_path, |
337 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 503 base::Bind(&NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect, |
338 AsWeakPtr(), check_error_state), | 504 AsWeakPtr(), check_error_state), |
339 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 505 base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure, |
340 AsWeakPtr(), service_path)); | 506 AsWeakPtr(), service_path)); |
341 } | 507 } |
342 | 508 |
343 void NetworkConnectionHandler::DisconnectNetwork( | 509 void NetworkConnectionHandlerImpl::DisconnectNetwork( |
344 const std::string& service_path, | 510 const std::string& service_path, |
345 const base::Closure& success_callback, | 511 const base::Closure& success_callback, |
346 const network_handler::ErrorCallback& error_callback) { | 512 const network_handler::ErrorCallback& error_callback) { |
347 NET_LOG_USER("DisconnectNetwork", service_path); | 513 NET_LOG_USER("DisconnectNetwork", service_path); |
348 for (auto& observer : observers_) | 514 for (auto& observer : observers_) |
349 observer.DisconnectRequested(service_path); | 515 observer.DisconnectRequested(service_path); |
350 | 516 |
351 const NetworkState* network = | 517 const NetworkState* network = |
352 network_state_handler_->GetNetworkState(service_path); | 518 network_state_handler_->GetNetworkState(service_path); |
353 if (!network) { | 519 if (!network) { |
354 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); | 520 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); |
355 network_handler::RunErrorCallback(error_callback, service_path, | 521 network_handler::RunErrorCallback(error_callback, service_path, |
356 kErrorNotFound, ""); | 522 kErrorNotFound, ""); |
357 return; | 523 return; |
358 } | 524 } |
359 if (!network->IsConnectedState() && !network->IsConnectingState()) { | 525 if (!network->IsConnectedState() && !network->IsConnectingState()) { |
360 NET_LOG_ERROR("Disconnect Error: Not Connected", service_path); | 526 NET_LOG_ERROR("Disconnect Error: Not Connected", service_path); |
361 network_handler::RunErrorCallback(error_callback, service_path, | 527 network_handler::RunErrorCallback(error_callback, service_path, |
362 kErrorNotConnected, ""); | 528 kErrorNotConnected, ""); |
363 return; | 529 return; |
364 } | 530 } |
365 pending_requests_.erase(service_path); | 531 pending_requests_.erase(service_path); |
366 CallShillDisconnect(service_path, success_callback, error_callback); | 532 CallShillDisconnect(service_path, success_callback, error_callback); |
367 } | 533 } |
368 | 534 |
369 bool NetworkConnectionHandler::HasConnectingNetwork( | 535 bool NetworkConnectionHandlerImpl::HasConnectingNetwork( |
370 const std::string& service_path) { | 536 const std::string& service_path) { |
371 return pending_requests_.count(service_path) != 0; | 537 return pending_requests_.count(service_path) != 0; |
372 } | 538 } |
373 | 539 |
374 bool NetworkConnectionHandler::HasPendingConnectRequest() { | 540 bool NetworkConnectionHandlerImpl::HasPendingConnectRequest() { |
375 return pending_requests_.size() > 0; | 541 return pending_requests_.size() > 0; |
376 } | 542 } |
377 | 543 |
378 void NetworkConnectionHandler::SetTetherDelegate( | 544 void NetworkConnectionHandlerImpl::NetworkListChanged() { |
379 TetherDelegate* tether_delegate) { | |
380 tether_delegate_ = tether_delegate; | |
381 } | |
382 | |
383 void NetworkConnectionHandler::NetworkListChanged() { | |
384 CheckAllPendingRequests(); | 545 CheckAllPendingRequests(); |
385 } | 546 } |
386 | 547 |
387 void NetworkConnectionHandler::NetworkPropertiesUpdated( | 548 void NetworkConnectionHandlerImpl::NetworkPropertiesUpdated( |
388 const NetworkState* network) { | 549 const NetworkState* network) { |
389 if (HasConnectingNetwork(network->path())) | 550 if (HasConnectingNetwork(network->path())) |
390 CheckPendingRequest(network->path()); | 551 CheckPendingRequest(network->path()); |
391 } | 552 } |
392 | 553 |
393 NetworkConnectionHandler::ConnectRequest* | 554 NetworkConnectionHandlerImpl::ConnectRequest* |
394 NetworkConnectionHandler::GetPendingRequest(const std::string& service_path) { | 555 NetworkConnectionHandlerImpl::GetPendingRequest( |
556 const std::string& service_path) { | |
395 std::map<std::string, ConnectRequest>::iterator iter = | 557 std::map<std::string, ConnectRequest>::iterator iter = |
396 pending_requests_.find(service_path); | 558 pending_requests_.find(service_path); |
397 return iter != pending_requests_.end() ? &(iter->second) : NULL; | 559 return iter != pending_requests_.end() ? &(iter->second) : NULL; |
398 } | 560 } |
399 | 561 |
400 // ConnectToNetwork implementation | 562 // ConnectToNetwork implementation |
401 | 563 |
402 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 564 void NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect( |
403 bool check_error_state, | 565 bool check_error_state, |
404 const std::string& service_path, | 566 const std::string& service_path, |
405 const base::DictionaryValue& service_properties) { | 567 const base::DictionaryValue& service_properties) { |
406 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 568 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
407 | 569 |
408 // If 'passphrase_required' is still true, then the 'Passphrase' property | 570 // If 'passphrase_required' is still true, then the 'Passphrase' property |
409 // has not been set to a minimum length value. | 571 // has not been set to a minimum length value. |
410 bool passphrase_required = false; | 572 bool passphrase_required = false; |
411 service_properties.GetBooleanWithoutPathExpansion( | 573 service_properties.GetBooleanWithoutPathExpansion( |
412 shill::kPassphraseRequiredProperty, &passphrase_required); | 574 shill::kPassphraseRequiredProperty, &passphrase_required); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 CallShillConnect(service_path); | 713 CallShillConnect(service_path); |
552 return; | 714 return; |
553 } | 715 } |
554 } | 716 } |
555 | 717 |
556 if (!config_properties.empty()) { | 718 if (!config_properties.empty()) { |
557 NET_LOG_EVENT("Configuring Network", service_path); | 719 NET_LOG_EVENT("Configuring Network", service_path); |
558 configuration_handler_->SetShillProperties( | 720 configuration_handler_->SetShillProperties( |
559 service_path, config_properties, | 721 service_path, config_properties, |
560 NetworkConfigurationObserver::SOURCE_USER_ACTION, | 722 NetworkConfigurationObserver::SOURCE_USER_ACTION, |
561 base::Bind(&NetworkConnectionHandler::CallShillConnect, AsWeakPtr(), | 723 base::Bind(&NetworkConnectionHandlerImpl::CallShillConnect, AsWeakPtr(), |
562 service_path), | 724 service_path), |
563 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 725 base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure, |
564 AsWeakPtr(), service_path)); | 726 AsWeakPtr(), service_path)); |
565 return; | 727 return; |
566 } | 728 } |
567 | 729 |
568 // Otherwise, we probably still need to configure the network since | 730 // Otherwise, we probably still need to configure the network since |
569 // 'Connectable' is false. If |check_error_state| is true, signal an | 731 // 'Connectable' is false. If |check_error_state| is true, signal an |
570 // error, otherwise attempt to connect to possibly gain additional error | 732 // error, otherwise attempt to connect to possibly gain additional error |
571 // state from Shill (or in case 'Connectable' is improperly unset). | 733 // state from Shill (or in case 'Connectable' is improperly unset). |
572 if (check_error_state) | 734 if (check_error_state) |
573 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 735 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
574 else | 736 else |
575 CallShillConnect(service_path); | 737 CallShillConnect(service_path); |
576 } | 738 } |
577 | 739 |
578 bool NetworkConnectionHandler::IsNetworkProhibitedByPolicy( | 740 bool NetworkConnectionHandlerImpl::IsNetworkProhibitedByPolicy( |
579 const std::string& type, | 741 const std::string& type, |
580 const std::string& guid, | 742 const std::string& guid, |
581 const std::string& profile_path) { | 743 const std::string& profile_path) { |
582 if (!logged_in_) | 744 if (!logged_in_) |
583 return false; | 745 return false; |
584 if (type != shill::kTypeWifi) | 746 if (type != shill::kTypeWifi) |
585 return false; | 747 return false; |
586 const base::DictionaryValue* global_network_config = | 748 const base::DictionaryValue* global_network_config = |
587 managed_configuration_handler_->GetGlobalConfigFromPolicy( | 749 managed_configuration_handler_->GetGlobalConfigFromPolicy( |
588 std::string() /* no username hash, device policy */); | 750 std::string() /* no username hash, device policy */); |
589 if (!global_network_config) | 751 if (!global_network_config) |
590 return false; | 752 return false; |
591 bool policy_prohibites = false; | 753 bool policy_prohibites = false; |
592 if (!global_network_config->GetBooleanWithoutPathExpansion( | 754 if (!global_network_config->GetBooleanWithoutPathExpansion( |
593 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, | 755 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, |
594 &policy_prohibites) || | 756 &policy_prohibites) || |
595 !policy_prohibites) { | 757 !policy_prohibites) { |
596 return false; | 758 return false; |
597 } | 759 } |
598 return !managed_configuration_handler_->FindPolicyByGuidAndProfile( | 760 return !managed_configuration_handler_->FindPolicyByGuidAndProfile( |
599 guid, profile_path, nullptr /* onc_source */); | 761 guid, profile_path, nullptr /* onc_source */); |
600 } | 762 } |
601 | 763 |
602 void NetworkConnectionHandler::QueueConnectRequest( | 764 void NetworkConnectionHandlerImpl::QueueConnectRequest( |
603 const std::string& service_path) { | 765 const std::string& service_path) { |
604 ConnectRequest* request = GetPendingRequest(service_path); | 766 ConnectRequest* request = GetPendingRequest(service_path); |
605 if (!request) { | 767 if (!request) { |
606 NET_LOG_ERROR("No pending request to queue", service_path); | 768 NET_LOG_ERROR("No pending request to queue", service_path); |
607 return; | 769 return; |
608 } | 770 } |
609 | 771 |
610 const int kMaxCertLoadTimeSeconds = 15; | 772 const int kMaxCertLoadTimeSeconds = 15; |
611 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_; | 773 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_; |
612 if (dtime > base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds)) { | 774 if (dtime > base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds)) { |
613 NET_LOG_ERROR("Certificate load timeout", service_path); | 775 NET_LOG_ERROR("Certificate load timeout", service_path); |
614 InvokeConnectErrorCallback(service_path, request->error_callback, | 776 InvokeConnectErrorCallback(service_path, request->error_callback, |
615 kErrorCertLoadTimeout); | 777 kErrorCertLoadTimeout); |
616 return; | 778 return; |
617 } | 779 } |
618 | 780 |
619 NET_LOG_EVENT("Connect Request Queued", service_path); | 781 NET_LOG_EVENT("Connect Request Queued", service_path); |
620 queued_connect_.reset(new ConnectRequest( | 782 queued_connect_.reset(new ConnectRequest( |
621 service_path, request->profile_path, | 783 service_path, request->profile_path, |
622 request->success_callback, request->error_callback)); | 784 request->success_callback, request->error_callback)); |
623 pending_requests_.erase(service_path); | 785 pending_requests_.erase(service_path); |
624 | 786 |
625 // Post a delayed task to check to see if certificates have loaded. If they | 787 // Post a delayed task to check to see if certificates have loaded. If they |
626 // haven't, and queued_connect_ has not been cleared (e.g. by a successful | 788 // haven't, and queued_connect_ has not been cleared (e.g. by a successful |
627 // connect request), cancel the request and notify the user. | 789 // connect request), cancel the request and notify the user. |
628 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 790 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
629 FROM_HERE, base::Bind(&NetworkConnectionHandler::CheckCertificatesLoaded, | 791 FROM_HERE, |
630 AsWeakPtr()), | 792 base::Bind(&NetworkConnectionHandlerImpl::CheckCertificatesLoaded, |
793 AsWeakPtr()), | |
631 base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds) - dtime); | 794 base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds) - dtime); |
632 } | 795 } |
633 | 796 |
634 void NetworkConnectionHandler::CheckCertificatesLoaded() { | 797 void NetworkConnectionHandlerImpl::CheckCertificatesLoaded() { |
635 if (certificates_loaded_) | 798 if (certificates_loaded_) |
636 return; | 799 return; |
637 // If queued_connect_ has been cleared (e.g. another connect request occurred | 800 // If queued_connect_ has been cleared (e.g. another connect request occurred |
638 // and wasn't queued), do nothing here. | 801 // and wasn't queued), do nothing here. |
639 if (!queued_connect_) | 802 if (!queued_connect_) |
640 return; | 803 return; |
641 // Otherwise, notify the user. | 804 // Otherwise, notify the user. |
642 NET_LOG_ERROR("Certificate load timeout", queued_connect_->service_path); | 805 NET_LOG_ERROR("Certificate load timeout", queued_connect_->service_path); |
643 InvokeConnectErrorCallback(queued_connect_->service_path, | 806 InvokeConnectErrorCallback(queued_connect_->service_path, |
644 queued_connect_->error_callback, | 807 queued_connect_->error_callback, |
645 kErrorCertLoadTimeout); | 808 kErrorCertLoadTimeout); |
646 queued_connect_.reset(); | 809 queued_connect_.reset(); |
647 } | 810 } |
648 | 811 |
649 void NetworkConnectionHandler::ConnectToQueuedNetwork() { | 812 void NetworkConnectionHandlerImpl::ConnectToQueuedNetwork() { |
650 DCHECK(queued_connect_); | 813 DCHECK(queued_connect_); |
651 | 814 |
652 // Make a copy of |queued_connect_| parameters, because |queued_connect_| | 815 // Make a copy of |queued_connect_| parameters, because |queued_connect_| |
653 // will get reset at the beginning of |ConnectToNetwork|. | 816 // will get reset at the beginning of |ConnectToNetwork|. |
654 std::string service_path = queued_connect_->service_path; | 817 std::string service_path = queued_connect_->service_path; |
655 base::Closure success_callback = queued_connect_->success_callback; | 818 base::Closure success_callback = queued_connect_->success_callback; |
656 network_handler::ErrorCallback error_callback = | 819 network_handler::ErrorCallback error_callback = |
657 queued_connect_->error_callback; | 820 queued_connect_->error_callback; |
658 | 821 |
659 NET_LOG_EVENT("Connecting to Queued Network", service_path); | 822 NET_LOG_EVENT("Connecting to Queued Network", service_path); |
660 ConnectToNetwork(service_path, success_callback, error_callback, | 823 ConnectToNetwork(service_path, success_callback, error_callback, |
661 false /* check_error_state */); | 824 false /* check_error_state */); |
662 } | 825 } |
663 | 826 |
664 void NetworkConnectionHandler::CallShillConnect( | 827 void NetworkConnectionHandlerImpl::CallShillConnect( |
665 const std::string& service_path) { | 828 const std::string& service_path) { |
666 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); | 829 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); |
667 network_state_handler_->ClearLastErrorForNetwork(service_path); | 830 network_state_handler_->ClearLastErrorForNetwork(service_path); |
668 DBusThreadManager::Get()->GetShillServiceClient()->Connect( | 831 DBusThreadManager::Get()->GetShillServiceClient()->Connect( |
669 dbus::ObjectPath(service_path), | 832 dbus::ObjectPath(service_path), |
670 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, | 833 base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectSuccess, |
671 AsWeakPtr(), service_path), | 834 AsWeakPtr(), service_path), |
672 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, | 835 base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectFailure, |
673 AsWeakPtr(), service_path)); | 836 AsWeakPtr(), service_path)); |
674 } | 837 } |
675 | 838 |
676 void NetworkConnectionHandler::HandleConfigurationFailure( | 839 void NetworkConnectionHandlerImpl::HandleConfigurationFailure( |
677 const std::string& service_path, | 840 const std::string& service_path, |
678 const std::string& error_name, | 841 const std::string& error_name, |
679 std::unique_ptr<base::DictionaryValue> error_data) { | 842 std::unique_ptr<base::DictionaryValue> error_data) { |
680 ConnectRequest* request = GetPendingRequest(service_path); | 843 ConnectRequest* request = GetPendingRequest(service_path); |
681 if (!request) { | 844 if (!request) { |
682 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", | 845 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", |
683 service_path); | 846 service_path); |
684 return; | 847 return; |
685 } | 848 } |
686 network_handler::ErrorCallback error_callback = request->error_callback; | 849 network_handler::ErrorCallback error_callback = request->error_callback; |
687 pending_requests_.erase(service_path); | 850 pending_requests_.erase(service_path); |
688 InvokeConnectErrorCallback(service_path, error_callback, | 851 InvokeConnectErrorCallback(service_path, error_callback, |
689 kErrorConfigureFailed); | 852 kErrorConfigureFailed); |
690 } | 853 } |
691 | 854 |
692 void NetworkConnectionHandler::HandleShillConnectSuccess( | 855 void NetworkConnectionHandlerImpl::HandleShillConnectSuccess( |
693 const std::string& service_path) { | 856 const std::string& service_path) { |
694 ConnectRequest* request = GetPendingRequest(service_path); | 857 ConnectRequest* request = GetPendingRequest(service_path); |
695 if (!request) { | 858 if (!request) { |
696 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", | 859 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", |
697 service_path); | 860 service_path); |
698 return; | 861 return; |
699 } | 862 } |
700 request->connect_state = ConnectRequest::CONNECT_STARTED; | 863 request->connect_state = ConnectRequest::CONNECT_STARTED; |
701 NET_LOG_EVENT("Connect Request Acknowledged", service_path); | 864 NET_LOG_EVENT("Connect Request Acknowledged", service_path); |
702 // Do not call success_callback here, wait for one of the following | 865 // Do not call success_callback here, wait for one of the following |
703 // conditions: | 866 // conditions: |
704 // * State transitions to a non connecting state indicating success or failure | 867 // * State transitions to a non connecting state indicating success or failure |
705 // * Network is no longer in the visible list, indicating failure | 868 // * Network is no longer in the visible list, indicating failure |
706 CheckPendingRequest(service_path); | 869 CheckPendingRequest(service_path); |
707 } | 870 } |
708 | 871 |
709 void NetworkConnectionHandler::HandleShillConnectFailure( | 872 void NetworkConnectionHandlerImpl::HandleShillConnectFailure( |
710 const std::string& service_path, | 873 const std::string& service_path, |
711 const std::string& dbus_error_name, | 874 const std::string& dbus_error_name, |
712 const std::string& dbus_error_message) { | 875 const std::string& dbus_error_message) { |
713 ConnectRequest* request = GetPendingRequest(service_path); | 876 ConnectRequest* request = GetPendingRequest(service_path); |
714 if (!request) { | 877 if (!request) { |
715 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 878 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
716 service_path); | 879 service_path); |
717 return; | 880 return; |
718 } | 881 } |
719 network_handler::ErrorCallback error_callback = request->error_callback; | 882 network_handler::ErrorCallback error_callback = request->error_callback; |
720 pending_requests_.erase(service_path); | 883 pending_requests_.erase(service_path); |
721 std::string error; | 884 std::string error; |
722 if (dbus_error_name == shill::kErrorResultAlreadyConnected) { | 885 if (dbus_error_name == shill::kErrorResultAlreadyConnected) { |
723 error = kErrorConnected; | 886 error = kErrorConnected; |
724 } else if (dbus_error_name == shill::kErrorResultInProgress) { | 887 } else if (dbus_error_name == shill::kErrorResultInProgress) { |
725 error = kErrorConnecting; | 888 error = kErrorConnecting; |
726 } else { | 889 } else { |
727 NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name, | 890 NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name, |
728 service_path); | 891 service_path); |
729 error = kErrorConnectFailed; | 892 error = kErrorConnectFailed; |
730 } | 893 } |
731 InvokeConnectErrorCallback(service_path, error_callback, error); | 894 InvokeConnectErrorCallback(service_path, error_callback, error); |
732 } | 895 } |
733 | 896 |
734 void NetworkConnectionHandler::CheckPendingRequest( | 897 void NetworkConnectionHandlerImpl::CheckPendingRequest( |
735 const std::string service_path) { | 898 const std::string service_path) { |
736 ConnectRequest* request = GetPendingRequest(service_path); | 899 ConnectRequest* request = GetPendingRequest(service_path); |
737 DCHECK(request); | 900 DCHECK(request); |
738 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 901 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
739 return; // Request has not started, ignore update | 902 return; // Request has not started, ignore update |
740 const NetworkState* network = | 903 const NetworkState* network = |
741 network_state_handler_->GetNetworkState(service_path); | 904 network_state_handler_->GetNetworkState(service_path); |
742 if (!network) | 905 if (!network) |
743 return; // NetworkState may not be be updated yet. | 906 return; // NetworkState may not be be updated yet. |
744 | 907 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 NET_LOG_ERROR("Unexpected State: " + network->connection_state(), | 942 NET_LOG_ERROR("Unexpected State: " + network->connection_state(), |
780 service_path); | 943 service_path); |
781 } | 944 } |
782 } | 945 } |
783 | 946 |
784 network_handler::ErrorCallback error_callback = request->error_callback; | 947 network_handler::ErrorCallback error_callback = request->error_callback; |
785 pending_requests_.erase(service_path); | 948 pending_requests_.erase(service_path); |
786 InvokeConnectErrorCallback(service_path, error_callback, error_name); | 949 InvokeConnectErrorCallback(service_path, error_callback, error_name); |
787 } | 950 } |
788 | 951 |
789 void NetworkConnectionHandler::CheckAllPendingRequests() { | 952 void NetworkConnectionHandlerImpl::CheckAllPendingRequests() { |
790 for (std::map<std::string, ConnectRequest>::iterator iter = | 953 for (std::map<std::string, ConnectRequest>::iterator iter = |
791 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { | 954 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { |
792 CheckPendingRequest(iter->first); | 955 CheckPendingRequest(iter->first); |
793 } | 956 } |
794 } | 957 } |
795 | 958 |
796 // Connect callbacks | 959 // Connect callbacks |
797 | 960 |
798 void NetworkConnectionHandler::InvokeConnectSuccessCallback( | 961 void NetworkConnectionHandlerImpl::ErrorCallbackForPendingRequest( |
799 const std::string& service_path, | |
800 const base::Closure& success_callback) { | |
801 NET_LOG_EVENT("Connect Request Succeeded", service_path); | |
802 if (!success_callback.is_null()) | |
803 success_callback.Run(); | |
804 for (auto& observer : observers_) | |
805 observer.ConnectSucceeded(service_path); | |
806 } | |
807 | |
808 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | |
809 const std::string& service_path, | 962 const std::string& service_path, |
810 const std::string& error_name) { | 963 const std::string& error_name) { |
811 ConnectRequest* request = GetPendingRequest(service_path); | 964 ConnectRequest* request = GetPendingRequest(service_path); |
812 if (!request) { | 965 if (!request) { |
813 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", | 966 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", |
814 service_path); | 967 service_path); |
815 return; | 968 return; |
816 } | 969 } |
817 // Remove the entry before invoking the callback in case it triggers a retry. | 970 // Remove the entry before invoking the callback in case it triggers a retry. |
818 network_handler::ErrorCallback error_callback = request->error_callback; | 971 network_handler::ErrorCallback error_callback = request->error_callback; |
819 pending_requests_.erase(service_path); | 972 pending_requests_.erase(service_path); |
820 InvokeConnectErrorCallback(service_path, error_callback, error_name); | 973 InvokeConnectErrorCallback(service_path, error_callback, error_name); |
821 } | 974 } |
822 | 975 |
823 void NetworkConnectionHandler::InvokeConnectErrorCallback( | |
824 const std::string& service_path, | |
825 const network_handler::ErrorCallback& error_callback, | |
826 const std::string& error_name) { | |
827 NET_LOG_ERROR("Connect Failure: " + error_name, service_path); | |
828 network_handler::RunErrorCallback(error_callback, service_path, error_name, | |
829 ""); | |
830 for (auto& observer : observers_) | |
831 observer.ConnectFailed(service_path, error_name); | |
832 } | |
833 | |
834 // Disconnect | 976 // Disconnect |
835 | 977 |
836 void NetworkConnectionHandler::CallShillDisconnect( | 978 void NetworkConnectionHandlerImpl::CallShillDisconnect( |
837 const std::string& service_path, | 979 const std::string& service_path, |
838 const base::Closure& success_callback, | 980 const base::Closure& success_callback, |
839 const network_handler::ErrorCallback& error_callback) { | 981 const network_handler::ErrorCallback& error_callback) { |
840 NET_LOG_USER("Disconnect Request", service_path); | 982 NET_LOG_USER("Disconnect Request", service_path); |
841 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 983 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
842 dbus::ObjectPath(service_path), | 984 dbus::ObjectPath(service_path), |
843 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, | 985 base::Bind(&NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess, |
844 AsWeakPtr(), service_path, success_callback), | 986 AsWeakPtr(), service_path, success_callback), |
845 base::Bind(&network_handler::ShillErrorCallbackFunction, | 987 base::Bind(&network_handler::ShillErrorCallbackFunction, |
846 kErrorDisconnectFailed, service_path, error_callback)); | 988 kErrorDisconnectFailed, service_path, error_callback)); |
847 } | 989 } |
848 | 990 |
849 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 991 void NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess( |
850 const std::string& service_path, | 992 const std::string& service_path, |
851 const base::Closure& success_callback) { | 993 const base::Closure& success_callback) { |
852 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 994 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
853 if (!success_callback.is_null()) | 995 if (!success_callback.is_null()) |
854 success_callback.Run(); | 996 success_callback.Run(); |
855 } | 997 } |
856 | 998 |
857 } // namespace chromeos | 999 } // namespace chromeos |
OLD | NEW |