| OLD | NEW |
| 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 "chrome/browser/chromeos/net/network_state_notifier.h" |
| 6 | 6 |
| 7 #include "ash/common/system/system_notifier.h" |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/location.h" | 9 #include "base/location.h" |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/net/shill_error.h" |
| 14 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 15 #include "chrome/grit/generated_resources.h" |
| 12 #include "chromeos/network/network_configuration_handler.h" | 16 #include "chromeos/network/network_configuration_handler.h" |
| 13 #include "chromeos/network/network_connection_handler.h" | 17 #include "chromeos/network/network_connection_handler.h" |
| 14 #include "chromeos/network/network_state.h" | 18 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_handler.h" | 19 #include "chromeos/network/network_state_handler.h" |
| 16 #include "chromeos/network/shill_property_util.h" | 20 #include "chromeos/network/shill_property_util.h" |
| 17 #include "components/device_event_log/device_event_log.h" | 21 #include "components/device_event_log/device_event_log.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/chromeos/network/network_connect.h" | |
| 22 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" | 25 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" |
| 23 #include "ui/chromeos/strings/grit/ui_chromeos_strings.h" | |
| 24 #include "ui/message_center/message_center.h" | 26 #include "ui/message_center/message_center.h" |
| 25 #include "ui/message_center/notification.h" | 27 #include "ui/message_center/notification.h" |
| 26 | 28 |
| 27 using chromeos::NetworkConnectionHandler; | 29 namespace chromeos { |
| 28 using chromeos::NetworkHandler; | |
| 29 using chromeos::NetworkState; | |
| 30 using chromeos::NetworkStateHandler; | |
| 31 using chromeos::NetworkTypePattern; | |
| 32 | 30 |
| 33 namespace { | 31 namespace { |
| 34 | 32 |
| 35 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; | 33 const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; |
| 36 | 34 |
| 37 // Ignore in-progress error. | 35 // Ignore in-progress error. |
| 38 bool ShillErrorIsIgnored(const std::string& shill_error) { | 36 bool ShillErrorIsIgnored(const std::string& shill_error) { |
| 39 if (shill_error == shill::kErrorResultInProgress) | 37 if (shill_error == shill::kErrorResultInProgress) |
| 40 return true; | 38 return true; |
| 41 return false; | 39 return false; |
| 42 } | 40 } |
| 43 | 41 |
| 44 // Error messages based on |error_name|, not network_state->error(). | 42 // Error messages based on |error_name|, not network_state->error(). |
| 45 base::string16 GetConnectErrorString(const std::string& error_name) { | 43 base::string16 GetConnectErrorString(const std::string& error_name) { |
| 46 if (error_name == NetworkConnectionHandler::kErrorNotFound) | 44 if (error_name == NetworkConnectionHandler::kErrorNotFound) |
| 47 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); | 45 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); |
| 48 if (error_name == NetworkConnectionHandler::kErrorConfigureFailed) { | 46 if (error_name == NetworkConnectionHandler::kErrorConfigureFailed) { |
| 49 return l10n_util::GetStringUTF16( | 47 return l10n_util::GetStringUTF16( |
| 50 IDS_CHROMEOS_NETWORK_ERROR_CONFIGURE_FAILED); | 48 IDS_CHROMEOS_NETWORK_ERROR_CONFIGURE_FAILED); |
| 51 } | 49 } |
| 52 if (error_name == NetworkConnectionHandler::kErrorCertLoadTimeout) { | 50 if (error_name == NetworkConnectionHandler::kErrorCertLoadTimeout) { |
| 53 return l10n_util::GetStringUTF16( | 51 return l10n_util::GetStringUTF16( |
| 54 IDS_CHROMEOS_NETWORK_ERROR_CERTIFICATES_NOT_LOADED); | 52 IDS_CHROMEOS_NETWORK_ERROR_CERTIFICATES_NOT_LOADED); |
| 55 } | 53 } |
| 56 if (error_name == ui::NetworkConnect::kErrorActivateFailed) { | 54 if (error_name == NetworkConnectionHandler::kErrorActivateFailed) { |
| 57 return l10n_util::GetStringUTF16( | 55 return l10n_util::GetStringUTF16( |
| 58 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); | 56 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); |
| 59 } | 57 } |
| 60 return base::string16(); | 58 return base::string16(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 int GetErrorNotificationIconId(const std::string& network_type) { | 61 int GetErrorNotificationIconId(const std::string& network_type) { |
| 64 if (network_type == shill::kTypeVPN) | 62 if (network_type == shill::kTypeVPN) |
| 65 return IDR_AURA_UBER_TRAY_NETWORK_VPN; | 63 return IDR_AURA_UBER_TRAY_NETWORK_VPN; |
| 66 if (network_type == shill::kTypeCellular) | 64 if (network_type == shill::kTypeCellular) |
| 67 return IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR; | 65 return IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR; |
| 68 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; | 66 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; |
| 69 } | 67 } |
| 70 | 68 |
| 71 void ShowErrorNotification(const std::string& service_path, | 69 void ShowErrorNotification(const std::string& service_path, |
| 72 const std::string& notification_id, | 70 const std::string& notification_id, |
| 73 const std::string& network_type, | 71 const std::string& network_type, |
| 74 const base::string16& title, | 72 const base::string16& title, |
| 75 const base::string16& message, | 73 const base::string16& message, |
| 76 const base::Closure& callback) { | 74 const base::Closure& callback) { |
| 77 NET_LOG(ERROR) << "ShowErrorNotification: " << service_path << ": " | 75 NET_LOG(ERROR) << "ShowErrorNotification: " << service_path << ": " |
| 78 << base::UTF16ToUTF8(title); | 76 << base::UTF16ToUTF8(title); |
| 79 const gfx::Image& icon = | 77 const gfx::Image& icon = |
| 80 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 78 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 81 GetErrorNotificationIconId(network_type)); | 79 GetErrorNotificationIconId(network_type)); |
| 82 message_center::MessageCenter::Get()->AddNotification( | 80 message_center::MessageCenter::Get()->AddNotification( |
| 83 message_center::Notification::CreateSystemNotification( | 81 message_center::Notification::CreateSystemNotification( |
| 84 notification_id, title, message, icon, | 82 notification_id, title, message, icon, |
| 85 ui::NetworkStateNotifier::kNotifierNetworkError, callback)); | 83 ash::system_notifier::kNotifierNetworkError, callback)); |
| 86 } | 84 } |
| 87 | 85 |
| 88 } // namespace | 86 } // namespace |
| 89 | 87 |
| 90 namespace ui { | |
| 91 | |
| 92 const char NetworkStateNotifier::kNotifierNetwork[] = "ui.chromeos.network"; | |
| 93 const char NetworkStateNotifier::kNotifierNetworkError[] = | |
| 94 "ui.chromeos.network.error"; | |
| 95 | |
| 96 const char NetworkStateNotifier::kNetworkConnectNotificationId[] = | 88 const char NetworkStateNotifier::kNetworkConnectNotificationId[] = |
| 97 "chrome://settings/internet/connect"; | 89 "chrome://settings/internet/connect"; |
| 98 const char NetworkStateNotifier::kNetworkActivateNotificationId[] = | 90 const char NetworkStateNotifier::kNetworkActivateNotificationId[] = |
| 99 "chrome://settings/internet/activate"; | 91 "chrome://settings/internet/activate"; |
| 100 const char NetworkStateNotifier::kNetworkOutOfCreditsNotificationId[] = | 92 const char NetworkStateNotifier::kNetworkOutOfCreditsNotificationId[] = |
| 101 "chrome://settings/internet/out-of-credits"; | 93 "chrome://settings/internet/out-of-credits"; |
| 102 | 94 |
| 103 NetworkStateNotifier::NetworkStateNotifier(NetworkConnect* network_connect) | 95 NetworkStateNotifier::NetworkStateNotifier() |
| 104 : network_connect_(network_connect), | 96 : did_show_out_of_credits_(false), weak_ptr_factory_(this) { |
| 105 did_show_out_of_credits_(false), | |
| 106 weak_ptr_factory_(this) { | |
| 107 if (!NetworkHandler::IsInitialized()) | 97 if (!NetworkHandler::IsInitialized()) |
| 108 return; | 98 return; |
| 109 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 99 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 110 handler->AddObserver(this, FROM_HERE); | 100 handler->AddObserver(this, FROM_HERE); |
| 111 UpdateDefaultNetwork(handler->DefaultNetwork()); | 101 UpdateDefaultNetwork(handler->DefaultNetwork()); |
| 112 NetworkHandler::Get()->network_connection_handler()->AddObserver(this); | 102 NetworkHandler::Get()->network_connection_handler()->AddObserver(this); |
| 113 } | 103 } |
| 114 | 104 |
| 115 NetworkStateNotifier::~NetworkStateNotifier() { | 105 NetworkStateNotifier::~NetworkStateNotifier() { |
| 116 if (!NetworkHandler::IsInitialized()) | 106 if (!NetworkHandler::IsInitialized()) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 217 |
| 228 did_show_out_of_credits_ = true; | 218 did_show_out_of_credits_ = true; |
| 229 base::TimeDelta dtime = base::Time::Now() - out_of_credits_notify_time_; | 219 base::TimeDelta dtime = base::Time::Now() - out_of_credits_notify_time_; |
| 230 if (dtime.InSeconds() > kMinTimeBetweenOutOfCreditsNotifySeconds) { | 220 if (dtime.InSeconds() > kMinTimeBetweenOutOfCreditsNotifySeconds) { |
| 231 out_of_credits_notify_time_ = base::Time::Now(); | 221 out_of_credits_notify_time_ = base::Time::Now(); |
| 232 base::string16 error_msg = l10n_util::GetStringFUTF16( | 222 base::string16 error_msg = l10n_util::GetStringFUTF16( |
| 233 IDS_NETWORK_OUT_OF_CREDITS_BODY, base::UTF8ToUTF16(cellular->name())); | 223 IDS_NETWORK_OUT_OF_CREDITS_BODY, base::UTF8ToUTF16(cellular->name())); |
| 234 ShowErrorNotification( | 224 ShowErrorNotification( |
| 235 cellular->path(), kNetworkOutOfCreditsNotificationId, cellular->type(), | 225 cellular->path(), kNetworkOutOfCreditsNotificationId, cellular->type(), |
| 236 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_CREDITS_TITLE), error_msg, | 226 l10n_util::GetStringUTF16(IDS_NETWORK_OUT_OF_CREDITS_TITLE), error_msg, |
| 237 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, | 227 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 238 weak_ptr_factory_.GetWeakPtr(), cellular->path())); | 228 weak_ptr_factory_.GetWeakPtr(), cellular->guid())); |
| 239 } | 229 } |
| 240 } | 230 } |
| 241 | 231 |
| 242 void NetworkStateNotifier::UpdateCellularActivating( | 232 void NetworkStateNotifier::UpdateCellularActivating( |
| 243 const NetworkState* cellular) { | 233 const NetworkState* cellular) { |
| 244 // Keep track of any activating cellular network. | 234 // Keep track of any activating cellular network. |
| 245 std::string activation_state = cellular->activation_state(); | 235 std::string activation_state = cellular->activation_state(); |
| 246 if (activation_state == shill::kActivationStateActivating) { | 236 if (activation_state == shill::kActivationStateActivating) { |
| 247 cellular_activating_.insert(cellular->path()); | 237 cellular_activating_.insert(cellular->path()); |
| 248 return; | 238 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 260 else | 250 else |
| 261 icon_id = IDR_AURA_UBER_TRAY_NOTIFICATION_3G; | 251 icon_id = IDR_AURA_UBER_TRAY_NOTIFICATION_3G; |
| 262 const gfx::Image& icon = | 252 const gfx::Image& icon = |
| 263 ui::ResourceBundle::GetSharedInstance().GetImageNamed(icon_id); | 253 ui::ResourceBundle::GetSharedInstance().GetImageNamed(icon_id); |
| 264 message_center::MessageCenter::Get()->AddNotification( | 254 message_center::MessageCenter::Get()->AddNotification( |
| 265 message_center::Notification::CreateSystemNotification( | 255 message_center::Notification::CreateSystemNotification( |
| 266 kNetworkActivateNotificationId, | 256 kNetworkActivateNotificationId, |
| 267 l10n_util::GetStringUTF16(IDS_NETWORK_CELLULAR_ACTIVATED_TITLE), | 257 l10n_util::GetStringUTF16(IDS_NETWORK_CELLULAR_ACTIVATED_TITLE), |
| 268 l10n_util::GetStringFUTF16(IDS_NETWORK_CELLULAR_ACTIVATED, | 258 l10n_util::GetStringFUTF16(IDS_NETWORK_CELLULAR_ACTIVATED, |
| 269 base::UTF8ToUTF16((cellular->name()))), | 259 base::UTF8ToUTF16((cellular->name()))), |
| 270 icon, kNotifierNetwork, | 260 icon, ash::system_notifier::kNotifierNetwork, |
| 271 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, | 261 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 272 weak_ptr_factory_.GetWeakPtr(), cellular->path()))); | 262 weak_ptr_factory_.GetWeakPtr(), cellular->guid()))); |
| 273 } | 263 } |
| 274 | 264 |
| 275 void NetworkStateNotifier::ShowNetworkConnectError( | 265 void NetworkStateNotifier::ShowNetworkConnectError( |
| 276 const std::string& error_name, | 266 const std::string& error_name, |
| 277 const std::string& service_path) { | 267 const std::string& service_path) { |
| 278 if (service_path.empty()) { | 268 if (service_path.empty()) { |
| 279 base::DictionaryValue shill_properties; | 269 base::DictionaryValue shill_properties; |
| 280 ShowConnectErrorNotification(error_name, service_path, shill_properties); | 270 ShowConnectErrorNotification(error_name, service_path, shill_properties); |
| 281 return; | 271 return; |
| 282 } | 272 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 300 return; | 290 return; |
| 301 } | 291 } |
| 302 message_center::MessageCenter::Get()->AddNotification( | 292 message_center::MessageCenter::Get()->AddNotification( |
| 303 message_center::Notification::CreateSystemNotification( | 293 message_center::Notification::CreateSystemNotification( |
| 304 kNetworkActivateNotificationId, | 294 kNetworkActivateNotificationId, |
| 305 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), | 295 l10n_util::GetStringUTF16(IDS_NETWORK_ACTIVATION_ERROR_TITLE), |
| 306 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, | 296 l10n_util::GetStringFUTF16(IDS_NETWORK_ACTIVATION_NEEDS_CONNECTION, |
| 307 base::UTF8ToUTF16(cellular->name())), | 297 base::UTF8ToUTF16(cellular->name())), |
| 308 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 298 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 309 IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR), | 299 IDR_AURA_UBER_TRAY_NETWORK_FAILED_CELLULAR), |
| 310 kNotifierNetworkError, | 300 ash::system_notifier::kNotifierNetworkError, |
| 311 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, | 301 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 312 weak_ptr_factory_.GetWeakPtr(), service_path))); | 302 weak_ptr_factory_.GetWeakPtr(), cellular->guid()))); |
| 313 } | 303 } |
| 314 | 304 |
| 315 void NetworkStateNotifier::RemoveConnectNotification() { | 305 void NetworkStateNotifier::RemoveConnectNotification() { |
| 316 message_center::MessageCenter* message_center = | 306 message_center::MessageCenter* message_center = |
| 317 message_center::MessageCenter::Get(); | 307 message_center::MessageCenter::Get(); |
| 318 if (message_center) { | 308 if (message_center) { |
| 319 message_center->RemoveNotification(kNetworkConnectNotificationId, | 309 message_center->RemoveNotification(kNetworkConnectNotificationId, |
| 320 false /* not by user */); | 310 false /* not by user */); |
| 321 } | 311 } |
| 322 } | 312 } |
| 323 | 313 |
| 324 void NetworkStateNotifier::ConnectErrorPropertiesSucceeded( | 314 void NetworkStateNotifier::ConnectErrorPropertiesSucceeded( |
| 325 const std::string& error_name, | 315 const std::string& error_name, |
| 326 const std::string& service_path, | 316 const std::string& service_path, |
| 327 const base::DictionaryValue& shill_properties) { | 317 const base::DictionaryValue& shill_properties) { |
| 328 std::string state; | 318 std::string state; |
| 329 shill_properties.GetStringWithoutPathExpansion(shill::kStateProperty, &state); | 319 shill_properties.GetStringWithoutPathExpansion(shill::kStateProperty, &state); |
| 330 if (chromeos::NetworkState::StateIsConnected(state) || | 320 if (NetworkState::StateIsConnected(state) || |
| 331 chromeos::NetworkState::StateIsConnecting(state)) { | 321 NetworkState::StateIsConnecting(state)) { |
| 332 // Network is no longer in an error state. This can happen if an | 322 // Network is no longer in an error state. This can happen if an |
| 333 // unexpected idle state transition occurs, see crbug.com/333955. | 323 // unexpected idle state transition occurs, see crbug.com/333955. |
| 334 return; | 324 return; |
| 335 } | 325 } |
| 336 ShowConnectErrorNotification(error_name, service_path, shill_properties); | 326 ShowConnectErrorNotification(error_name, service_path, shill_properties); |
| 337 } | 327 } |
| 338 | 328 |
| 339 void NetworkStateNotifier::ConnectErrorPropertiesFailed( | 329 void NetworkStateNotifier::ConnectErrorPropertiesFailed( |
| 340 const std::string& error_name, | 330 const std::string& error_name, |
| 341 const std::string& service_path, | 331 const std::string& service_path, |
| 342 const std::string& shill_connect_error, | 332 const std::string& shill_connect_error, |
| 343 std::unique_ptr<base::DictionaryValue> shill_error_data) { | 333 std::unique_ptr<base::DictionaryValue> shill_error_data) { |
| 344 base::DictionaryValue shill_properties; | 334 base::DictionaryValue shill_properties; |
| 345 ShowConnectErrorNotification(error_name, service_path, shill_properties); | 335 ShowConnectErrorNotification(error_name, service_path, shill_properties); |
| 346 } | 336 } |
| 347 | 337 |
| 348 void NetworkStateNotifier::ShowConnectErrorNotification( | 338 void NetworkStateNotifier::ShowConnectErrorNotification( |
| 349 const std::string& error_name, | 339 const std::string& error_name, |
| 350 const std::string& service_path, | 340 const std::string& service_path, |
| 351 const base::DictionaryValue& shill_properties) { | 341 const base::DictionaryValue& shill_properties) { |
| 352 base::string16 error = GetConnectErrorString(error_name); | 342 base::string16 error = GetConnectErrorString(error_name); |
| 353 NET_LOG(DEBUG) << "Notify: " << service_path | 343 NET_LOG(DEBUG) << "Notify: " << service_path |
| 354 << ": Connect error: " << error_name << ": " | 344 << ": Connect error: " << error_name << ": " |
| 355 << base::UTF16ToUTF8(error); | 345 << base::UTF16ToUTF8(error); |
| 346 |
| 347 const NetworkState* network = |
| 348 NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 349 service_path); |
| 350 std::string guid = network ? network->guid() : ""; |
| 351 |
| 356 if (error.empty()) { | 352 if (error.empty()) { |
| 357 std::string shill_error; | 353 std::string shill_error; |
| 358 shill_properties.GetStringWithoutPathExpansion(shill::kErrorProperty, | 354 shill_properties.GetStringWithoutPathExpansion(shill::kErrorProperty, |
| 359 &shill_error); | 355 &shill_error); |
| 360 if (!chromeos::NetworkState::ErrorIsValid(shill_error)) { | 356 if (!NetworkState::ErrorIsValid(shill_error)) { |
| 361 shill_properties.GetStringWithoutPathExpansion( | 357 shill_properties.GetStringWithoutPathExpansion( |
| 362 shill::kPreviousErrorProperty, &shill_error); | 358 shill::kPreviousErrorProperty, &shill_error); |
| 363 NET_LOG(DEBUG) << "Notify: " << service_path | 359 NET_LOG(DEBUG) << "Notify: " << service_path |
| 364 << ": Service.PreviousError: " << shill_error; | 360 << ": Service.PreviousError: " << shill_error; |
| 365 if (!chromeos::NetworkState::ErrorIsValid(shill_error)) | 361 if (!NetworkState::ErrorIsValid(shill_error)) |
| 366 shill_error.clear(); | 362 shill_error.clear(); |
| 367 } else { | 363 } else { |
| 368 NET_LOG(DEBUG) << "Notify: " << service_path | 364 NET_LOG(DEBUG) << "Notify: " << service_path |
| 369 << ": Service.Error: " << shill_error; | 365 << ": Service.Error: " << shill_error; |
| 370 } | 366 } |
| 371 | 367 |
| 372 const NetworkState* network = | |
| 373 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
| 374 service_path); | |
| 375 if (network) { | 368 if (network) { |
| 376 // Always log last_error, but only use it if shill_error is empty. | 369 // Always log last_error, but only use it if shill_error is empty. |
| 377 // TODO(stevenjb): This shouldn't ever be necessary, but is kept here as | 370 // TODO(stevenjb): This shouldn't ever be necessary, but is kept here as |
| 378 // a failsafe since more information is better than less when debugging | 371 // a failsafe since more information is better than less when debugging |
| 379 // and we have encountered some strange edge cases before. | 372 // and we have encountered some strange edge cases before. |
| 380 NET_LOG(DEBUG) << "Notify: " << service_path | 373 NET_LOG(DEBUG) << "Notify: " << service_path |
| 381 << ": Network.last_error: " << network->last_error(); | 374 << ": Network.last_error: " << network->last_error(); |
| 382 if (shill_error.empty()) | 375 if (shill_error.empty()) |
| 383 shill_error = network->last_error(); | 376 shill_error = network->last_error(); |
| 384 } | 377 } |
| 385 | 378 |
| 386 if (ShillErrorIsIgnored(shill_error)) { | 379 if (ShillErrorIsIgnored(shill_error)) { |
| 387 NET_LOG(DEBUG) << "Notify: " << service_path | 380 NET_LOG(DEBUG) << "Notify: " << service_path |
| 388 << ": Ignoring error: " << error_name; | 381 << ": Ignoring error: " << error_name; |
| 389 return; | 382 return; |
| 390 } | 383 } |
| 391 | 384 error = shill_error::GetShillErrorString(shill_error, guid); |
| 392 error = network_connect_->GetShillErrorString(shill_error, service_path); | |
| 393 if (error.empty()) { | 385 if (error.empty()) { |
| 394 if (error_name == NetworkConnectionHandler::kErrorConnectFailed && | 386 if (error_name == NetworkConnectionHandler::kErrorConnectFailed && |
| 395 network && !network->connectable()) { | 387 network && !network->connectable()) { |
| 396 // Connect failure on non connectable network with no additional | 388 // Connect failure on non connectable network with no additional |
| 397 // information. We expect the UI to show configuration UI so do not | 389 // information. We expect the UI to show configuration UI so do not |
| 398 // show an additional (and unhelpful) notification. | 390 // show an additional (and unhelpful) notification. |
| 399 return; | 391 return; |
| 400 } | 392 } |
| 401 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 393 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
| 402 } | 394 } |
| 403 } | 395 } |
| 404 NET_LOG(ERROR) << "Notify: " << service_path | 396 NET_LOG(ERROR) << "Notify: " << service_path |
| 405 << ": Connect error: " + base::UTF16ToUTF8(error); | 397 << ": Connect error: " + base::UTF16ToUTF8(error); |
| 406 | 398 |
| 407 std::string network_name = | 399 std::string network_name = shill_property_util::GetNameFromProperties( |
| 408 chromeos::shill_property_util::GetNameFromProperties(service_path, | 400 service_path, shill_properties); |
| 409 shill_properties); | |
| 410 std::string network_error_details; | 401 std::string network_error_details; |
| 411 shill_properties.GetStringWithoutPathExpansion(shill::kErrorDetailsProperty, | 402 shill_properties.GetStringWithoutPathExpansion(shill::kErrorDetailsProperty, |
| 412 &network_error_details); | 403 &network_error_details); |
| 413 | 404 |
| 414 base::string16 error_msg; | 405 base::string16 error_msg; |
| 415 if (!network_error_details.empty()) { | 406 if (!network_error_details.empty()) { |
| 416 // network_name should't be empty if network_error_details is set. | 407 // network_name should't be empty if network_error_details is set. |
| 417 error_msg = l10n_util::GetStringFUTF16( | 408 error_msg = l10n_util::GetStringFUTF16( |
| 418 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE, | 409 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE, |
| 419 base::UTF8ToUTF16(network_name), error, | 410 base::UTF8ToUTF16(network_name), error, |
| 420 base::UTF8ToUTF16(network_error_details)); | 411 base::UTF8ToUTF16(network_error_details)); |
| 421 } else if (network_name.empty()) { | 412 } else if (network_name.empty()) { |
| 422 error_msg = l10n_util::GetStringFUTF16( | 413 error_msg = l10n_util::GetStringFUTF16( |
| 423 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_NO_NAME, error); | 414 IDS_NETWORK_CONNECTION_ERROR_MESSAGE_NO_NAME, error); |
| 424 } else { | 415 } else { |
| 425 error_msg = | 416 error_msg = |
| 426 l10n_util::GetStringFUTF16(IDS_NETWORK_CONNECTION_ERROR_MESSAGE, | 417 l10n_util::GetStringFUTF16(IDS_NETWORK_CONNECTION_ERROR_MESSAGE, |
| 427 base::UTF8ToUTF16(network_name), error); | 418 base::UTF8ToUTF16(network_name), error); |
| 428 } | 419 } |
| 429 | 420 |
| 430 std::string network_type; | 421 std::string network_type; |
| 431 shill_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, | 422 shill_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, |
| 432 &network_type); | 423 &network_type); |
| 433 | 424 |
| 434 ShowErrorNotification( | 425 ShowErrorNotification( |
| 435 service_path, kNetworkConnectNotificationId, network_type, | 426 service_path, kNetworkConnectNotificationId, network_type, |
| 436 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), error_msg, | 427 l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), error_msg, |
| 437 base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, | 428 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 438 weak_ptr_factory_.GetWeakPtr(), service_path)); | 429 weak_ptr_factory_.GetWeakPtr(), guid)); |
| 439 } | 430 } |
| 440 | 431 |
| 441 void NetworkStateNotifier::ShowVpnDisconnectedNotification( | 432 void NetworkStateNotifier::ShowVpnDisconnectedNotification( |
| 442 const NetworkState* vpn) { | 433 const NetworkState* vpn) { |
| 443 base::string16 error_msg = l10n_util::GetStringFUTF16( | 434 base::string16 error_msg = l10n_util::GetStringFUTF16( |
| 444 IDS_NETWORK_VPN_CONNECTION_LOST_BODY, base::UTF8ToUTF16(vpn->name())); | 435 IDS_NETWORK_VPN_CONNECTION_LOST_BODY, base::UTF8ToUTF16(vpn->name())); |
| 445 ShowErrorNotification( | 436 ShowErrorNotification( |
| 446 vpn->path(), kNetworkConnectNotificationId, shill::kTypeVPN, | 437 vpn->path(), kNetworkConnectNotificationId, shill::kTypeVPN, |
| 447 l10n_util::GetStringUTF16(IDS_NETWORK_VPN_CONNECTION_LOST_TITLE), | 438 l10n_util::GetStringUTF16(IDS_NETWORK_VPN_CONNECTION_LOST_TITLE), |
| 448 error_msg, base::Bind(&NetworkStateNotifier::ShowNetworkSettingsForPath, | 439 error_msg, base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 449 weak_ptr_factory_.GetWeakPtr(), vpn->path())); | 440 weak_ptr_factory_.GetWeakPtr(), vpn->guid())); |
| 450 } | 441 } |
| 451 | 442 |
| 452 void NetworkStateNotifier::ShowNetworkSettingsForPath( | 443 void NetworkStateNotifier::ShowNetworkSettings(const std::string& network_id) { |
| 453 const std::string& service_path) { | 444 if (!SystemTrayClient::Get()) |
| 454 network_connect_->ShowNetworkSettingsForPath(service_path); | 445 return; |
| 446 SystemTrayClient::Get()->ShowNetworkSettings(network_id); |
| 455 } | 447 } |
| 456 | 448 |
| 457 } // namespace ui | 449 } // namespace chromeos |
| OLD | NEW |