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