| Index: ash/system/chromeos/network/network_state_notifier.cc
|
| diff --git a/ash/system/chromeos/network/network_state_notifier.cc b/ash/system/chromeos/network/network_state_notifier.cc
|
| index 1c971a32a44360d4df4b71d6c223f8e70343b96d..7a5475579e8e14ea6115cec072226e24396fe2e4 100644
|
| --- a/ash/system/chromeos/network/network_state_notifier.cc
|
| +++ b/ash/system/chromeos/network/network_state_notifier.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/strings/string16.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chromeos/network/network_configuration_handler.h"
|
| #include "chromeos/network/network_connection_handler.h"
|
| #include "chromeos/network/network_event_log.h"
|
| #include "chromeos/network/network_state.h"
|
| @@ -46,7 +47,8 @@ string16 GetConnectErrorString(const std::string& error_name) {
|
| namespace ash {
|
|
|
| NetworkStateNotifier::NetworkStateNotifier()
|
| - : cellular_out_of_credits_(false) {
|
| + : cellular_out_of_credits_(false),
|
| + weak_ptr_factory_(this) {
|
| if (!NetworkHandler::IsInitialized())
|
| return;
|
| NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
|
| @@ -65,16 +67,6 @@ NetworkStateNotifier::~NetworkStateNotifier() {
|
| this, FROM_HERE);
|
| }
|
|
|
| -void NetworkStateNotifier::NetworkListChanged() {
|
| - // Trigger any pending connect failed error if the network list changes
|
| - // (which indicates all NetworkState entries are up to date). This is in
|
| - // case a connect attempt fails because a network is no longer visible.
|
| - if (!connect_failed_network_.empty()) {
|
| - ShowNetworkConnectError(
|
| - NetworkConnectionHandler::kErrorConnectFailed, connect_failed_network_);
|
| - }
|
| -}
|
| -
|
| void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) {
|
| if (!network || !network->IsConnectedState())
|
| return;
|
| @@ -82,18 +74,12 @@ void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) {
|
| last_active_network_ = network->path();
|
| // Reset state for new connected network
|
| cellular_out_of_credits_ = false;
|
| + NetworkPropertiesUpdated(network);
|
| }
|
| }
|
|
|
| void NetworkStateNotifier::NetworkPropertiesUpdated(
|
| const NetworkState* network) {
|
| - DCHECK(network);
|
| - // Trigger a pending connect failed error for |network| when the Error
|
| - // property has been set.
|
| - if (network->path() == connect_failed_network_ && !network->error().empty()) {
|
| - ShowNetworkConnectError(
|
| - NetworkConnectionHandler::kErrorConnectFailed, connect_failed_network_);
|
| - }
|
| // Trigger "Out of credits" notification if the cellular network is the most
|
| // recent default network (i.e. we have not switched to another network).
|
| if (network->type() == flimflam::kTypeCellular &&
|
| @@ -139,43 +125,92 @@ void NetworkStateNotifier::NotificationLinkClicked(
|
| void NetworkStateNotifier::ShowNetworkConnectError(
|
| const std::string& error_name,
|
| const std::string& service_path) {
|
| - const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
|
| - GetNetworkState(service_path);
|
| - if (error_name == NetworkConnectionHandler::kErrorConnectFailed &&
|
| - service_path != connect_failed_network_) {
|
| - // Shill may not have set the Error property yet. First request an update
|
| - // and wait for either the update to complete or the network list to be
|
| - // updated before displaying the error.
|
| - connect_failed_network_ = service_path;
|
| - return;
|
| - }
|
| - connect_failed_network_.clear();
|
| + // Get the up-to-date properties for the network and display the error.
|
| + NetworkHandler::Get()->network_configuration_handler()->GetProperties(
|
| + service_path,
|
| + base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesSucceeded,
|
| + weak_ptr_factory_.GetWeakPtr(), error_name),
|
| + base::Bind(&NetworkStateNotifier::ConnectErrorPropertiesFailed,
|
| + weak_ptr_factory_.GetWeakPtr(), error_name, service_path));
|
| +}
|
| +
|
| +void NetworkStateNotifier::ConnectErrorPropertiesSucceeded(
|
| + const std::string& error_name,
|
| + const std::string& service_path,
|
| + const base::DictionaryValue& shill_properties) {
|
| + ShowConnectErrorNotification(error_name, service_path, shill_properties);
|
| +}
|
|
|
| +void NetworkStateNotifier::ConnectErrorPropertiesFailed(
|
| + const std::string& error_name,
|
| + const std::string& service_path,
|
| + const std::string& shill_error_name,
|
| + scoped_ptr<base::DictionaryValue> shill_error_data) {
|
| + base::DictionaryValue shill_properties;
|
| + ShowConnectErrorNotification(error_name, service_path, shill_properties);
|
| +}
|
| +
|
| +void NetworkStateNotifier::ShowConnectErrorNotification(
|
| + const std::string& error_name,
|
| + const std::string& service_path,
|
| + const base::DictionaryValue& shill_properties) {
|
| string16 error = GetConnectErrorString(error_name);
|
| - if (error.empty() && network)
|
| - error = network_connect::ErrorString(network->error());
|
| - if (error.empty())
|
| - error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
|
| + if (error.empty()) {
|
| + std::string network_error;
|
| + shill_properties.GetStringWithoutPathExpansion(
|
| + flimflam::kErrorProperty, &network_error);
|
| + error = network_connect::ErrorString(network_error);
|
| + if (error.empty())
|
| + error = l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
|
| + }
|
| NET_LOG_ERROR("Connect error notification: " + UTF16ToUTF8(error),
|
| service_path);
|
|
|
| - std::string name = network ? network->name() : "";
|
| + std::string network_name =
|
| + NetworkState::GetNameFromProperties(service_path, shill_properties);
|
| + std::string network_error_details;
|
| + shill_properties.GetStringWithoutPathExpansion(
|
| + shill::kErrorDetailsProperty, &network_error_details);
|
| +
|
| string16 error_msg;
|
| - if (network && !network->error_details().empty()) {
|
| + if (!network_error_details.empty()) {
|
| error_msg = l10n_util::GetStringFUTF16(
|
| IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_SERVER_MESSAGE,
|
| - UTF8ToUTF16(name), error, UTF8ToUTF16(network->error_details()));
|
| + UTF8ToUTF16(network_name), error,
|
| + UTF8ToUTF16(network_error_details));
|
| } else {
|
| error_msg = l10n_util::GetStringFUTF16(
|
| IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_DETAILS,
|
| - UTF8ToUTF16(name), error);
|
| + UTF8ToUTF16(network_name), error);
|
| + }
|
| +
|
| + std::string network_type;
|
| + shill_properties.GetStringWithoutPathExpansion(
|
| + flimflam::kTypeProperty, &network_type);
|
| +
|
| + NetworkObserver::NetworkType type = NetworkObserver::NETWORK_UNKNOWN;
|
| + if (network_type == flimflam::kTypeCellular) {
|
| + std::string network_technology;
|
| + shill_properties.GetStringWithoutPathExpansion(
|
| + flimflam::kNetworkTechnologyProperty, &network_technology);
|
| + if (network_technology == flimflam::kNetworkTechnologyLte ||
|
| + network_technology == flimflam::kNetworkTechnologyLteAdvanced)
|
| + type = NetworkObserver::NETWORK_CELLULAR_LTE;
|
| + else
|
| + type = NetworkObserver::NETWORK_CELLULAR;
|
| + } else if (network_type == flimflam::kTypeEthernet) {
|
| + type = NetworkObserver:: NETWORK_ETHERNET;
|
| + } else if (network_type == flimflam::kTypeWifi) {
|
| + type = NetworkObserver:: NETWORK_WIFI;
|
| + } else {
|
| + NOTREACHED();
|
| }
|
|
|
| std::vector<string16> no_links;
|
| ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
|
| this,
|
| NetworkObserver::ERROR_CONNECT_FAILED,
|
| - NetworkObserver::GetNetworkTypeForNetworkState(network),
|
| + type,
|
| l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE),
|
| error_msg,
|
| no_links);
|
|
|