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

Side by Side Diff: ash/system/chromeos/network/network_connect.cc

Issue 690943003: Move network_connect code to ui/chromeos/network (Take 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(Empty)
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.
4
5 #include "ash/system/chromeos/network/network_connect.h"
6
7 #include "ash/system/chromeos/network/network_state_notifier.h"
8 #include "base/bind.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chromeos/login/login_state.h"
14 #include "chromeos/network/device_state.h"
15 #include "chromeos/network/network_activation_handler.h"
16 #include "chromeos/network/network_configuration_handler.h"
17 #include "chromeos/network/network_connection_handler.h"
18 #include "chromeos/network/network_event_log.h"
19 #include "chromeos/network/network_handler_callbacks.h"
20 #include "chromeos/network/network_profile.h"
21 #include "chromeos/network/network_profile_handler.h"
22 #include "chromeos/network/network_state.h"
23 #include "chromeos/network/network_state_handler.h"
24 #include "grit/ash_resources.h"
25 #include "grit/ash_strings.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/message_center/message_center.h"
30 #include "ui/message_center/notification.h"
31
32 using chromeos::DeviceState;
33 using chromeos::NetworkConfigurationHandler;
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;
41
42 namespace ash {
43
44 namespace {
45
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;
52 }
53
54 const NetworkState* GetNetworkState(const std::string& service_path) {
55 return NetworkHandler::Get()->network_state_handler()->GetNetworkState(
56 service_path);
57 }
58
59 class NetworkConnectImpl : public NetworkConnect {
60 public:
61 explicit NetworkConnectImpl(Delegate* delegate);
62 ~NetworkConnectImpl() override;
63
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;
80
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);
113
114 Delegate* delegate_;
115 scoped_ptr<NetworkStateNotifier> network_state_notifier_;
116 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_;
117
118 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl);
119 };
120
121 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate)
122 : delegate_(delegate), weak_factory_(this) {
123 network_state_notifier_.reset(new NetworkStateNotifier(this));
124 }
125
126 NetworkConnectImpl::~NetworkConnectImpl() {
127 }
128
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;
135 }
136
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);
141 }
142 return;
143 }
144
145 if (network->type() == shill::kTypeWimax ||
146 network->type() == shill::kTypeVPN) {
147 delegate_->ShowNetworkConfigure(service_path);
148 return;
149 }
150
151 if (network->type() == shill::kTypeCellular) {
152 if (network->RequiresActivation()) {
153 ActivateCellular(service_path);
154 return;
155 }
156 if (network->cellular_out_of_credits()) {
157 ShowMobileSetup(service_path);
158 return;
159 }
160 // No special configure or setup for |network|, show the settings UI.
161 if (chromeos::LoginState::Get()->IsUserLoggedIn()) {
162 delegate_->ShowNetworkSettings(service_path);
163 }
164 return;
165 }
166 NOTREACHED();
167 }
168
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;
177 }
178
179 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) {
180 NET_LOG_ERROR("User profile specified before login", "");
181 return false;
182 }
183
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;
189 }
190
191 *profile_path = profile->path;
192 return true;
193 }
194
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);
200
201 // If a new connect attempt canceled this connect, no need to notify the
202 // user.
203 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled)
204 return;
205
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;
212 }
213
214 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
215 if (!delegate_->ShowEnrollNetwork(service_path)) {
216 HandleUnconfiguredNetwork(service_path);
217 }
218 return;
219 }
220
221 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) {
222 ActivateCellular(service_path);
223 return;
224 }
225
226 if (error_name == NetworkConnectionHandler::kErrorConnected ||
227 error_name == NetworkConnectionHandler::kErrorConnecting) {
228 ShowNetworkSettings(service_path);
229 return;
230 }
231
232 // ConnectFailed or unknown error; show a notification.
233 network_state_notifier_->ShowNetworkConnectError(error_name, service_path);
234
235 // Only show a configure dialog if there was a ConnectFailed error.
236 if (error_name != shill::kErrorConnectFailed)
237 return;
238
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;
245
246 HandleUnconfiguredNetwork(service_path);
247 }
248
249 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) {
250 NET_LOG_USER("Connect Succeeded", service_path);
251 network_state_notifier_->RemoveConnectNotification();
252 }
253
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);
266 }
267
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);
275 }
276
277 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) {
278 NET_LOG_USER("Activation Succeeded", service_path);
279 }
280
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, "");
287 }
288
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);
297 }
298
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;
308 }
309 properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
310 profile_path);
311 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration(
312 *properties, base::Bind(&NetworkConnectImpl::OnConfigureSucceeded,
313 weak_factory_.GetWeakPtr(), connect_on_configure),
314 base::Bind(&NetworkConnectImpl::OnConfigureFailed,
315 weak_factory_.GetWeakPtr()));
316 }
317
318 void NetworkConnectImpl::SetPropertiesFailed(
319 const std::string& desc,
320 const std::string& service_path,
321 const std::string& config_error_name,
322 scoped_ptr<base::DictionaryValue> error_data) {
323 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
324 network_state_notifier_->ShowNetworkConnectError(
325 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
326 }
327
328 void NetworkConnectImpl::SetPropertiesToClear(
329 base::DictionaryValue* properties_to_set,
330 std::vector<std::string>* properties_to_clear) {
331 // Move empty string properties to properties_to_clear.
332 for (base::DictionaryValue::Iterator iter(*properties_to_set);
333 !iter.IsAtEnd(); iter.Advance()) {
334 std::string value_str;
335 if (iter.value().GetAsString(&value_str) && value_str.empty())
336 properties_to_clear->push_back(iter.key());
337 }
338 // Remove cleared properties from properties_to_set.
339 for (std::vector<std::string>::iterator iter = properties_to_clear->begin();
340 iter != properties_to_clear->end(); ++iter) {
341 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL);
342 }
343 }
344
345 void NetworkConnectImpl::ClearPropertiesAndConnect(
346 const std::string& service_path,
347 const std::vector<std::string>& properties_to_clear) {
348 NET_LOG_USER("ClearPropertiesAndConnect", service_path);
349 // After configuring a network, ignore any (possibly stale) error state.
350 const bool check_error_state = false;
351 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
352 service_path, properties_to_clear,
353 base::Bind(&NetworkConnectImpl::CallConnectToNetwork,
354 weak_factory_.GetWeakPtr(), service_path, check_error_state),
355 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
356 weak_factory_.GetWeakPtr(), "ClearProperties", service_path));
357 }
358
359 void NetworkConnectImpl::ConfigureSetProfileSucceeded(
360 const std::string& service_path,
361 scoped_ptr<base::DictionaryValue> properties_to_set) {
362 std::vector<std::string> properties_to_clear;
363 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
364 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
365 service_path, *properties_to_set,
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));
370 }
371
372 // Public methods
373
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().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;
387 }
388 }
389 const bool check_error_state = true;
390 CallConnectToNetwork(service_path, check_error_state);
391 }
392
393 void NetworkConnectImpl::SetTechnologyEnabled(
394 const NetworkTypePattern& technology,
395 bool enabled_state) {
396 std::string log_string = base::StringPrintf(
397 "technology %s, target state: %s", technology.ToDebugString().c_str(),
398 (enabled_state ? "ENABLED" : "DISABLED"));
399 NET_LOG_USER("SetTechnologyEnabled", log_string);
400 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
401 bool enabled = handler->IsTechnologyEnabled(technology);
402 if (enabled_state == enabled) {
403 NET_LOG_USER("Technology already in target state.", log_string);
404 return;
405 }
406 if (enabled) {
407 // User requested to disable the technology.
408 handler->SetTechnologyEnabled(technology, false,
409 chromeos::network_handler::ErrorCallback());
410 return;
411 }
412 // If we're dealing with a mobile network, then handle SIM lock here.
413 // SIM locking only applies to cellular, so the code below won't execute
414 // if |technology| has been explicitly set to WiMAX.
415 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) {
416 const DeviceState* mobile = handler->GetDeviceStateByType(technology);
417 if (!mobile) {
418 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string);
419 return;
420 }
421 // The following only applies to cellular.
422 if (mobile->type() == shill::kTypeCellular) {
423 if (mobile->IsSimAbsent()) {
424 // If this is true, then we have a cellular device with no SIM
425 // inserted. TODO(armansito): Chrome should display a notification here,
426 // prompting the user to insert a SIM card and restart the device to
427 // enable cellular. See crbug.com/125171.
428 NET_LOG_USER("Cannot enable cellular device without SIM.", log_string);
429 return;
430 }
431 if (!mobile->sim_lock_type().empty()) {
432 // A SIM has been inserted, but it is locked. Let the user unlock it
433 // via the dialog.
434 delegate_->ShowMobileSimDialog();
435 return;
436 }
437 }
438 }
439 handler->SetTechnologyEnabled(technology, true,
440 chromeos::network_handler::ErrorCallback());
441 }
442
443 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) {
444 NET_LOG_USER("ActivateCellular", service_path);
445 const NetworkState* cellular = GetNetworkState(service_path);
446 if (!cellular || cellular->type() != shill::kTypeCellular) {
447 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
448 return;
449 }
450 const DeviceState* cellular_device =
451 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
452 cellular->device_path());
453 if (!cellular_device) {
454 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
455 return;
456 }
457 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
458 // For non direct activation, show the mobile setup dialog which can be
459 // used to activate the network.
460 ShowMobileSetup(service_path);
461 return;
462 }
463 if (cellular->activation_state() == shill::kActivationStateActivated) {
464 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
465 return;
466 }
467
468 NetworkHandler::Get()->network_activation_handler()->Activate(
469 service_path,
470 "", // carrier
471 base::Bind(&NetworkConnectImpl::OnActivateSucceeded,
472 weak_factory_.GetWeakPtr(), service_path),
473 base::Bind(&NetworkConnectImpl::OnActivateFailed,
474 weak_factory_.GetWeakPtr(), service_path));
475 }
476
477 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) {
478 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
479 const NetworkState* cellular = handler->GetNetworkState(service_path);
480 if (!cellular || cellular->type() != shill::kTypeCellular) {
481 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
482 return;
483 }
484 if (cellular->activation_state() != shill::kActivationStateActivated &&
485 cellular->activation_type() == shill::kActivationTypeNonCellular &&
486 !handler->DefaultNetwork()) {
487 network_state_notifier_->ShowMobileActivationError(service_path);
488 return;
489 }
490 delegate_->ShowMobileSetupDialog(service_path);
491 }
492
493 void NetworkConnectImpl::ConfigureNetworkAndConnect(
494 const std::string& service_path,
495 const base::DictionaryValue& properties,
496 bool shared) {
497 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
498
499 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
500
501 std::string profile_path;
502 if (!GetNetworkProfilePath(shared, &profile_path)) {
503 network_state_notifier_->ShowNetworkConnectError(
504 NetworkConnectionHandler::kErrorConfigureFailed, service_path);
505 return;
506 }
507 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile(
508 service_path, profile_path,
509 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded,
510 weak_factory_.GetWeakPtr(), service_path,
511 base::Passed(&properties_to_set)),
512 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
513 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path,
514 service_path));
515 }
516
517 void NetworkConnectImpl::CreateConfigurationAndConnect(
518 base::DictionaryValue* properties,
519 bool shared) {
520 NET_LOG_USER("CreateConfigurationAndConnect", "");
521 CallCreateConfiguration(properties, shared, true /* connect_on_configure */);
522 }
523
524 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties,
525 bool shared) {
526 NET_LOG_USER("CreateConfiguration", "");
527 CallCreateConfiguration(properties, shared, false /* connect_on_configure */);
528 }
529
530 base::string16 NetworkConnectImpl::GetErrorString(
531 const std::string& error,
532 const std::string& service_path) {
533 if (error.empty())
534 return base::string16();
535 if (error == shill::kErrorOutOfRange)
536 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
537 if (error == shill::kErrorPinMissing)
538 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
539 if (error == shill::kErrorDhcpFailed)
540 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED);
541 if (error == shill::kErrorConnectFailed)
542 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED);
543 if (error == shill::kErrorBadPassphrase)
544 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE);
545 if (error == shill::kErrorBadWEPKey)
546 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY);
547 if (error == shill::kErrorActivationFailed) {
548 return l10n_util::GetStringUTF16(
549 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
550 }
551 if (error == shill::kErrorNeedEvdo)
552 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO);
553 if (error == shill::kErrorNeedHomeNetwork) {
554 return l10n_util::GetStringUTF16(
555 IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK);
556 }
557 if (error == shill::kErrorOtaspFailed)
558 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED);
559 if (error == shill::kErrorAaaFailed)
560 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED);
561 if (error == shill::kErrorInternal)
562 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL);
563 if (error == shill::kErrorDNSLookupFailed) {
564 return l10n_util::GetStringUTF16(
565 IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED);
566 }
567 if (error == shill::kErrorHTTPGetFailed) {
568 return l10n_util::GetStringUTF16(
569 IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED);
570 }
571 if (error == shill::kErrorIpsecPskAuthFailed) {
572 return l10n_util::GetStringUTF16(
573 IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED);
574 }
575 if (error == shill::kErrorIpsecCertAuthFailed) {
576 return l10n_util::GetStringUTF16(
577 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
578 }
579 if (error == shill::kErrorEapAuthenticationFailed) {
580 const NetworkState* network = GetNetworkState(service_path);
581 // TLS always requires a client certificate, so show a cert auth
582 // failed message for TLS. Other EAP methods do not generally require
583 // a client certicate.
584 if (network && network->eap_method() == shill::kEapMethodTLS) {
585 return l10n_util::GetStringUTF16(
586 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED);
587 } else {
588 return l10n_util::GetStringUTF16(
589 IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED);
590 }
591 }
592 if (error == shill::kErrorEapLocalTlsFailed) {
593 return l10n_util::GetStringUTF16(
594 IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED);
595 }
596 if (error == shill::kErrorEapRemoteTlsFailed) {
597 return l10n_util::GetStringUTF16(
598 IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED);
599 }
600 if (error == shill::kErrorPppAuthFailed) {
601 return l10n_util::GetStringUTF16(
602 IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED);
603 }
604
605 if (base::StringToLowerASCII(error) ==
606 base::StringToLowerASCII(std::string(shill::kUnknownString))) {
607 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
608 }
609 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
610 base::UTF8ToUTF16(error));
611 }
612
613 void NetworkConnectImpl::ShowNetworkSettings(const std::string& service_path) {
614 delegate_->ShowNetworkSettings(service_path);
615 }
616
617 } // namespace
618
619 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed";
620
621 static NetworkConnect* g_network_connect = NULL;
622
623 // static
624 void NetworkConnect::Initialize(Delegate* delegate) {
625 CHECK(g_network_connect == NULL);
626 g_network_connect = new NetworkConnectImpl(delegate);
627 }
628
629 // static
630 void NetworkConnect::Shutdown() {
631 CHECK(g_network_connect);
632 delete g_network_connect;
633 g_network_connect = NULL;
634 }
635
636 // static
637 NetworkConnect* NetworkConnect::Get() {
638 CHECK(g_network_connect);
639 return g_network_connect;
640 }
641
642 NetworkConnect::NetworkConnect() {
643 }
644
645 NetworkConnect::~NetworkConnect() {
646 }
647
648 } // ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/network_connect.h ('k') | ash/system/chromeos/network/network_state_list_detailed_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698