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 | |
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
24 files changed, 500 insertions, 417 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); diff --git a/chrome/app/chromeos_strings.grdp b/chrome/app/chromeos_strings.grdp index fe74e69..5184438 100644 --- a/chrome/app/chromeos_strings.grdp +++ b/chrome/app/chromeos_strings.grdp @@ -162,12 +162,6 @@ Press any key to continue exploring. <message name="IDS_NETWORK_ENROLLMENT_HANDLER_BUTTON" desc="Text of the accept button for generating a new network certificate."> Get new certificate </message> - <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> <message name="IDS_NETWORK_ACTIVATION_ERROR_TITLE" desc="Title for network connection error notification"> Network Activation Error </message> @@ -2554,47 +2548,6 @@ Battery full Unable to connect. </message> - <!-- Network state strings for ChromeOS --> - <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> - <!-- Captive Portal state strings for ChromeOS --> <message name="IDS_CHROMEOS_CAPTIVE_PORTAL_STATUS_UNKNOWN" desc="Captive Portal status in about:network: Unknown"> Unknown @@ -2615,65 +2568,6 @@ Battery full Unrecognized </message> - <!-- Network error strings for ChromeOS --> - <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> - <!-- Cellular network technology description strings for ChromeOS --> <message name="IDS_CHROMEOS_NETWORK_CELLULAR_TECHNOLOGY_UNKNOWN" desc="Description of unknown cellular network technology. Shown under details on chrome:stettings/internet page."> Unknown diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index f20abda..91da9a0 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -18,7 +18,9 @@ #include "chrome/browser/chromeos/cros/network_library_impl_stub.h" #include "chrome/common/net/x509_certificate_model.h" #include "chromeos/network/cros_network_functions.h" +#include "chromeos/network/network_state_handler.h" #include "content/public/browser/browser_thread.h" +#include "grit/ash_strings.h" #include "grit/generated_resources.h" #include "net/base/url_util.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -444,6 +446,13 @@ void Network::AttemptConnection(const base::Closure& closure) { closure.Run(); } +void Network::set_connecting() { + state_ = STATE_CONNECT_REQUESTED; + // Set the connecting network in NetworkStateHandler for the status area UI. + if (NetworkStateHandler::IsInitialized()) + NetworkStateHandler::Get()->set_connecting_network(service_path()); +} + void Network::SetProfilePath(const std::string& profile_path) { VLOG(1) << "Setting profile for: " << name_ << " to: " << profile_path; SetOrClearStringProperty( diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 69dc679..757c27c 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -562,9 +562,7 @@ class Network { } void set_name(const std::string& name) { name_ = name; } void set_mode(ConnectionMode mode) { mode_ = mode; } - void set_connecting() { - state_ = STATE_CONNECT_REQUESTED; - } + void set_connecting(); void set_is_behind_portal_for_testing(bool value) { is_behind_portal_for_testing_ = value; } diff --git a/chrome/browser/chromeos/network_message_observer.cc b/chrome/browser/chromeos/network_message_observer.cc deleted file mode 100644 index 7892ecc..0000000 --- a/chrome/browser/chromeos/network_message_observer.cc +++ /dev/null @@ -1,196 +0,0 @@ -// 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 "chrome/browser/chromeos/network_message_observer.h" - -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/system/chromeos/network/network_observer.h" -#include "ash/system/tray/system_tray.h" -#include "ash/system/tray/system_tray_notifier.h" -#include "base/bind.h" -#include "base/callback.h" -#include "base/prefs/pref_service.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/network_library.h" -#include "chrome/browser/chromeos/notifications/balloon_view_host_chromeos.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/singleton_tabs.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/time_format.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { -ash::NetworkObserver::NetworkType GetAshNetworkType( - chromeos::ConnectionType connection_type) { - switch (connection_type) { - case chromeos::TYPE_CELLULAR: - return ash::NetworkObserver::NETWORK_CELLULAR; - case chromeos::TYPE_ETHERNET: - return ash::NetworkObserver::NETWORK_ETHERNET; - case chromeos::TYPE_WIFI: - return ash::NetworkObserver::NETWORK_WIFI; - case chromeos::TYPE_BLUETOOTH: - return ash::NetworkObserver::NETWORK_BLUETOOTH; - default: - return ash::NetworkObserver::NETWORK_UNKNOWN; - } -} - -} // namespace - -namespace chromeos { - -class NetworkMessageNotification : public ash::NetworkTrayDelegate { - public: - NetworkMessageNotification(Profile* profile, - ash::NetworkObserver::MessageType error_type) - : error_type_(error_type) { - switch (error_type) { - case ash::NetworkObserver::ERROR_CONNECT_FAILED: - title_ = l10n_util::GetStringUTF16(IDS_NETWORK_CONNECTION_ERROR_TITLE); - return; - case ash::NetworkObserver::MESSAGE_DATA_PROMO: - NOTREACHED(); - return; - } - NOTREACHED(); - } - - // Overridden from ash::NetworkTrayDelegate: - virtual void NotificationLinkClicked(size_t index) OVERRIDE { - base::ListValue empty_value; - if (!callback_.is_null()) - callback_.Run(&empty_value); - } - - void Hide() { - ash::Shell::GetInstance()->system_tray_notifier()-> - NotifyClearNetworkMessage(error_type_); - } - - void SetTitle(const string16& title) { - title_ = title; - } - - void Show(chromeos::ConnectionType connection_type, - const string16& message, - const string16& link_text, - const BalloonViewHost::MessageCallback& callback, - bool urgent, bool sticky) { - callback_ = callback; - std::vector<string16> links; - links.push_back(link_text); - ash::NetworkObserver::NetworkType network_type = GetAshNetworkType( - connection_type); - ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage( - this, error_type_, network_type, title_, message, links); - } - - void ShowAlways(chromeos::ConnectionType connection_type, - const string16& message, - const string16& link_text, - const BalloonViewHost::MessageCallback& callback, - bool urgent, bool sticky) { - Show(connection_type, message, link_text, callback, urgent, sticky); - } - - private: - string16 title_; - ash::NetworkObserver::MessageType error_type_; - BalloonViewHost::MessageCallback callback_; -}; - -NetworkMessageObserver::NetworkMessageObserver(Profile* profile) { - notification_connection_error_.reset( - new NetworkMessageNotification( - profile, ash::NetworkObserver::ERROR_CONNECT_FAILED)); - NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); - OnNetworkManagerChanged(netlib); - // Note that this gets added as a NetworkManagerObserver - // and UserActionObserver in startup_browser_creator.cc -} - -NetworkMessageObserver::~NetworkMessageObserver() { - NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); - netlib->RemoveNetworkManagerObserver(this); - netlib->RemoveUserActionObserver(this); - notification_connection_error_->Hide(); -} - -void NetworkMessageObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { - const Network* new_failed_network = NULL; - // Check to see if we have any newly failed networks. - for (WifiNetworkVector::const_iterator it = cros->wifi_networks().begin(); - it != cros->wifi_networks().end(); it++) { - const WifiNetwork* net = *it; - if (net->notify_failure()) { - new_failed_network = net; - break; // There should only be one failed network. - } - } - - if (!new_failed_network) { - for (WimaxNetworkVector::const_iterator it = cros->wimax_networks().begin(); - it != cros->wimax_networks().end(); ++it) { - const WimaxNetwork* net = *it; - if (net->notify_failure()) { - new_failed_network = net; - break; // There should only be one failed network. - } - } - } - - if (!new_failed_network) { - for (CellularNetworkVector::const_iterator it = - cros->cellular_networks().begin(); - it != cros->cellular_networks().end(); it++) { - const CellularNetwork* net = *it; - if (net->notify_failure()) { - new_failed_network = net; - break; // There should only be one failed network. - } - } - } - - if (!new_failed_network) { - for (VirtualNetworkVector::const_iterator it = - cros->virtual_networks().begin(); - it != cros->virtual_networks().end(); it++) { - const VirtualNetwork* net = *it; - if (net->notify_failure()) { - new_failed_network = net; - break; // There should only be one failed network. - } - } - } - - // Show connection error notification if necessary. - if (new_failed_network) { - VLOG(1) << "Failed Network: " << new_failed_network->service_path(); - notification_connection_error_->ShowAlways( - new_failed_network->type(), - l10n_util::GetStringFUTF16( - IDS_NETWORK_CONNECTION_ERROR_MESSAGE_WITH_DETAILS, - UTF8ToUTF16(new_failed_network->name()), - UTF8ToUTF16(new_failed_network->GetErrorString())), - string16(), BalloonViewHost::MessageCallback(), false, false); - } -} - -void NetworkMessageObserver::OnConnectionInitiated(NetworkLibrary* cros, - const Network* network) { - // If user initiated any network connection, we hide the error notification. - notification_connection_error_->Hide(); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/network_message_observer.h b/chrome/browser/chromeos/network_message_observer.h deleted file mode 100644 index c1a8a0b..0000000 --- a/chrome/browser/chromeos/network_message_observer.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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 CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_ -#define CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_ - -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/weak_ptr.h" -#include "chrome/browser/chromeos/cros/network_library.h" - -class Profile; - -namespace chromeos { - -// The network message observer displays a system notification for network -// messages. - -class NetworkMessageNotification; - -class NetworkMessageObserver - : public NetworkLibrary::NetworkManagerObserver, - public NetworkLibrary::UserActionObserver, - public base::SupportsWeakPtr<NetworkMessageObserver> { - public: - explicit NetworkMessageObserver(Profile* profile); - virtual ~NetworkMessageObserver(); - - private: - // NetworkLibrary::NetworkManagerObserver implementation. - virtual void OnNetworkManagerChanged(NetworkLibrary* obj) OVERRIDE; - - // NetworkLibrary::UserActionObserver implementation. - virtual void OnConnectionInitiated(NetworkLibrary* obj, - const Network* network) OVERRIDE; - - typedef std::map<std::string, ConnectionState> NetworkStateMap; - - // Notification for connection errors - scoped_ptr<NetworkMessageNotification> notification_connection_error_; - - DISALLOW_COPY_AND_ASSIGN(NetworkMessageObserver); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_NETWORK_MESSAGE_OBSERVER_H_ diff --git a/chrome/browser/chromeos/profile_startup.cc b/chrome/browser/chromeos/profile_startup.cc index a01ba4e..56216de 100644 --- a/chrome/browser/chromeos/profile_startup.cc +++ b/chrome/browser/chromeos/profile_startup.cc @@ -8,7 +8,6 @@ #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/customization_document.h" #include "chrome/browser/chromeos/enterprise_extension_observer.h" -#include "chrome/browser/chromeos/network_message_observer.h" #include "chrome/browser/chromeos/sms_observer.h" #include "chrome/browser/profiles/profile.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -27,15 +26,6 @@ void ProfileStartup(Profile* profile, bool process_startup) { profile->InitChromeOSPreferences(); if (process_startup) { - // These observers are singletons. They are never deleted but the pointers - // are kept in a statics so that they are not reported as leaks. - static chromeos::NetworkMessageObserver* network_message_observer = - new chromeos::NetworkMessageObserver(profile); - chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> - AddNetworkManagerObserver(network_message_observer); - chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> - AddUserActionObserver(network_message_observer); - static chromeos::SmsObserver* sms_observer = new chromeos::SmsObserver(profile); chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc index 34c390f..7a634c5 100644 --- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc @@ -54,6 +54,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "grit/ash_resources.h" +#include "grit/ash_strings.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 111dd41..b63068e 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -552,8 +552,6 @@ 'browser/chromeos/net/onc_utils.h', 'browser/chromeos/network_login_observer.cc', 'browser/chromeos/network_login_observer.h', - 'browser/chromeos/network_message_observer.cc', - 'browser/chromeos/network_message_observer.h', 'browser/chromeos/notifications/balloon_view_host_chromeos.cc', 'browser/chromeos/notifications/balloon_view_host_chromeos.h', 'browser/chromeos/offline/offline_load_page.cc', diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc index 0186204..d8e0432 100644 --- a/chromeos/network/network_state_handler.cc +++ b/chromeos/network/network_state_handler.cc @@ -376,8 +376,7 @@ void NetworkStateHandler::UpdateManagedStateProperties( // Signal connection state changed after all properties have been updated. if (network->connection_state() != prev_connection_state) OnNetworkConnectionStateChanged(network); - FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, - NetworkPropertiesUpdated(network)); + NetworkPropertiesUpdated(network); } network_event_log::AddEntry( kLogModule, "PropertiesReceived", @@ -397,8 +396,7 @@ void NetworkStateHandler::UpdateNetworkServiceProperty( if (network->connection_state() != prev_connection_state) OnNetworkConnectionStateChanged(network); - FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, - NetworkPropertiesUpdated(network)); + NetworkPropertiesUpdated(network); std::string detail = network->name() + "." + key; std::string vstr = ValueAsString(value); @@ -416,9 +414,7 @@ void NetworkStateHandler::UpdateNetworkServiceIPAddress( std::string detail = network->name() + ".IPAddress = " + ip_address; network_event_log::AddEntry(kLogModule, "NetworkIPChanged", detail); network->set_ip_address(ip_address); - FOR_EACH_OBSERVER( - NetworkStateHandlerObserver, observers_, - NetworkPropertiesUpdated(network)); + NetworkPropertiesUpdated(network); } void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, @@ -545,4 +541,12 @@ void NetworkStateHandler::OnDefaultNetworkChanged() { DefaultNetworkChanged(default_network)); } +void NetworkStateHandler::NetworkPropertiesUpdated( + const NetworkState* network) { + if (network->path() == connecting_network_ && !network->IsConnectingState()) + connecting_network_.clear(); + FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, + NetworkPropertiesUpdated(network)); +} + } // namespace chromeos diff --git a/chromeos/network/network_state_handler.h b/chromeos/network/network_state_handler.h index dcc9d8a..0a93136 100644 --- a/chromeos/network/network_state_handler.h +++ b/chromeos/network/network_state_handler.h @@ -144,6 +144,11 @@ class CHROMEOS_EXPORT NetworkStateHandler static const char kMatchTypeMobile[]; static const char kMatchTypeNonVirtual[]; + const std::string& connecting_network() const { return connecting_network_; } + void set_connecting_network(const std::string& service_path) { + connecting_network_ = service_path; + } + protected: NetworkStateHandler(); @@ -218,6 +223,9 @@ class CHROMEOS_EXPORT NetworkStateHandler // Logs an event and notifies observers. void OnDefaultNetworkChanged(); + // Notifies observers and updates connecting_network_. + void NetworkPropertiesUpdated(const NetworkState* network); + // Shill property handler instance, owned by this class. scoped_ptr<internal::ShillPropertyHandler> shill_property_handler_; @@ -231,6 +239,12 @@ class CHROMEOS_EXPORT NetworkStateHandler // Keeps track of the default network for notifying observers when it changes. std::string default_network_path_; + // Convenience member to track the user initiated connecting network. Set + // externally when a connection is requested and cleared here when the state + // changes to something other than Connecting (after observers are notified). + // TODO(stevenjb): Move this to NetworkConfigurationHandler. + std::string connecting_network_; + DISALLOW_COPY_AND_ASSIGN(NetworkStateHandler); }; |