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

Side by Side Diff: ui/chromeos/network/network_state_notifier.cc

Issue 1272003002: Allow networkingPrivate to request configure UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback Created 5 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
« no previous file with comments | « ui/chromeos/network/network_connect.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_state_notifier.h" 5 #include "ui/chromeos/network/network_state_notifier.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chromeos/network/network_configuration_handler.h" 12 #include "chromeos/network/network_configuration_handler.h"
13 #include "chromeos/network/network_connection_handler.h" 13 #include "chromeos/network/network_connection_handler.h"
14 #include "chromeos/network/network_event_log.h"
15 #include "chromeos/network/network_state.h" 14 #include "chromeos/network/network_state.h"
16 #include "chromeos/network/network_state_handler.h" 15 #include "chromeos/network/network_state_handler.h"
17 #include "chromeos/network/shill_property_util.h" 16 #include "chromeos/network/shill_property_util.h"
17 #include "components/device_event_log/device_event_log.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/chromeos/network/network_connect.h" 21 #include "ui/chromeos/network/network_connect.h"
22 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" 22 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h"
23 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h" 23 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h"
24 #include "ui/message_center/message_center.h" 24 #include "ui/message_center/message_center.h"
25 #include "ui/message_center/notification.h" 25 #include "ui/message_center/notification.h"
26 26
27 using chromeos::NetworkConnectionHandler; 27 using chromeos::NetworkConnectionHandler;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 int GetErrorNotificationIconId(const std::string& network_type) { 63 int GetErrorNotificationIconId(const std::string& network_type) {
64 if (network_type == shill::kTypeVPN) 64 if (network_type == shill::kTypeVPN)
65 return IDR_AURA_UBER_TRAY_NETWORK_VPN; 65 return IDR_AURA_UBER_TRAY_NETWORK_VPN;
66 if (network_type == shill::kTypeCellular) 66 if (network_type == shill::kTypeCellular)
67 return IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR; 67 return IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR;
68 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; 68 return IDR_AURA_UBER_TRAY_NETWORK_FAILED;
69 } 69 }
70 70
71 void ShowErrorNotification(const std::string& notification_id, 71 void ShowErrorNotification(const std::string& service_path,
72 const std::string& notification_id,
72 const std::string& network_type, 73 const std::string& network_type,
73 const base::string16& title, 74 const base::string16& title,
74 const base::string16& message, 75 const base::string16& message,
75 const base::Closure& callback) { 76 const base::Closure& callback) {
77 NET_LOG(ERROR) << "ShowErrorNotification: " << service_path << ": "
78 << base::UTF16ToUTF8(title);
76 const gfx::Image& icon = 79 const gfx::Image& icon =
77 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 80 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
78 GetErrorNotificationIconId(network_type)); 81 GetErrorNotificationIconId(network_type));
79 message_center::MessageCenter::Get()->AddNotification( 82 message_center::MessageCenter::Get()->AddNotification(
80 message_center::Notification::CreateSystemNotification( 83 message_center::Notification::CreateSystemNotification(
81 notification_id, title, message, icon, 84 notification_id, title, message, icon,
82 ui::NetworkStateNotifier::kNotifierNetworkError, callback)); 85 ui::NetworkStateNotifier::kNotifierNetworkError, callback));
83 } 86 }
84 87
85 } // namespace 88 } // namespace
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ->HasPendingConnectRequest()) 215 ->HasPendingConnectRequest())
213 return; 216 return;
214 217
215 did_show_out_of_credits_ = true; 218 did_show_out_of_credits_ = true;
216 base::TimeDelta dtime = base::Time::Now() - out_of_credits_notify_time_; 219 base::TimeDelta dtime = base::Time::Now() - out_of_credits_notify_time_;
217 if (dtime.InSeconds() > kMinTimeBetweenOutOfCreditsNotifySeconds) { 220 if (dtime.InSeconds() > kMinTimeBetweenOutOfCreditsNotifySeconds) {
218 out_of_credits_notify_time_ = base::Time::Now(); 221 out_of_credits_notify_time_ = base::Time::Now();
219 base::string16 error_msg = l10n_util::GetStringFUTF16( 222 base::string16 error_msg = l10n_util::GetStringFUTF16(
220 IDS_NETWORK_OUT_OF_CREDITS_BODY, base::UTF8ToUTF16(cellular->name())); 223 IDS_NETWORK_OUT_OF_CREDITS_BODY, base::UTF8ToUTF16(cellular->name()));
221 ShowErrorNotification( 224 ShowErrorNotification(
222 kNetworkOutOfCreditsNotificationId, cellular->type(), 225 cellular->path(), kNetworkOutOfCreditsNotificationId, cellular->type(),
223 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_CREDITS_TITLE), error_msg, 226 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_CREDITS_TITLE), error_msg,
224 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, 227 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath,
225 weak_ptr_factory_.GetWeakPtr(), cellular->path())); 228 weak_ptr_factory_.GetWeakPtr(), cellular->path()));
226 } 229 }
227 } 230 }
228 231
229 void NetworkStateNotifier::UpdateCellularActivating( 232 void NetworkStateNotifier::UpdateCellularActivating(
230 const NetworkState* cellular) { 233 const NetworkState* cellular) {
231 // Keep track of any activating cellular network. 234 // Keep track of any activating cellular network.
232 std::string activation_state = cellular->activation_state(); 235 std::string activation_state = cellular->activation_state();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesFailed, 278 base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesFailed,
276 weak_ptr_factory_.GetWeakPtr(), error_name, service_path)); 279 weak_ptr_factory_.GetWeakPtr(), error_name, service_path));
277 } 280 }
278 281
279 void NetworkStateNotifier::ShowMobileActivationError( 282 void NetworkStateNotifier::ShowMobileActivationError(
280 const std::string& service_path) { 283 const std::string& service_path) {
281 const NetworkState* cellular = 284 const NetworkState* cellular =
282 NetworkHandler::Get()->network_state_handler()->GetNetworkState( 285 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
283 service_path); 286 service_path);
284 if (!cellular || cellular->type() != shill::kTypeCellular) { 287 if (!cellular || cellular->type() != shill::kTypeCellular) {
285 NET_LOG_ERROR("ShowMobileActivationError without Cellular network", 288 NET_LOG(ERROR) << "ShowMobileActivationError without Cellular network: "
286 service_path); 289 << service_path;
287 return; 290 return;
288 } 291 }
289 message_center::MessageCenter::Get()->AddNotification( 292 message_center::MessageCenter::Get()->AddNotification(
290 message_center::Notification::CreateSystemNotification( 293 message_center::Notification::CreateSystemNotification(
291 kNetworkActivateNotificationId, 294 kNetworkActivateNotificationId,
292 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), 295 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE),
293 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, 296 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION,
294 base::UTF8ToUTF16(cellular->name())), 297 base::UTF8ToUTF16(cellular->name())),
295 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 298 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
296 IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR), 299 IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 scoped_ptr<base::DictionaryValue> shill_error_data) { 333 scoped_ptr<base::DictionaryValue> shill_error_data) {
331 base::DictionaryValue shill_properties; 334 base::DictionaryValue shill_properties;
332 ShowConnectErrorNotification(error_name, service_path, shill_properties); 335 ShowConnectErrorNotification(error_name, service_path, shill_properties);
333 } 336 }
334 337
335 void NetworkStateNotifier::ShowConnectErrorNotification( 338 void NetworkStateNotifier::ShowConnectErrorNotification(
336 const std::string& error_name, 339 const std::string& error_name,
337 const std::string& service_path, 340 const std::string& service_path,
338 const base::DictionaryValue& shill_properties) { 341 const base::DictionaryValue& shill_properties) {
339 base::string16 error = GetConnectErrorString(error_name); 342 base::string16 error = GetConnectErrorString(error_name);
343 NET_LOG(DEBUG) << "Notify: " << service_path
344 << ": Connect error: " << error_name << ": "
345 << base::UTF16ToUTF8(error);
340 if (error.empty()) { 346 if (error.empty()) {
341 std::string shill_error; 347 std::string shill_error;
342 shill_properties.GetStringWithoutPathExpansion(shill::kErrorProperty, 348 shill_properties.GetStringWithoutPathExpansion(shill::kErrorProperty,
343 &shill_error); 349 &shill_error);
344 if (!chromeos::NetworkState::ErrorIsValid(shill_error)) { 350 if (!chromeos::NetworkState::ErrorIsValid(shill_error)) {
345 shill_properties.GetStringWithoutPathExpansion( 351 shill_properties.GetStringWithoutPathExpansion(
346 shill::kPreviousErrorProperty, &shill_error); 352 shill::kPreviousErrorProperty, &shill_error);
347 NET_LOG_DEBUG("Notify Service.PreviousError: " + shill_error, 353 NET_LOG(DEBUG) << "Notify: " << service_path
348 service_path); 354 << ": Service.PreviousError: " << shill_error;
349 if (!chromeos::NetworkState::ErrorIsValid(shill_error)) 355 if (!chromeos::NetworkState::ErrorIsValid(shill_error))
350 shill_error.clear(); 356 shill_error.clear();
351 } else { 357 } else {
352 NET_LOG_DEBUG("Notify Service.Error: " + shill_error, service_path); 358 NET_LOG(DEBUG) << "Notify: " << service_path
359 << ": Service.Error: " << shill_error;
353 } 360 }
354 361
355 const NetworkState* network = 362 const NetworkState* network =
356 NetworkHandler::Get()->network_state_handler()->GetNetworkState( 363 NetworkHandler::Get()->network_state_handler()->GetNetworkState(
357 service_path); 364 service_path);
358 if (network) { 365 if (network) {
359 // Always log last_error, but only use it if shill_error is empty. 366 // Always log last_error, but only use it if shill_error is empty.
360 // TODO(stevenjb): This shouldn't ever be necessary, but is kept here as 367 // TODO(stevenjb): This shouldn't ever be necessary, but is kept here as
361 // a failsafe since more information is better than less when debugging 368 // a failsafe since more information is better than less when debugging
362 // and we have encountered some strange edge cases before. 369 // and we have encountered some strange edge cases before.
363 NET_LOG_DEBUG("Notify Network.last_error: " + network->last_error(), 370 NET_LOG(DEBUG) << "Notify: " << service_path
364 service_path); 371 << ": Network.last_error: " << network->last_error();
365 if (shill_error.empty()) 372 if (shill_error.empty())
366 shill_error = network->last_error(); 373 shill_error = network->last_error();
367 } 374 }
368 375
369 if (ShillErrorIsIgnored(shill_error)) { 376 if (ShillErrorIsIgnored(shill_error)) {
370 NET_LOG_DEBUG("Notify Ignoring error: " + error_name, service_path); 377 NET_LOG(DEBUG) << "Notify: " << service_path
378 << ": Ignoring error: " << error_name;
371 return; 379 return;
372 } 380 }
373 381
374 error = network_connect_->GetShillErrorString(shill_error, service_path); 382 error = network_connect_->GetShillErrorString(shill_error, service_path);
375 if (error.empty()) 383 if (error.empty()) {
384 if (error_name == NetworkConnectionHandler::kErrorConnectFailed &&
385 network && !network->connectable()) {
386 // Connect failure on non connectable network with no additional
387 // information. We expect the UI to show configuration UI so do not
388 // show an additional (and unhelpful) notification.
389 return;
390 }
376 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); 391 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
392 }
377 } 393 }
378 NET_LOG_ERROR("Notify connect error: " + base::UTF16ToUTF8(error), 394 NET_LOG(ERROR) << "Notify: " << service_path
379 service_path); 395 << ": Connect error: " + base::UTF16ToUTF8(error);
380 396
381 std::string network_name = 397 std::string network_name =
382 chromeos::shill_property_util::GetNameFromProperties(service_path, 398 chromeos::shill_property_util::GetNameFromProperties(service_path,
383 shill_properties); 399 shill_properties);
384 std::string network_error_details; 400 std::string network_error_details;
385 shill_properties.GetStringWithoutPathExpansion(shill::kErrorDetailsProperty, 401 shill_properties.GetStringWithoutPathExpansion(shill::kErrorDetailsProperty,
386 &network_error_details); 402 &network_error_details);
387 403
388 base::string16 error_msg; 404 base::string16 error_msg;
389 if (!network_error_details.empty()) { 405 if (!network_error_details.empty()) {
390 // network_name should't be empty if network_error_details is set. 406 // network_name should't be empty if network_error_details is set.
391 error_msg = l10n_util::GetStringFUTF16( 407 error_msg = l10n_util::GetStringFUTF16(
392 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE, 408 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE,
393 base::UTF8ToUTF16(network_name), error, 409 base::UTF8ToUTF16(network_name), error,
394 base::UTF8ToUTF16(network_error_details)); 410 base::UTF8ToUTF16(network_error_details));
395 } else if (network_name.empty()) { 411 } else if (network_name.empty()) {
396 error_msg = l10n_util::GetStringFUTF16( 412 error_msg = l10n_util::GetStringFUTF16(
397 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_NO_NAME, error); 413 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_NO_NAME, error);
398 } else { 414 } else {
399 error_msg = 415 error_msg =
400 l10n_util::GetStringFUTF16(IDS_NETWORK_CONNECTION_ERROR_MESSAGE, 416 l10n_util::GetStringFUTF16(IDS_NETWORK_CONNECTION_ERROR_MESSAGE,
401 base::UTF8ToUTF16(network_name), error); 417 base::UTF8ToUTF16(network_name), error);
402 } 418 }
403 419
404 std::string network_type; 420 std::string network_type;
405 shill_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, 421 shill_properties.GetStringWithoutPathExpansion(shill::kTypeProperty,
406 &network_type); 422 &network_type);
407 423
408 ShowErrorNotification( 424 ShowErrorNotification(
409 kNetworkConnectNotificationId, network_type, 425 service_path, kNetworkConnectNotificationId, network_type,
410 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), error_msg, 426 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), error_msg,
411 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, 427 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath,
412 weak_ptr_factory_.GetWeakPtr(), service_path)); 428 weak_ptr_factory_.GetWeakPtr(), service_path));
413 } 429 }
414 430
415 void NetworkStateNotifier::ShowVpnDisconnectedNotification( 431 void NetworkStateNotifier::ShowVpnDisconnectedNotification(
416 const NetworkState* vpn) { 432 const NetworkState* vpn) {
417 base::string16 error_msg = l10n_util::GetStringFUTF16( 433 base::string16 error_msg = l10n_util::GetStringFUTF16(
418 IDS_NETWORK_VPN_CONNECTION_LOST_BODY, base::UTF8ToUTF16(vpn->name())); 434 IDS_NETWORK_VPN_CONNECTION_LOST_BODY, base::UTF8ToUTF16(vpn->name()));
419 ShowErrorNotification( 435 ShowErrorNotification(
420 kNetworkConnectNotificationId, shill::kTypeVPN, 436 vpn->path(), kNetworkConnectNotificationId, shill::kTypeVPN,
421 l10n_util::GetStringUTF16(IDS_NETWORK_VPN_CONNECTION_LOST_TITLE), 437 l10n_util::GetStringUTF16(IDS_NETWORK_VPN_CONNECTION_LOST_TITLE),
422 error_msg, base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, 438 error_msg, base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath,
423 weak_ptr_factory_.GetWeakPtr(), vpn->path())); 439 weak_ptr_factory_.GetWeakPtr(), vpn->path()));
424 } 440 }
425 441
426 void NetworkStateNotifier::ShowNetworkSettingsForPath( 442 void NetworkStateNotifier::ShowNetworkSettingsForPath(
427 const std::string& service_path) { 443 const std::string& service_path) {
428 network_connect_->ShowNetworkSettingsForPath(service_path); 444 network_connect_->ShowNetworkSettingsForPath(service_path);
429 } 445 }
430 446
431 } // namespace ui 447 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_connect.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698