diff options
-rw-r--r-- | ash/ash_switches.cc | 4 | ||||
-rw-r--r-- | ash/ash_switches.h | 1 | ||||
-rw-r--r-- | ash/system/chromeos/network/tray_network.cc | 18 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 8 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 77 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/net/connectivity_state_helper.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chromeos/about_network.cc | 4 | ||||
-rw-r--r-- | chromeos/chromeos.gyp | 3 | ||||
-rw-r--r-- | chromeos/chromeos_switches.cc | 5 | ||||
-rw-r--r-- | chromeos/chromeos_switches.h | 2 | ||||
-rw-r--r-- | chromeos/network/network_device_handler.cc | 176 | ||||
-rw-r--r-- | chromeos/network/network_device_handler.h | 106 | ||||
-rw-r--r-- | chromeos/network/network_device_handler_unittest.cc | 136 |
16 files changed, 56 insertions, 500 deletions
diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index ce9e07a..b50b7d4 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -60,6 +60,10 @@ const char kAshEnableWorkspaceScrubbing[] = "ash-enable-workspace-scrubbing"; const char kAshEnableMemoryMonitor[] = "ash-enable-memory-monitor"; #endif +// Enable new network handlers in the status area. +const char kAshEnableNewNetworkStatusArea[] = + "ash-enable-new-network-status-area"; + // Disable the per application grouping version of the launcher. const char kAshDisablePerAppLauncher[] = "ash-disable-per-app-launcher"; diff --git a/ash/ash_switches.h b/ash/ash_switches.h index ef330f4..d371a53 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -34,6 +34,7 @@ ASH_EXPORT extern const char kAshEnableBrightnessControl[]; #if defined(OS_LINUX) ASH_EXPORT extern const char kAshEnableMemoryMonitor[]; #endif +ASH_EXPORT extern const char kAshEnableNewNetworkStatusArea[]; ASH_EXPORT extern const char kAshEnableOak[]; ASH_EXPORT extern const char kAshEnableTrayDragging[]; ASH_EXPORT extern const char kAshEnableWorkspaceScrubbing[]; diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc index 54c2ed0..ab0118d 100644 --- a/ash/system/chromeos/network/tray_network.cc +++ b/ash/system/chromeos/network/tray_network.cc @@ -4,6 +4,7 @@ #include "ash/system/chromeos/network/tray_network.h" +#include "ash/ash_switches.h" #include "ash/shell.h" #include "ash/system/chromeos/network/network_list_detailed_view.h" #include "ash/system/chromeos/network/network_list_detailed_view_base.h" @@ -17,7 +18,6 @@ #include "ash/system/tray/tray_item_view.h" #include "ash/system/tray/tray_notification_view.h" #include "base/command_line.h" -#include "chromeos/chromeos_switches.h" #include "chromeos/network/network_state_handler.h" #include "grit/ash_resources.h" #include "grit/ash_strings.h" @@ -53,6 +53,11 @@ int GetMessageIcon( return 0; } +bool UseNewNetworkHandlers() { + return CommandLine::ForCurrentProcess()->HasSwitch( + ash::switches::kAshEnableNewNetworkStatusArea); +} + } // namespace namespace ash { @@ -341,10 +346,8 @@ TrayNetwork::TrayNetwork(SystemTray* system_tray) notification_(NULL), messages_(new tray::NetworkMessages()), request_wifi_view_(false) { - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { + if (UseNewNetworkHandlers()) network_state_observer_.reset(new TrayNetworkStateObserver(this)); - } Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); } @@ -377,8 +380,7 @@ views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { !delegate->GetWifiEnabled()); request_wifi_view_ = false; } else { - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { + if (UseNewNetworkHandlers()) { detailed_ = new tray::NetworkStateListDetailedView(this, status); } else { detailed_ = new tray::NetworkListDetailedView( @@ -456,10 +458,8 @@ void TrayNetwork::ClearNetworkMessage(MessageType message_type) { } void TrayNetwork::OnWillToggleWifi() { - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { + if (UseNewNetworkHandlers()) return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() - } if (!detailed_ || detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { request_wifi_view_ = true; diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 276b873..f12d0dd 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6796,11 +6796,11 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_ENABLE_MEMORY_MONITOR_DESCRIPTION" desc="Title for the flag to enable advanced gestures."> Enables visual memory monitor in status area. </message> - <message name="IDS_FLAGS_ENABLE_NEW_NETWORK_HANDLERS_NAME" desc="Title for the flag to enable using the new network handlers."> - Enable new network handlers + <message name="IDS_FLAGS_ASH_ENABLE_NEW_NETWORK_STATUS_AREA_NAME" desc="Title for the flag to enable using the new network handlers."> + Enable new network handlers in the status area </message> - <message name="IDS_FLAGS_ENABLE_NEW_NETWORK_HANDLERS_DESCRIPTION" desc="Title for the flag to enable using the new Network State Handler."> - Enables the new network handlers which handle Shill communication without using NetworkLibrary. + <message name="IDS_FLAGS_ASH_ENABLE_NEW_NETWORK_STATUS_AREA_DESCRIPTION" desc="Title for the flag to enable using the new Network State Handler."> + Enables the new network handlers which handle Shill communication without using NetworkLibrary for the status area. </message> <message name="IDS_FLAGS_ENABLE_NETWORK_STATE_HANDLER_NAME" desc="Title for the flag to enable using the new Network State Handler."> Enable New Network State Handler diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 43ae7aff..32a18cb 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1124,11 +1124,11 @@ const Experiment kExperiments[] = { #endif #endif #if defined(OS_CHROMEOS) - { "enable-new-network-handlers", - IDS_FLAGS_ENABLE_NEW_NETWORK_HANDLERS_NAME, - IDS_FLAGS_ENABLE_NEW_NETWORK_HANDLERS_DESCRIPTION, + { "ash-enable-new-network-status-area", + IDS_FLAGS_ASH_ENABLE_NEW_NETWORK_STATUS_AREA_NAME, + IDS_FLAGS_ASH_ENABLE_NEW_NETWORK_STATUS_AREA_DESCRIPTION, kOsCrOS, - SINGLE_VALUE_TYPE(chromeos::switches::kEnableNewNetworkHandlers), + SINGLE_VALUE_TYPE(ash::switches::kAshEnableNewNetworkStatusArea), }, { "enable-carrier-switching", diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index d2ea657..a232795 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -92,7 +92,6 @@ #include "chromeos/network/network_change_notifier_chromeos.h" #include "chromeos/network/network_change_notifier_factory_chromeos.h" #include "chromeos/network/network_configuration_handler.h" -#include "chromeos/network/network_device_handler.h" #include "chromeos/network/network_event_log.h" #include "chromeos/network/network_state_handler.h" #include "chromeos/power/power_state_override.h" @@ -236,11 +235,8 @@ namespace internal { // destructor will get called if and only if this has been instantiated. class DBusServices { public: - DBusServices(const content::MainFunctionParams& parameters, - bool use_new_network_change_notifier) - : use_new_network_change_notifier_(use_new_network_change_notifier), - cros_initialized_(false), - network_handlers_initialized_(false) { + explicit DBusServices(const content::MainFunctionParams& parameters) + : cros_initialized_(false) { // Initialize CrosLibrary only for the browser, unless running tests // (which do their own CrosLibrary setup). if (!parameters.ui_task) { @@ -259,11 +255,22 @@ class DBusServices { disks::DiskMountManager::Initialize(); cryptohome::AsyncMethodCaller::Initialize(); + // Always initialize these handlers which should not conflict with + // NetworkLibrary. + chromeos::network_event_log::Initialize(); + chromeos::GeolocationHandler::Initialize(); + chromeos::NetworkStateHandler::Initialize(); + chromeos::NetworkConfigurationHandler::Initialize(); + // Initialize the network change notifier for Chrome OS. The network // change notifier starts to monitor changes from the power manager and // the network manager. - if (!use_new_network_change_notifier_) + if (CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kEnableNewNetworkChangeNotifier)) { + NetworkChangeNotifierFactoryChromeos::GetInstance()->Initialize(); + } else { CrosNetworkChangeNotifierFactory::GetInstance()->Init(); + } // Likewise, initialize the upgrade detector for Chrome OS. The upgrade // detector starts to monitor changes from the update engine. @@ -282,29 +289,6 @@ class DBusServices { OwnerKeyUtil::Create()); } - // TODO(stevenjb): Move this into DBusServices() once the switch is no - // longer required. (Switch is set in about_flags.cc and not applied until - // after DBusServices() is called). - void InitializeNetworkHandlers() { - network_handlers_initialized_ = true; - - // Always initialize these handlers which should not conflict with - // NetworkLibrary. - chromeos::network_event_log::Initialize(); - chromeos::GeolocationHandler::Initialize(); - - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { - chromeos::NetworkDeviceHandler::Initialize(); - chromeos::NetworkStateHandler::Initialize(); - chromeos::NetworkConfigurationHandler::Initialize(); - // TODO(gauravsh): This needs re-factoring. NetworkChangeNotifier choice - // needs to be made before about:flags are processed. - if (use_new_network_change_notifier_) - NetworkChangeNotifierFactoryChromeos::GetInstance()->Initialize(); - } - } - ~DBusServices() { // CrosLibrary is shut down before DBusThreadManager even though it // is initialized first becuase some of its libraries depend on DBus @@ -315,17 +299,10 @@ class DBusServices { CrosLibrary::Shutdown(); chromeos::ConnectivityStateHelper::Shutdown(); - if (network_handlers_initialized_) { - if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { - chromeos::NetworkDeviceHandler::Shutdown(); - chromeos::NetworkStateHandler::Shutdown(); - chromeos::NetworkConfigurationHandler::Shutdown(); - } - - chromeos::GeolocationHandler::Shutdown(); - chromeos::network_event_log::Shutdown(); - } + chromeos::NetworkStateHandler::Shutdown(); + chromeos::NetworkConfigurationHandler::Shutdown(); + chromeos::GeolocationHandler::Shutdown(); + chromeos::network_event_log::Shutdown(); cryptohome::AsyncMethodCaller::Shutdown(); disks::DiskMountManager::Shutdown(); @@ -336,9 +313,7 @@ class DBusServices { } private: - bool use_new_network_change_notifier_; bool cros_initialized_; - bool network_handlers_initialized_; DISALLOW_COPY_AND_ASSIGN(DBusServices); }; @@ -349,8 +324,7 @@ class DBusServices { ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos( const content::MainFunctionParams& parameters) - : ChromeBrowserMainPartsLinux(parameters), - use_new_network_change_notifier_(false) { + : ChromeBrowserMainPartsLinux(parameters) { } ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() { @@ -411,13 +385,12 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopStart() { // Note: At the time this is called, we have not processed about:flags // so this requires that the network handler flag was passed in at the command // line. - if (!CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { - network_change_factory = new CrosNetworkChangeNotifierFactory(); - } else { + if (CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kEnableNewNetworkChangeNotifier)) { LOG(WARNING) << "Using new connection change notifier."; network_change_factory = new NetworkChangeNotifierFactoryChromeos(); - use_new_network_change_notifier_ = true; + } else { + network_change_factory = new CrosNetworkChangeNotifierFactory(); } net::NetworkChangeNotifier::SetFactory(network_change_factory); ChromeBrowserMainPartsLinux::PreMainMessageLoopStart(); @@ -427,8 +400,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { MessageLoopForUI* message_loop = MessageLoopForUI::current(); message_loop->AddObserver(g_message_loop_observer.Pointer()); - dbus_services_.reset(new internal::DBusServices( - parameters(), use_new_network_change_notifier_)); + dbus_services_.reset(new internal::DBusServices(parameters())); ChromeBrowserMainPartsLinux::PostMainMessageLoopStart(); } @@ -437,7 +409,6 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { // about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads. void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { // Must be called after about_flags settings are applied (see note above). - dbus_services_->InitializeNetworkHandlers(); chromeos::ConnectivityStateHelper::Initialize(); AudioHandler::Initialize(); diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index df73d20..5783b28 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -771,10 +771,10 @@ std::string LoginUtilsImpl::GetOffTheRecordCommandLine( ash::switches::kAshTouchHud, ash::switches::kAuraLegacyPowerButton, ash::switches::kAuraNoShadows, + ash::switches::kAshEnableNewNetworkStatusArea, cc::switches::kDisableThreadedAnimation, cc::switches::kEnablePartialSwap, chromeos::switches::kDbusStub, - chromeos::switches::kEnableNewNetworkHandlers, gfx::switches::kEnableBrowserTextSubpixelPositioning, gfx::switches::kEnableWebkitTextSubpixelPositioning, views::corewm::switches::kWindowAnimationsDisabled, diff --git a/chrome/browser/chromeos/net/connectivity_state_helper.cc b/chrome/browser/chromeos/net/connectivity_state_helper.cc index 4afc337..aaa8467 100644 --- a/chrome/browser/chromeos/net/connectivity_state_helper.cc +++ b/chrome/browser/chromeos/net/connectivity_state_helper.cc @@ -52,7 +52,7 @@ class ConnectivityStateHelperNetworkLibrary void ConnectivityStateHelper::Initialize() { CHECK(!g_connectivity_state_helper); if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { + chromeos::switches::kEnableNewNetworkChangeNotifier)) { g_connectivity_state_helper = new ConnectivityStateHelperImpl(); } else { g_connectivity_state_helper = diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index c4f1c48..5087ad2 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "ash/ash_switches.h" #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" @@ -79,7 +80,6 @@ #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/session_manager_client.h" @@ -741,7 +741,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); Network* network = crosnet->FindNetworkByPath(network_id); if (CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kEnableNewNetworkHandlers)) { + ash::switches::kAshEnableNewNetworkStatusArea)) { // If the new network handlers are enabled, this should always trigger // displaying the network settings UI. if (network) diff --git a/chrome/browser/ui/webui/chromeos/about_network.cc b/chrome/browser/ui/webui/chromeos/about_network.cc index 0117531f..0a108b1 100644 --- a/chrome/browser/ui/webui/chromeos/about_network.cc +++ b/chrome/browser/ui/webui/chromeos/about_network.cc @@ -4,13 +4,13 @@ #include "chrome/browser/ui/webui/chromeos/about_network.h" +#include "ash/ash_switches.h" #include "base/command_line.h" #include "base/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/ui/webui/about_ui.h" -#include "chromeos/chromeos_switches.h" #include "chromeos/network/network_event_log.h" #include "chromeos/network/network_state.h" #include "chromeos/network/network_state_handler.h" @@ -285,7 +285,7 @@ std::string AboutNetwork(const std::string& query) { if (network_event_log::IsInitialized()) output += GetHeaderEventLogInfo(); if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableNewNetworkHandlers)) { + ash::switches::kAshEnableNewNetworkStatusArea)) { output += GetNetworkStateHtmlInfo(); } else { output += GetCrosNetworkHtmlInfo(); diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index aff5f13..a5ac803 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -139,8 +139,6 @@ 'network/network_change_notifier_factory_chromeos.h', 'network/network_configuration_handler.cc', 'network/network_configuration_handler.h', - 'network/network_device_handler.cc', - 'network/network_device_handler.h', 'network/network_event_log.cc', 'network/network_event_log.h', 'network/network_handler_callbacks.cc', @@ -338,7 +336,6 @@ 'network/geolocation_handler_unittest.cc', 'network/network_change_notifier_chromeos_unittest.cc', 'network/network_configuration_handler_unittest.cc', - 'network/network_device_handler_unittest.cc', 'network/network_event_log_unittest.cc', 'network/network_sms_handler_unittest.cc', 'network/network_state_handler_unittest.cc', diff --git a/chromeos/chromeos_switches.cc b/chromeos/chromeos_switches.cc index b8769de..4fe2854 100644 --- a/chromeos/chromeos_switches.cc +++ b/chromeos/chromeos_switches.cc @@ -13,8 +13,9 @@ const char kChromeOSReleaseBoard[] = "chromeos-release-board"; // Forces the stub implementation of dbus clients. const char kDbusStub[] = "dbus-stub"; -// Enables the new NetworkStateHandler class. -const char kEnableNewNetworkHandlers[] = "enable-new-network-handlers"; +// Enables the new NetworkChangeNotifier using the NetworkStateHandler class. +const char kEnableNewNetworkChangeNotifier[] = + "enable-new-network-change-notifier"; // Enables screensaver extensions. const char kEnableScreensaverExtensions[] = "enable-screensaver-extensions"; diff --git a/chromeos/chromeos_switches.h b/chromeos/chromeos_switches.h index 9cee7a3..233b986 100644 --- a/chromeos/chromeos_switches.h +++ b/chromeos/chromeos_switches.h @@ -22,7 +22,7 @@ namespace switches { // Please keep alphabetized. CHROMEOS_EXPORT extern const char kChromeOSReleaseBoard[]; CHROMEOS_EXPORT extern const char kDbusStub[]; -CHROMEOS_EXPORT extern const char kEnableNewNetworkHandlers[]; +CHROMEOS_EXPORT extern const char kEnableNewNetworkChangeNotifier[]; CHROMEOS_EXPORT extern const char kEnableScreensaverExtensions[]; CHROMEOS_EXPORT extern const char kSmsTestMessages[]; diff --git a/chromeos/network/network_device_handler.cc b/chromeos/network/network_device_handler.cc deleted file mode 100644 index 4bff925..0000000 --- a/chromeos/network/network_device_handler.cc +++ /dev/null @@ -1,176 +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 "chromeos/network/network_device_handler.h" - -#include "base/bind.h" -#include "base/values.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_device_client.h" -#include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/network/network_event_log.h" -#include "chromeos/network/network_handler_callbacks.h" -#include "dbus/object_path.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -namespace { -const char kLogModule[] = "NetworkDeviceHandler"; -} - -namespace chromeos { - -static NetworkDeviceHandler* g_network_device_handler = NULL; - -//------------------------------------------------------------------------------ -// NetworkDeviceHandler public methods - -NetworkDeviceHandler::~NetworkDeviceHandler() { - DBusThreadManager::Get()->GetShillManagerClient()-> - RemovePropertyChangedObserver(this); -} - -void NetworkDeviceHandler::AddObserver(Observer* observer) { - observers_.AddObserver(observer); -} - -void NetworkDeviceHandler::RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); -} - -// static -void NetworkDeviceHandler::Initialize() { - CHECK(!g_network_device_handler); - g_network_device_handler = new NetworkDeviceHandler(); - g_network_device_handler->Init(); -} - -// static -void NetworkDeviceHandler::Shutdown() { - CHECK(g_network_device_handler); - delete g_network_device_handler; - g_network_device_handler = NULL; -} - -// static -NetworkDeviceHandler* NetworkDeviceHandler::Get() { - CHECK(g_network_device_handler) - << "NetworkDeviceHandler::Get() called before Initialize()"; - return g_network_device_handler; -} - -//------------------------------------------------------------------------------ -// ShillPropertyChangedObserver overrides - -void NetworkDeviceHandler::OnPropertyChanged(const std::string& key, - const base::Value& value) { - if (key != flimflam::kDevicesProperty) - return; - const base::ListValue* devices = NULL; - if (!value.GetAsList(&devices)) { - LOG(ERROR) << "Failed to parse Devices property."; - return; - } - DevicePropertyChanged(devices); -} - -//------------------------------------------------------------------------------ -// Private methods - -NetworkDeviceHandler::NetworkDeviceHandler() - : devices_ready_(false), - weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { -} - -void NetworkDeviceHandler::Init() { - ShillManagerClient* shill_manager = - DBusThreadManager::Get()->GetShillManagerClient(); - shill_manager->GetProperties( - base::Bind(&NetworkDeviceHandler::ManagerPropertiesCallback, - weak_ptr_factory_.GetWeakPtr())); - shill_manager->AddPropertyChangedObserver(this); -} - -void NetworkDeviceHandler::ManagerPropertiesCallback( - DBusMethodCallStatus call_status, - const base::DictionaryValue& properties) { - if (call_status != DBUS_METHOD_CALL_SUCCESS) { - LOG(ERROR) << "Failed to get Manager properties: " << call_status; - return; - } - const base::ListValue* devices = NULL; - if (!properties.GetListWithoutPathExpansion( - flimflam::kDevicesProperty, &devices)) { - LOG(WARNING) << "Devices property not found"; - return; - } - DevicePropertyChanged(devices); -} - -void NetworkDeviceHandler::DevicePropertyChanged( - const base::ListValue* devices) { - DCHECK(devices); - devices_ready_ = false; - devices_.clear(); - pending_device_paths_.clear(); - for (size_t i = 0; i < devices->GetSize(); i++) { - std::string device_path; - if (!devices->GetString(i, &device_path)) { - LOG(WARNING) << "Failed to parse device[" << i << "]"; - continue; - } - pending_device_paths_.insert(device_path); - DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( - dbus::ObjectPath(device_path), - base::Bind(&NetworkDeviceHandler::DevicePropertiesCallback, - weak_ptr_factory_.GetWeakPtr(), - device_path)); - } -} - -void NetworkDeviceHandler::DevicePropertiesCallback( - const std::string& device_path, - DBusMethodCallStatus call_status, - const base::DictionaryValue& properties) { - if (call_status != DBUS_METHOD_CALL_SUCCESS) { - LOG(ERROR) << "Failed to get Device properties for " << device_path - << ": " << call_status; - } else { - GetDeviceProperties(device_path, properties); - } - pending_device_paths_.erase(device_path); - if (pending_device_paths_.empty()) { - devices_ready_ = true; - FOR_EACH_OBSERVER(Observer, observers_, NetworkDevicesUpdated(devices_)); - } -} - -void NetworkDeviceHandler::GetDeviceProperties( - const std::string& device_path, - const base::DictionaryValue& properties) { - std::string type; - if (!properties.GetStringWithoutPathExpansion( - flimflam::kTypeProperty, &type)) { - LOG(WARNING) << "Failed to parse Type property for " << device_path; - return; - } - Device& device = devices_[device_path]; - device.type = type; - properties.GetBooleanWithoutPathExpansion( - flimflam::kPoweredProperty, &device.powered); - properties.GetBooleanWithoutPathExpansion( - flimflam::kScanningProperty, &device.scanning); - properties.GetIntegerWithoutPathExpansion( - flimflam::kScanIntervalProperty, &device.scan_interval); -} - -//------------------------------------------------------------------------------ - -NetworkDeviceHandler::Device::Device() - : powered(false), scanning(false), scan_interval(0) { -} - -NetworkDeviceHandler::Device::~Device() { -} - -} // namespace chromeos diff --git a/chromeos/network/network_device_handler.h b/chromeos/network/network_device_handler.h deleted file mode 100644 index 0b90f04..0000000 --- a/chromeos/network/network_device_handler.h +++ /dev/null @@ -1,106 +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 CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ -#define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ - -#include <map> -#include <set> -#include <string> - -#include "base/memory/weak_ptr.h" -#include "base/observer_list.h" -#include "chromeos/chromeos_export.h" -#include "chromeos/dbus/dbus_method_call_status.h" -#include "chromeos/dbus/shill_property_changed_observer.h" - -namespace base { -class DictionaryValue; -class ListValue; -class Value; -} - -namespace chromeos { - -class CHROMEOS_EXPORT NetworkDeviceHandler - : public ShillPropertyChangedObserver { - public: - struct Device { - Device(); - ~Device(); - std::string type; - bool powered; - bool scanning; - int scan_interval; - }; - typedef std::map<std::string, Device> DeviceMap; - - class Observer { - public: - typedef NetworkDeviceHandler::DeviceMap DeviceMap; - - // Called when devices are updated. Passes the updated map of devices. - virtual void NetworkDevicesUpdated(const DeviceMap& devices) = 0; - - protected: - virtual ~Observer() {} - }; - - virtual ~NetworkDeviceHandler(); - - // Manage the global instance. Must be initialized before any calls to Get(). - static void Initialize(); - static void Shutdown(); - static NetworkDeviceHandler* Get(); - - // Add/remove observers. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - bool devices_ready() const { return devices_ready_; } - const DeviceMap& devices() const { return devices_; } - - // ShillPropertyChangedObserver overrides - virtual void OnPropertyChanged(const std::string& key, - const base::Value& value) OVERRIDE; - - private: - friend class NetworkDeviceHandlerTest; - NetworkDeviceHandler(); - void Init(); - - void ManagerPropertiesCallback(DBusMethodCallStatus call_status, - const base::DictionaryValue& properties); - void DevicePropertyChanged(const base::ListValue* devices); - void DevicePropertiesCallback(const std::string& device_path, - DBusMethodCallStatus call_status, - const base::DictionaryValue& properties); - void NetworkPropertiesCallback(const std::string& device_path, - const std::string& network_path, - DBusMethodCallStatus call_status, - const base::DictionaryValue& properties); - void GetDeviceProperties(const std::string& device_path, - const base::DictionaryValue& properties); - - // True when the device list is up to date. - bool devices_ready_; - - // Map of Device structs, valid when |devices_ready_| is true. - DeviceMap devices_; - - // Map of pending devices. - std::set<std::string> pending_device_paths_; - - // Observer list - ObserverList<Observer> observers_; - - // For Shill client callbacks - base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandler); -}; - -} // namespace chromeos - -#endif // CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_ diff --git a/chromeos/network/network_device_handler_unittest.cc b/chromeos/network/network_device_handler_unittest.cc deleted file mode 100644 index 589b97a..0000000 --- a/chromeos/network/network_device_handler_unittest.cc +++ /dev/null @@ -1,136 +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 "chromeos/network/network_device_handler.h" - -#include "base/bind.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "base/values.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_device_client.h" -#include "chromeos/dbus/shill_manager_client.h" -#include "dbus/object_path.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -namespace chromeos { - -namespace { - -class TestObserver : public NetworkDeviceHandler::Observer { - public: - TestObserver() : device_updates_(0) {} - - virtual void NetworkDevicesUpdated(const DeviceMap& devices) { - ++device_updates_; - devices_ = devices; - } - - int device_updates() { return device_updates_; } - const DeviceMap& devices() { return devices_; } - - private: - int device_updates_; - DeviceMap devices_; -}; - -} // namespace - -class NetworkDeviceHandlerTest : public testing::Test { - public: - NetworkDeviceHandlerTest() - : manager_test_(NULL), - device_test_(NULL) { - } - virtual ~NetworkDeviceHandlerTest() { - } - - virtual void SetUp() OVERRIDE { - // Initialize DBusThreadManager with a stub implementation. - DBusThreadManager::InitializeWithStub(); - // Get the test interface for manager / device. - manager_test_ = - DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); - ASSERT_TRUE(manager_test_); - device_test_ = - DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); - ASSERT_TRUE(device_test_); - } - - virtual void TearDown() OVERRIDE { - device_handler_->RemoveObserver(observer_.get()); - observer_.reset(); - device_handler_.reset(); - DBusThreadManager::Shutdown(); - } - - void AddDevice(const std::string& type, const std::string& id) { - manager_test_->AddDevice(id); - device_test_->AddDevice(id, type, std::string("/device/" + id)); - } - - void RemoveDevice(const std::string& id) { - manager_test_->RemoveDevice(id); - device_test_->RemoveDevice(id); - } - - // Call this after any initial Shill client setup - void SetupNetworkDeviceHandler() { - device_handler_.reset(new NetworkDeviceHandler()); - device_handler_->Init(); - observer_.reset(new TestObserver()); - device_handler_->AddObserver(observer_.get()); - } - - protected: - MessageLoopForUI message_loop_; - scoped_ptr<TestObserver> observer_; - scoped_ptr<NetworkDeviceHandler> device_handler_; - ShillManagerClient::TestInterface* manager_test_; - ShillDeviceClient::TestInterface* device_test_; - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); -}; - -TEST_F(NetworkDeviceHandlerTest, NetworkDeviceHandlerStub) { - SetupNetworkDeviceHandler(); - EXPECT_FALSE(device_handler_->devices_ready()); - - message_loop_.RunUntilIdle(); - EXPECT_EQ(1, observer_->device_updates()); - EXPECT_TRUE(device_handler_->devices_ready()); - // ShillManagerClient default stub entries are in shill_manager_client.cc. - // TODO(stevenjb): Eliminate default stub entries and add them explicitly. - const size_t kNumShillManagerClientStubImplDevices = 2; - EXPECT_EQ(kNumShillManagerClientStubImplDevices, - device_handler_->devices().size()); -} - -TEST_F(NetworkDeviceHandlerTest, NetworkDeviceHandlerPropertyChanged) { - // This relies on the stub dbus implementations for ShillManagerClient, - SetupNetworkDeviceHandler(); - - message_loop_.RunUntilIdle(); - EXPECT_EQ(1, observer_->device_updates()); - const size_t kNumShillManagerClientStubImplDevices = 2; - EXPECT_EQ(kNumShillManagerClientStubImplDevices, observer_->devices().size()); - - // Add a device. - const std::string kTestDevicePath("test_wifi_device1"); - AddDevice(flimflam::kTypeWifi, kTestDevicePath); - message_loop_.RunUntilIdle(); - EXPECT_EQ(2, observer_->device_updates()); - EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, - observer_->devices().size()); - - // Remove a device - RemoveDevice(kTestDevicePath); - message_loop_.RunUntilIdle(); - EXPECT_EQ(3, observer_->device_updates()); - EXPECT_EQ(kNumShillManagerClientStubImplDevices, observer_->devices().size()); -} - -} // namespace chromeos |