base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / chromeos / network / network_connect.cc
blobe1d98566c0c6661e05b321bbb1fa57fdc91fdb67
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& properties,
72 bool shared) override;
73 void CreateConfigurationAndConnect(base::DictionaryValue* properties,
74 bool shared) override;
75 void CreateConfiguration(base::DictionaryValue* properties,
76 bool shared) override;
77 base::string16 GetErrorString(const std::string& error,
78 const std::string& service_path) override;
79 void ShowNetworkSettings(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() != shill::kSecurityNone) {
140 delegate_->ShowNetworkConfigure(service_path);
142 return;
145 if (network->type() == shill::kTypeWimax ||
146 network->type() == shill::kTypeVPN) {
147 delegate_->ShowNetworkConfigure(service_path);
148 return;
151 if (network->type() == shill::kTypeCellular) {
152 if (network->RequiresActivation()) {
153 ActivateCellular(service_path);
154 return;
156 if (network->cellular_out_of_credits()) {
157 ShowMobileSetup(service_path);
158 return;
160 // No special configure or setup for |network|, show the settings UI.
161 if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
162 delegate_->ShowNetworkSettings(service_path);
164 return;
166 NOTREACHED();
169 // If |shared| is true, sets |profile_path| to the shared profile path.
170 // Otherwise sets |profile_path| to the user profile path if authenticated and
171 // available. Returns 'false' if unable to set |profile_path|.
172 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared,
173 std::string* profile_path) {
174 if (shared) {
175 *profile_path = NetworkProfileHandler::GetSharedProfilePath();
176 return true;
179 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) {
180 NET_LOG_ERROR("User profile specified before login", "");
181 return false;
184 const NetworkProfile* profile =
185 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile();
186 if (!profile) {
187 NET_LOG_ERROR("No user profile for unshared network configuration", "");
188 return false;
191 *profile_path = profile->path;
192 return true;
195 void NetworkConnectImpl::OnConnectFailed(
196 const std::string& service_path,
197 const std::string& error_name,
198 scoped_ptr<base::DictionaryValue> error_data) {
199 NET_LOG_ERROR("Connect Failed: " + error_name, service_path);
201 // If a new connect attempt canceled this connect, no need to notify the
202 // user.
203 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled)
204 return;
206 if (error_name == shill::kErrorBadPassphrase ||
207 error_name == NetworkConnectionHandler::kErrorPassphraseRequired ||
208 error_name == NetworkConnectionHandler::kErrorConfigurationRequired ||
209 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) {
210 HandleUnconfiguredNetwork(service_path);
211 return;
214 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
215 if (!delegate_->ShowEnrollNetwork(service_path)) {
216 HandleUnconfiguredNetwork(service_path);
218 return;
221 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) {
222 ActivateCellular(service_path);
223 return;
226 if (error_name == NetworkConnectionHandler::kErrorConnected ||
227 error_name == NetworkConnectionHandler::kErrorConnecting) {
228 ShowNetworkSettings(service_path);
229 return;
232 // ConnectFailed or unknown error; show a notification.
233 network_state_notifier_->ShowNetworkConnectError(error_name, service_path);
235 // Only show a configure dialog if there was a ConnectFailed error.
236 if (error_name != shill::kErrorConnectFailed)
237 return;
239 // If Shill reports an InProgress error, don't try to configure the network.
240 std::string dbus_error_name;
241 error_data.get()->GetString(chromeos::network_handler::kDbusErrorName,
242 &dbus_error_name);
243 if (dbus_error_name == shill::kErrorResultInProgress)
244 return;
246 HandleUnconfiguredNetwork(service_path);
249 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) {
250 NET_LOG_USER("Connect Succeeded", service_path);
251 network_state_notifier_->RemoveConnectNotification();
254 // If |check_error_state| is true, error state for the network is checked,
255 // otherwise any current error state is ignored (e.g. for recently configured
256 // networks or repeat connect attempts).
257 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path,
258 bool check_error_state) {
259 network_state_notifier_->RemoveConnectNotification();
260 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
261 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded,
262 weak_factory_.GetWeakPtr(), service_path),
263 base::Bind(&NetworkConnectImpl::OnConnectFailed,
264 weak_factory_.GetWeakPtr(), service_path),
265 check_error_state);
268 void NetworkConnectImpl::OnActivateFailed(
269 const std::string& service_path,
270 const std::string& error_name,
271 scoped_ptr<base::DictionaryValue> error_data) {
272 NET_LOG_ERROR("Unable to activate network", service_path);
273 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed,
274 service_path);
277 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) {
278 NET_LOG_USER("Activation Succeeded", service_path);
281 void NetworkConnectImpl::OnConfigureFailed(
282 const std::string& error_name,
283 scoped_ptr<base::DictionaryValue> error_data) {
284 NET_LOG_ERROR("Unable to configure network", "");
285 network_state_notifier_->ShowNetworkConnectError(
286 NetworkConnectionHandler::kErrorConfigureFailed, "");
289 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure,
290 const std::string& service_path) {
291 NET_LOG_USER("Configure Succeeded", service_path);
292 if (!connect_on_configure)
293 return;
294 // After configuring a network, ignore any (possibly stale) error state.
295 const bool check_error_state = false;
296 CallConnectToNetwork(service_path, check_error_state);
299 void NetworkConnectImpl::CallCreateConfiguration(
300 base::DictionaryValue* properties,
301 bool shared,
302 bool connect_on_configure) {
303 std::string profile_path;
304 if (!GetNetworkProfilePath(shared, &profile_path)) {
305 network_state_notifier_->ShowNetworkConnectError(
306 NetworkConnectionHandler::kErrorConfigureFailed, "");
307 return;
309 properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
310 profile_path);
311 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration(
312 *properties, NetworkConfigurationObserver::SOURCE_USER_ACTION,
313 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded,
314 weak_factory_.GetWeakPtr(), connect_on_configure),
315 base::Bind(&NetworkConnectImpl::OnConfigureFailed,
316 weak_factory_.GetWeakPtr()));
319 void NetworkConnectImpl::SetPropertiesFailed(
320 const std::string& desc,
321 const std::string& service_path,
322 const std::string& config_error_name,
323 scoped_ptr<base::DictionaryValue> error_data) {
324 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
325 network_state_notifier_->ShowNetworkConnectError(
326 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
329 void NetworkConnectImpl::SetPropertiesToClear(
330 base::DictionaryValue* properties_to_set,
331 std::vector<std::string>* properties_to_clear) {
332 // Move empty string properties to properties_to_clear.
333 for (base::DictionaryValue::Iterator iter(*properties_to_set);
334 !iter.IsAtEnd(); iter.Advance()) {
335 std::string value_str;
336 if (iter.value().GetAsString(&value_str) && value_str.empty())
337 properties_to_clear->push_back(iter.key());
339 // Remove cleared properties from properties_to_set.
340 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
341 iter != properties_to_clear->end(); ++iter) {
342 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
346 void NetworkConnectImpl::ClearPropertiesAndConnect(
347 const std::string& service_path,
348 const std::vector<std::string>& properties_to_clear) {
349 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
350 // After configuring a network, ignore any (possibly stale) error state.
351 const bool check_error_state = false;
352 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
353 service_path, properties_to_clear,
354 base::Bind(&NetworkConnectImpl::CallConnectToNetwork,
355 weak_factory_.GetWeakPtr(), service_path, check_error_state),
356 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
357 weak_factory_.GetWeakPtr(), "ClearProperties", service_path));
360 void NetworkConnectImpl::ConfigureSetProfileSucceeded(
361 const std::string& service_path,
362 scoped_ptr<base::DictionaryValue> properties_to_set) {
363 std::vector<std::string> properties_to_clear;
364 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
365 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
366 service_path, *properties_to_set,
367 NetworkConfigurationObserver::SOURCE_USER_ACTION,
368 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect,
369 weak_factory_.GetWeakPtr(), service_path, properties_to_clear),
370 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
371 weak_factory_.GetWeakPtr(), "SetProperties", service_path));
374 // Public methods
376 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) {
377 NET_LOG_USER("ConnectToNetwork", service_path);
378 const NetworkState* network = GetNetworkState(service_path);
379 if (network) {
380 if (!network->error().empty() && !network->security().empty()) {
381 NET_LOG_USER("Configure: " + network->error(), service_path);
382 // If the network is in an error state, show the configuration UI
383 // directly to avoid a spurious notification.
384 HandleUnconfiguredNetwork(service_path);
385 return;
386 } else if (network->RequiresActivation()) {
387 ActivateCellular(service_path);
388 return;
391 const bool check_error_state = true;
392 CallConnectToNetwork(service_path, check_error_state);
395 void NetworkConnectImpl::SetTechnologyEnabled(
396 const NetworkTypePattern& technology,
397 bool enabled_state) {
398 std::string log_string = base::StringPrintf(
399 "technology %s, target state: %s", technology.ToDebugString().c_str(),
400 (enabled_state ? "ENABLED" : "DISABLED"));
401 NET_LOG_USER("SetTechnologyEnabled", log_string);
402 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
403 bool enabled = handler->IsTechnologyEnabled(technology);
404 if (enabled_state == enabled) {
405 NET_LOG_USER("Technology already in target state.", log_string);
406 return;
408 if (enabled) {
409 // User requested to disable the technology.
410 handler->SetTechnologyEnabled(technology, false,
411 chromeos::network_handler::ErrorCallback());
412 return;
414 // If we're dealing with a mobile network, then handle SIM lock here.
415 // SIM locking only applies to cellular, so the code below won't execute
416 // if |technology| has been explicitly set to WiMAX.
417 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) {
418 const DeviceState* mobile = handler->GetDeviceStateByType(technology);
419 if (!mobile) {
420 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string);
421 return;
423 // The following only applies to cellular.
424 if (mobile->type() == shill::kTypeCellular) {
425 if (mobile->IsSimAbsent()) {
426 // If this is true, then we have a cellular device with no SIM
427 // inserted. TODO(armansito): Chrome should display a notification here,
428 // prompting the user to insert a SIM card and restart the device to
429 // enable cellular. See crbug.com/125171.
430 NET_LOG_USER("Cannot enable cellular device without SIM.", log_string);
431 return;
433 if (!mobile->sim_lock_type().empty()) {
434 // A SIM has been inserted, but it is locked. Let the user unlock it
435 // via the dialog.
436 delegate_->ShowMobileSimDialog();
437 return;
441 handler->SetTechnologyEnabled(technology, true,
442 chromeos::network_handler::ErrorCallback());
445 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) {
446 NET_LOG_USER("ActivateCellular", service_path);
447 const NetworkState* cellular = GetNetworkState(service_path);
448 if (!cellular || cellular->type() != shill::kTypeCellular) {
449 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
450 return;
452 const DeviceState* cellular_device =
453 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
454 cellular->device_path());
455 if (!cellular_device) {
456 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
457 return;
459 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
460 // For non direct activation, show the mobile setup dialog which can be
461 // used to activate the network.
462 ShowMobileSetup(service_path);
463 return;
465 if (cellular->activation_state() == shill::kActivationStateActivated) {
466 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
467 return;
470 NetworkHandler::Get()->network_activation_handler()->Activate(
471 service_path,
472 "", // carrier
473 base::Bind(&NetworkConnectImpl::OnActivateSucceeded,
474 weak_factory_.GetWeakPtr(), service_path),
475 base::Bind(&NetworkConnectImpl::OnActivateFailed,
476 weak_factory_.GetWeakPtr(), service_path));
479 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) {
480 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
481 const NetworkState* cellular = handler->GetNetworkState(service_path);
482 if (!cellular || cellular->type() != shill::kTypeCellular) {
483 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
484 return;
486 if (cellular->activation_state() != shill::kActivationStateActivated &&
487 cellular->activation_type() == shill::kActivationTypeNonCellular &&
488 !handler->DefaultNetwork()) {
489 network_state_notifier_->ShowMobileActivationError(service_path);
490 return;
492 delegate_->ShowMobileSetupDialog(service_path);
495 void NetworkConnectImpl::ConfigureNetworkAndConnect(
496 const std::string& service_path,
497 const base::DictionaryValue& properties,
498 bool shared) {
499 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
501 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
503 std::string profile_path;
504 if (!GetNetworkProfilePath(shared, &profile_path)) {
505 network_state_notifier_->ShowNetworkConnectError(
506 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
507 return;
509 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile(
510 service_path, profile_path,
511 NetworkConfigurationObserver::SOURCE_USER_ACTION,
512 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded,
513 weak_factory_.GetWeakPtr(), service_path,
514 base::Passed(&properties_to_set)),
515 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
516 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path,
517 service_path));
520 void NetworkConnectImpl::CreateConfigurationAndConnect(
521 base::DictionaryValue* properties,
522 bool shared) {
523 NET_LOG_USER("CreateConfigurationAndConnect", "");
524 CallCreateConfiguration(properties, shared, true /* connect_on_configure */);
527 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties,
528 bool shared) {
529 NET_LOG_USER("CreateConfiguration", "");
530 CallCreateConfiguration(properties, shared, false /* connect_on_configure */);
533 base::string16 NetworkConnectImpl::GetErrorString(
534 const std::string& error,
535 const std::string& service_path) {
536 if (error.empty())
537 return base::string16();
538 if (error == shill::kErrorOutOfRange)
539 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
540 if (error == shill::kErrorPinMissing)
541 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
542 if (error == shill::kErrorDhcpFailed)
543 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED);
544 if (error == shill::kErrorConnectFailed)
545 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED);
546 if (error == shill::kErrorBadPassphrase)
547 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE);
548 if (error == shill::kErrorBadWEPKey)
549 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY);
550 if (error == shill::kErrorActivationFailed) {
551 return l10n_util::GetStringUTF16(
552 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
554 if (error == shill::kErrorNeedEvdo)
555 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO);
556 if (error == shill::kErrorNeedHomeNetwork) {
557 return l10n_util::GetStringUTF16(
558 IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK);
560 if (error == shill::kErrorOtaspFailed)
561 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED);
562 if (error == shill::kErrorAaaFailed)
563 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED);
564 if (error == shill::kErrorInternal)
565 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL);
566 if (error == shill::kErrorDNSLookupFailed) {
567 return l10n_util::GetStringUTF16(
568 IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED);
570 if (error == shill::kErrorHTTPGetFailed) {
571 return l10n_util::GetStringUTF16(
572 IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED);
574 if (error == shill::kErrorIpsecPskAuthFailed) {
575 return l10n_util::GetStringUTF16(
576 IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED);
578 if (error == shill::kErrorIpsecCertAuthFailed) {
579 return l10n_util::GetStringUTF16(
580 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
582 if (error == shill::kErrorEapAuthenticationFailed) {
583 const NetworkState* network = GetNetworkState(service_path);
584 // TLS always requires a client certificate, so show a cert auth
585 // failed message for TLS. Other EAP methods do not generally require
586 // a client certicate.
587 if (network && network->eap_method() == shill::kEapMethodTLS) {
588 return l10n_util::GetStringUTF16(
589 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
590 } else {
591 return l10n_util::GetStringUTF16(
592 IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED);
595 if (error == shill::kErrorEapLocalTlsFailed) {
596 return l10n_util::GetStringUTF16(
597 IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED);
599 if (error == shill::kErrorEapRemoteTlsFailed) {
600 return l10n_util::GetStringUTF16(
601 IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED);
603 if (error == shill::kErrorPppAuthFailed) {
604 return l10n_util::GetStringUTF16(
605 IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED);
608 if (base::StringToLowerASCII(error) ==
609 base::StringToLowerASCII(std::string(shill::kUnknownString))) {
610 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
612 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
613 base::UTF8ToUTF16(error));
616 void NetworkConnectImpl::ShowNetworkSettings(const std::string& service_path) {
617 delegate_->ShowNetworkSettings(service_path);
620 } // namespace
622 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed";
624 static NetworkConnect* g_network_connect = NULL;
626 // static
627 void NetworkConnect::Initialize(Delegate* delegate) {
628 CHECK(g_network_connect == NULL);
629 g_network_connect = new NetworkConnectImpl(delegate);
632 // static
633 void NetworkConnect::Shutdown() {
634 CHECK(g_network_connect);
635 delete g_network_connect;
636 g_network_connect = NULL;
639 // static
640 NetworkConnect* NetworkConnect::Get() {
641 CHECK(g_network_connect);
642 return g_network_connect;
645 NetworkConnect::NetworkConnect() {
648 NetworkConnect::~NetworkConnect() {
651 } // namespace ui