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 a90350507b190b3f22c8a4327b283130af1b5415..1c971a32a44360d4df4b71d6c223f8e70343b96d 100644 |
--- a/ash/system/chromeos/network/network_state_notifier.cc |
+++ b/ash/system/chromeos/network/network_state_notifier.cc |
@@ -32,6 +32,12 @@ const int kMinTimeBetweenOutOfCreditsNotifySeconds = 10 * 60; |
string16 GetConnectErrorString(const std::string& error_name) { |
if (error_name == NetworkConnectionHandler::kErrorNotFound) |
return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); |
+ if (error_name == NetworkConnectionHandler::kErrorConfigureFailed) |
+ return l10n_util::GetStringUTF16( |
+ IDS_CHROMEOS_NETWORK_ERROR_CONFIGURE_FAILED); |
+ if (error_name == NetworkConnectionHandler::kErrorActivateFailed) |
+ return l10n_util::GetStringUTF16( |
+ IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); |
return string16(); |
} |
@@ -41,17 +47,31 @@ namespace ash { |
NetworkStateNotifier::NetworkStateNotifier() |
: cellular_out_of_credits_(false) { |
- if (NetworkHandler::IsInitialized()) { |
- NetworkHandler::Get()->network_state_handler()->AddObserver( |
- this, FROM_HERE); |
- InitializeNetworks(); |
- } |
+ if (!NetworkHandler::IsInitialized()) |
+ return; |
+ NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
+ |
+ // Initialize |last_active_network_|. |
+ const NetworkState* default_network = |
+ NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
+ if (default_network && default_network->IsConnectedState()) |
+ last_active_network_ = default_network->path(); |
} |
NetworkStateNotifier::~NetworkStateNotifier() { |
- if (NetworkHandler::IsInitialized()) { |
- NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
- this, FROM_HERE); |
+ if (!NetworkHandler::IsInitialized()) |
+ return; |
+ NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
+ 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_); |
} |
} |
@@ -65,40 +85,15 @@ void NetworkStateNotifier::DefaultNetworkChanged(const NetworkState* network) { |
} |
} |
-void NetworkStateNotifier::NetworkConnectionStateChanged( |
- const NetworkState* network) { |
- NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
- std::string prev_state; |
- std::string new_state = network->connection_state(); |
- CachedStateMap::iterator iter = cached_state_.find(network->path()); |
- if (iter != cached_state_.end()) { |
- prev_state = iter->second; |
- if (prev_state == new_state) |
- return; // No state change |
- VLOG(1) << "NetworkStateNotifier: State: " << prev_state |
- << " ->: " << new_state; |
- iter->second = new_state; |
- } else { |
- VLOG(1) << "NetworkStateNotifier: New Service: " << network->path() |
- << " State: " << new_state; |
- cached_state_[network->path()] = new_state; |
- return; // New network, no state change |
- } |
- |
- if (new_state != flimflam::kStateFailure) |
- return; |
- |
- if (network->path() != handler->connecting_network()) |
- return; // Only show notifications for explicitly connected networks |
- |
- NET_LOG_EVENT("ConnectionFailure", network->path()); |
- |
- ShowConnectError("", 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 && |
@@ -146,17 +141,24 @@ void NetworkStateNotifier::ShowNetworkConnectError( |
const std::string& service_path) { |
const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
GetNetworkState(service_path); |
- ShowConnectError(error_name, network); |
-} |
+ 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(); |
-void NetworkStateNotifier::ShowConnectError(const std::string& error_name, |
- const NetworkState* network) { |
- std::vector<string16> no_links; |
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); |
+ NET_LOG_ERROR("Connect error notification: " + UTF16ToUTF8(error), |
+ service_path); |
+ |
std::string name = network ? network->name() : ""; |
string16 error_msg; |
if (network && !network->error_details().empty()) { |
@@ -168,6 +170,8 @@ void NetworkStateNotifier::ShowConnectError(const std::string& error_name, |
IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_DETAILS, |
UTF8ToUTF16(name), error); |
} |
+ |
+ std::vector<string16> no_links; |
ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( |
this, |
NetworkObserver::ERROR_CONNECT_FAILED, |
@@ -177,21 +181,4 @@ void NetworkStateNotifier::ShowConnectError(const std::string& error_name, |
no_links); |
} |
-void NetworkStateNotifier::InitializeNetworks() { |
- NetworkStateHandler::NetworkStateList network_list; |
- NetworkHandler::Get()->network_state_handler()->GetNetworkList(&network_list); |
- VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " |
- << network_list.size(); |
- for (NetworkStateHandler::NetworkStateList::iterator iter = |
- network_list.begin(); iter != network_list.end(); ++iter) { |
- const NetworkState* network = *iter; |
- VLOG(2) << " Network: " << network->path(); |
- cached_state_[network->path()] = network->connection_state(); |
- } |
- const NetworkState* default_network = |
- NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
- if (default_network && default_network->IsConnectedState()) |
- last_active_network_ = default_network->path(); |
-} |
- |
} // namespace ash |