| 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 "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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 NetworkStateNotifier::NetworkStateNotifier(NetworkConnect* network_connect) | 94 NetworkStateNotifier::NetworkStateNotifier(NetworkConnect* network_connect) |
| 95 : network_connect_(network_connect), | 95 : network_connect_(network_connect), |
| 96 did_show_out_of_credits_(false), | 96 did_show_out_of_credits_(false), |
| 97 weak_ptr_factory_(this) { | 97 weak_ptr_factory_(this) { |
| 98 if (!NetworkHandler::IsInitialized()) | 98 if (!NetworkHandler::IsInitialized()) |
| 99 return; | 99 return; |
| 100 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 100 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 101 handler->AddObserver(this, FROM_HERE); | 101 handler->AddObserver(this, FROM_HERE); |
| 102 UpdateDefaultNetwork(handler->DefaultNetwork()); | 102 UpdateDefaultNetwork(handler->DefaultNetwork()); |
| 103 NetworkHandler::Get()->network_connection_handler()->AddObserver(this); |
| 103 } | 104 } |
| 104 | 105 |
| 105 NetworkStateNotifier::~NetworkStateNotifier() { | 106 NetworkStateNotifier::~NetworkStateNotifier() { |
| 106 if (!NetworkHandler::IsInitialized()) | 107 if (!NetworkHandler::IsInitialized()) |
| 107 return; | 108 return; |
| 108 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | 109 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 109 FROM_HERE); | 110 FROM_HERE); |
| 111 NetworkHandler::Get()->network_connection_handler()->RemoveObserver(this); |
| 112 } |
| 113 |
| 114 void NetworkStateNotifier::ConnectFailed(const std::string& service_path, |
| 115 const std::string& error_name) { |
| 116 // Only show a notification for certain errors. Other failures are expected |
| 117 // to be handled by the UI that initiated the connect request. |
| 118 // Note: kErrorConnectFailed may also cause the configure dialog to be |
| 119 // displayed, but we rely on the notification system to show additional |
| 120 // details if available. |
| 121 if (error_name != NetworkConnectionHandler::kErrorConnectFailed && |
| 122 error_name != NetworkConnectionHandler::kErrorNotFound && |
| 123 error_name != NetworkConnectionHandler::kErrorConfigureFailed && |
| 124 error_name != NetworkConnectionHandler::kErrorCertLoadTimeout) { |
| 125 return; |
| 126 } |
| 127 ShowNetworkConnectError(error_name, service_path); |
| 110 } | 128 } |
| 111 | 129 |
| 112 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { | 130 void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { |
| 113 if (!UpdateDefaultNetwork(network)) | 131 if (!UpdateDefaultNetwork(network)) |
| 114 return; | 132 return; |
| 115 // If the default network changes to another network, allow the out of | 133 // If the default network changes to another network, allow the out of |
| 116 // credits notification to be shown again. A delay prevents the notification | 134 // credits notification to be shown again. A delay prevents the notification |
| 117 // from being shown too frequently (see below). | 135 // from being shown too frequently (see below). |
| 118 if (network) | 136 if (network) |
| 119 did_show_out_of_credits_ = false; | 137 did_show_out_of_credits_ = false; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 service_path); | 327 service_path); |
| 310 if (shill_error.empty()) | 328 if (shill_error.empty()) |
| 311 shill_error = network->last_error(); | 329 shill_error = network->last_error(); |
| 312 } | 330 } |
| 313 | 331 |
| 314 if (ShillErrorIsIgnored(shill_error)) { | 332 if (ShillErrorIsIgnored(shill_error)) { |
| 315 NET_LOG_DEBUG("Notify Ignoring error: " + error_name, service_path); | 333 NET_LOG_DEBUG("Notify Ignoring error: " + error_name, service_path); |
| 316 return; | 334 return; |
| 317 } | 335 } |
| 318 | 336 |
| 319 error = network_connect_->GetErrorString(shill_error, service_path); | 337 error = network_connect_->GetShillErrorString(shill_error, service_path); |
| 320 if (error.empty()) | 338 if (error.empty()) |
| 321 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 339 error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
| 322 } | 340 } |
| 323 NET_LOG_ERROR("Notify connect error: " + base::UTF16ToUTF8(error), | 341 NET_LOG_ERROR("Notify connect error: " + base::UTF16ToUTF8(error), |
| 324 service_path); | 342 service_path); |
| 325 | 343 |
| 326 std::string network_name = | 344 std::string network_name = |
| 327 chromeos::shill_property_util::GetNameFromProperties(service_path, | 345 chromeos::shill_property_util::GetNameFromProperties(service_path, |
| 328 shill_properties); | 346 shill_properties); |
| 329 std::string network_error_details; | 347 std::string network_error_details; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 356 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, | 374 base::Bind(&NetworkStateNotifier::ShowNetworkSettings, |
| 357 weak_ptr_factory_.GetWeakPtr(), service_path)); | 375 weak_ptr_factory_.GetWeakPtr(), service_path)); |
| 358 } | 376 } |
| 359 | 377 |
| 360 void NetworkStateNotifier::ShowNetworkSettings( | 378 void NetworkStateNotifier::ShowNetworkSettings( |
| 361 const std::string& service_path) { | 379 const std::string& service_path) { |
| 362 network_connect_->ShowNetworkSettings(service_path); | 380 network_connect_->ShowNetworkSettings(service_path); |
| 363 } | 381 } |
| 364 | 382 |
| 365 } // namespace ui | 383 } // namespace ui |
| OLD | NEW |