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

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

Issue 2434683003: Move NetworkStateNotifier and NetworkConnect from src/ui (Closed)
Patch Set: Created 4 years, 2 months 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/chromeos/network/network_connect.h" 5 #include "chromeos/network/network_connect.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.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" 11 #include "base/values.h"
14 #include "chromeos/login/login_state.h" 12 #include "chromeos/login/login_state.h"
15 #include "chromeos/network/device_state.h" 13 #include "chromeos/network/device_state.h"
16 #include "chromeos/network/network_activation_handler.h" 14 #include "chromeos/network/network_activation_handler.h"
17 #include "chromeos/network/network_configuration_handler.h" 15 #include "chromeos/network/network_configuration_handler.h"
18 #include "chromeos/network/network_connection_handler.h" 16 #include "chromeos/network/network_connection_handler.h"
19 #include "chromeos/network/network_event_log.h" 17 #include "chromeos/network/network_event_log.h"
20 #include "chromeos/network/network_handler_callbacks.h" 18 #include "chromeos/network/network_handler_callbacks.h"
21 #include "chromeos/network/network_profile.h" 19 #include "chromeos/network/network_profile.h"
22 #include "chromeos/network/network_profile_handler.h" 20 #include "chromeos/network/network_profile_handler.h"
23 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
24 #include "chromeos/network/network_state_handler.h" 22 #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" 23 #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 24
33 using chromeos::DeviceState; 25 namespace chromeos {
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 26
46 namespace { 27 namespace {
47 28
48 // Returns true for carriers that can be activated through Shill instead of 29 // Returns true for carriers that can be activated through Shill instead of
49 // through a WebUI dialog. 30 // through a WebUI dialog.
50 bool IsDirectActivatedCarrier(const std::string& carrier) { 31 bool IsDirectActivatedCarrier(const std::string& carrier) {
51 if (carrier == shill::kCarrierSprint) 32 if (carrier == shill::kCarrierSprint)
52 return true; 33 return true;
53 return false; 34 return false;
54 } 35 }
55 36
56 const NetworkState* GetNetworkState(const std::string& service_path) { 37 const NetworkState* GetNetworkState(const std::string& service_path) {
57 return NetworkHandler::Get()->network_state_handler()->GetNetworkState( 38 return NetworkHandler::Get()->network_state_handler()->GetNetworkState(
58 service_path); 39 service_path);
59 } 40 }
60 41
61 class NetworkConnectImpl : public NetworkConnect { 42 class NetworkConnectImpl : public NetworkConnect {
62 public: 43 public:
63 explicit NetworkConnectImpl(Delegate* delegate); 44 explicit NetworkConnectImpl(Delegate* delegate);
64 ~NetworkConnectImpl() override; 45 ~NetworkConnectImpl() override;
65 46
66 // NetworkConnect 47 // NetworkConnect
67 void ConnectToNetwork(const std::string& service_path) override; 48 void ConnectToNetwork(const std::string& service_path) override;
68 bool MaybeShowConfigureUI(const std::string& service_path, 49 bool MaybeShowConfigureUI(const std::string& service_path,
69 const std::string& connect_error) override; 50 const std::string& connect_error) override;
70 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology, 51 void SetTechnologyEnabled(const NetworkTypePattern& technology,
71 bool enabled_state) override; 52 bool enabled_state) override;
72 void ActivateCellular(const std::string& service_path) override; 53 void ActivateCellular(const std::string& service_path) override;
73 void ShowMobileSetup(const std::string& service_path) override; 54 void ShowMobileSetup(const std::string& service_path) override;
74 void ConfigureNetworkAndConnect(const std::string& service_path, 55 void ConfigureNetworkAndConnect(const std::string& service_path,
75 const base::DictionaryValue& shill_properties, 56 const base::DictionaryValue& shill_properties,
76 bool shared) override; 57 bool shared) override;
77 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties, 58 void CreateConfigurationAndConnect(base::DictionaryValue* shill_properties,
78 bool shared) override; 59 bool shared) override;
79 void CreateConfiguration(base::DictionaryValue* shill_properties, 60 void CreateConfiguration(base::DictionaryValue* shill_properties,
80 bool shared) override; 61 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 62
85 private: 63 private:
86 void HandleUnconfiguredNetwork(const std::string& service_path); 64 void HandleUnconfiguredNetwork(const std::string& service_path);
87 void OnConnectFailed(const std::string& service_path, 65 void OnConnectFailed(const std::string& service_path,
88 const std::string& error_name, 66 const std::string& error_name,
89 std::unique_ptr<base::DictionaryValue> error_data); 67 std::unique_ptr<base::DictionaryValue> error_data);
90 bool MaybeShowConfigureUIImpl(const std::string& service_path, 68 bool MaybeShowConfigureUIImpl(const std::string& service_path,
91 const std::string& connect_error); 69 const std::string& connect_error);
92 bool GetNetworkProfilePath(bool shared, std::string* profile_path); 70 bool GetNetworkProfilePath(bool shared, std::string* profile_path);
93 void OnConnectSucceeded(const std::string& service_path); 71 void OnConnectSucceeded(const std::string& service_path);
(...skipping 16 matching lines...) Expand all
110 const std::string& config_error_name, 88 const std::string& config_error_name,
111 std::unique_ptr<base::DictionaryValue> error_data); 89 std::unique_ptr<base::DictionaryValue> error_data);
112 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, 90 void SetPropertiesToClear(base::DictionaryValue* properties_to_set,
113 std::vector<std::string>* properties_to_clear); 91 std::vector<std::string>* properties_to_clear);
114 void ClearPropertiesAndConnect( 92 void ClearPropertiesAndConnect(
115 const std::string& service_path, 93 const std::string& service_path,
116 const std::vector<std::string>& properties_to_clear); 94 const std::vector<std::string>& properties_to_clear);
117 void ConfigureSetProfileSucceeded( 95 void ConfigureSetProfileSucceeded(
118 const std::string& service_path, 96 const std::string& service_path,
119 std::unique_ptr<base::DictionaryValue> properties_to_set); 97 std::unique_ptr<base::DictionaryValue> properties_to_set);
98 void ShowNetworkConnectError(const std::string& error_name,
99 const std::string& service_path);
120 100
121 Delegate* delegate_; 101 Delegate* delegate_;
122 std::unique_ptr<NetworkStateNotifier> network_state_notifier_;
123 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_; 102 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_;
124 103
125 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl); 104 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl);
126 }; 105 };
127 106
128 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate) 107 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate)
129 : delegate_(delegate), weak_factory_(this) { 108 : delegate_(delegate), weak_factory_(this) {}
130 network_state_notifier_.reset(new NetworkStateNotifier(this));
131 }
132 109
133 NetworkConnectImpl::~NetworkConnectImpl() { 110 NetworkConnectImpl::~NetworkConnectImpl() {}
134 }
135 111
136 void NetworkConnectImpl::HandleUnconfiguredNetwork( 112 void NetworkConnectImpl::HandleUnconfiguredNetwork(
137 const std::string& service_path) { 113 const std::string& service_path) {
138 const NetworkState* network = GetNetworkState(service_path); 114 const NetworkState* network = GetNetworkState(service_path);
139 if (!network) { 115 if (!network) {
140 NET_LOG_ERROR("Configuring unknown network", service_path); 116 NET_LOG_ERROR("Configuring unknown network", service_path);
141 return; 117 return;
142 } 118 }
143 119
144 if (network->type() == shill::kTypeWifi) { 120 if (network->type() == shill::kTypeWifi) {
(...skipping 19 matching lines...) Expand all
164 if (network->type() == shill::kTypeCellular) { 140 if (network->type() == shill::kTypeCellular) {
165 if (network->RequiresActivation()) { 141 if (network->RequiresActivation()) {
166 ActivateCellular(service_path); 142 ActivateCellular(service_path);
167 return; 143 return;
168 } 144 }
169 if (network->cellular_out_of_credits()) { 145 if (network->cellular_out_of_credits()) {
170 ShowMobileSetup(service_path); 146 ShowMobileSetup(service_path);
171 return; 147 return;
172 } 148 }
173 // No special configure or setup for |network|, show the settings UI. 149 // No special configure or setup for |network|, show the settings UI.
174 if (chromeos::LoginState::Get()->IsUserLoggedIn()) { 150 if (LoginState::Get()->IsUserLoggedIn())
James Cook 2016/10/20 00:11:43 Not for this CL: It would be very nice to eliminat
stevenjb 2016/10/20 00:57:23 Acknowledged. Long term plan is to include network
James Cook 2016/10/20 15:48:41 Just for my knowledge: "include network settings i
stevenjb 2016/10/20 17:16:16 Correct. ShowNetworkSettings would behave differen
175 ShowNetworkSettingsForPath(service_path); 151 delegate_->ShowNetworkSettings(network->guid());
176 }
177 return; 152 return;
178 } 153 }
179 NOTREACHED(); 154 NOTREACHED();
180 } 155 }
181 156
182 // If |shared| is true, sets |profile_path| to the shared profile path. 157 // 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 158 // Otherwise sets |profile_path| to the user profile path if authenticated and
184 // available. Returns 'false' if unable to set |profile_path|. 159 // available. Returns 'false' if unable to set |profile_path|.
185 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared, 160 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared,
186 std::string* profile_path) { 161 std::string* profile_path) {
187 if (shared) { 162 if (shared) {
188 *profile_path = NetworkProfileHandler::GetSharedProfilePath(); 163 *profile_path = NetworkProfileHandler::GetSharedProfilePath();
189 return true; 164 return true;
190 } 165 }
191 166
192 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) { 167 if (!LoginState::Get()->UserHasNetworkProfile()) {
193 NET_LOG_ERROR("User profile specified before login", ""); 168 NET_LOG_ERROR("User profile specified before login", "");
194 return false; 169 return false;
195 } 170 }
196 171
197 const NetworkProfile* profile = 172 const NetworkProfile* profile =
198 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); 173 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile();
199 if (!profile) { 174 if (!profile) {
200 NET_LOG_ERROR("No user profile for unshared network configuration", ""); 175 NET_LOG_ERROR("No user profile for unshared network configuration", "");
201 return false; 176 return false;
202 } 177 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 base::Bind(&NetworkConnectImpl::OnConnectFailed, 237 base::Bind(&NetworkConnectImpl::OnConnectFailed,
263 weak_factory_.GetWeakPtr(), service_path), 238 weak_factory_.GetWeakPtr(), service_path),
264 check_error_state); 239 check_error_state);
265 } 240 }
266 241
267 void NetworkConnectImpl::OnActivateFailed( 242 void NetworkConnectImpl::OnActivateFailed(
268 const std::string& service_path, 243 const std::string& service_path,
269 const std::string& error_name, 244 const std::string& error_name,
270 std::unique_ptr<base::DictionaryValue> error_data) { 245 std::unique_ptr<base::DictionaryValue> error_data) {
271 NET_LOG_ERROR("Unable to activate network", service_path); 246 NET_LOG_ERROR("Unable to activate network", service_path);
272 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed, 247 ShowNetworkConnectError(NetworkConnectionHandler::kErrorActivateFailed,
273 service_path); 248 service_path);
274 } 249 }
275 250
276 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) { 251 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) {
277 NET_LOG_USER("Activation Succeeded", service_path); 252 NET_LOG_USER("Activation Succeeded", service_path);
278 } 253 }
279 254
280 void NetworkConnectImpl::OnConfigureFailed( 255 void NetworkConnectImpl::OnConfigureFailed(
281 const std::string& error_name, 256 const std::string& error_name,
282 std::unique_ptr<base::DictionaryValue> error_data) { 257 std::unique_ptr<base::DictionaryValue> error_data) {
283 NET_LOG_ERROR("Unable to configure network", ""); 258 NET_LOG_ERROR("Unable to configure network", "");
284 network_state_notifier_->ShowNetworkConnectError( 259 ShowNetworkConnectError(NetworkConnectionHandler::kErrorConfigureFailed, "");
285 NetworkConnectionHandler::kErrorConfigureFailed, "");
286 } 260 }
287 261
288 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure, 262 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure,
289 const std::string& service_path, 263 const std::string& service_path,
290 const std::string& guid) { 264 const std::string& guid) {
291 NET_LOG_USER("Configure Succeeded", service_path); 265 NET_LOG_USER("Configure Succeeded", service_path);
292 if (!connect_on_configure) 266 if (!connect_on_configure)
293 return; 267 return;
294 // After configuring a network, ignore any (possibly stale) error state. 268 // After configuring a network, ignore any (possibly stale) error state.
295 const bool check_error_state = false; 269 const bool check_error_state = false;
296 CallConnectToNetwork(service_path, check_error_state); 270 CallConnectToNetwork(service_path, check_error_state);
297 } 271 }
298 272
299 void NetworkConnectImpl::CallCreateConfiguration( 273 void NetworkConnectImpl::CallCreateConfiguration(
300 base::DictionaryValue* shill_properties, 274 base::DictionaryValue* shill_properties,
301 bool shared, 275 bool shared,
302 bool connect_on_configure) { 276 bool connect_on_configure) {
303 std::string profile_path; 277 std::string profile_path;
304 if (!GetNetworkProfilePath(shared, &profile_path)) { 278 if (!GetNetworkProfilePath(shared, &profile_path)) {
305 network_state_notifier_->ShowNetworkConnectError( 279 ShowNetworkConnectError(NetworkConnectionHandler::kErrorConfigureFailed,
306 NetworkConnectionHandler::kErrorConfigureFailed, ""); 280 "");
307 return; 281 return;
308 } 282 }
309 shill_properties->SetStringWithoutPathExpansion(shill::kProfileProperty, 283 shill_properties->SetStringWithoutPathExpansion(shill::kProfileProperty,
310 profile_path); 284 profile_path);
311 NetworkHandler::Get() 285 NetworkHandler::Get()
312 ->network_configuration_handler() 286 ->network_configuration_handler()
313 ->CreateShillConfiguration( 287 ->CreateShillConfiguration(
314 *shill_properties, NetworkConfigurationObserver::SOURCE_USER_ACTION, 288 *shill_properties, NetworkConfigurationObserver::SOURCE_USER_ACTION,
315 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded, 289 base::Bind(&NetworkConnectImpl::OnConfigureSucceeded,
316 weak_factory_.GetWeakPtr(), connect_on_configure), 290 weak_factory_.GetWeakPtr(), connect_on_configure),
317 base::Bind(&NetworkConnectImpl::OnConfigureFailed, 291 base::Bind(&NetworkConnectImpl::OnConfigureFailed,
318 weak_factory_.GetWeakPtr())); 292 weak_factory_.GetWeakPtr()));
319 } 293 }
320 294
321 void NetworkConnectImpl::SetPropertiesFailed( 295 void NetworkConnectImpl::SetPropertiesFailed(
322 const std::string& desc, 296 const std::string& desc,
323 const std::string& service_path, 297 const std::string& service_path,
324 const std::string& config_error_name, 298 const std::string& config_error_name,
325 std::unique_ptr<base::DictionaryValue> error_data) { 299 std::unique_ptr<base::DictionaryValue> error_data) {
326 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); 300 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path);
327 network_state_notifier_->ShowNetworkConnectError( 301 ShowNetworkConnectError(NetworkConnectionHandler::kErrorConfigureFailed,
328 NetworkConnectionHandler::kErrorConfigureFailed, service_path); 302 service_path);
329 } 303 }
330 304
331 void NetworkConnectImpl::SetPropertiesToClear( 305 void NetworkConnectImpl::SetPropertiesToClear(
332 base::DictionaryValue* properties_to_set, 306 base::DictionaryValue* properties_to_set,
333 std::vector<std::string>* properties_to_clear) { 307 std::vector<std::string>* properties_to_clear) {
334 // Move empty string properties to properties_to_clear. 308 // Move empty string properties to properties_to_clear.
335 for (base::DictionaryValue::Iterator iter(*properties_to_set); 309 for (base::DictionaryValue::Iterator iter(*properties_to_set);
336 !iter.IsAtEnd(); iter.Advance()) { 310 !iter.IsAtEnd(); iter.Advance()) {
337 std::string value_str; 311 std::string value_str;
338 if (iter.value().GetAsString(&value_str) && value_str.empty()) 312 if (iter.value().GetAsString(&value_str) && value_str.empty())
(...skipping 27 matching lines...) Expand all
366 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); 340 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear);
367 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties( 341 NetworkHandler::Get()->network_configuration_handler()->SetShillProperties(
368 service_path, *properties_to_set, 342 service_path, *properties_to_set,
369 NetworkConfigurationObserver::SOURCE_USER_ACTION, 343 NetworkConfigurationObserver::SOURCE_USER_ACTION,
370 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect, 344 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect,
371 weak_factory_.GetWeakPtr(), service_path, properties_to_clear), 345 weak_factory_.GetWeakPtr(), service_path, properties_to_clear),
372 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, 346 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
373 weak_factory_.GetWeakPtr(), "SetProperties", service_path)); 347 weak_factory_.GetWeakPtr(), "SetProperties", service_path));
374 } 348 }
375 349
350 void NetworkConnectImpl::ShowNetworkConnectError(
351 const std::string& error_name,
352 const std::string& service_path) {
353 std::string guid;
354 if (!service_path.empty()) {
355 const NetworkState* network = GetNetworkState(service_path);
356 if (!network)
James Cook 2016/10/20 00:11:43 Just for my knowledge: If there's no known network
stevenjb 2016/10/20 00:57:23 I guess we can go ahead and fall through, we alrea
357 return;
358 guid = network->guid();
359 }
360 delegate_->ShowNetworkConnectError(error_name, guid);
361 }
362
376 // Public methods 363 // Public methods
377 364
378 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) { 365 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) {
379 NET_LOG_USER("ConnectToNetwork", service_path); 366 NET_LOG_USER("ConnectToNetwork", service_path);
380 const NetworkState* network = GetNetworkState(service_path); 367 const NetworkState* network = GetNetworkState(service_path);
381 if (network) { 368 if (network) {
382 if (!network->error().empty() && !network->security_class().empty()) { 369 if (!network->error().empty() && !network->security_class().empty()) {
383 NET_LOG_USER("Configure: " + network->error(), service_path); 370 NET_LOG_USER("Configure: " + network->error(), service_path);
384 // If the network is in an error state, show the configuration UI 371 // If the network is in an error state, show the configuration UI
385 // directly to avoid a spurious notification. 372 // directly to avoid a spurious notification.
(...skipping 23 matching lines...) Expand all
409 NET_LOG_USER("SetTechnologyEnabled", log_string); 396 NET_LOG_USER("SetTechnologyEnabled", log_string);
410 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 397 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
411 bool enabled = handler->IsTechnologyEnabled(technology); 398 bool enabled = handler->IsTechnologyEnabled(technology);
412 if (enabled_state == enabled) { 399 if (enabled_state == enabled) {
413 NET_LOG_USER("Technology already in target state.", log_string); 400 NET_LOG_USER("Technology already in target state.", log_string);
414 return; 401 return;
415 } 402 }
416 if (enabled) { 403 if (enabled) {
417 // User requested to disable the technology. 404 // User requested to disable the technology.
418 handler->SetTechnologyEnabled(technology, false, 405 handler->SetTechnologyEnabled(technology, false,
419 chromeos::network_handler::ErrorCallback()); 406 network_handler::ErrorCallback());
420 return; 407 return;
421 } 408 }
422 // If we're dealing with a mobile network, then handle SIM lock here. 409 // 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 410 // SIM locking only applies to cellular, so the code below won't execute
424 // if |technology| has been explicitly set to WiMAX. 411 // if |technology| has been explicitly set to WiMAX.
425 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) { 412 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) {
426 const DeviceState* mobile = handler->GetDeviceStateByType(technology); 413 const DeviceState* mobile = handler->GetDeviceStateByType(technology);
427 if (!mobile) { 414 if (!mobile) {
428 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string); 415 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string);
429 return; 416 return;
(...skipping 10 matching lines...) Expand all
440 } 427 }
441 if (!mobile->sim_lock_type().empty()) { 428 if (!mobile->sim_lock_type().empty()) {
442 // A SIM has been inserted, but it is locked. Let the user unlock it 429 // A SIM has been inserted, but it is locked. Let the user unlock it
443 // via the dialog. 430 // via the dialog.
444 delegate_->ShowMobileSimDialog(); 431 delegate_->ShowMobileSimDialog();
445 return; 432 return;
446 } 433 }
447 } 434 }
448 } 435 }
449 handler->SetTechnologyEnabled(technology, true, 436 handler->SetTechnologyEnabled(technology, true,
450 chromeos::network_handler::ErrorCallback()); 437 network_handler::ErrorCallback());
451 } 438 }
452 439
453 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) { 440 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) {
454 NET_LOG_USER("ActivateCellular", service_path); 441 NET_LOG_USER("ActivateCellular", service_path);
455 const NetworkState* cellular = GetNetworkState(service_path); 442 const NetworkState* cellular = GetNetworkState(service_path);
456 if (!cellular || cellular->type() != shill::kTypeCellular) { 443 if (!cellular || cellular->type() != shill::kTypeCellular) {
457 NET_LOG_ERROR("ActivateCellular with no Service", service_path); 444 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
458 return; 445 return;
459 } 446 }
460 const DeviceState* cellular_device = 447 const DeviceState* cellular_device =
(...skipping 26 matching lines...) Expand all
487 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) { 474 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) {
488 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 475 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
489 const NetworkState* cellular = handler->GetNetworkState(service_path); 476 const NetworkState* cellular = handler->GetNetworkState(service_path);
490 if (!cellular || cellular->type() != shill::kTypeCellular) { 477 if (!cellular || cellular->type() != shill::kTypeCellular) {
491 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path); 478 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
492 return; 479 return;
493 } 480 }
494 if (cellular->activation_state() != shill::kActivationStateActivated && 481 if (cellular->activation_state() != shill::kActivationStateActivated &&
495 cellular->activation_type() == shill::kActivationTypeNonCellular && 482 cellular->activation_type() == shill::kActivationTypeNonCellular &&
496 !handler->DefaultNetwork()) { 483 !handler->DefaultNetwork()) {
497 network_state_notifier_->ShowMobileActivationError(service_path); 484 delegate_->ShowMobileActivationError(cellular->guid());
498 return; 485 return;
499 } 486 }
500 delegate_->ShowMobileSetupDialog(service_path); 487 delegate_->ShowMobileSetupDialog(service_path);
501 } 488 }
502 489
503 void NetworkConnectImpl::ConfigureNetworkAndConnect( 490 void NetworkConnectImpl::ConfigureNetworkAndConnect(
504 const std::string& service_path, 491 const std::string& service_path,
505 const base::DictionaryValue& properties, 492 const base::DictionaryValue& properties,
506 bool shared) { 493 bool shared) {
507 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); 494 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
508 495
509 std::unique_ptr<base::DictionaryValue> properties_to_set( 496 std::unique_ptr<base::DictionaryValue> properties_to_set(
510 properties.DeepCopy()); 497 properties.DeepCopy());
511 498
512 std::string profile_path; 499 std::string profile_path;
513 if (!GetNetworkProfilePath(shared, &profile_path)) { 500 if (!GetNetworkProfilePath(shared, &profile_path)) {
514 network_state_notifier_->ShowNetworkConnectError( 501 ShowNetworkConnectError(NetworkConnectionHandler::kErrorConfigureFailed,
515 NetworkConnectionHandler::kErrorConfigureFailed, service_path); 502 service_path);
516 return; 503 return;
517 } 504 }
518 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( 505 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile(
519 service_path, profile_path, 506 service_path, profile_path,
520 NetworkConfigurationObserver::SOURCE_USER_ACTION, 507 NetworkConfigurationObserver::SOURCE_USER_ACTION,
521 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded, 508 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded,
522 weak_factory_.GetWeakPtr(), service_path, 509 weak_factory_.GetWeakPtr(), service_path,
523 base::Passed(&properties_to_set)), 510 base::Passed(&properties_to_set)),
524 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, 511 base::Bind(&NetworkConnectImpl::SetPropertiesFailed,
525 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path, 512 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path,
526 service_path)); 513 service_path));
527 } 514 }
528 515
529 void NetworkConnectImpl::CreateConfigurationAndConnect( 516 void NetworkConnectImpl::CreateConfigurationAndConnect(
530 base::DictionaryValue* properties, 517 base::DictionaryValue* properties,
531 bool shared) { 518 bool shared) {
532 NET_LOG_USER("CreateConfigurationAndConnect", ""); 519 NET_LOG_USER("CreateConfigurationAndConnect", "");
533 CallCreateConfiguration(properties, shared, true /* connect_on_configure */); 520 CallCreateConfiguration(properties, shared, true /* connect_on_configure */);
534 } 521 }
535 522
536 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties, 523 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties,
537 bool shared) { 524 bool shared) {
538 NET_LOG_USER("CreateConfiguration", ""); 525 NET_LOG_USER("CreateConfiguration", "");
539 CallCreateConfiguration(properties, shared, false /* connect_on_configure */); 526 CallCreateConfiguration(properties, shared, false /* connect_on_configure */);
540 } 527 }
541 528
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 529 } // namespace
631 530
632 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed";
633
634 static NetworkConnect* g_network_connect = NULL; 531 static NetworkConnect* g_network_connect = NULL;
635 532
636 // static 533 // static
637 void NetworkConnect::Initialize(Delegate* delegate) { 534 void NetworkConnect::Initialize(Delegate* delegate) {
638 CHECK(g_network_connect == NULL); 535 CHECK(g_network_connect == NULL);
639 g_network_connect = new NetworkConnectImpl(delegate); 536 g_network_connect = new NetworkConnectImpl(delegate);
640 } 537 }
641 538
642 // static 539 // static
643 void NetworkConnect::Shutdown() { 540 void NetworkConnect::Shutdown() {
644 CHECK(g_network_connect); 541 CHECK(g_network_connect);
645 delete g_network_connect; 542 delete g_network_connect;
646 g_network_connect = NULL; 543 g_network_connect = NULL;
647 } 544 }
648 545
649 // static 546 // static
650 NetworkConnect* NetworkConnect::Get() { 547 NetworkConnect* NetworkConnect::Get() {
651 CHECK(g_network_connect); 548 CHECK(g_network_connect);
652 return g_network_connect; 549 return g_network_connect;
653 } 550 }
654 551
655 NetworkConnect::NetworkConnect() { 552 NetworkConnect::NetworkConnect() {}
656 }
657 553
658 NetworkConnect::~NetworkConnect() { 554 NetworkConnect::~NetworkConnect() {}
659 }
660 555
661 } // namespace ui 556 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698