diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 20:39:00 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 20:39:00 +0000 |
commit | 88471ffea5fcdfab97e07975c670ebe9ff4fec4a (patch) | |
tree | 417037c9615a97e109d0fb74ee7503576e2931f2 /chromeos | |
parent | 787a090dea46d71ec7cc48d145215e975564db59 (diff) | |
download | chromium_src-88471ffea5fcdfab97e07975c670ebe9ff4fec4a.zip chromium_src-88471ffea5fcdfab97e07975c670ebe9ff4fec4a.tar.gz chromium_src-88471ffea5fcdfab97e07975c670ebe9ff4fec4a.tar.bz2 |
Enable NetworkStateHandler always
This CL should have no affect on Chrome's behavior.
It does the following:
* Removes --enable-new-network-handlers and always enables them
* Adds --ash-enable-new-network-status-area and uses that to control whether
or not to use the new status area code
* Adds --enable-new-network-change-notifier and uses that to control whether
or not to use the new NetworkStateHandler based network change notifier
* Deletes the unused NetworkDeviceHandler (this was added thinking that it
was needed for Geolocation, but it turned out that the code had changed
between Flimflam and Shill so it wasn't necessary)
BUG=161869
For chrome/browser/ui/webui/chromeos, ash/ash_switches:
TBR=xiyuan@chromium.org,sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/12095106
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-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 |
6 files changed, 4 insertions, 424 deletions
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 |