diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 00:59:50 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-15 00:59:50 +0000 |
commit | 7e778b6fae741045e60074d60514d0372576e156 (patch) | |
tree | 41ea7eb97448920289c1d2e49833b64222087c57 /ash | |
parent | 96fa304a3c62935792cb42c17cf8544d73091543 (diff) | |
download | chromium_src-7e778b6fae741045e60074d60514d0372576e156.zip chromium_src-7e778b6fae741045e60074d60514d0372576e156.tar.gz chromium_src-7e778b6fae741045e60074d60514d0372576e156.tar.bz2 |
Replace NetworkMessageObserver with Ash code using NetworkStateHandler
Note: Depends on https://chromiumcodereview.appspot.com/12726002/
BUG=164236
For ash.gyp and shelf_layout_manager_unittest:
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/12440012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 3 | ||||
-rw-r--r-- | ash/ash_chromeos_strings.grdp | 108 | ||||
-rw-r--r-- | ash/shelf/shelf_layout_manager_unittest.cc | 4 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_list_detailed_view.cc | 7 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_notifier.cc | 172 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_notifier.h | 43 | ||||
-rw-r--r-- | ash/system/chromeos/network/network_state_notifier_unittest.cc | 105 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network.cc | 8 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network.h | 2 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network_state_observer.cc | 23 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network_state_observer.h | 6 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 13 | ||||
-rw-r--r-- | ash/system/tray/system_tray.h | 6 | ||||
-rw-r--r-- | ash/system/tray/system_tray_unittest.cc | 6 |
14 files changed, 464 insertions, 42 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 6e5cb09..87b783b 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -199,6 +199,8 @@ 'system/chromeos/network/network_observer.h', 'system/chromeos/network/network_state_list_detailed_view.cc', 'system/chromeos/network/network_state_list_detailed_view.h', + 'system/chromeos/network/network_state_notifier.cc', + 'system/chromeos/network/network_state_notifier.h', 'system/chromeos/network/tray_network.cc', 'system/chromeos/network/tray_network.h', 'system/chromeos/network/tray_network_state_observer.cc', @@ -635,6 +637,7 @@ 'shell/window_type_launcher.cc', 'shell/window_watcher.cc', 'shell/window_watcher_unittest.cc', + 'system/chromeos/network/network_state_notifier_unittest.cc', 'system/tray/system_tray_unittest.cc', 'system/web_notification/web_notification_tray_unittest.cc', 'test/ash_unittests.cc', diff --git a/ash/ash_chromeos_strings.grdp b/ash/ash_chromeos_strings.grdp index ea3318b..221d0c2 100644 --- a/ash/ash_chromeos_strings.grdp +++ b/ash/ash_chromeos_strings.grdp @@ -110,4 +110,112 @@ Searching for cellular networks... </message> + <!-- Other Network UI strings --> + <message name="IDS_NETWORK_CONNECTION_ERROR_TITLE" desc="Title for network connection error notification"> + Network Connection Error + </message> + <message name="IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_DETAILS" desc="Message for network connection error notification with details"> + Failed to connect to network '<ph name="name">$1<ex>GoogleGuest</ex></ph>': <ph name="details">$2<ex>Unrecognized error</ex></ph> + </message> + + <!-- Network state strings --> + <message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN"> + Unknown + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_IDLE" desc="Network state in about:network: IDLE"> + Idle + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_CARRIER" desc="Network state in about:network: CARRIER"> + Carrier + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION" desc="Network state in about:network: ASSOCIATION"> + Association + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION" desc="Network state in about:network: CONFIGURATION"> + Configuration + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_READY" desc="Network state in about:network: READY"> + Connected + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_DISCONNECT" desc="Network state in about:network: DISCONNECT"> + Disconnect + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_FAILURE" desc="Network state in about:network: FAILURE"> + Failure + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE" desc="Network state in about:network: ACTIVATION_FAILURE"> + Activation failure + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED" desc="Network state in about:network: Unrecognized"> + Unrecognized state + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_PORTAL" desc="Network state in about:network: Portal"> + Portal state + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_ONLINE" desc="Network state in about:network: Online"> + Online state + </message> + <message name="IDS_CHROMEOS_NETWORK_STATE_CONNECT_REQUESTED" desc="Network state in about:network: Connect Requested"> + Connect Requested + </message> + + <!-- Network error strings --> + <message name="IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN" desc="Network error in about:network: UNKNOWN"> + Unknown network error + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE" desc="Network error in about:network: OUT_OF_RANGE"> + Out of range + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING" desc="Network error in about:network: PIN_MISSING"> + PIN missing + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED" desc="Network error in about:network: DHCP_FAILED"> + DHCP lookup failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED" desc="Network error in about:network: CONNECT_FAILED"> + Connect failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE" desc="Network error in about:network: BAD_PASSPHRASE"> + Bad passphrase + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY" desc="Network error in about:network: BAD_WEPKEY"> + Bad WEP key + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED" desc="Network error in about:network: ACTIVATION_FAILED"> + Activation failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO" desc="Network error in about:network: NEED_EVDO"> + Need EVDO + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK" desc="Network error in about:network: NEED_HOME_NETWORK"> + Need home network + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED" desc="Network error in about:network: OTASP_FAILED"> + OTASP failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED" desc="Network error in about:network: AAA_FAILED"> + AAA check failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_INTERNAL" desc="Network error in about:network: INTERNAL"> + Internal error + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED" desc="Network error in about:network: DNS_LOOKUP_FAILED"> + DNS lookup failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED" desc="Network error in about:network: HTTP_GET_FAILED"> + HTTP get failed + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED" desc="Network error in about:network: IPSEC_PSK_AUTH_FAILED"> + Failed to authenticate with provided pre-shared key + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_IPSEC_CERT_AUTH_FAILED" desc="Network error in about:network: IPSEC_CERT_AUTH_FAILED"> + Failed to authenticate with provided certificate + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED" desc="Network error in about:network: PPP_AUTH_FAILED"> + Failed to authenticate with provided username or password + </message> + <message name="IDS_CHROMEOS_NETWORK_ERROR_UNRECOGNIZED" desc="Network error in about:network: Unrecognized"> + Unrecognized error + </message> + </grit-part> diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc index fe900a3..ded8741 100644 --- a/ash/shelf/shelf_layout_manager_unittest.cc +++ b/ash/shelf/shelf_layout_manager_unittest.cc @@ -914,7 +914,7 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureRevealsTrayBubble) { generator.GestureScrollSequence(start, end, base::TimeDelta::FromMilliseconds(10), 1); EXPECT_TRUE(tray->HasSystemBubble()); - tray->CloseBubbleForTest(); + tray->CloseSystemBubbleForTest(); RunAllPendingInMessageLoop(); EXPECT_FALSE(tray->HasSystemBubble()); @@ -1081,7 +1081,7 @@ TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { EXPECT_TRUE(shelf->IsVisible()); if (!i) { // In our first iteration we make sure there is no bubble. - tray->CloseBubbleForTest(); + tray->CloseSystemBubbleForTest(); EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); } else { // In our second iteration we show a bubble. diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc index e34c278..707a9d2 100644 --- a/ash/system/chromeos/network/network_state_list_detailed_view.cc +++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc @@ -770,15 +770,14 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { void NetworkStateListDetailedView::ConnectToNetwork( const std::string& service_path) { - const NetworkState* network = - NetworkStateHandler::Get()->GetNetworkState(service_path); + NetworkStateHandler* handler = NetworkStateHandler::Get(); + const NetworkState* network = handler->GetNetworkState(service_path); if (!network) return; - if (!network->IsConnectedState()) - TrayNetworkStateObserver::AddConnectingNetwork(service_path); if (CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kUseNewNetworkConfigurationHandlers) && !network->IsConnectedState()) { + handler->set_connecting_network(service_path); chromeos::NetworkConfigurationHandler::Get()->Connect( service_path, base::Bind(&base::DoNothing), diff --git a/ash/system/chromeos/network/network_state_notifier.cc b/ash/system/chromeos/network/network_state_notifier.cc new file mode 100644 index 0000000..ba3d137 --- /dev/null +++ b/ash/system/chromeos/network/network_state_notifier.cc @@ -0,0 +1,172 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/chromeos/network/network_state_notifier.h" + +#include "ash/shell.h" +#include "ash/system/chromeos/network/network_observer.h" +#include "ash/system/tray/system_tray_notifier.h" +#include "base/string16.h" +#include "base/utf_string_conversions.h" +#include "chromeos/network/network_event_log.h" +#include "chromeos/network/network_state.h" +#include "chromeos/network/network_state_handler.h" +#include "grit/ash_strings.h" +#include "third_party/cros_system_api/dbus/service_constants.h" +#include "ui/base/l10n/l10n_util.h" + +namespace { +const char kLogModule[] = "NetworkStateNotifier"; + +ash::NetworkObserver::NetworkType GetAshNetworkType(const std::string& type) { + if (type == flimflam::kTypeCellular) + return ash::NetworkObserver::NETWORK_CELLULAR; + if (type == flimflam::kTypeEthernet) + return ash::NetworkObserver::NETWORK_ETHERNET; + if (type == flimflam::kTypeWifi) + return ash::NetworkObserver::NETWORK_WIFI; + if (type == flimflam::kTypeBluetooth) + return ash::NetworkObserver::NETWORK_BLUETOOTH; + return ash::NetworkObserver::NETWORK_UNKNOWN; +} + +string16 GetErrorString(const std::string& error) { + if (error == flimflam::kErrorOutOfRange) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); + if (error == flimflam::kErrorPinMissing) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); + if (error == flimflam::kErrorDhcpFailed) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED); + if (error == flimflam::kErrorConnectFailed) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); + if (error == flimflam::kErrorBadPassphrase) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE); + if (error == flimflam::kErrorBadWEPKey) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY); + if (error == flimflam::kErrorActivationFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); + } + if (error == flimflam::kErrorNeedEvdo) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO); + if (error == flimflam::kErrorNeedHomeNetwork) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK); + } + if (error == flimflam::kErrorOtaspFailed) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED); + if (error == flimflam::kErrorAaaFailed) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED); + if (error == flimflam::kErrorInternal) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL); + if (error == flimflam::kErrorDNSLookupFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED); + } + if (error == flimflam::kErrorHTTPGetFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED); + } + if (error == flimflam::kErrorIpsecPskAuthFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED); + } + if (error == flimflam::kErrorIpsecCertAuthFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_IPSEC_CERT_AUTH_FAILED); + } + if (error == flimflam::kErrorPppAuthFailed) { + return l10n_util::GetStringUTF16( + IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED); + } + if (error == flimflam::kUnknownString) + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); + return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED); +} + +} // namespace + +using chromeos::NetworkState; +using chromeos::NetworkStateHandler; + +namespace ash { +namespace internal { + +NetworkStateNotifier::NetworkStateNotifier() { + if (NetworkStateHandler::Get()) { + NetworkStateHandler::Get()->AddObserver(this); + InitializeNetworks(); + } +} + +NetworkStateNotifier::~NetworkStateNotifier() { + if (NetworkStateHandler::Get()) + NetworkStateHandler::Get()->RemoveObserver(this); +} + +void NetworkStateNotifier::NetworkConnectionStateChanged( + const NetworkState* network) { + NetworkStateHandler* handler = NetworkStateHandler::Get(); + 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 + } + bool notify_failure = false; + if (new_state == flimflam::kStateFailure && + prev_state != flimflam::kStateIdle) { + // Note: Idle -> Failure sometimes happens on resume when the network + // device is not ready yet, but is not an actual failure. + notify_failure = true; + } else if (new_state == flimflam::kStateIdle && + NetworkState::StateIsConnecting(prev_state) && + network->path() == handler->connecting_network()) { + // Connecting -> Idle without an error shouldn't happen but sometimes does. + notify_failure = true; + } + if (!notify_failure) + return; + + chromeos::network_event_log::AddEntry( + kLogModule, "ConnectionFailure", network->path()); + + std::vector<string16> no_links; + ash::NetworkObserver::NetworkType network_type = + GetAshNetworkType(network->type()); + string16 error = GetErrorString(network->error()); + ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( + NULL, ash::NetworkObserver::ERROR_CONNECT_FAILED, network_type, + l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE), + l10n_util::GetStringFUTF16( + IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_DETAILS, + UTF8ToUTF16(network->name()), error), + no_links); +} + +void NetworkStateNotifier::InitializeNetworks() { + NetworkStateList network_list; + NetworkStateHandler::Get()->GetNetworkList(&network_list); + VLOG(1) << "NetworkStateNotifier:InitializeNetworks: " + << network_list.size(); + for (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(); + } +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/chromeos/network/network_state_notifier.h b/ash/system/chromeos/network/network_state_notifier.h new file mode 100644 index 0000000..129e507 --- /dev/null +++ b/ash/system/chromeos/network/network_state_notifier.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ +#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ + +#include <map> + +#include "ash/ash_export.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chromeos/network/network_state_handler_observer.h" + +namespace ash { +namespace internal { + +// This class observes NetworkStateHandler and generates notifications +// on connection failures. +class ASH_EXPORT NetworkStateNotifier : + public chromeos::NetworkStateHandlerObserver { + public: + NetworkStateNotifier(); + virtual ~NetworkStateNotifier(); + + // NetworkStateHandlerObserver + virtual void NetworkConnectionStateChanged( + const chromeos::NetworkState* network) OVERRIDE; + + private: + typedef std::map<std::string, std::string> CachedStateMap; + + void InitializeNetworks(); + + CachedStateMap cached_state_; + + DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifier); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_NOTIFIER_H_ diff --git a/ash/system/chromeos/network/network_state_notifier_unittest.cc b/ash/system/chromeos/network/network_state_notifier_unittest.cc new file mode 100644 index 0000000..3c3a386 --- /dev/null +++ b/ash/system/chromeos/network/network_state_notifier_unittest.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/chromeos/network/network_state_notifier.h" + +#include "ash/root_window_controller.h" +#include "ash/shelf/shelf_widget.h" +#include "ash/system/status_area_widget.h" +#include "ash/system/tray/system_tray.h" +#include "ash/test/ash_test_base.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/shill_device_client.h" +#include "chromeos/dbus/shill_service_client.h" +#include "chromeos/network/network_state_handler.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace { + +ash::SystemTray* GetSystemTray() { + return ash::Shell::GetPrimaryRootWindowController()->shelf()-> + status_area_widget()->system_tray(); +} + +} // namespace + +using chromeos::NetworkStateHandler; +using chromeos::DBusThreadManager; +using chromeos::ShillDeviceClient; +using chromeos::ShillServiceClient; + +namespace ash { +namespace test { + +using internal::NetworkStateNotifier; + +class NetworkStateNotifierTest : public AshTestBase { + public: + NetworkStateNotifierTest() {} + virtual ~NetworkStateNotifierTest() {} + + virtual void SetUp() OVERRIDE { + DBusThreadManager::InitializeWithStub(); + SetupDefaultShillState(); + NetworkStateHandler::Initialize(); + RunAllPendingInMessageLoop(); + AshTestBase::SetUp(); + } + + virtual void TearDown() OVERRIDE { + AshTestBase::TearDown(); + NetworkStateHandler::Shutdown(); + DBusThreadManager::Shutdown(); + } + + protected: + void SetupDefaultShillState() { + RunAllPendingInMessageLoop(); + ShillDeviceClient::TestInterface* device_test = + DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); + device_test->ClearDevices(); + device_test->AddDevice("/device/stub_wifi_device1", + flimflam::kTypeWifi, "stub_wifi_device1"); + device_test->AddDevice("/device/stub_cellular_device1", + flimflam::kTypeCellular, "stub_cellular_device1"); + + ShillServiceClient::TestInterface* service_test = + DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); + service_test->ClearServices(); + const bool add_to_watchlist = true; + // Create wifi and cellular networks and set to online. + service_test->AddService("wifi1", "wifi1", + flimflam::kTypeWifi, flimflam::kStateOnline, + add_to_watchlist); + RunAllPendingInMessageLoop(); + } + + void SetServiceState(const std::string& service_path, + const std::string& state) { + ShillServiceClient::TestInterface* service_test = + DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); + service_test->SetServiceProperty(service_path, flimflam::kStateProperty, + base::StringValue(state)); + RunAllPendingInMessageLoop(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(NetworkStateNotifierTest); +}; + +TEST_F(NetworkStateNotifierTest, ConnectionFailure) { + EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); + // Connected -> Failure should spawn a notification + SetServiceState("wifi1", flimflam::kStateFailure); + EXPECT_TRUE(GetSystemTray()->CloseNotificationBubbleForTest()); + // Failure -> Idle should not spawn a notification + SetServiceState("wifi1", flimflam::kStateIdle); + EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); + // Idle -> Failure should also not spawn a notification + SetServiceState("wifi1", flimflam::kStateFailure); + EXPECT_FALSE(GetSystemTray()->HasNotificationBubble()); +} + +} // namespace test +} // namespace ash diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc index 9bde13d..d409f8d 100644 --- a/ash/system/chromeos/network/tray_network.cc +++ b/ash/system/chromeos/network/tray_network.cc @@ -10,6 +10,7 @@ #include "ash/system/chromeos/network/network_list_detailed_view.h" #include "ash/system/chromeos/network/network_list_detailed_view_base.h" #include "ash/system/chromeos/network/network_state_list_detailed_view.h" +#include "ash/system/chromeos/network/network_state_notifier.h" #include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_notifier.h" @@ -408,10 +409,13 @@ TrayNetwork::TrayNetwork(SystemTray* system_tray) request_wifi_view_(false) { if (UseNewNetworkHandlers()) network_state_observer_.reset(new TrayNetworkStateObserver(this)); + if (NetworkStateHandler::IsInitialized()) + network_state_notifier_.reset(new NetworkStateNotifier()); Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); } TrayNetwork::~TrayNetwork() { + network_state_notifier_.reset(); Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); } @@ -563,8 +567,8 @@ void TrayNetwork::GetNetworkStateHandlerImageAndLabel( // network, or the connection was user requested, use the connecting // network. if (connecting_network && - (!connected_network || TrayNetworkStateObserver::HasConnectingNetwork( - connecting_network->path()))) { + (!connected_network || + handler->connecting_network() == connecting_network->path())) { network = connecting_network; } else { network = connected_network; diff --git a/ash/system/chromeos/network/tray_network.h b/ash/system/chromeos/network/tray_network.h index 7736056..241154e 100644 --- a/ash/system/chromeos/network/tray_network.h +++ b/ash/system/chromeos/network/tray_network.h @@ -21,6 +21,7 @@ class NetworkState; namespace ash { namespace internal { +class NetworkStateNotifier; class TrayNetworkStateObserver; namespace tray { @@ -92,6 +93,7 @@ private: scoped_ptr<tray::NetworkMessages> messages_; bool request_wifi_view_; scoped_ptr<TrayNetworkStateObserver> network_state_observer_; + scoped_ptr<NetworkStateNotifier> network_state_notifier_; DISALLOW_COPY_AND_ASSIGN(TrayNetwork); }; diff --git a/ash/system/chromeos/network/tray_network_state_observer.cc b/ash/system/chromeos/network/tray_network_state_observer.cc index 30b6ca7..2b94540 100644 --- a/ash/system/chromeos/network/tray_network_state_observer.cc +++ b/ash/system/chromeos/network/tray_network_state_observer.cc @@ -11,15 +11,6 @@ #include "chromeos/network/network_state_handler.h" #include "third_party/cros_system_api/dbus/service_constants.h" -namespace { - -std::set<std::string>& GetConnectingNetworks() { - static std::set<std::string> s_connecting_networks_; - return s_connecting_networks_; -} - -} - namespace ash { namespace internal { @@ -51,22 +42,8 @@ void TrayNetworkStateObserver::DefaultNetworkChanged( void TrayNetworkStateObserver::NetworkPropertiesUpdated( const chromeos::NetworkState* network) { - if (!network->IsConnectingState()) - GetConnectingNetworks().erase(network->path()); delegate_->NetworkServiceChanged(network); } -// static -void TrayNetworkStateObserver::AddConnectingNetwork( - const std::string& service_path) { - GetConnectingNetworks().insert(service_path); -} - -// static -bool TrayNetworkStateObserver::HasConnectingNetwork( - const std::string& service_path) { - return GetConnectingNetworks().count(service_path) > 0; -} - } // namespace ash } // namespace internal diff --git a/ash/system/chromeos/network/tray_network_state_observer.h b/ash/system/chromeos/network/tray_network_state_observer.h index 4a61dfd..fc9faf9 100644 --- a/ash/system/chromeos/network/tray_network_state_observer.h +++ b/ash/system/chromeos/network/tray_network_state_observer.h @@ -42,12 +42,6 @@ class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver { virtual void NetworkPropertiesUpdated( const chromeos::NetworkState* network) OVERRIDE; - // Keep track of user initiated connecting networks - static void AddConnectingNetwork(const std::string& service_path); - - // Returns true if a user initiated connection to |network| occured - static bool HasConnectingNetwork(const std::string& service_path); - private: Delegate* delegate_; diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index f82e808..967500f 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -270,6 +270,10 @@ bool SystemTray::HasSystemBubble() const { return system_bubble_.get() != NULL; } +bool SystemTray::HasNotificationBubble() const { + return notification_bubble_.get() != NULL; +} + internal::SystemTrayBubble* SystemTray::GetSystemBubble() { if (!system_bubble_.get()) return NULL; @@ -290,13 +294,20 @@ bool SystemTray::IsMouseInNotificationBubble() const { Shell::GetScreen()->GetCursorScreenPoint()); } -bool SystemTray::CloseBubbleForTest() const { +bool SystemTray::CloseSystemBubbleForTest() const { if (!system_bubble_.get()) return false; system_bubble_->bubble()->Close(); return true; } +bool SystemTray::CloseNotificationBubbleForTest() const { + if (!notification_bubble_.get()) + return false; + notification_bubble_->bubble()->Close(); + return true; +} + // Private methods. bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index 9080216..0988524 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -112,6 +112,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // of being created). bool HasSystemBubble() const; + // Returns true if there is a notification bubble. + bool HasNotificationBubble() const; + // Returns true if the system_bubble_ exists and is of type |type|. bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type); @@ -127,7 +130,8 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // Accessors for testing. // Returns true if the bubble exists. - bool CloseBubbleForTest() const; + bool CloseSystemBubbleForTest() const; + bool CloseNotificationBubbleForTest() const; // Overridden from TrayBackgroundView. virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; diff --git a/ash/system/tray/system_tray_unittest.cc b/ash/system/tray/system_tray_unittest.cc index ca1db67..8ec6c9e 100644 --- a/ash/system/tray/system_tray_unittest.cc +++ b/ash/system/tray/system_tray_unittest.cc @@ -139,9 +139,9 @@ TEST_F(SystemTrayTest, SystemTrayDefaultView) { tray->ShowDefaultView(BUBBLE_CREATE_NEW); // Ensure that closing the bubble destroys it. - ASSERT_TRUE(tray->CloseBubbleForTest()); + ASSERT_TRUE(tray->CloseSystemBubbleForTest()); RunAllPendingInMessageLoop(); - ASSERT_FALSE(tray->CloseBubbleForTest()); + ASSERT_FALSE(tray->CloseSystemBubbleForTest()); } TEST_F(SystemTrayTest, SystemTrayTestItems) { @@ -245,7 +245,7 @@ TEST_F(SystemTrayTest, SystemTrayNotifications) { ASSERT_TRUE(test_item->notification_view() != NULL); // Hide the detailed view, ensure the notificaiton view still exists. - ASSERT_TRUE(tray->CloseBubbleForTest()); + ASSERT_TRUE(tray->CloseSystemBubbleForTest()); RunAllPendingInMessageLoop(); ASSERT_TRUE(detailed_item->detailed_view() == NULL); ASSERT_TRUE(test_item->notification_view() != NULL); |