Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / ui / chromeos / network / network_connect.cc
blob23e1109b392f6dd688dd1bcc9d36680cef79870f
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
3 // found in the LICENSE file.
5 #include "ui/chromeos/network/network_connect.h"
7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "chromeos/login/login_state.h"
13 #include "chromeos/network/device_state.h"
14 #include "chromeos/network/network_activation_handler.h"
15 #include "chromeos/network/network_configuration_handler.h"
16 #include "chromeos/network/network_connection_handler.h"
17 #include "chromeos/network/network_event_log.h"
18 #include "chromeos/network/network_handler_callbacks.h"
19 #include "chromeos/network/network_profile.h"
20 #include "chromeos/network/network_profile_handler.h"
21 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h"
23 #include "grit/ui_chromeos_strings.h"
24 #include "third_party/cros_system_api/dbus/service_constants.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/chromeos/network/network_state_notifier.h"
28 #include "ui/message_center/message_center.h"
29 #include "ui/message_center/notification.h"
31 using chromeos::DeviceState;
32 using chromeos::NetworkConfigurationHandler;
33 using chromeos::NetworkConfigurationObserver;
34 using chromeos::NetworkConnectionHandler;
35 using chromeos::NetworkHandler;
36 using chromeos::NetworkProfile;
37 using chromeos::NetworkProfileHandler;
38 using chromeos::NetworkState;
39 using chromeos::NetworkStateHandler;
40 using chromeos::NetworkTypePattern;
42 namespace ui {
44 namespace {
46 // Returns true for carriers that can be activated through Shill instead of
47 // through a WebUI dialog.
48 bool IsDirectActivatedCarrier(const std::string& carrier) {
49 if (carrier == shill::kCarrierSprint)
50 return true;
51 return false;
54 const NetworkState* GetNetworkState(const std::string& service_path) {
55 return NetworkHandler::Get()->network_state_handler()->GetNetworkState(
56 service_path);
59 class NetworkConnectImpl : public NetworkConnect {
60 public:
61 explicit NetworkConnectImpl(Delegate* delegate);
62 ~NetworkConnectImpl() override;
64 // NetworkConnect
65 void ConnectToNetwork(const std::string& service_path) override;
66 bool MaybeShowConfigureUI(const std::string& service_path,
67 const std::string& connect_error) override;
68 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology,
69 bool enabled_state) override;
70 void ActivateCellular(const std::string& service_path) override;
71 void ShowMobileSetup(const std::string& service_path) override;
72 void ConfigureNetworkAndConnect(const std::string& service_path,
73 const base::DictionaryValue& shill_properties,
74 bool shared) override;
75 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties,
76 bool shared) override;
77 void CreateConfiguration(base::DictionaryValue* shill_properties,
78 bool shared) override;
79 base::string16 GetShillErrorString(const std::string& error,
80 const std::string& service_path) override;
81 void ShowNetworkSettingsForPath(const std::string& service_path) override;
83 private:
84 void HandleUnconfiguredNetwork(const std::string& service_path);
85 void OnConnectFailed(const std::string& service_path,
86 const std::string& error_name,
87 scoped_ptr<base::DictionaryValue> error_data);
88 bool MaybeShowConfigureUIImpl(const std::string& service_path,
89 const std::string& connect_error);
90 bool GetNetworkProfilePath(bool shared, std::string* profile_path);
91 void OnConnectSucceeded(const std::string& service_path);
92 void CallConnectToNetwork(const std::string& service_path,
93 bool check_error_state);
94 void OnActivateFailed(const std::string& service_path,
95 const std::string& error_name,
96 scoped_ptr<base::DictionaryValue> error_data);
97 void OnActivateSucceeded(const std::string& service_path);
98 void OnConfigureFailed(const std::string& error_name,
99 scoped_ptr<base::DictionaryValue> error_data);
100 void OnConfigureSucceeded(bool connect_on_configure,
101 const std::string& service_path);
102 void CallCreateConfiguration(base::DictionaryValue* properties,
103 bool shared,
104 bool connect_on_configure);
105 void SetPropertiesFailed(const std::string& desc,
106 const std::string& service_path,
107 const std::string& config_error_name,
108 scoped_ptr<base::DictionaryValue> error_data);
109 void SetPropertiesToClear(base::DictionaryValue* properties_to_set,
110 std::vector<std::string>* properties_to_clear);
111 void ClearPropertiesAndConnect(
112 const std::string& service_path,
113 const std::vector<std::string>& properties_to_clear);
114 void ConfigureSetProfileSucceeded(
115 const std::string& service_path,
116 scoped_ptr<base::DictionaryValue> properties_to_set);
118 Delegate* delegate_;
119 scoped_ptr<NetworkStateNotifier> network_state_notifier_;
120 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_;
122 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl);
125 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate)
126 : delegate_(delegate), weak_factory_(this) {
127 network_state_notifier_.reset(new NetworkStateNotifier(this));
130 NetworkConnectImpl::~NetworkConnectImpl() {
133 void NetworkConnectImpl::HandleUnconfiguredNetwork(
134 const std::string& service_path) {
135 const NetworkState* network = GetNetworkState(service_path);
136 if (!network) {
137 NET_LOG_ERROR("Configuring unknown network", service_path);
138 return;
141 if (network->type() == shill::kTypeWifi) {
142 // Only show the config view for secure networks, otherwise do nothing.
143 if (network->security_class() != shill::kSecurityNone) {
144 delegate_->ShowNetworkConfigure(service_path);
146 return;
149 if (network->type() == shill::kTypeWimax) {
150 delegate_->ShowNetworkConfigure(service_path);
151 return;
154 if (network->type() == shill::kTypeVPN) {
155 // Third-party VPNs handle configuration UI themselves.
156 if (network->vpn_provider_type() != shill::kProviderThirdPartyVpn)
157 delegate_->ShowNetworkConfigure(service_path);
158 return;
161 if (network->type() == shill::kTypeCellular) {
162 if (network->RequiresActivation()) {
163 ActivateCellular(service_path);
164 return;
166 if (network->cellular_out_of_credits()) {
167 ShowMobileSetup(service_path);
168 return;
170 // No special configure or setup for |network|, show the settings UI.
171 if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
172 ShowNetworkSettingsForPath(service_path);
174 return;
176 NOTREACHED();
179 // If |shared| is true, sets |profile_path| to the shared profile path.
180 // Otherwise sets |profile_path| to the user profile path if authenticated and
181 // available. Returns 'false' if unable to set |profile_path|.
182 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared,
183 std::string* profile_path) {
184 if (shared) {
185 *profile_path = NetworkProfileHandler::GetSharedProfilePath();
186 return true;
189 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) {
190 NET_LOG_ERROR("User profile specified before login", "");
191 return false;
194 const NetworkProfile* profile =
195 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile();
196 if (!profile) {
197 NET_LOG_ERROR("No user profile for unshared network configuration", "");
198 return false;
201 *profile_path = profile->path;
202 return true;
205 void NetworkConnectImpl::OnConnectFailed(
206 const std::string& service_path,
207 const std::string& error_name,
208 scoped_ptr<base::DictionaryValue> error_data) {
209 MaybeShowConfigureUIImpl(service_path, error_name);
212 // This handles connect failures that are a direct result of a user initiated
213 // connect request and result in a new UI being shown. Note: notifications are
214 // handled by NetworkStateNotifier.
215 bool NetworkConnectImpl::MaybeShowConfigureUIImpl(
216 const std::string& service_path,
217 const std::string& connect_error) {
218 NET_LOG_ERROR("Connect Failed: " + connect_error, service_path);
220 if (connect_error == NetworkConnectionHandler::kErrorBadPassphrase ||
221 connect_error == NetworkConnectionHandler::kErrorPassphraseRequired ||
222 connect_error == NetworkConnectionHandler::kErrorConfigurationRequired ||
223 connect_error == NetworkConnectionHandler::kErrorAuthenticationRequired) {
224 HandleUnconfiguredNetwork(service_path);
225 return true;
228 if (connect_error == NetworkConnectionHandler::kErrorCertificateRequired) {
229 if (!delegate_->ShowEnrollNetwork(service_path))
230 HandleUnconfiguredNetwork(service_path);
231 return true;
234 // Only show a configure dialog if there was a ConnectFailed error. The dialog
235 // allows the user to request a new connect attempt or cancel. Note: a
236 // notification may also be displayed by NetworkStateNotifier in this case.
237 if (connect_error == NetworkConnectionHandler::kErrorConnectFailed) {
238 HandleUnconfiguredNetwork(service_path);
239 return true;
242 // Notifications for other connect failures are handled by
243 // NetworkStateNotifier, so no need to do anything else here.
244 return false;
247 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) {
248 NET_LOG_USER("Connect Succeeded", service_path);
251 // If |check_error_state| is true, error state for the network is checked,
252 // otherwise any current error state is ignored (e.g. for recently configured
253 // networks or repeat connect attempts).
254 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path,
255 bool check_error_state) {
256 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
257 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded,
258 weak_factory_.GetWeakPtr(), service_path),
259 base::Bind(&NetworkConnectImpl::OnConnectFailed,
260 weak_factory_.GetWeakPtr(), service_path),
261 check_error_state);
264 void NetworkConnectImpl::OnActivateFailed(
265 const std::string& service_path,
266 const std::string& error_name,
267 scoped_ptr<base::DictionaryValue> error_data) {
268 NET_LOG_ERROR("Unable to activate network", service_path);
269 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed,
270 service_path);
273 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) {
274 NET_LOG_USER("Activation Succeeded", service_path);
277 void NetworkConnectImpl::OnConfigureFailed(
278 const std::string& error_name,
279 scoped_ptr<base::DictionaryValue> error_data) {
280 NET_LOG_ERROR("Unable to configure network", "");
281 network_state_notifier_->ShowNetworkConnectError(
282 NetworkConnectionHandler::kErrorConfigureFailed, "");
285 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure,
286 const std::string& service_path) {
287 NET_LOG_USER("Configure Succeeded", service_path);
288 if (!connect_on_configure)
289 return;
290 // After configuring a network, ignore any (possibly stale) error state.
291 const bool check_error_state = false;
292 CallConnectToNetwork(service_path, check_error_state);
295 void NetworkConnectImpl::CallCreateConfiguration(
296 base::DictionaryValue* shill_properties,
297 bool shared,
298 bool connect_on_configure) {
299 std::string profile_path;
300 if (!GetNetworkProfilePath(shared, &profile_path)) {
301 network_state_notifier_->ShowNetworkConnectError(
302 NetworkConnectionHandler::kErrorConfigureFailed, "");
303 return;
305 shill_properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
306 profile_path);
307 NetworkHandler::Get()
308 ->network_configuration_handler()
309 ->CreateShillConfiguration(
310 *shill_properties, NetworkConfigurationObserver::SOURCE_USER_ACTION,
311 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded,
312 weak_factory_.GetWeakPtr(), connect_on_configure),
313 base::Bind(&NetworkConnectImpl::OnConfigureFailed,
314 weak_factory_.GetWeakPtr()));
317 void NetworkConnectImpl::SetPropertiesFailed(
318 const std::string& desc,
319 const std::string& service_path,
320 const std::string& config_error_name,
321 scoped_ptr<base::DictionaryValue> error_data) {
322 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
323 network_state_notifier_->ShowNetworkConnectError(
324 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
327 void NetworkConnectImpl::SetPropertiesToClear(
328 base::DictionaryValue* properties_to_set,
329 std::vector<std::string>* properties_to_clear) {
330 // Move empty string properties to properties_to_clear.
331 for (base::DictionaryValue::Iterator iter(*properties_to_set);
332 !iter.IsAtEnd(); iter.Advance()) {
333 std::string value_str;
334 if (iter.value().GetAsString(&value_str) && value_str.empty())
335 properties_to_clear->push_back(iter.key());
337 // Remove cleared properties from properties_to_set.
338 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
339 iter != properties_to_clear->end(); ++iter) {
340 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
344 void NetworkConnectImpl::ClearPropertiesAndConnect(
345 const std::string& service_path,
346 const std::vector<std::string>& properties_to_clear) {
347 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
348 // After configuring a network, ignore any (possibly stale) error state.
349 const bool check_error_state = false;
350 NetworkHandler::Get()->network_configuration_handler()->ClearShillProperties(
351 service_path, properties_to_clear,
352 base::Bind(&NetworkConnectImpl::CallConnectToNetwork,
353 weak_factory_.GetWeakPtr(), service_path, check_error_state),
354 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
355 weak_factory_.GetWeakPtr(), "ClearProperties", service_path));
358 void NetworkConnectImpl::ConfigureSetProfileSucceeded(
359 const std::string& service_path,
360 scoped_ptr<base::DictionaryValue> properties_to_set) {
361 std::vector<std::string> properties_to_clear;
362 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
363 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties(
364 service_path, *properties_to_set,
365 NetworkConfigurationObserver::SOURCE_USER_ACTION,
366 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect,
367 weak_factory_.GetWeakPtr(), service_path, properties_to_clear),
368 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
369 weak_factory_.GetWeakPtr(), "SetProperties", service_path));
372 // Public methods
374 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) {
375 NET_LOG_USER("ConnectToNetwork", service_path);
376 const NetworkState* network = GetNetworkState(service_path);
377 if (network) {
378 if (!network->error().empty() && !network->security_class().empty()) {
379 NET_LOG_USER("Configure: " + network->error(), service_path);
380 // If the network is in an error state, show the configuration UI
381 // directly to avoid a spurious notification.
382 HandleUnconfiguredNetwork(service_path);
383 return;
384 } else if (network->RequiresActivation()) {
385 ActivateCellular(service_path);
386 return;
389 const bool check_error_state = true;
390 CallConnectToNetwork(service_path, check_error_state);
393 bool NetworkConnectImpl::MaybeShowConfigureUI(
394 const std::string& service_path,
395 const std::string& connect_error) {
396 return MaybeShowConfigureUIImpl(service_path, connect_error);
399 void NetworkConnectImpl::SetTechnologyEnabled(
400 const NetworkTypePattern& technology,
401 bool enabled_state) {
402 std::string log_string = base::StringPrintf(
403 "technology %s, target state: %s", technology.ToDebugString().c_str(),
404 (enabled_state ? "ENABLED" : "DISABLED"));
405 NET_LOG_USER("SetTechnologyEnabled", log_string);
406 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
407 bool enabled = handler->IsTechnologyEnabled(technology);
408 if (enabled_state == enabled) {
409 NET_LOG_USER("Technology already in target state.", log_string);
410 return;
412 if (enabled) {
413 // User requested to disable the technology.
414 handler->SetTechnologyEnabled(technology, false,
415 chromeos::network_handler::ErrorCallback());
416 return;
418 // If we're dealing with a mobile network, then handle SIM lock here.
419 // SIM locking only applies to cellular, so the code below won't execute
420 // if |technology| has been explicitly set to WiMAX.
421 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) {
422 const DeviceState* mobile = handler->GetDeviceStateByType(technology);
423 if (!mobile) {
424 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string);
425 return;
427 // The following only applies to cellular.
428 if (mobile->type() == shill::kTypeCellular) {
429 if (mobile->IsSimAbsent()) {
430 // If this is true, then we have a cellular device with no SIM
431 // inserted. TODO(armansito): Chrome should display a notification here,
432 // prompting the user to insert a SIM card and restart the device to
433 // enable cellular. See crbug.com/125171.
434 NET_LOG_USER("Cannot enable cellular device without SIM.", log_string);
435 return;
437 if (!mobile->sim_lock_type().empty()) {
438 // A SIM has been inserted, but it is locked. Let the user unlock it
439 // via the dialog.
440 delegate_->ShowMobileSimDialog();
441 return;
445 handler->SetTechnologyEnabled(technology, true,
446 chromeos::network_handler::ErrorCallback());
449 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) {
450 NET_LOG_USER("ActivateCellular", service_path);
451 const NetworkState* cellular = GetNetworkState(service_path);
452 if (!cellular || cellular->type() != shill::kTypeCellular) {
453 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
454 return;
456 const DeviceState* cellular_device =
457 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
458 cellular->device_path());
459 if (!cellular_device) {
460 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
461 return;
463 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
464 // For non direct activation, show the mobile setup dialog which can be
465 // used to activate the network.
466 ShowMobileSetup(service_path);
467 return;
469 if (cellular->activation_state() == shill::kActivationStateActivated) {
470 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
471 return;
474 NetworkHandler::Get()->network_activation_handler()->Activate(
475 service_path,
476 "", // carrier
477 base::Bind(&NetworkConnectImpl::OnActivateSucceeded,
478 weak_factory_.GetWeakPtr(), service_path),
479 base::Bind(&NetworkConnectImpl::OnActivateFailed,
480 weak_factory_.GetWeakPtr(), service_path));
483 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) {
484 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
485 const NetworkState* cellular = handler->GetNetworkState(service_path);
486 if (!cellular || cellular->type() != shill::kTypeCellular) {
487 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
488 return;
490 if (cellular->activation_state() != shill::kActivationStateActivated &&
491 cellular->activation_type() == shill::kActivationTypeNonCellular &&
492 !handler->DefaultNetwork()) {
493 network_state_notifier_->ShowMobileActivationError(service_path);
494 return;
496 delegate_->ShowMobileSetupDialog(service_path);
499 void NetworkConnectImpl::ConfigureNetworkAndConnect(
500 const std::string& service_path,
501 const base::DictionaryValue& properties,
502 bool shared) {
503 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
505 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
507 std::string profile_path;
508 if (!GetNetworkProfilePath(shared, &profile_path)) {
509 network_state_notifier_->ShowNetworkConnectError(
510 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
511 return;
513 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile(
514 service_path, profile_path,
515 NetworkConfigurationObserver::SOURCE_USER_ACTION,
516 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded,
517 weak_factory_.GetWeakPtr(), service_path,
518 base::Passed(&properties_to_set)),
519 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
520 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path,
521 service_path));
524 void NetworkConnectImpl::CreateConfigurationAndConnect(
525 base::DictionaryValue* properties,
526 bool shared) {
527 NET_LOG_USER("CreateConfigurationAndConnect", "");
528 CallCreateConfiguration(properties, shared, true /* connect_on_configure */);
531 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties,
532 bool shared) {
533 NET_LOG_USER("CreateConfiguration", "");
534 CallCreateConfiguration(properties, shared, false /* connect_on_configure */);
537 base::string16 NetworkConnectImpl::GetShillErrorString(
538 const std::string& error,
539 const std::string& service_path) {
540 if (error.empty())
541 return base::string16();
542 if (error == shill::kErrorOutOfRange)
543 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
544 if (error == shill::kErrorPinMissing)
545 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
546 if (error == shill::kErrorDhcpFailed)
547 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED);
548 if (error == shill::kErrorConnectFailed)
549 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED);
550 if (error == shill::kErrorBadPassphrase)
551 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE);
552 if (error == shill::kErrorBadWEPKey)
553 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY);
554 if (error == shill::kErrorActivationFailed) {
555 return l10n_util::GetStringUTF16(
556 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
558 if (error == shill::kErrorNeedEvdo)
559 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO);
560 if (error == shill::kErrorNeedHomeNetwork) {
561 return l10n_util::GetStringUTF16(
562 IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK);
564 if (error == shill::kErrorOtaspFailed)
565 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED);
566 if (error == shill::kErrorAaaFailed)
567 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED);
568 if (error == shill::kErrorInternal)
569 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL);
570 if (error == shill::kErrorDNSLookupFailed) {
571 return l10n_util::GetStringUTF16(
572 IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED);
574 if (error == shill::kErrorHTTPGetFailed) {
575 return l10n_util::GetStringUTF16(
576 IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED);
578 if (error == shill::kErrorIpsecPskAuthFailed) {
579 return l10n_util::GetStringUTF16(
580 IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED);
582 if (error == shill::kErrorIpsecCertAuthFailed) {
583 return l10n_util::GetStringUTF16(
584 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
586 if (error == shill::kErrorEapAuthenticationFailed) {
587 const NetworkState* network = GetNetworkState(service_path);
588 // TLS always requires a client certificate, so show a cert auth
589 // failed message for TLS. Other EAP methods do not generally require
590 // a client certicate.
591 if (network && network->eap_method() == shill::kEapMethodTLS) {
592 return l10n_util::GetStringUTF16(
593 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
594 } else {
595 return l10n_util::GetStringUTF16(
596 IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED);
599 if (error == shill::kErrorEapLocalTlsFailed) {
600 return l10n_util::GetStringUTF16(
601 IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED);
603 if (error == shill::kErrorEapRemoteTlsFailed) {
604 return l10n_util::GetStringUTF16(
605 IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED);
607 if (error == shill::kErrorPppAuthFailed) {
608 return l10n_util::GetStringUTF16(
609 IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED);
612 if (base::ToLowerASCII(error) == base::ToLowerASCII(shill::kUnknownString)) {
613 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
615 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
616 base::UTF8ToUTF16(error));
619 void NetworkConnectImpl::ShowNetworkSettingsForPath(
620 const std::string& service_path) {
621 const NetworkState* network = GetNetworkState(service_path);
622 delegate_->ShowNetworkSettingsForGuid(network ? network->guid() : "");
625 } // namespace
627 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed";
629 static NetworkConnect* g_network_connect = NULL;
631 // static
632 void NetworkConnect::Initialize(Delegate* delegate) {
633 CHECK(g_network_connect == NULL);
634 g_network_connect = new NetworkConnectImpl(delegate);
637 // static
638 void NetworkConnect::Shutdown() {
639 CHECK(g_network_connect);
640 delete g_network_connect;
641 g_network_connect = NULL;
644 // static
645 NetworkConnect* NetworkConnect::Get() {
646 CHECK(g_network_connect);
647 return g_network_connect;
650 NetworkConnect::NetworkConnect() {
653 NetworkConnect::~NetworkConnect() {
656 } // namespace ui