Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chromeos/network/network_connection_handler_impl.cc

Issue 2861883002: [CrOS Tether] Transform NetworkConnectionHandler to an interface. (Closed)
Patch Set: stevenjb@ comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_impl.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 10 matching lines...) Expand all
33 34
34 bool IsAuthenticationError(const std::string& error) { 35 bool IsAuthenticationError(const std::string& error) {
35 return (error == shill::kErrorBadWEPKey || 36 return (error == shill::kErrorBadWEPKey ||
36 error == shill::kErrorPppAuthFailed || 37 error == shill::kErrorPppAuthFailed ||
37 error == shill::kErrorEapLocalTlsFailed || 38 error == shill::kErrorEapLocalTlsFailed ||
38 error == shill::kErrorEapRemoteTlsFailed || 39 error == shill::kErrorEapRemoteTlsFailed ||
39 error == shill::kErrorEapAuthenticationFailed); 40 error == shill::kErrorEapAuthenticationFailed);
40 } 41 }
41 42
42 bool VPNRequiresCredentials(const std::string& service_path, 43 bool VPNRequiresCredentials(const std::string& service_path,
43 const std::string& provider_type, 44 const std::string& provider_type,
44 const base::DictionaryValue& provider_properties) { 45 const base::DictionaryValue& provider_properties) {
45 if (provider_type == shill::kProviderOpenVpn) { 46 if (provider_type == shill::kProviderOpenVpn) {
46 std::string username; 47 std::string username;
47 provider_properties.GetStringWithoutPathExpansion( 48 provider_properties.GetStringWithoutPathExpansion(
48 shill::kOpenVPNUserProperty, &username); 49 shill::kOpenVPNUserProperty, &username);
49 if (username.empty()) { 50 if (username.empty()) {
50 NET_LOG_EVENT("OpenVPN: No username", service_path); 51 NET_LOG_EVENT("OpenVPN: No username", service_path);
51 return true; 52 return true;
52 } 53 }
53 bool passphrase_required = false; 54 bool passphrase_required = false;
54 provider_properties.GetBooleanWithoutPathExpansion( 55 provider_properties.GetBooleanWithoutPathExpansion(
(...skipping 23 matching lines...) Expand all
78 } 79 }
79 80
80 std::string GetDefaultUserProfilePath(const NetworkState* network) { 81 std::string GetDefaultUserProfilePath(const NetworkState* network) {
81 if (!NetworkHandler::IsInitialized() || 82 if (!NetworkHandler::IsInitialized() ||
82 (LoginState::IsInitialized() && 83 (LoginState::IsInitialized() &&
83 !LoginState::Get()->UserHasNetworkProfile()) || 84 !LoginState::Get()->UserHasNetworkProfile()) ||
84 (network && network->type() == shill::kTypeWifi && 85 (network && network->type() == shill::kTypeWifi &&
85 network->security_class() == shill::kSecurityNone)) { 86 network->security_class() == shill::kSecurityNone)) {
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
96 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; 97 NetworkConnectionHandlerImpl::ConnectRequest::ConnectRequest(
97 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; 98 const std::string& service_path,
98 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; 99 const std::string& profile_path,
99 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; 100 const base::Closure& success,
100 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = 101 const network_handler::ErrorCallback& error)
101 "passphrase-required"; 102 : service_path(service_path),
102 const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase"; 103 profile_path(profile_path),
103 const char NetworkConnectionHandler::kErrorCertificateRequired[] = 104 connect_state(CONNECT_REQUESTED),
104 "certificate-required"; 105 success_callback(success),
105 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = 106 error_callback(error) {}
106 "configuration-required";
107 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] =
108 "authentication-required";
109 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed";
110 const char NetworkConnectionHandler::kErrorDisconnectFailed[] =
111 "disconnect-failed";
112 const char NetworkConnectionHandler::kErrorConfigureFailed[] =
113 "configure-failed";
114 const char NetworkConnectionHandler::kErrorConnectCanceled[] =
115 "connect-canceled";
116 const char NetworkConnectionHandler::kErrorCertLoadTimeout[] =
117 "cert-load-timeout";
118 const char NetworkConnectionHandler::kErrorUnmanagedNetwork[] =
119 "unmanaged-network";
120 const char NetworkConnectionHandler::kErrorActivateFailed[] = "activate-failed";
121 const char NetworkConnectionHandler::kErrorEnabledOrDisabledWhenNotAvailable[] =
122 "not-available";
123 const char
124 NetworkConnectionHandler::kErrorTetherConnectionAttemptWithNoDelegate[] =
125 "tether-with-no-delegate";
126 107
127 struct NetworkConnectionHandler::ConnectRequest { 108 NetworkConnectionHandlerImpl::ConnectRequest::~ConnectRequest() {}
128 ConnectRequest(const std::string& service_path,
129 const std::string& profile_path,
130 const base::Closure& success,
131 const network_handler::ErrorCallback& error)
132 : service_path(service_path),
133 profile_path(profile_path),
134 connect_state(CONNECT_REQUESTED),
135 success_callback(success),
136 error_callback(error) {
137 }
138 enum ConnectState {
139 CONNECT_REQUESTED = 0,
140 CONNECT_STARTED = 1,
141 CONNECT_CONNECTING = 2
142 };
143 std::string service_path;
144 std::string profile_path;
145 ConnectState connect_state;
146 base::Closure success_callback;
147 network_handler::ErrorCallback error_callback;
148 };
149 109
150 NetworkConnectionHandler::NetworkConnectionHandler() 110 NetworkConnectionHandlerImpl::ConnectRequest::ConnectRequest(
111 const ConnectRequest& other)
112 : service_path(other.service_path),
113 profile_path(other.profile_path),
114 connect_state(other.connect_state),
115 success_callback(other.success_callback),
116 error_callback(other.error_callback) {}
117
118 NetworkConnectionHandlerImpl::NetworkConnectionHandlerImpl()
151 : cert_loader_(NULL), 119 : cert_loader_(NULL),
152 network_state_handler_(NULL), 120 network_state_handler_(NULL),
153 configuration_handler_(NULL), 121 configuration_handler_(NULL),
154 logged_in_(false), 122 logged_in_(false),
155 certificates_loaded_(false), 123 certificates_loaded_(false) {}
156 tether_delegate_(nullptr) {}
157 124
158 NetworkConnectionHandler::~NetworkConnectionHandler() { 125 NetworkConnectionHandlerImpl::~NetworkConnectionHandlerImpl() {
159 if (network_state_handler_) 126 if (network_state_handler_)
160 network_state_handler_->RemoveObserver(this, FROM_HERE); 127 network_state_handler_->RemoveObserver(this, FROM_HERE);
161 if (cert_loader_) 128 if (cert_loader_)
162 cert_loader_->RemoveObserver(this); 129 cert_loader_->RemoveObserver(this);
163 if (LoginState::IsInitialized()) 130 if (LoginState::IsInitialized())
164 LoginState::Get()->RemoveObserver(this); 131 LoginState::Get()->RemoveObserver(this);
165 } 132 }
166 133
167 void NetworkConnectionHandler::Init( 134 void NetworkConnectionHandlerImpl::Init(
168 NetworkStateHandler* network_state_handler, 135 NetworkStateHandler* network_state_handler,
169 NetworkConfigurationHandler* network_configuration_handler, 136 NetworkConfigurationHandler* network_configuration_handler,
170 ManagedNetworkConfigurationHandler* managed_network_configuration_handler) { 137 ManagedNetworkConfigurationHandler* managed_network_configuration_handler) {
171 if (LoginState::IsInitialized()) 138 if (LoginState::IsInitialized())
172 LoginState::Get()->AddObserver(this); 139 LoginState::Get()->AddObserver(this);
173 140
174 if (CertLoader::IsInitialized()) { 141 if (CertLoader::IsInitialized()) {
175 cert_loader_ = CertLoader::Get(); 142 cert_loader_ = CertLoader::Get();
176 cert_loader_->AddObserver(this); 143 cert_loader_->AddObserver(this);
177 if (cert_loader_->certificates_loaded()) { 144 if (cert_loader_->certificates_loaded()) {
178 NET_LOG_EVENT("Certificates Loaded", ""); 145 NET_LOG_EVENT("Certificates Loaded", "");
179 certificates_loaded_ = true; 146 certificates_loaded_ = true;
180 } 147 }
181 } else { 148 } else {
182 // TODO(tbarzic): Require a mock or stub cert_loader in tests. 149 // TODO(tbarzic): Require a mock or stub cert_loader in tests.
183 NET_LOG_EVENT("Certificate Loader not initialized", ""); 150 NET_LOG_EVENT("Certificate Loader not initialized", "");
184 certificates_loaded_ = true; 151 certificates_loaded_ = true;
185 } 152 }
186 153
187 if (network_state_handler) { 154 if (network_state_handler) {
188 network_state_handler_ = network_state_handler; 155 network_state_handler_ = network_state_handler;
189 network_state_handler_->AddObserver(this, FROM_HERE); 156 network_state_handler_->AddObserver(this, FROM_HERE);
190 } 157 }
191 configuration_handler_ = network_configuration_handler; 158 configuration_handler_ = network_configuration_handler;
192 managed_configuration_handler_ = managed_network_configuration_handler; 159 managed_configuration_handler_ = managed_network_configuration_handler;
193 160
194 // After this point, the NetworkConnectionHandler is fully initialized (all 161 // After this point, the NetworkConnectionHandlerImpl is fully initialized
195 // handler references set, observers registered, ...). 162 // (all handler references set, observers registered, ...).
196 163
197 if (LoginState::IsInitialized()) 164 if (LoginState::IsInitialized())
198 LoggedInStateChanged(); 165 LoggedInStateChanged();
199 } 166 }
200 167
201 void NetworkConnectionHandler::AddObserver( 168 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(); 169 LoginState* login_state = LoginState::Get();
213 if (logged_in_ || !login_state->IsUserLoggedIn()) 170 if (logged_in_ || !login_state->IsUserLoggedIn())
214 return; 171 return;
215 172
216 logged_in_ = true; 173 logged_in_ = true;
217 logged_in_time_ = base::TimeTicks::Now(); 174 logged_in_time_ = base::TimeTicks::Now();
218 } 175 }
219 176
220 void NetworkConnectionHandler::OnCertificatesLoaded( 177 void NetworkConnectionHandlerImpl::OnCertificatesLoaded(
221 const net::CertificateList& cert_list, 178 const net::CertificateList& cert_list,
222 bool initial_load) { 179 bool initial_load) {
223 certificates_loaded_ = true; 180 certificates_loaded_ = true;
224 NET_LOG_EVENT("Certificates Loaded", ""); 181 NET_LOG_EVENT("Certificates Loaded", "");
225 if (queued_connect_) 182 if (queued_connect_)
226 ConnectToQueuedNetwork(); 183 ConnectToQueuedNetwork();
227 } 184 }
228 185
229 void NetworkConnectionHandler::InitiateTetherNetworkConnection( 186 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, 187 const std::string& service_path,
244 const base::Closure& success_callback, 188 const base::Closure& success_callback,
245 const network_handler::ErrorCallback& error_callback, 189 const network_handler::ErrorCallback& error_callback,
246 bool check_error_state) { 190 bool check_error_state) {
247 NET_LOG_USER("ConnectToNetwork", service_path); 191 NET_LOG_USER("ConnectToNetwork", service_path);
248 for (auto& observer : observers_) 192 for (auto& observer : observers_)
249 observer.ConnectToNetworkRequested(service_path); 193 observer.ConnectToNetworkRequested(service_path);
250 194
251 // Clear any existing queued connect request. 195 // Clear any existing queued connect request.
252 queued_connect_.reset(); 196 queued_connect_.reset();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 248 }
305 249
306 // If the network does not have a profile path, specify the correct default 250 // If the network does not have a profile path, specify the correct default
307 // profile here and set it once connected. Otherwise leave it empty to 251 // profile here and set it once connected. Otherwise leave it empty to
308 // indicate that it does not need to be set. 252 // indicate that it does not need to be set.
309 std::string profile_path; 253 std::string profile_path;
310 if (!network || network->profile_path().empty()) 254 if (!network || network->profile_path().empty())
311 profile_path = GetDefaultUserProfilePath(network); 255 profile_path = GetDefaultUserProfilePath(network);
312 256
313 // All synchronous checks passed, add |service_path| to connecting list. 257 // All synchronous checks passed, add |service_path| to connecting list.
314 pending_requests_.insert(std::make_pair( 258 pending_requests_.emplace(
315 service_path, 259 service_path, ConnectRequest(service_path, profile_path, success_callback,
316 ConnectRequest(service_path, profile_path, 260 error_callback));
317 success_callback, error_callback)));
318 261
319 // Connect immediately to 'connectable' networks. 262 // Connect immediately to 'connectable' networks.
320 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. 263 // TODO(stevenjb): Shill needs to properly set Connectable for VPN.
321 if (network && network->connectable() && network->type() != shill::kTypeVPN) { 264 if (network && network->connectable() && network->type() != shill::kTypeVPN) {
322 if (IsNetworkProhibitedByPolicy(network->type(), network->guid(), 265 if (IsNetworkProhibitedByPolicy(network->type(), network->guid(),
323 network->profile_path())) { 266 network->profile_path())) {
324 ErrorCallbackForPendingRequest(service_path, kErrorUnmanagedNetwork); 267 ErrorCallbackForPendingRequest(service_path, kErrorUnmanagedNetwork);
325 return; 268 return;
326 } 269 }
327 270
328 CallShillConnect(service_path); 271 CallShillConnect(service_path);
329 return; 272 return;
330 } 273 }
331 274
332 // Request additional properties to check. VerifyConfiguredAndConnect will 275 // Request additional properties to check. VerifyConfiguredAndConnect will
333 // use only these properties, not cached properties, to ensure that they 276 // use only these properties, not cached properties, to ensure that they
334 // are up to date after any recent configuration. 277 // are up to date after any recent configuration.
335 configuration_handler_->GetShillProperties( 278 configuration_handler_->GetShillProperties(
336 service_path, 279 service_path,
337 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, 280 base::Bind(&NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect,
338 AsWeakPtr(), check_error_state), 281 AsWeakPtr(), check_error_state),
339 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, 282 base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure,
340 AsWeakPtr(), service_path)); 283 AsWeakPtr(), service_path));
341 } 284 }
342 285
343 void NetworkConnectionHandler::DisconnectNetwork( 286 void NetworkConnectionHandlerImpl::DisconnectNetwork(
344 const std::string& service_path, 287 const std::string& service_path,
345 const base::Closure& success_callback, 288 const base::Closure& success_callback,
346 const network_handler::ErrorCallback& error_callback) { 289 const network_handler::ErrorCallback& error_callback) {
347 NET_LOG_USER("DisconnectNetwork", service_path); 290 NET_LOG_USER("DisconnectNetwork", service_path);
348 for (auto& observer : observers_) 291 for (auto& observer : observers_)
349 observer.DisconnectRequested(service_path); 292 observer.DisconnectRequested(service_path);
350 293
351 const NetworkState* network = 294 const NetworkState* network =
352 network_state_handler_->GetNetworkState(service_path); 295 network_state_handler_->GetNetworkState(service_path);
353 if (!network) { 296 if (!network) {
354 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); 297 NET_LOG_ERROR("Disconnect Error: Not Found", service_path);
355 network_handler::RunErrorCallback(error_callback, service_path, 298 network_handler::RunErrorCallback(error_callback, service_path,
356 kErrorNotFound, ""); 299 kErrorNotFound, "");
357 return; 300 return;
358 } 301 }
359 if (!network->IsConnectedState() && !network->IsConnectingState()) { 302 if (!network->IsConnectedState() && !network->IsConnectingState()) {
360 NET_LOG_ERROR("Disconnect Error: Not Connected", service_path); 303 NET_LOG_ERROR("Disconnect Error: Not Connected", service_path);
361 network_handler::RunErrorCallback(error_callback, service_path, 304 network_handler::RunErrorCallback(error_callback, service_path,
362 kErrorNotConnected, ""); 305 kErrorNotConnected, "");
363 return; 306 return;
364 } 307 }
365 pending_requests_.erase(service_path); 308 pending_requests_.erase(service_path);
366 CallShillDisconnect(service_path, success_callback, error_callback); 309 CallShillDisconnect(service_path, success_callback, error_callback);
367 } 310 }
368 311
369 bool NetworkConnectionHandler::HasConnectingNetwork( 312 bool NetworkConnectionHandlerImpl::HasConnectingNetwork(
370 const std::string& service_path) { 313 const std::string& service_path) {
371 return pending_requests_.count(service_path) != 0; 314 return pending_requests_.count(service_path) != 0;
372 } 315 }
373 316
374 bool NetworkConnectionHandler::HasPendingConnectRequest() { 317 bool NetworkConnectionHandlerImpl::HasPendingConnectRequest() {
375 return pending_requests_.size() > 0; 318 return pending_requests_.size() > 0;
376 } 319 }
377 320
378 void NetworkConnectionHandler::SetTetherDelegate( 321 void NetworkConnectionHandlerImpl::NetworkListChanged() {
379 TetherDelegate* tether_delegate) {
380 tether_delegate_ = tether_delegate;
381 }
382
383 void NetworkConnectionHandler::NetworkListChanged() {
384 CheckAllPendingRequests(); 322 CheckAllPendingRequests();
385 } 323 }
386 324
387 void NetworkConnectionHandler::NetworkPropertiesUpdated( 325 void NetworkConnectionHandlerImpl::NetworkPropertiesUpdated(
388 const NetworkState* network) { 326 const NetworkState* network) {
389 if (HasConnectingNetwork(network->path())) 327 if (HasConnectingNetwork(network->path()))
390 CheckPendingRequest(network->path()); 328 CheckPendingRequest(network->path());
391 } 329 }
392 330
393 NetworkConnectionHandler::ConnectRequest* 331 NetworkConnectionHandlerImpl::ConnectRequest*
394 NetworkConnectionHandler::GetPendingRequest(const std::string& service_path) { 332 NetworkConnectionHandlerImpl::GetPendingRequest(
333 const std::string& service_path) {
395 std::map<std::string, ConnectRequest>::iterator iter = 334 std::map<std::string, ConnectRequest>::iterator iter =
396 pending_requests_.find(service_path); 335 pending_requests_.find(service_path);
397 return iter != pending_requests_.end() ? &(iter->second) : NULL; 336 return iter != pending_requests_.end() ? &(iter->second) : NULL;
398 } 337 }
399 338
400 // ConnectToNetwork implementation 339 // ConnectToNetwork implementation
401 340
402 void NetworkConnectionHandler::VerifyConfiguredAndConnect( 341 void NetworkConnectionHandlerImpl::VerifyConfiguredAndConnect(
403 bool check_error_state, 342 bool check_error_state,
404 const std::string& service_path, 343 const std::string& service_path,
405 const base::DictionaryValue& service_properties) { 344 const base::DictionaryValue& service_properties) {
406 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); 345 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path);
407 346
408 // If 'passphrase_required' is still true, then the 'Passphrase' property 347 // If 'passphrase_required' is still true, then the 'Passphrase' property
409 // has not been set to a minimum length value. 348 // has not been set to a minimum length value.
410 bool passphrase_required = false; 349 bool passphrase_required = false;
411 service_properties.GetBooleanWithoutPathExpansion( 350 service_properties.GetBooleanWithoutPathExpansion(
412 shill::kPassphraseRequiredProperty, &passphrase_required); 351 shill::kPassphraseRequiredProperty, &passphrase_required);
413 if (passphrase_required) { 352 if (passphrase_required) {
414 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); 353 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired);
415 return; 354 return;
416 } 355 }
417 356
418 std::string type, security_class; 357 std::string type, security_class;
419 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); 358 service_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type);
420 service_properties.GetStringWithoutPathExpansion( 359 service_properties.GetStringWithoutPathExpansion(
421 shill::kSecurityClassProperty, &security_class); 360 shill::kSecurityClassProperty, &security_class);
422 bool connectable = false; 361 bool connectable = false;
423 service_properties.GetBooleanWithoutPathExpansion( 362 service_properties.GetBooleanWithoutPathExpansion(shill::kConnectableProperty,
424 shill::kConnectableProperty, &connectable); 363 &connectable);
425 364
426 // In case NetworkState was not available in ConnectToNetwork (e.g. it had 365 // In case NetworkState was not available in ConnectToNetwork (e.g. it had
427 // been recently configured), we need to check Connectable again. 366 // been recently configured), we need to check Connectable again.
428 if (connectable && type != shill::kTypeVPN) { 367 if (connectable && type != shill::kTypeVPN) {
429 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. 368 // TODO(stevenjb): Shill needs to properly set Connectable for VPN.
430 CallShillConnect(service_path); 369 CallShillConnect(service_path);
431 return; 370 return;
432 } 371 }
433 372
434 // Get VPN provider type and host (required for configuration) and ensure 373 // Get VPN provider type and host (required for configuration) and ensure
435 // that required VPN non-cert properties are set. 374 // that required VPN non-cert properties are set.
436 const base::DictionaryValue* provider_properties = NULL; 375 const base::DictionaryValue* provider_properties = NULL;
437 std::string vpn_provider_type, vpn_provider_host, vpn_client_cert_id; 376 std::string vpn_provider_type, vpn_provider_host, vpn_client_cert_id;
438 if (type == shill::kTypeVPN) { 377 if (type == shill::kTypeVPN) {
439 // VPN Provider values are read from the "Provider" dictionary, not the 378 // VPN Provider values are read from the "Provider" dictionary, not the
440 // "Provider.Type", etc keys (which are used only to set the values). 379 // "Provider.Type", etc keys (which are used only to set the values).
441 if (service_properties.GetDictionaryWithoutPathExpansion( 380 if (service_properties.GetDictionaryWithoutPathExpansion(
442 shill::kProviderProperty, &provider_properties)) { 381 shill::kProviderProperty, &provider_properties)) {
443 provider_properties->GetStringWithoutPathExpansion( 382 provider_properties->GetStringWithoutPathExpansion(shill::kTypeProperty,
444 shill::kTypeProperty, &vpn_provider_type); 383 &vpn_provider_type);
445 provider_properties->GetStringWithoutPathExpansion( 384 provider_properties->GetStringWithoutPathExpansion(shill::kHostProperty,
446 shill::kHostProperty, &vpn_provider_host); 385 &vpn_provider_host);
447 provider_properties->GetStringWithoutPathExpansion( 386 provider_properties->GetStringWithoutPathExpansion(
448 shill::kL2tpIpsecClientCertIdProperty, &vpn_client_cert_id); 387 shill::kL2tpIpsecClientCertIdProperty, &vpn_client_cert_id);
449 } 388 }
450 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { 389 if (vpn_provider_type.empty() || vpn_provider_host.empty()) {
451 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); 390 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
452 return; 391 return;
453 } 392 }
454 } 393 }
455 394
456 std::string guid; 395 std::string guid;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 457 }
519 458
520 // Check certificate properties from policy. 459 // Check certificate properties from policy.
521 if (cert_config_from_policy.client_cert_type == 460 if (cert_config_from_policy.client_cert_type ==
522 onc::client_cert::kPattern) { 461 onc::client_cert::kPattern) {
523 if (!ClientCertResolver::ResolveCertificatePatternSync( 462 if (!ClientCertResolver::ResolveCertificatePatternSync(
524 client_cert_type, cert_config_from_policy, &config_properties)) { 463 client_cert_type, cert_config_from_policy, &config_properties)) {
525 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); 464 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired);
526 return; 465 return;
527 } 466 }
528 } else if (check_error_state && 467 } else if (check_error_state && !client_cert::IsCertificateConfigured(
529 !client_cert::IsCertificateConfigured(client_cert_type, 468 client_cert_type, service_properties)) {
530 service_properties)) {
531 // Network may not be configured. 469 // Network may not be configured.
532 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); 470 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
533 return; 471 return;
534 } 472 }
535 } 473 }
536 474
537 if (type == shill::kTypeVPN) { 475 if (type == shill::kTypeVPN) {
538 // VPN may require a username, and/or passphrase to be set. (Check after 476 // VPN may require a username, and/or passphrase to be set. (Check after
539 // ensuring that any required certificates are configured). 477 // ensuring that any required certificates are configured).
540 DCHECK(provider_properties); 478 DCHECK(provider_properties);
541 if (VPNRequiresCredentials( 479 if (VPNRequiresCredentials(service_path, vpn_provider_type,
542 service_path, vpn_provider_type, *provider_properties)) { 480 *provider_properties)) {
543 NET_LOG_USER("VPN Requires Credentials", service_path); 481 NET_LOG_USER("VPN Requires Credentials", service_path);
544 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); 482 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
545 return; 483 return;
546 } 484 }
547 485
548 // If it's L2TP/IPsec PSK, there is no properties to configure, so proceed 486 // If it's L2TP/IPsec PSK, there is no properties to configure, so proceed
549 // to connect. 487 // to connect.
550 if (client_cert_type == client_cert::CONFIG_TYPE_NONE) { 488 if (client_cert_type == client_cert::CONFIG_TYPE_NONE) {
551 CallShillConnect(service_path); 489 CallShillConnect(service_path);
552 return; 490 return;
553 } 491 }
554 } 492 }
555 493
556 if (!config_properties.empty()) { 494 if (!config_properties.empty()) {
557 NET_LOG_EVENT("Configuring Network", service_path); 495 NET_LOG_EVENT("Configuring Network", service_path);
558 configuration_handler_->SetShillProperties( 496 configuration_handler_->SetShillProperties(
559 service_path, config_properties, 497 service_path, config_properties,
560 NetworkConfigurationObserver::SOURCE_USER_ACTION, 498 NetworkConfigurationObserver::SOURCE_USER_ACTION,
561 base::Bind(&NetworkConnectionHandler::CallShillConnect, AsWeakPtr(), 499 base::Bind(&NetworkConnectionHandlerImpl::CallShillConnect, AsWeakPtr(),
562 service_path), 500 service_path),
563 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, 501 base::Bind(&NetworkConnectionHandlerImpl::HandleConfigurationFailure,
564 AsWeakPtr(), service_path)); 502 AsWeakPtr(), service_path));
565 return; 503 return;
566 } 504 }
567 505
568 // Otherwise, we probably still need to configure the network since 506 // Otherwise, we probably still need to configure the network since
569 // 'Connectable' is false. If |check_error_state| is true, signal an 507 // 'Connectable' is false. If |check_error_state| is true, signal an
570 // error, otherwise attempt to connect to possibly gain additional error 508 // error, otherwise attempt to connect to possibly gain additional error
571 // state from Shill (or in case 'Connectable' is improperly unset). 509 // state from Shill (or in case 'Connectable' is improperly unset).
572 if (check_error_state) 510 if (check_error_state)
573 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); 511 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired);
574 else 512 else
575 CallShillConnect(service_path); 513 CallShillConnect(service_path);
576 } 514 }
577 515
578 bool NetworkConnectionHandler::IsNetworkProhibitedByPolicy( 516 bool NetworkConnectionHandlerImpl::IsNetworkProhibitedByPolicy(
579 const std::string& type, 517 const std::string& type,
580 const std::string& guid, 518 const std::string& guid,
581 const std::string& profile_path) { 519 const std::string& profile_path) {
582 if (!logged_in_) 520 if (!logged_in_)
583 return false; 521 return false;
584 if (type != shill::kTypeWifi) 522 if (type != shill::kTypeWifi)
585 return false; 523 return false;
586 const base::DictionaryValue* global_network_config = 524 const base::DictionaryValue* global_network_config =
587 managed_configuration_handler_->GetGlobalConfigFromPolicy( 525 managed_configuration_handler_->GetGlobalConfigFromPolicy(
588 std::string() /* no username hash, device policy */); 526 std::string() /* no username hash, device policy */);
589 if (!global_network_config) 527 if (!global_network_config)
590 return false; 528 return false;
591 bool policy_prohibites = false; 529 bool policy_prohibites = false;
592 if (!global_network_config->GetBooleanWithoutPathExpansion( 530 if (!global_network_config->GetBooleanWithoutPathExpansion(
593 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, 531 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect,
594 &policy_prohibites) || 532 &policy_prohibites) ||
595 !policy_prohibites) { 533 !policy_prohibites) {
596 return false; 534 return false;
597 } 535 }
598 return !managed_configuration_handler_->FindPolicyByGuidAndProfile( 536 return !managed_configuration_handler_->FindPolicyByGuidAndProfile(
599 guid, profile_path, nullptr /* onc_source */); 537 guid, profile_path, nullptr /* onc_source */);
600 } 538 }
601 539
602 void NetworkConnectionHandler::QueueConnectRequest( 540 void NetworkConnectionHandlerImpl::QueueConnectRequest(
603 const std::string& service_path) { 541 const std::string& service_path) {
604 ConnectRequest* request = GetPendingRequest(service_path); 542 ConnectRequest* request = GetPendingRequest(service_path);
605 if (!request) { 543 if (!request) {
606 NET_LOG_ERROR("No pending request to queue", service_path); 544 NET_LOG_ERROR("No pending request to queue", service_path);
607 return; 545 return;
608 } 546 }
609 547
610 const int kMaxCertLoadTimeSeconds = 15; 548 const int kMaxCertLoadTimeSeconds = 15;
611 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_; 549 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_;
612 if (dtime > base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds)) { 550 if (dtime > base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds)) {
613 NET_LOG_ERROR("Certificate load timeout", service_path); 551 NET_LOG_ERROR("Certificate load timeout", service_path);
614 InvokeConnectErrorCallback(service_path, request->error_callback, 552 InvokeConnectErrorCallback(service_path, request->error_callback,
615 kErrorCertLoadTimeout); 553 kErrorCertLoadTimeout);
616 return; 554 return;
617 } 555 }
618 556
619 NET_LOG_EVENT("Connect Request Queued", service_path); 557 NET_LOG_EVENT("Connect Request Queued", service_path);
620 queued_connect_.reset(new ConnectRequest( 558 queued_connect_.reset(new ConnectRequest(service_path, request->profile_path,
621 service_path, request->profile_path, 559 request->success_callback,
622 request->success_callback, request->error_callback)); 560 request->error_callback));
623 pending_requests_.erase(service_path); 561 pending_requests_.erase(service_path);
624 562
625 // Post a delayed task to check to see if certificates have loaded. If they 563 // 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 564 // haven't, and queued_connect_ has not been cleared (e.g. by a successful
627 // connect request), cancel the request and notify the user. 565 // connect request), cancel the request and notify the user.
628 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 566 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
629 FROM_HERE, base::Bind(&NetworkConnectionHandler::CheckCertificatesLoaded, 567 FROM_HERE,
630 AsWeakPtr()), 568 base::Bind(&NetworkConnectionHandlerImpl::CheckCertificatesLoaded,
569 AsWeakPtr()),
631 base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds) - dtime); 570 base::TimeDelta::FromSeconds(kMaxCertLoadTimeSeconds) - dtime);
632 } 571 }
633 572
634 void NetworkConnectionHandler::CheckCertificatesLoaded() { 573 void NetworkConnectionHandlerImpl::CheckCertificatesLoaded() {
635 if (certificates_loaded_) 574 if (certificates_loaded_)
636 return; 575 return;
637 // If queued_connect_ has been cleared (e.g. another connect request occurred 576 // If queued_connect_ has been cleared (e.g. another connect request occurred
638 // and wasn't queued), do nothing here. 577 // and wasn't queued), do nothing here.
639 if (!queued_connect_) 578 if (!queued_connect_)
640 return; 579 return;
641 // Otherwise, notify the user. 580 // Otherwise, notify the user.
642 NET_LOG_ERROR("Certificate load timeout", queued_connect_->service_path); 581 NET_LOG_ERROR("Certificate load timeout", queued_connect_->service_path);
643 InvokeConnectErrorCallback(queued_connect_->service_path, 582 InvokeConnectErrorCallback(queued_connect_->service_path,
644 queued_connect_->error_callback, 583 queued_connect_->error_callback,
645 kErrorCertLoadTimeout); 584 kErrorCertLoadTimeout);
646 queued_connect_.reset(); 585 queued_connect_.reset();
647 } 586 }
648 587
649 void NetworkConnectionHandler::ConnectToQueuedNetwork() { 588 void NetworkConnectionHandlerImpl::ConnectToQueuedNetwork() {
650 DCHECK(queued_connect_); 589 DCHECK(queued_connect_);
651 590
652 // Make a copy of |queued_connect_| parameters, because |queued_connect_| 591 // Make a copy of |queued_connect_| parameters, because |queued_connect_|
653 // will get reset at the beginning of |ConnectToNetwork|. 592 // will get reset at the beginning of |ConnectToNetwork|.
654 std::string service_path = queued_connect_->service_path; 593 std::string service_path = queued_connect_->service_path;
655 base::Closure success_callback = queued_connect_->success_callback; 594 base::Closure success_callback = queued_connect_->success_callback;
656 network_handler::ErrorCallback error_callback = 595 network_handler::ErrorCallback error_callback =
657 queued_connect_->error_callback; 596 queued_connect_->error_callback;
658 597
659 NET_LOG_EVENT("Connecting to Queued Network", service_path); 598 NET_LOG_EVENT("Connecting to Queued Network", service_path);
660 ConnectToNetwork(service_path, success_callback, error_callback, 599 ConnectToNetwork(service_path, success_callback, error_callback,
661 false /* check_error_state */); 600 false /* check_error_state */);
662 } 601 }
663 602
664 void NetworkConnectionHandler::CallShillConnect( 603 void NetworkConnectionHandlerImpl::CallShillConnect(
665 const std::string& service_path) { 604 const std::string& service_path) {
666 NET_LOG_EVENT("Sending Connect Request to Shill", service_path); 605 NET_LOG_EVENT("Sending Connect Request to Shill", service_path);
667 network_state_handler_->ClearLastErrorForNetwork(service_path); 606 network_state_handler_->ClearLastErrorForNetwork(service_path);
668 DBusThreadManager::Get()->GetShillServiceClient()->Connect( 607 DBusThreadManager::Get()->GetShillServiceClient()->Connect(
669 dbus::ObjectPath(service_path), 608 dbus::ObjectPath(service_path),
670 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, 609 base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectSuccess,
671 AsWeakPtr(), service_path), 610 AsWeakPtr(), service_path),
672 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, 611 base::Bind(&NetworkConnectionHandlerImpl::HandleShillConnectFailure,
673 AsWeakPtr(), service_path)); 612 AsWeakPtr(), service_path));
674 } 613 }
675 614
676 void NetworkConnectionHandler::HandleConfigurationFailure( 615 void NetworkConnectionHandlerImpl::HandleConfigurationFailure(
677 const std::string& service_path, 616 const std::string& service_path,
678 const std::string& error_name, 617 const std::string& error_name,
679 std::unique_ptr<base::DictionaryValue> error_data) { 618 std::unique_ptr<base::DictionaryValue> error_data) {
680 ConnectRequest* request = GetPendingRequest(service_path); 619 ConnectRequest* request = GetPendingRequest(service_path);
681 if (!request) { 620 if (!request) {
682 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", 621 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.",
683 service_path); 622 service_path);
684 return; 623 return;
685 } 624 }
686 network_handler::ErrorCallback error_callback = request->error_callback; 625 network_handler::ErrorCallback error_callback = request->error_callback;
687 pending_requests_.erase(service_path); 626 pending_requests_.erase(service_path);
688 InvokeConnectErrorCallback(service_path, error_callback, 627 InvokeConnectErrorCallback(service_path, error_callback,
689 kErrorConfigureFailed); 628 kErrorConfigureFailed);
690 } 629 }
691 630
692 void NetworkConnectionHandler::HandleShillConnectSuccess( 631 void NetworkConnectionHandlerImpl::HandleShillConnectSuccess(
693 const std::string& service_path) { 632 const std::string& service_path) {
694 ConnectRequest* request = GetPendingRequest(service_path); 633 ConnectRequest* request = GetPendingRequest(service_path);
695 if (!request) { 634 if (!request) {
696 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", 635 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.",
697 service_path); 636 service_path);
698 return; 637 return;
699 } 638 }
700 request->connect_state = ConnectRequest::CONNECT_STARTED; 639 request->connect_state = ConnectRequest::CONNECT_STARTED;
701 NET_LOG_EVENT("Connect Request Acknowledged", service_path); 640 NET_LOG_EVENT("Connect Request Acknowledged", service_path);
702 // Do not call success_callback here, wait for one of the following 641 // Do not call success_callback here, wait for one of the following
703 // conditions: 642 // conditions:
704 // * State transitions to a non connecting state indicating success or failure 643 // * State transitions to a non connecting state indicating success or failure
705 // * Network is no longer in the visible list, indicating failure 644 // * Network is no longer in the visible list, indicating failure
706 CheckPendingRequest(service_path); 645 CheckPendingRequest(service_path);
707 } 646 }
708 647
709 void NetworkConnectionHandler::HandleShillConnectFailure( 648 void NetworkConnectionHandlerImpl::HandleShillConnectFailure(
710 const std::string& service_path, 649 const std::string& service_path,
711 const std::string& dbus_error_name, 650 const std::string& dbus_error_name,
712 const std::string& dbus_error_message) { 651 const std::string& dbus_error_message) {
713 ConnectRequest* request = GetPendingRequest(service_path); 652 ConnectRequest* request = GetPendingRequest(service_path);
714 if (!request) { 653 if (!request) {
715 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", 654 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.",
716 service_path); 655 service_path);
717 return; 656 return;
718 } 657 }
719 network_handler::ErrorCallback error_callback = request->error_callback; 658 network_handler::ErrorCallback error_callback = request->error_callback;
720 pending_requests_.erase(service_path); 659 pending_requests_.erase(service_path);
721 std::string error; 660 std::string error;
722 if (dbus_error_name == shill::kErrorResultAlreadyConnected) { 661 if (dbus_error_name == shill::kErrorResultAlreadyConnected) {
723 error = kErrorConnected; 662 error = kErrorConnected;
724 } else if (dbus_error_name == shill::kErrorResultInProgress) { 663 } else if (dbus_error_name == shill::kErrorResultInProgress) {
725 error = kErrorConnecting; 664 error = kErrorConnecting;
726 } else { 665 } else {
727 NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name, 666 NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name,
728 service_path); 667 service_path);
729 error = kErrorConnectFailed; 668 error = kErrorConnectFailed;
730 } 669 }
731 InvokeConnectErrorCallback(service_path, error_callback, error); 670 InvokeConnectErrorCallback(service_path, error_callback, error);
732 } 671 }
733 672
734 void NetworkConnectionHandler::CheckPendingRequest( 673 void NetworkConnectionHandlerImpl::CheckPendingRequest(
735 const std::string service_path) { 674 const std::string service_path) {
736 ConnectRequest* request = GetPendingRequest(service_path); 675 ConnectRequest* request = GetPendingRequest(service_path);
737 DCHECK(request); 676 DCHECK(request);
738 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) 677 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED)
739 return; // Request has not started, ignore update 678 return; // Request has not started, ignore update
740 const NetworkState* network = 679 const NetworkState* network =
741 network_state_handler_->GetNetworkState(service_path); 680 network_state_handler_->GetNetworkState(service_path);
742 if (!network) 681 if (!network)
743 return; // NetworkState may not be be updated yet. 682 return; // NetworkState may not be be updated yet.
744 683
745 if (network->IsConnectingState()) { 684 if (network->IsConnectingState()) {
746 request->connect_state = ConnectRequest::CONNECT_CONNECTING; 685 request->connect_state = ConnectRequest::CONNECT_CONNECTING;
747 return; 686 return;
748 } 687 }
749 if (network->IsConnectedState()) { 688 if (network->IsConnectedState()) {
750 if (!request->profile_path.empty()) { 689 if (!request->profile_path.empty()) {
751 // If a profile path was specified, set it on a successful connection. 690 // If a profile path was specified, set it on a successful connection.
752 configuration_handler_->SetNetworkProfile( 691 configuration_handler_->SetNetworkProfile(
753 service_path, 692 service_path, request->profile_path,
754 request->profile_path,
755 NetworkConfigurationObserver::SOURCE_USER_ACTION, 693 NetworkConfigurationObserver::SOURCE_USER_ACTION,
756 base::Bind(&base::DoNothing), 694 base::Bind(&base::DoNothing),
757 chromeos::network_handler::ErrorCallback()); 695 chromeos::network_handler::ErrorCallback());
758 } 696 }
759 InvokeConnectSuccessCallback(request->service_path, 697 InvokeConnectSuccessCallback(request->service_path,
760 request->success_callback); 698 request->success_callback);
761 pending_requests_.erase(service_path); 699 pending_requests_.erase(service_path);
762 return; 700 return;
763 } 701 }
764 if (network->connection_state() == shill::kStateIdle && 702 if (network->connection_state() == shill::kStateIdle &&
(...skipping 14 matching lines...) Expand all
779 NET_LOG_ERROR("Unexpected State: " + network->connection_state(), 717 NET_LOG_ERROR("Unexpected State: " + network->connection_state(),
780 service_path); 718 service_path);
781 } 719 }
782 } 720 }
783 721
784 network_handler::ErrorCallback error_callback = request->error_callback; 722 network_handler::ErrorCallback error_callback = request->error_callback;
785 pending_requests_.erase(service_path); 723 pending_requests_.erase(service_path);
786 InvokeConnectErrorCallback(service_path, error_callback, error_name); 724 InvokeConnectErrorCallback(service_path, error_callback, error_name);
787 } 725 }
788 726
789 void NetworkConnectionHandler::CheckAllPendingRequests() { 727 void NetworkConnectionHandlerImpl::CheckAllPendingRequests() {
790 for (std::map<std::string, ConnectRequest>::iterator iter = 728 for (std::map<std::string, ConnectRequest>::iterator iter =
791 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { 729 pending_requests_.begin();
730 iter != pending_requests_.end(); ++iter) {
792 CheckPendingRequest(iter->first); 731 CheckPendingRequest(iter->first);
793 } 732 }
794 } 733 }
795 734
796 // Connect callbacks 735 // Connect callbacks
797 736
798 void NetworkConnectionHandler::InvokeConnectSuccessCallback( 737 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, 738 const std::string& service_path,
810 const std::string& error_name) { 739 const std::string& error_name) {
811 ConnectRequest* request = GetPendingRequest(service_path); 740 ConnectRequest* request = GetPendingRequest(service_path);
812 if (!request) { 741 if (!request) {
813 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", 742 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.",
814 service_path); 743 service_path);
815 return; 744 return;
816 } 745 }
817 // Remove the entry before invoking the callback in case it triggers a retry. 746 // Remove the entry before invoking the callback in case it triggers a retry.
818 network_handler::ErrorCallback error_callback = request->error_callback; 747 network_handler::ErrorCallback error_callback = request->error_callback;
819 pending_requests_.erase(service_path); 748 pending_requests_.erase(service_path);
820 InvokeConnectErrorCallback(service_path, error_callback, error_name); 749 InvokeConnectErrorCallback(service_path, error_callback, error_name);
821 } 750 }
822 751
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 752 // Disconnect
835 753
836 void NetworkConnectionHandler::CallShillDisconnect( 754 void NetworkConnectionHandlerImpl::CallShillDisconnect(
837 const std::string& service_path, 755 const std::string& service_path,
838 const base::Closure& success_callback, 756 const base::Closure& success_callback,
839 const network_handler::ErrorCallback& error_callback) { 757 const network_handler::ErrorCallback& error_callback) {
840 NET_LOG_USER("Disconnect Request", service_path); 758 NET_LOG_USER("Disconnect Request", service_path);
841 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( 759 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
842 dbus::ObjectPath(service_path), 760 dbus::ObjectPath(service_path),
843 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, 761 base::Bind(&NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess,
844 AsWeakPtr(), service_path, success_callback), 762 AsWeakPtr(), service_path, success_callback),
845 base::Bind(&network_handler::ShillErrorCallbackFunction, 763 base::Bind(&network_handler::ShillErrorCallbackFunction,
846 kErrorDisconnectFailed, service_path, error_callback)); 764 kErrorDisconnectFailed, service_path, error_callback));
847 } 765 }
848 766
849 void NetworkConnectionHandler::HandleShillDisconnectSuccess( 767 void NetworkConnectionHandlerImpl::HandleShillDisconnectSuccess(
850 const std::string& service_path, 768 const std::string& service_path,
851 const base::Closure& success_callback) { 769 const base::Closure& success_callback) {
852 NET_LOG_EVENT("Disconnect Request Sent", service_path); 770 NET_LOG_EVENT("Disconnect Request Sent", service_path);
853 if (!success_callback.is_null()) 771 if (!success_callback.is_null())
854 success_callback.Run(); 772 success_callback.Run();
855 } 773 }
856 774
857 } // namespace chromeos 775 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_connection_handler_impl.h ('k') | chromeos/network/network_connection_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698