OLD | NEW |
---|---|
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. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 return; | 83 return; |
81 } | 84 } |
82 | 85 |
83 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { | 86 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { |
84 network_connect::ActivateCellular(service_path); | 87 network_connect::ActivateCellular(service_path); |
85 return; | 88 return; |
86 } | 89 } |
87 | 90 |
88 if (error_name == NetworkConnectionHandler::kErrorConnected || | 91 if (error_name == NetworkConnectionHandler::kErrorConnected || |
89 error_name == NetworkConnectionHandler::kErrorConnecting) { | 92 error_name == NetworkConnectionHandler::kErrorConnecting) { |
90 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | 93 network_connect::ShowNetworkSettings(service_path); |
91 service_path); | |
92 return; | 94 return; |
93 } | 95 } |
94 | 96 |
95 // ConnectFailed or unknown error; show a notification. | 97 // ConnectFailed or unknown error; show a notification. |
96 ShowErrorNotification(error_name, service_path); | 98 ShowErrorNotification(error_name, service_path); |
97 | 99 |
98 // Show a configure dialog for ConnectFailed errors. | 100 // Show a configure dialog for ConnectFailed errors. |
99 if (error_name != NetworkConnectionHandler::kErrorConnectFailed) | 101 if (error_name != NetworkConnectionHandler::kErrorConnectFailed) |
100 return; | 102 return; |
101 | 103 |
(...skipping 15 matching lines...) Expand all Loading... | |
117 } | 119 } |
118 | 120 |
119 // If |check_error_state| is true, error state for the network is checked, | 121 // 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 | 122 // 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 | 123 // 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 | 124 // any configuration UI on failure and may be NULL (in which case the default |
123 // window will be used). | 125 // window will be used). |
124 void CallConnectToNetwork(const std::string& service_path, | 126 void CallConnectToNetwork(const std::string& service_path, |
125 bool check_error_state, | 127 bool check_error_state, |
126 gfx::NativeWindow owning_window) { | 128 gfx::NativeWindow owning_window) { |
127 NET_LOG_USER("ConnectToNetwork", service_path); | |
128 | |
129 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( | 129 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( |
130 NetworkObserver::ERROR_CONNECT_FAILED); | 130 NetworkObserver::ERROR_CONNECT_FAILED); |
131 | 131 |
132 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | 132 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( |
133 service_path, | 133 service_path, |
134 base::Bind(&OnConnectSucceeded, service_path), | 134 base::Bind(&OnConnectSucceeded, service_path), |
135 base::Bind(&OnConnectFailed, service_path, owning_window), | 135 base::Bind(&OnConnectFailed, service_path, owning_window), |
136 check_error_state); | 136 check_error_state); |
137 } | 137 } |
138 | 138 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 properties_to_clear), | 241 properties_to_clear), |
242 base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); | 242 base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); |
243 } | 243 } |
244 | 244 |
245 } // namespace | 245 } // namespace |
246 | 246 |
247 namespace network_connect { | 247 namespace network_connect { |
248 | 248 |
249 void ConnectToNetwork(const std::string& service_path, | 249 void ConnectToNetwork(const std::string& service_path, |
250 gfx::NativeWindow owning_window) { | 250 gfx::NativeWindow owning_window) { |
251 NET_LOG_USER("ConnectToNetwork", service_path); | |
251 const bool check_error_state = true; | 252 const bool check_error_state = true; |
252 CallConnectToNetwork(service_path, check_error_state, owning_window); | 253 CallConnectToNetwork(service_path, check_error_state, owning_window); |
253 } | 254 } |
254 | 255 |
255 void ActivateCellular(const std::string& service_path) { | 256 void ActivateCellular(const std::string& service_path) { |
256 NET_LOG_USER("ActivateCellular", service_path); | 257 NET_LOG_USER("ActivateCellular", service_path); |
257 const NetworkState* cellular = | 258 const NetworkState* cellular = |
258 NetworkHandler::Get()->network_state_handler()-> | 259 NetworkHandler::Get()->network_state_handler()-> |
259 GetNetworkState(service_path); | 260 GetNetworkState(service_path); |
260 if (!cellular || cellular->type() != flimflam::kTypeCellular) { | 261 if (!cellular || cellular->type() != flimflam::kTypeCellular) { |
261 NET_LOG_ERROR("ActivateCellular with no Service", service_path); | 262 NET_LOG_ERROR("ActivateCellular with no Service", service_path); |
262 return; | 263 return; |
263 } | 264 } |
264 const DeviceState* cellular_device = | 265 const DeviceState* cellular_device = |
265 NetworkHandler::Get()->network_state_handler()-> | 266 NetworkHandler::Get()->network_state_handler()-> |
266 GetDeviceState(cellular->device_path()); | 267 GetDeviceState(cellular->device_path()); |
267 if (!cellular_device) { | 268 if (!cellular_device) { |
268 NET_LOG_ERROR("ActivateCellular with no Device", service_path); | 269 NET_LOG_ERROR("ActivateCellular with no Device", service_path); |
269 return; | 270 return; |
270 } | 271 } |
271 if (!IsDirectActivatedCarrier(cellular_device->carrier())) { | 272 if (!IsDirectActivatedCarrier(cellular_device->carrier())) { |
272 // For non direct activation, show the mobile setup dialog which can be | 273 // 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 | 274 // used to activate the network. Only show the dialog, if an account |
274 // management URL is available. | 275 // management URL is available. |
275 if (!cellular->payment_url().empty()) | 276 if (!cellular->payment_url().empty()) |
276 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetup( | 277 ShowMobileSetup(service_path); |
277 service_path); | |
278 return; | 278 return; |
279 } | 279 } |
280 if (cellular->activation_state() == flimflam::kActivationStateActivated) { | 280 if (cellular->activation_state() == flimflam::kActivationStateActivated) { |
281 NET_LOG_ERROR("ActivateCellular for activated service", service_path); | 281 NET_LOG_ERROR("ActivateCellular for activated service", service_path); |
282 return; | 282 return; |
283 } | 283 } |
284 | 284 |
285 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork( | 285 NetworkHandler::Get()->network_connection_handler()->ActivateNetwork( |
286 service_path, | 286 service_path, |
287 "", // carrier | 287 "", // carrier |
288 base::Bind(&OnActivateSucceeded, service_path), | 288 base::Bind(&OnActivateSucceeded, service_path), |
289 base::Bind(&OnActivateFailed, service_path)); | 289 base::Bind(&OnActivateFailed, service_path)); |
290 } | 290 } |
291 | 291 |
292 void ShowMobileSetup(const std::string& service_path) { | |
293 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
294 const NetworkState* cellular = handler->GetNetworkState(service_path); | |
295 if (cellular && cellular->type() == flimflam::kTypeCellular && | |
296 cellular->activation_state() != flimflam::kActivationStateActivated && | |
pneubeck (no reviews)
2013/08/20 08:32:26
the first three conditions
cellular && cellular
stevenjb
2013/08/20 20:47:43
I think we may want show MobileSetupDialog even if
| |
297 cellular->activate_over_non_cellular_networks() && | |
298 !handler->DefaultNetwork()) { | |
299 std::string technology = cellular->network_technology(); | |
300 ash::NetworkObserver::NetworkType network_type = | |
301 (technology == flimflam::kNetworkTechnologyLte || | |
302 technology == flimflam::kNetworkTechnologyLteAdvanced) | |
303 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE | |
304 : ash::NetworkObserver::NETWORK_CELLULAR; | |
305 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( | |
306 NULL, | |
307 ash::NetworkObserver::ERROR_CONNECT_FAILED, | |
308 network_type, | |
309 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), | |
310 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, | |
311 UTF8ToUTF16((cellular->name()))), | |
312 std::vector<string16>()); | |
313 return; | |
314 } | |
315 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetupDialog( | |
316 service_path); | |
317 } | |
318 | |
292 void ConfigureNetworkAndConnect(const std::string& service_path, | 319 void ConfigureNetworkAndConnect(const std::string& service_path, |
293 const base::DictionaryValue& properties, | 320 const base::DictionaryValue& properties, |
294 bool shared) { | 321 bool shared) { |
295 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | 322 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); |
296 | 323 |
297 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | 324 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); |
298 | 325 |
299 std::string profile_path; | 326 std::string profile_path; |
300 if (!GetNetworkProfilePath(shared, &profile_path)) { | 327 if (!GetNetworkProfilePath(shared, &profile_path)) { |
301 ShowErrorNotification( | 328 ShowErrorNotification( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 } | 415 } |
389 | 416 |
390 if (StringToLowerASCII(error) == | 417 if (StringToLowerASCII(error) == |
391 StringToLowerASCII(std::string(flimflam::kUnknownString))) { | 418 StringToLowerASCII(std::string(flimflam::kUnknownString))) { |
392 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 419 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
393 } | 420 } |
394 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, | 421 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, |
395 UTF8ToUTF16(error)); | 422 UTF8ToUTF16(error)); |
396 } | 423 } |
397 | 424 |
425 void ShowNetworkSettings(const std::string& service_path) { | |
426 if (!ash::Shell::HasInstance()) | |
pneubeck (no reviews)
2013/08/20 08:32:26
should the other functions check this as well?
stevenjb
2013/08/20 20:47:43
Yes, at least anything that gets called by a callb
| |
427 return; | |
428 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | |
429 service_path); | |
430 } | |
431 | |
398 } // network_connect | 432 } // network_connect |
399 } // ash | 433 } // ash |
OLD | NEW |