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

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

Issue 23075012: Update NetworkStateNotifier to use message_center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update string ids, handle empty name 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"
9 #include "ash/system/chromeos/network/network_state_notifier.h" 8 #include "ash/system/chromeos/network/network_state_notifier.h"
10 #include "ash/system/tray/system_tray_delegate.h" 9 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/system_tray_notifier.h" 10 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/bind.h" 11 #include "base/bind.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 14 #include "base/values.h"
16 #include "chromeos/login/login_state.h" 15 #include "chromeos/login/login_state.h"
17 #include "chromeos/network/device_state.h" 16 #include "chromeos/network/device_state.h"
18 #include "chromeos/network/network_configuration_handler.h" 17 #include "chromeos/network/network_configuration_handler.h"
19 #include "chromeos/network/network_connection_handler.h" 18 #include "chromeos/network/network_connection_handler.h"
20 #include "chromeos/network/network_event_log.h" 19 #include "chromeos/network/network_event_log.h"
21 #include "chromeos/network/network_handler_callbacks.h" 20 #include "chromeos/network/network_handler_callbacks.h"
22 #include "chromeos/network/network_profile.h" 21 #include "chromeos/network/network_profile.h"
23 #include "chromeos/network/network_profile_handler.h" 22 #include "chromeos/network/network_profile_handler.h"
24 #include "chromeos/network/network_state.h" 23 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h" 24 #include "chromeos/network/network_state_handler.h"
26 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
27 #include "grit/ash_strings.h" 26 #include "grit/ash_strings.h"
28 #include "third_party/cros_system_api/dbus/service_constants.h" 27 #include "third_party/cros_system_api/dbus/service_constants.h"
29 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/message_center/message_center.h"
31 #include "ui/message_center/notification.h"
31 32
32 using chromeos::DeviceState; 33 using chromeos::DeviceState;
33 using chromeos::NetworkConfigurationHandler; 34 using chromeos::NetworkConfigurationHandler;
34 using chromeos::NetworkConnectionHandler; 35 using chromeos::NetworkConnectionHandler;
35 using chromeos::NetworkHandler; 36 using chromeos::NetworkHandler;
36 using chromeos::NetworkProfile; 37 using chromeos::NetworkProfile;
37 using chromeos::NetworkProfileHandler; 38 using chromeos::NetworkProfileHandler;
38 using chromeos::NetworkState; 39 using chromeos::NetworkState;
39 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
40 41
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return; 113 return;
113 114
114 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork( 115 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
115 service_path); 116 service_path);
116 } 117 }
117 118
118 void OnConnectSucceeded(const std::string& service_path) { 119 void OnConnectSucceeded(const std::string& service_path) {
119 NET_LOG_USER("Connect Succeeded", service_path); 120 NET_LOG_USER("Connect Succeeded", service_path);
120 if (!ash::Shell::HasInstance()) 121 if (!ash::Shell::HasInstance())
121 return; 122 return;
122 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 123 message_center::MessageCenter::Get()->RemoveNotification(
123 NetworkObserver::ERROR_CONNECT_FAILED); 124 network_connect::kNetworkConnectNotificationId, false /* by_user */);
124 } 125 }
125 126
126 // If |check_error_state| is true, error state for the network is checked, 127 // If |check_error_state| is true, error state for the network is checked,
127 // otherwise any current error state is ignored (e.g. for recently configured 128 // otherwise any current error state is ignored (e.g. for recently configured
128 // networks or repeat connect attempts). |owning_window| will be used to parent 129 // networks or repeat connect attempts). |owning_window| will be used to parent
129 // any configuration UI on failure and may be NULL (in which case the default 130 // any configuration UI on failure and may be NULL (in which case the default
130 // window will be used). 131 // window will be used).
131 void CallConnectToNetwork(const std::string& service_path, 132 void CallConnectToNetwork(const std::string& service_path,
132 bool check_error_state, 133 bool check_error_state,
133 gfx::NativeWindow owning_window) { 134 gfx::NativeWindow owning_window) {
134 if (!ash::Shell::HasInstance()) 135 if (!ash::Shell::HasInstance())
135 return; 136 return;
136 ash::Shell::GetInstance()->system_tray_notifier()->NotifyClearNetworkMessage( 137 message_center::MessageCenter::Get()->RemoveNotification(
137 NetworkObserver::ERROR_CONNECT_FAILED); 138 network_connect::kNetworkConnectNotificationId, false /* by_user */);
138 139
139 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( 140 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
140 service_path, 141 service_path,
141 base::Bind(&OnConnectSucceeded, service_path), 142 base::Bind(&OnConnectSucceeded, service_path),
142 base::Bind(&OnConnectFailed, service_path, owning_window), 143 base::Bind(&OnConnectFailed, service_path, owning_window),
143 check_error_state); 144 check_error_state);
144 } 145 }
145 146
146 void OnActivateFailed(const std::string& service_path, 147 void OnActivateFailed(const std::string& service_path,
147 const std::string& error_name, 148 const std::string& error_name,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 base::Bind(&ClearPropertiesAndConnect, 247 base::Bind(&ClearPropertiesAndConnect,
247 service_path, 248 service_path,
248 properties_to_clear), 249 properties_to_clear),
249 base::Bind(&SetPropertiesFailed, "SetProperties", service_path)); 250 base::Bind(&SetPropertiesFailed, "SetProperties", service_path));
250 } 251 }
251 252
252 } // namespace 253 } // namespace
253 254
254 namespace network_connect { 255 namespace network_connect {
255 256
257 const char kNetworkConnectNotificationId[] =
258 "chrome://settings/internet/connect";
259 const char kNetworkActivateNotificationId[] =
260 "chrome://settings/internet/activate";
261
256 void ConnectToNetwork(const std::string& service_path, 262 void ConnectToNetwork(const std::string& service_path,
257 gfx::NativeWindow owning_window) { 263 gfx::NativeWindow owning_window) {
258 NET_LOG_USER("ConnectToNetwork", service_path); 264 NET_LOG_USER("ConnectToNetwork", service_path);
265 const NetworkState* network =
266 NetworkHandler::Get()->network_state_handler()->
267 GetNetworkState(service_path);
268 if (network && !network->error().empty()) {
269 NET_LOG_USER("Configure: " + network->error(), service_path);
270 // If the network is in an error state, show the configuration UI
271 // directly to avoid a spurrious notification.
272 ash::Shell::GetInstance()->system_tray_delegate()->ConfigureNetwork(
273 service_path);
274 return;
275 }
259 const bool check_error_state = true; 276 const bool check_error_state = true;
260 CallConnectToNetwork(service_path, check_error_state, owning_window); 277 CallConnectToNetwork(service_path, check_error_state, owning_window);
261 } 278 }
262 279
263 void ActivateCellular(const std::string& service_path) { 280 void ActivateCellular(const std::string& service_path) {
264 NET_LOG_USER("ActivateCellular", service_path); 281 NET_LOG_USER("ActivateCellular", service_path);
265 const NetworkState* cellular = 282 const NetworkState* cellular =
266 NetworkHandler::Get()->network_state_handler()-> 283 NetworkHandler::Get()->network_state_handler()->
267 GetNetworkState(service_path); 284 GetNetworkState(service_path);
268 if (!cellular || cellular->type() != flimflam::kTypeCellular) { 285 if (!cellular || cellular->type() != flimflam::kTypeCellular) {
(...skipping 30 matching lines...) Expand all
299 void ShowMobileSetup(const std::string& service_path) { 316 void ShowMobileSetup(const std::string& service_path) {
300 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 317 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
301 const NetworkState* cellular = handler->GetNetworkState(service_path); 318 const NetworkState* cellular = handler->GetNetworkState(service_path);
302 if (!cellular || cellular->type() != flimflam::kTypeCellular) { 319 if (!cellular || cellular->type() != flimflam::kTypeCellular) {
303 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path); 320 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path);
304 return; 321 return;
305 } 322 }
306 if (cellular->activation_state() != flimflam::kActivationStateActivated && 323 if (cellular->activation_state() != flimflam::kActivationStateActivated &&
307 cellular->activate_over_non_cellular_networks() && 324 cellular->activate_over_non_cellular_networks() &&
308 !handler->DefaultNetwork()) { 325 !handler->DefaultNetwork()) {
309 std::string technology = cellular->network_technology(); 326 message_center::MessageCenter::Get()->AddNotification(
310 ash::NetworkObserver::NetworkType network_type = 327 message_center::Notification::CreateSystemNotification(
311 (technology == flimflam::kNetworkTechnologyLte || 328 ash::network_connect::kNetworkActivateNotificationId,
312 technology == flimflam::kNetworkTechnologyLteAdvanced) 329 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
313 ? ash::NetworkObserver::NETWORK_CELLULAR_LTE 330 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
314 : ash::NetworkObserver::NETWORK_CELLULAR; 331 UTF8ToUTF16(cellular->name())),
315 ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( 332 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
316 NULL, 333 IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED),
317 ash::NetworkObserver::ERROR_CONNECT_FAILED, 334 base::Bind(&ash::network_connect::ShowNetworkSettings,
318 network_type, 335 service_path)));
Jun Mukai 2013/08/20 22:25:36 As we discussed on another crbug, the clicked noti
stevenjb 2013/08/20 22:33:15 Yes, it is expected that the notification will be
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; 336 return;
324 } 337 }
325 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetupDialog( 338 ash::Shell::GetInstance()->system_tray_delegate()->ShowMobileSetupDialog(
326 service_path); 339 service_path);
327 } 340 }
328 341
329 void ConfigureNetworkAndConnect(const std::string& service_path, 342 void ConfigureNetworkAndConnect(const std::string& service_path,
330 const base::DictionaryValue& properties, 343 const base::DictionaryValue& properties,
331 bool shared) { 344 bool shared) {
332 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); 345 NET_LOG_USER("ConfigureNetworkAndConnect", service_path);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 447
435 void ShowNetworkSettings(const std::string& service_path) { 448 void ShowNetworkSettings(const std::string& service_path) {
436 if (!ash::Shell::HasInstance()) 449 if (!ash::Shell::HasInstance())
437 return; 450 return;
438 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( 451 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings(
439 service_path); 452 service_path);
440 } 453 }
441 454
442 } // network_connect 455 } // network_connect
443 } // ash 456 } // ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698