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

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

Issue 22796014: Eliminate c/b/chromeos/options/network_connect.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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 | Annotate | Revision Log
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 "ash/system/chromeos/network/network_connect.h" 5 #include "ash/system/chromeos/network/network_connect.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/network/network_observer.h" 8 #include "ash/system/chromeos/network/network_observer.h"
9 #include "ash/system/chromeos/network/network_state_notifier.h" 9 #include "ash/system/chromeos/network/network_state_notifier.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/system_tray_notifier.h" 11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chromeos/login/login_state.h" 16 #include "chromeos/login/login_state.h"
17 #include "chromeos/network/device_state.h" 17 #include "chromeos/network/device_state.h"
18 #include "chromeos/network/network_configuration_handler.h" 18 #include "chromeos/network/network_configuration_handler.h"
19 #include "chromeos/network/network_connection_handler.h" 19 #include "chromeos/network/network_connection_handler.h"
20 #include "chromeos/network/network_event_log.h" 20 #include "chromeos/network/network_event_log.h"
21 #include "chromeos/network/network_handler_callbacks.h" 21 #include "chromeos/network/network_handler_callbacks.h"
22 #include "chromeos/network/network_profile.h" 22 #include "chromeos/network/network_profile.h"
23 #include "chromeos/network/network_profile_handler.h" 23 #include "chromeos/network/network_profile_handler.h"
24 #include "chromeos/network/network_state.h" 24 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h" 25 #include "chromeos/network/network_state_handler.h"
26 #include "grit/ash_resources.h"
26 #include "grit/ash_strings.h" 27 #include "grit/ash_strings.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h" 28 #include "third_party/cros_system_api/dbus/service_constants.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h"
29 31
30 using chromeos::DeviceState; 32 using chromeos::DeviceState;
31 using chromeos::NetworkConfigurationHandler; 33 using chromeos::NetworkConfigurationHandler;
32 using chromeos::NetworkConnectionHandler; 34 using chromeos::NetworkConnectionHandler;
33 using chromeos::NetworkHandler; 35 using chromeos::NetworkHandler;
34 using chromeos::NetworkProfile; 36 using chromeos::NetworkProfile;
35 using chromeos::NetworkProfileHandler; 37 using chromeos::NetworkProfileHandler;
36 using chromeos::NetworkState; 38 using chromeos::NetworkState;
39 using chromeos::NetworkStateHandler;
37 40
38 namespace ash { 41 namespace ash {
39 42
40 namespace { 43 namespace {
41 44
42 // TODO(stevenjb): This should be in service_constants.h 45 // TODO(stevenjb): This should be in service_constants.h
43 const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress"; 46 const char kErrorInProgress[] = "org.chromium.flimflam.Error.InProgress";
44 47
45 // Returns true for carriers that can be activated through Shill instead of 48 // Returns true for carriers that can be activated through Shill instead of
46 // through a WebUI dialog. 49 // through a WebUI dialog.
47 bool IsDirectActivatedCarrier(const std::string& carrier) { 50 bool IsDirectActivatedCarrier(const std::string& carrier) {
48 if (carrier == shill::kCarrierSprint) 51 if (carrier == shill::kCarrierSprint)
49 return true; 52 return true;
50 return false; 53 return false;
51 } 54 }
52 55
53 void ShowErrorNotification(const std::string& error, 56 void ShowErrorNotification(const std::string& error,
54 const std::string& service_path) { 57 const std::string& service_path) {
55 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> 58 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()->
56 ShowNetworkConnectError(error, service_path); 59 ShowNetworkConnectError(error, service_path);
57 } 60 }
58 61
59 void OnConnectFailed(const std::string& service_path, 62 void OnConnectFailed(const std::string& service_path,
60 gfx::NativeWindow owning_window, 63 gfx::NativeWindow owning_window,
61 const std::string& error_name, 64 const std::string& error_name,
62 scoped_ptr<base::DictionaryValue> error_data) { 65 scoped_ptr<base::DictionaryValue> error_data) {
63 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); 66 NET_LOG_ERROR("Connect Failed: " + error_name, service_path);
64 67
68 if (!ash::Shell::HasInstance())
69 return;
70
65 // If a new connect attempt canceled this connect, no need to notify the user. 71 // If a new connect attempt canceled this connect, no need to notify the user.
66 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) 72 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled)
67 return; 73 return;
68 74
69 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired || 75 if (error_name == NetworkConnectionHandler::kErrorPassphraseRequired ||
70 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || 76 error_name == NetworkConnectionHandler::kErrorConfigurationRequired ||
71 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { 77 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) {
72 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 78 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
73 service_path); 79 service_path);
74 return; 80 return;
75 } 81 }
76 82
77 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { 83 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) {
78 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork( 84 ash::Shell::GetInstance()->system_tray_delegate()->EnrollOrConfigureNetwork(
79 service_path, owning_window); 85 service_path, owning_window);
80 return; 86 return;
81 } 87 }
82 88
83 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { 89 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) {
84 network_connect::ActivateCellular(service_path); 90 network_connect::ActivateCellular(service_path);
85 return; 91 return;
86 } 92 }
87 93
88 if (error_name == NetworkConnectionHandler::kErrorConnected || 94 if (error_name == NetworkConnectionHandler::kErrorConnected ||
89 error_name == NetworkConnectionHandler::kErrorConnecting) { 95 error_name == NetworkConnectionHandler::kErrorConnecting) {
90 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( 96 network_connect::ShowNetworkSettings(service_path);
91 service_path);
92 return; 97 return;
93 } 98 }
94 99
95 // ConnectFailed or unknown error; show a notification. 100 // ConnectFailed or unknown error; show a notification.
96 ShowErrorNotification(error_name, service_path); 101 ShowErrorNotification(error_name, service_path);
97 102
98 // Show a configure dialog for ConnectFailed errors. 103 // Show a configure dialog for ConnectFailed errors.
99 if (error_name != NetworkConnectionHandler::kErrorConnectFailed) 104 if (error_name != NetworkConnectionHandler::kErrorConnectFailed)
100 return; 105 return;
101 106
102 // If Shill reports an InProgress error, don't try to configure the network. 107 // If Shill reports an InProgress error, don't try to configure the network.
103 std::string dbus_error_name; 108 std::string dbus_error_name;
104 error_data.get()->GetString( 109 error_data.get()->GetString(
105 chromeos::network_handler::kDbusErrorName, &dbus_error_name); 110 chromeos::network_handler::kDbusErrorName, &dbus_error_name);
106 if (dbus_error_name == kErrorInProgress) 111 if (dbus_error_name == kErrorInProgress)
107 return; 112 return;
108 113
109 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 114 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
110 service_path); 115 service_path);
111 } 116 }
112 117
113 void OnConnectSucceeded(const std::string& service_path) { 118 void OnConnectSucceeded(const std::string& service_path) {
114 NET_LOG_USER("Connect Succeeded", service_path); 119 NET_LOG_USER("Connect Succeeded", service_path);
120 if (!ash::Shell::HasInstance())
121 return;
115 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 122 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
116 NetworkObserver::ERROR_CONNECT_FAILED); 123 NetworkObserver::ERROR_CONNECT_FAILED);
117 } 124 }
118 125
119 // If |check_error_state| is true, error state for the network is checked, 126 // If |check_error_state| is true, error state for the network is checked,
120 // otherwise any current error state is ignored (e.g. for recently configured 127 // otherwise any current error state is ignored (e.g. for recently configured
121 // networks or repeat connect attempts). |owning_window| will be used to parent 128 // networks or repeat connect attempts). |owning_window| will be used to parent
122 // any configuration UI on failure and may be NULL (in which case the default 129 // any configuration UI on failure and may be NULL (in which case the default
123 // window will be used). 130 // window will be used).
124 void CallConnectToNetwork(const std::string& service_path, 131 void CallConnectToNetwork(const std::string& service_path,
125 bool check_error_state, 132 bool check_error_state,
126 gfx::NativeWindow owning_window) { 133 gfx::NativeWindow owning_window) {
127 NET_LOG_USER("ConnectToNetwork", service_path); 134 if (!ash::Shell::HasInstance())
128 135 return;
129 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 136 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage(
130 NetworkObserver::ERROR_CONNECT_FAILED); 137 NetworkObserver::ERROR_CONNECT_FAILED);
131 138
132 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( 139 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
133 service_path, 140 service_path,
134 base::Bind(&OnConnectSucceeded, service_path), 141 base::Bind(&OnConnectSucceeded, service_path),
135 base::Bind(&OnConnectFailed, service_path, owning_window), 142 base::Bind(&OnConnectFailed, service_path, owning_window),
136 check_error_state); 143 check_error_state);
137 } 144 }
138 145
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 properties_to_clear), 248 properties_to_clear),
242 base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); 249 base::Bind(&SetPropertiesFailed, "SetProperties", service_path));
243 } 250 }
244 251
245 } // namespace 252 } // namespace
246 253
247 namespace network_connect { 254 namespace network_connect {
248 255
249 void ConnectToNetwork(const std::string& service_path, 256 void ConnectToNetwork(const std::string& service_path,
250 gfx::NativeWindow owning_window) { 257 gfx::NativeWindow owning_window) {
258 NET_LOG_USER("ConnectToNetwork", service_path);
251 const bool check_error_state = true; 259 const bool check_error_state = true;
252 CallConnectToNetwork(service_path, check_error_state, owning_window); 260 CallConnectToNetwork(service_path, check_error_state, owning_window);
253 } 261 }
254 262
255 void ActivateCellular(const std::string& service_path) { 263 void ActivateCellular(const std::string& service_path) {
256 NET_LOG_USER("ActivateCellular", service_path); 264 NET_LOG_USER("ActivateCellular", service_path);
257 const NetworkState* cellular = 265 const NetworkState* cellular =
258 NetworkHandler::Get()->network_state_handler()-> 266 NetworkHandler::Get()->network_state_handler()->
259 GetNetworkState(service_path); 267 GetNetworkState(service_path);
260 if (!cellular || cellular->type() != flimflam::kTypeCellular) { 268 if (!cellular || cellular->type() != flimflam::kTypeCellular) {
261 NET_LOG_ERROR("ActivateCellular with no Service", service_path); 269 NET_LOG_ERROR("ActivateCellular with no Service", service_path);
262 return; 270 return;
263 } 271 }
264 const DeviceState* cellular_device = 272 const DeviceState* cellular_device =
265 NetworkHandler::Get()->network_state_handler()-> 273 NetworkHandler::Get()->network_state_handler()->
266 GetDeviceState(cellular->device_path()); 274 GetDeviceState(cellular->device_path());
267 if (!cellular_device) { 275 if (!cellular_device) {
268 NET_LOG_ERROR("ActivateCellular with no Device", service_path); 276 NET_LOG_ERROR("ActivateCellular with no Device", service_path);
269 return; 277 return;
270 } 278 }
271 if (!IsDirectActivatedCarrier(cellular_device->carrier())) { 279 if (!IsDirectActivatedCarrier(cellular_device->carrier())) {
272 // For non direct activation, show the mobile setup dialog which can be 280 // For non direct activation, show the mobile setup dialog which can be
273 // used to activate the network. Only show the dialog, if an account 281 // used to activate the network. Only show the dialog, if an account
274 // management URL is available. 282 // management URL is available.
275 if (!cellular->payment_url().empty()) 283 if (!cellular->payment_url().empty())
276 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetup( 284 ShowMobileSetup(service_path);
277 service_path);
278 return; 285 return;
279 } 286 }
280 if (cellular->activation_state() == flimflam::kActivationStateActivated) { 287 if (cellular->activation_state() == flimflam::kActivationStateActivated) {
281 NET_LOG_ERROR("ActivateCellular for activated service", service_path); 288 NET_LOG_ERROR("ActivateCellular for activated service", service_path);
282 return; 289 return;
283 } 290 }
284 291
285 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork( 292 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork(
286 service_path, 293 service_path,
287 "", // carrier 294 "", // carrier
288 base::Bind(&OnActivateSucceeded, service_path), 295 base::Bind(&OnActivateSucceeded, service_path),
289 base::Bind(&OnActivateFailed, service_path)); 296 base::Bind(&OnActivateFailed, service_path));
290 } 297 }
291 298
299 void ShowMobileSetup(const std::string& service_path) {
300 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
301 const NetworkState* cellular = handler->GetNetworkState(service_path);
302 if (!cellular || cellular->type() != flimflam::kTypeCellular) {
303 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
304 return;
305 }
306 if (cellular->activation_state() != flimflam::kActivationStateActivated &&
307 cellular->activate_over_non_cellular_networks() &&
308 !handler->DefaultNetwork()) {
309 std::string technology = cellular->network_technology();
310 ash::NetworkObserver::NetworkType network_type =
311 (technology == flimflam::kNetworkTechnologyLte ||
312 technology == flimflam::kNetworkTechnologyLteAdvanced)
313 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE
314 : ash::NetworkObserver::NETWORK_CELLULAR;
315 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
316 NULL,
317 ash::NetworkObserver::ERROR_CONNECT_FAILED,
318 network_type,
319 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
320 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
321 UTF8ToUTF16((cellular->name()))),
322 std::vector<string16>());
323 return;
324 }
325 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetupDialog(
326 service_path);
327 }
328
292 void ConfigureNetworkAndConnect(const std::string& service_path, 329 void ConfigureNetworkAndConnect(const std::string& service_path,
293 const base::DictionaryValue& properties, 330 const base::DictionaryValue& properties,
294 bool shared) { 331 bool shared) {
295 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); 332 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
296 333
297 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); 334 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy());
298 335
299 std::string profile_path; 336 std::string profile_path;
300 if (!GetNetworkProfilePath(shared, &profile_path)) { 337 if (!GetNetworkProfilePath(shared, &profile_path)) {
301 ShowErrorNotification( 338 ShowErrorNotification(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 425 }
389 426
390 if (StringToLowerASCII(error) == 427 if (StringToLowerASCII(error) ==
391 StringToLowerASCII(std::string(flimflam::kUnknownString))) { 428 StringToLowerASCII(std::string(flimflam::kUnknownString))) {
392 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); 429 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
393 } 430 }
394 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, 431 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR,
395 UTF8ToUTF16(error)); 432 UTF8ToUTF16(error));
396 } 433 }
397 434
435 void ShowNetworkSettings(const std::string& service_path) {
436 if (!ash::Shell::HasInstance())
437 return;
438 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(
439 service_path);
440 }
441
398 } // network_connect 442 } // network_connect
399 } // ash 443 } // ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/network_connect.h ('k') | ash/system/chromeos/network/network_state_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698