Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / chromeos / network / network_connect.cc
blobe492f1273ca5cea7ba6318cf6c4dd34c2f25f167
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 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology,
67 bool enabled_state) override;
68 void ActivateCellular(const std::string& service_path) override;
69 void ShowMobileSetup(const std::string& service_path) override;
70 void ConfigureNetworkAndConnect(const std::string& service_path,
71 const base::DictionaryValue& shill_properties,
72 bool shared) override;
73 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties,
74 bool shared) override;
75 void CreateConfiguration(base::DictionaryValue* shill_properties,
76 bool shared) override;
77 base::string16 GetShillErrorString(const std::string& error,
78 const std::string& service_path) override;
79 void ShowNetworkSettingsForPath(const std::string& service_path) override;
81 private:
82 void HandleUnconfiguredNetwork(const std::string& service_path);
83 void OnConnectFailed(const std::string& service_path,
84 const std::string& error_name,
85 scoped_ptr<base::DictionaryValue> error_data);
86 bool GetNetworkProfilePath(bool shared, std::string* profile_path);
87 void OnConnectSucceeded(const std::string& service_path);
88 void CallConnectToNetwork(const std::string& service_path,
89 bool check_error_state);
90 void OnActivateFailed(const std::string& service_path,
91 const std::string& error_name,
92 scoped_ptr<base::DictionaryValue> error_data);
93 void OnActivateSucceeded(const std::string& service_path);
94 void OnConfigureFailed(const std::string& error_name,
95 scoped_ptr<base::DictionaryValue> error_data);
96 void OnConfigureSucceeded(bool connect_on_configure,
97 const std::string& service_path);
98 void CallCreateConfiguration(base::DictionaryValue* properties,
99 bool shared,
100 bool connect_on_configure);
101 void SetPropertiesFailed(const std::string& desc,
102 const std::string& service_path,
103 const std::string& config_error_name,
104 scoped_ptr<base::DictionaryValue> error_data);
105 void SetPropertiesToClear(base::DictionaryValue* properties_to_set,
106 std::vector<std::string>* properties_to_clear);
107 void ClearPropertiesAndConnect(
108 const std::string& service_path,
109 const std::vector<std::string>& properties_to_clear);
110 void ConfigureSetProfileSucceeded(
111 const std::string& service_path,
112 scoped_ptr<base::DictionaryValue> properties_to_set);
114 Delegate* delegate_;
115 scoped_ptr<NetworkStateNotifier> network_state_notifier_;
116 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_;
118 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl);
121 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate)
122 : delegate_(delegate), weak_factory_(this) {
123 network_state_notifier_.reset(new NetworkStateNotifier(this));
126 NetworkConnectImpl::~NetworkConnectImpl() {
129 void NetworkConnectImpl::HandleUnconfiguredNetwork(
130 const std::string& service_path) {
131 const NetworkState* network = GetNetworkState(service_path);
132 if (!network) {
133 NET_LOG_ERROR("Configuring unknown network", service_path);
134 return;
137 if (network->type() == shill::kTypeWifi) {
138 // Only show the config view for secure networks, otherwise do nothing.
139 if (network->security_class() != shill::kSecurityNone) {
140 delegate_->ShowNetworkConfigure(service_path);
142 return;
145 if (network->type() == shill::kTypeWimax) {
146 delegate_->ShowNetworkConfigure(service_path);
147 return;
150 if (network->type() == shill::kTypeVPN) {
151 // Third-party VPNs handle configuration UI themselves.
152 if (network->vpn_provider_type() != shill::kProviderThirdPartyVpn)
153 delegate_->ShowNetworkConfigure(service_path);
154 return;
157 if (network->type() == shill::kTypeCellular) {
158 if (network->RequiresActivation()) {
159 ActivateCellular(service_path);
160 return;
162 if (network->cellular_out_of_credits()) {
163 ShowMobileSetup(service_path);
164 return;
166 // No special configure or setup for |network|, show the settings UI.
167 if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
168 ShowNetworkSettingsForPath(service_path);
170 return;
172 NOTREACHED();
175 // If |shared| is true, sets |profile_path| to the shared profile path.
176 // Otherwise sets |profile_path| to the user profile path if authenticated and
177 // available. Returns 'false' if unable to set |profile_path|.
178 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared,
179 std::string* profile_path) {
180 if (shared) {
181 *profile_path = NetworkProfileHandler::GetSharedProfilePath();
182 return true;
185 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) {
186 NET_LOG_ERROR("User profile specified before login", "");
187 return false;
190 const NetworkProfile* profile =
191 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile();
192 if (!profile) {
193 NET_LOG_ERROR("No user profile for unshared network configuration", "");
194 return false;
197 *profile_path = profile->path;
198 return true;
201 // This handles connect failures that are a direct result of a user initiated
202 // connect request and result in a new UI being shown. Note: notifications are
203 // handled by NetworkStateNotifier.
204 void NetworkConnectImpl::OnConnectFailed(
205 const std::string& service_path,
206 const std::string& error_name,
207 scoped_ptr<base::DictionaryValue> error_data) {
208 NET_LOG_ERROR("Connect Failed: " + error_name, service_path);
210 if (error_name == NetworkConnectionHandler::kErrorBadPassphrase ||
211 error_name == NetworkConnectionHandler::kErrorPassphraseRequired ||
212 error_name == NetworkConnectionHandler::kErrorConfigurationRequired ||
213 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) {
214 HandleUnconfiguredNetwork(service_path);
215 return;
218 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
219 if (!delegate_->ShowEnrollNetwork(service_path))
220 HandleUnconfiguredNetwork(service_path);
221 return;
224 // Only show a configure dialog if there was a ConnectFailed error. The dialog
225 // allows the user to request a new connect attempt or cancel. Note: a
226 // notification may also be displayed by NetworkStateNotifier in this case.
227 if (error_name == NetworkConnectionHandler::kErrorConnectFailed)
228 HandleUnconfiguredNetwork(service_path);
230 // Notifications for other connect failures are handled by
231 // NetworkStateNotifier, so no need to do anything else here.
234 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) {
235 NET_LOG_USER("Connect Succeeded", service_path);
238 // If |check_error_state| is true, error state for the network is checked,
239 // otherwise any current error state is ignored (e.g. for recently configured
240 // networks or repeat connect attempts).
241 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path,
242 bool check_error_state) {
243 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
244 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded,
245 weak_factory_.GetWeakPtr(), service_path),
246 base::Bind(&NetworkConnectImpl::OnConnectFailed,
247 weak_factory_.GetWeakPtr(), service_path),
248 check_error_state);
251 void NetworkConnectImpl::OnActivateFailed(
252 const std::string& service_path,
253 const std::string& error_name,
254 scoped_ptr<base::DictionaryValue> error_data) {
255 NET_LOG_ERROR("Unable to activate network", service_path);
256 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed,
257 service_path);
260 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) {
261 NET_LOG_USER("Activation Succeeded", service_path);
264 void NetworkConnectImpl::OnConfigureFailed(
265 const std::string& error_name,
266 scoped_ptr<base::DictionaryValue> error_data) {
267 NET_LOG_ERROR("Unable to configure network", "");
268 network_state_notifier_->ShowNetworkConnectError(
269 NetworkConnectionHandler::kErrorConfigureFailed, "");
272 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure,
273 const std::string& service_path) {
274 NET_LOG_USER("Configure Succeeded", service_path);
275 if (!connect_on_configure)
276 return;
277 // After configuring a network, ignore any (possibly stale) error state.
278 const bool check_error_state = false;
279 CallConnectToNetwork(service_path, check_error_state);
282 void NetworkConnectImpl::CallCreateConfiguration(
283 base::DictionaryValue* shill_properties,
284 bool shared,
285 bool connect_on_configure) {
286 std::string profile_path;
287 if (!GetNetworkProfilePath(shared, &profile_path)) {
288 network_state_notifier_->ShowNetworkConnectError(
289 NetworkConnectionHandler::kErrorConfigureFailed, "");
290 return;
292 shill_properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
293 profile_path);
294 NetworkHandler::Get()
295 ->network_configuration_handler()
296 ->CreateShillConfiguration(
297 *shill_properties, NetworkConfigurationObserver::SOURCE_USER_ACTION,
298 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded,
299 weak_factory_.GetWeakPtr(), connect_on_configure),
300 base::Bind(&NetworkConnectImpl::OnConfigureFailed,
301 weak_factory_.GetWeakPtr()));
304 void NetworkConnectImpl::SetPropertiesFailed(
305 const std::string& desc,
306 const std::string& service_path,
307 const std::string& config_error_name,
308 scoped_ptr<base::DictionaryValue> error_data) {
309 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
310 network_state_notifier_->ShowNetworkConnectError(
311 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
314 void NetworkConnectImpl::SetPropertiesToClear(
315 base::DictionaryValue* properties_to_set,
316 std::vector<std::string>* properties_to_clear) {
317 // Move empty string properties to properties_to_clear.
318 for (base::DictionaryValue::Iterator iter(*properties_to_set);
319 !iter.IsAtEnd(); iter.Advance()) {
320 std::string value_str;
321 if (iter.value().GetAsString(&value_str) && value_str.empty())
322 properties_to_clear->push_back(iter.key());
324 // Remove cleared properties from properties_to_set.
325 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
326 iter != properties_to_clear->end(); ++iter) {
327 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
331 void NetworkConnectImpl::ClearPropertiesAndConnect(
332 const std::string& service_path,
333 const std::vector<std::string>& properties_to_clear) {
334 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
335 // After configuring a network, ignore any (possibly stale) error state.
336 const bool check_error_state = false;
337 NetworkHandler::Get()->network_configuration_handler()->ClearShillProperties(
338 service_path, properties_to_clear,
339 base::Bind(&NetworkConnectImpl::CallConnectToNetwork,
340 weak_factory_.GetWeakPtr(), service_path, check_error_state),
341 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
342 weak_factory_.GetWeakPtr(), "ClearProperties", service_path));
345 void NetworkConnectImpl::ConfigureSetProfileSucceeded(
346 const std::string& service_path,
347 scoped_ptr<base::DictionaryValue> properties_to_set) {
348 std::vector<std::string> properties_to_clear;
349 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
350 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties(
351 service_path, *properties_to_set,
352 NetworkConfigurationObserver::SOURCE_USER_ACTION,
353 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect,
354 weak_factory_.GetWeakPtr(), service_path, properties_to_clear),
355 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
356 weak_factory_.GetWeakPtr(), "SetProperties", service_path));
359 // Public methods
361 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) {
362 NET_LOG_USER("ConnectToNetwork", service_path);
363 const NetworkState* network = GetNetworkState(service_path);
364 if (network) {
365 if (!network->error().empty() && !network->security_class().empty()) {
366 NET_LOG_USER("Configure: " + network->error(), service_path);
367 // If the network is in an error state, show the configuration UI
368 // directly to avoid a spurious notification.
369 HandleUnconfiguredNetwork(service_path);
370 return;
371 } else if (network->RequiresActivation()) {
372 ActivateCellular(service_path);
373 return;
376 const bool check_error_state = true;
377 CallConnectToNetwork(service_path, check_error_state);
380 void NetworkConnectImpl::SetTechnologyEnabled(
381 const NetworkTypePattern& technology,
382 bool enabled_state) {
383 std::string log_string = base::StringPrintf(
384 "technology %s, target state: %s", technology.ToDebugString().c_str(),
385 (enabled_state ? "ENABLED" : "DISABLED"));
386 NET_LOG_USER("SetTechnologyEnabled", log_string);
387 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
388 bool enabled = handler->IsTechnologyEnabled(technology);
389 if (enabled_state == enabled) {
390 NET_LOG_USER("Technology already in target state.", log_string);
391 return;
393 if (enabled) {
394 // User requested to disable the technology.
395 handler->SetTechnologyEnabled(technology, false,
396 chromeos::network_handler::ErrorCallback());
397 return;
399 // If we're dealing with a mobile network, then handle SIM lock here.
400 // SIM locking only applies to cellular, so the code below won't execute
401 // if |technology| has been explicitly set to WiMAX.
402 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) {
403 const DeviceState* mobile = handler->GetDeviceStateByType(technology);
404 if (!mobile) {
405 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string);
406 return;
408 // The following only applies to cellular.
409 if (mobile->type() == shill::kTypeCellular) {
410 if (mobile->IsSimAbsent()) {
411 // If this is true, then we have a cellular device with no SIM
412 // inserted. TODO(armansito): Chrome should display a notification here,
413 // prompting the user to insert a SIM card and restart the device to
414 // enable cellular. See crbug.com/125171.
415 NET_LOG_USER("Cannot enable cellular device without SIM.", log_string);
416 return;
418 if (!mobile->sim_lock_type().empty()) {
419 // A SIM has been inserted, but it is locked. Let the user unlock it
420 // via the dialog.
421 delegate_->ShowMobileSimDialog();
422 return;
426 handler->SetTechnologyEnabled(technology, true,
427 chromeos::network_handler::ErrorCallback());
430 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) {
431 NET_LOG_USER("ActivateCellular", service_path);
432 const NetworkState* cellular = GetNetworkState(service_path);
433 if (!cellular || cellular->type() != shill::kTypeCellular) {
434 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
435 return;
437 const DeviceState* cellular_device =
438 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
439 cellular->device_path());
440 if (!cellular_device) {
441 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
442 return;
444 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
445 // For non direct activation, show the mobile setup dialog which can be
446 // used to activate the network.
447 ShowMobileSetup(service_path);
448 return;
450 if (cellular->activation_state() == shill::kActivationStateActivated) {
451 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
452 return;
455 NetworkHandler::Get()->network_activation_handler()->Activate(
456 service_path,
457 "", // carrier
458 base::Bind(&NetworkConnectImpl::OnActivateSucceeded,
459 weak_factory_.GetWeakPtr(), service_path),
460 base::Bind(&NetworkConnectImpl::OnActivateFailed,
461 weak_factory_.GetWeakPtr(), service_path));
464 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) {
465 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
466 const NetworkState* cellular = handler->GetNetworkState(service_path);
467 if (!cellular || cellular->type() != shill::kTypeCellular) {
468 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
469 return;
471 if (cellular->activation_state() != shill::kActivationStateActivated &&
472 cellular->activation_type() == shill::kActivationTypeNonCellular &&
473 !handler->DefaultNetwork()) {
474 network_state_notifier_->ShowMobileActivationError(service_path);
475 return;
477 delegate_->ShowMobileSetupDialog(service_path);
480 void NetworkConnectImpl::ConfigureNetworkAndConnect(
481 const std::string& service_path,
482 const base::DictionaryValue& properties,
483 bool shared) {
484 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
486 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
488 std::string profile_path;
489 if (!GetNetworkProfilePath(shared, &profile_path)) {
490 network_state_notifier_->ShowNetworkConnectError(
491 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
492 return;
494 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile(
495 service_path, profile_path,
496 NetworkConfigurationObserver::SOURCE_USER_ACTION,
497 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded,
498 weak_factory_.GetWeakPtr(), service_path,
499 base::Passed(&properties_to_set)),
500 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
501 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path,
502 service_path));
505 void NetworkConnectImpl::CreateConfigurationAndConnect(
506 base::DictionaryValue* properties,
507 bool shared) {
508 NET_LOG_USER("CreateConfigurationAndConnect", "");
509 CallCreateConfiguration(properties, shared, true /* connect_on_configure */);
512 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties,
513 bool shared) {
514 NET_LOG_USER("CreateConfiguration", "");
515 CallCreateConfiguration(properties, shared, false /* connect_on_configure */);
518 base::string16 NetworkConnectImpl::GetShillErrorString(
519 const std::string& error,
520 const std::string& service_path) {
521 if (error.empty())
522 return base::string16();
523 if (error == shill::kErrorOutOfRange)
524 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
525 if (error == shill::kErrorPinMissing)
526 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
527 if (error == shill::kErrorDhcpFailed)
528 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED);
529 if (error == shill::kErrorConnectFailed)
530 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED);
531 if (error == shill::kErrorBadPassphrase)
532 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE);
533 if (error == shill::kErrorBadWEPKey)
534 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY);
535 if (error == shill::kErrorActivationFailed) {
536 return l10n_util::GetStringUTF16(
537 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
539 if (error == shill::kErrorNeedEvdo)
540 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO);
541 if (error == shill::kErrorNeedHomeNetwork) {
542 return l10n_util::GetStringUTF16(
543 IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK);
545 if (error == shill::kErrorOtaspFailed)
546 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED);
547 if (error == shill::kErrorAaaFailed)
548 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED);
549 if (error == shill::kErrorInternal)
550 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL);
551 if (error == shill::kErrorDNSLookupFailed) {
552 return l10n_util::GetStringUTF16(
553 IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED);
555 if (error == shill::kErrorHTTPGetFailed) {
556 return l10n_util::GetStringUTF16(
557 IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED);
559 if (error == shill::kErrorIpsecPskAuthFailed) {
560 return l10n_util::GetStringUTF16(
561 IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED);
563 if (error == shill::kErrorIpsecCertAuthFailed) {
564 return l10n_util::GetStringUTF16(
565 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
567 if (error == shill::kErrorEapAuthenticationFailed) {
568 const NetworkState* network = GetNetworkState(service_path);
569 // TLS always requires a client certificate, so show a cert auth
570 // failed message for TLS. Other EAP methods do not generally require
571 // a client certicate.
572 if (network && network->eap_method() == shill::kEapMethodTLS) {
573 return l10n_util::GetStringUTF16(
574 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
575 } else {
576 return l10n_util::GetStringUTF16(
577 IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED);
580 if (error == shill::kErrorEapLocalTlsFailed) {
581 return l10n_util::GetStringUTF16(
582 IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED);
584 if (error == shill::kErrorEapRemoteTlsFailed) {
585 return l10n_util::GetStringUTF16(
586 IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED);
588 if (error == shill::kErrorPppAuthFailed) {
589 return l10n_util::GetStringUTF16(
590 IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED);
593 if (base::StringToLowerASCII(error) ==
594 base::StringToLowerASCII(std::string(shill::kUnknownString))) {
595 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
597 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
598 base::UTF8ToUTF16(error));
601 void NetworkConnectImpl::ShowNetworkSettingsForPath(
602 const std::string& service_path) {
603 const NetworkState* network = GetNetworkState(service_path);
604 delegate_->ShowNetworkSettingsForGuid(network ? network->guid() : "");
607 } // namespace
609 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed";
611 static NetworkConnect* g_network_connect = NULL;
613 // static
614 void NetworkConnect::Initialize(Delegate* delegate) {
615 CHECK(g_network_connect == NULL);
616 g_network_connect = new NetworkConnectImpl(delegate);
619 // static
620 void NetworkConnect::Shutdown() {
621 CHECK(g_network_connect);
622 delete g_network_connect;
623 g_network_connect = NULL;
626 // static
627 NetworkConnect* NetworkConnect::Get() {
628 CHECK(g_network_connect);
629 return g_network_connect;
632 NetworkConnect::NetworkConnect() {
635 NetworkConnect::~NetworkConnect() {
638 } // namespace ui