diff options
author | dubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 10:00:39 +0000 |
---|---|---|
committer | dubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 10:00:39 +0000 |
commit | b7c377e5e5e0daf67378e96368c7b8bf63b1883d (patch) | |
tree | 023544da3eaeb51cebc1e2a88bc121f563d7b11d /chromeos | |
parent | 8fe381e9c7ebec0b30ba72791fbe43362003459a (diff) | |
download | chromium_src-b7c377e5e5e0daf67378e96368c7b8bf63b1883d.zip chromium_src-b7c377e5e5e0daf67378e96368c7b8bf63b1883d.tar.gz chromium_src-b7c377e5e5e0daf67378e96368c7b8bf63b1883d.tar.bz2 |
Reland 176858 - Deprecate ShillNetworkClient and add GeolocationHandler
> Deprecate ShillNetworkClient and add GeolocationHandler
>
> Shill deprecated Manager.Network which was being used to get wifi access point data.
> This eliminates the dead code and adds GeolocationHandler which currently queries Shill.Manager for geolocation data, and caches and returns the result.
>
> BUG=167987
> For chrome/browser/geolocation:
> TBR=joth@chromium.org
>
> Review URL: https://chromiumcodereview.appspot.com/11887008
TBR=stevenjb@chromium.org
BUG=None
Review URL: https://codereview.chromium.org/11880043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
31 files changed, 578 insertions, 780 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 61ca41a..e9e5848 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -69,8 +69,6 @@ 'dbus/shill_device_client.h', 'dbus/shill_manager_client.cc', 'dbus/shill_manager_client.h', - 'dbus/shill_network_client.cc', - 'dbus/shill_network_client.h', 'dbus/shill_profile_client.cc', 'dbus/shill_profile_client.h', 'dbus/shill_service_client.cc', @@ -129,6 +127,8 @@ 'network/cros_network_functions.h', 'network/device_state.cc', 'network/device_state.h', + 'network/geolocation_handler.cc', + 'network/geolocation_handler.h', 'network/managed_state.cc', 'network/managed_state.h', 'network/network_change_notifier_chromeos.cc', @@ -155,8 +155,6 @@ 'network/network_state_handler_observer.h', 'network/network_util.cc', 'network/network_util.h', - 'network/sms_watcher.cc', - 'network/sms_watcher.h', 'network/onc/onc_certificate_importer.cc', 'network/onc/onc_certificate_importer.h', 'network/onc/onc_constants.cc', @@ -182,6 +180,8 @@ 'network/shill_property_handler.h', 'network/shill_service_observer.cc', 'network/shill_service_observer.h', + 'network/sms_watcher.cc', + 'network/sms_watcher.h', 'power/power_state_override.cc', 'power/power_state_override.h', ], @@ -232,8 +232,6 @@ 'dbus/mock_shill_ipconfig_client.h', 'dbus/mock_shill_manager_client.cc', 'dbus/mock_shill_manager_client.h', - 'dbus/mock_shill_network_client.cc', - 'dbus/mock_shill_network_client.h', 'dbus/mock_shill_profile_client.cc', 'dbus/mock_shill_profile_client.h', 'dbus/mock_shill_service_client.cc', @@ -319,7 +317,6 @@ 'dbus/shill_device_client_unittest.cc', 'dbus/shill_ipconfig_client_unittest.cc', 'dbus/shill_manager_client_unittest.cc', - 'dbus/shill_network_client_unittest.cc', 'dbus/shill_profile_client_unittest.cc', 'dbus/shill_service_client_unittest.cc', 'dbus/gsm_sms_client_unittest.cc', @@ -338,6 +335,7 @@ 'dbus/modem_messaging_client_unittest.cc', 'disks/disk_mount_manager_unittest.cc', 'network/cros_network_functions_unittest.cc', + 'network/geolocation_handler_unittest.cc', 'network/network_change_notifier_chromeos_unittest.cc', 'network/network_configuration_handler_unittest.cc', 'network/network_device_handler_unittest.cc', diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index ff712e6..846fb64 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -25,7 +25,6 @@ #include "chromeos/dbus/shill_device_client.h" #include "chromeos/dbus/shill_ipconfig_client.h" #include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/dbus/shill_network_client.h" #include "chromeos/dbus/shill_profile_client.h" #include "chromeos/dbus/shill_service_client.h" #include "chromeos/dbus/gsm_sms_client.h" @@ -102,8 +101,6 @@ class DBusThreadManagerImpl : public DBusThreadManager { ShillIPConfigClient::Create(client_type, system_bus_.get())); shill_manager_client_.reset( ShillManagerClient::Create(client_type, system_bus_.get())); - shill_network_client_.reset( - ShillNetworkClient::Create(client_type, system_bus_.get())); shill_profile_client_.reset( ShillProfileClient::Create(client_type, system_bus_.get())); shill_service_client_.reset( @@ -253,10 +250,6 @@ class DBusThreadManagerImpl : public DBusThreadManager { return shill_manager_client_.get(); } - virtual ShillNetworkClient* GetShillNetworkClient() OVERRIDE { - return shill_network_client_.get(); - } - virtual ShillProfileClient* GetShillProfileClient() OVERRIDE { return shill_profile_client_.get(); } @@ -369,7 +362,6 @@ class DBusThreadManagerImpl : public DBusThreadManager { scoped_ptr<ShillDeviceClient> shill_device_client_; scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_; scoped_ptr<ShillManagerClient> shill_manager_client_; - scoped_ptr<ShillNetworkClient> shill_network_client_; scoped_ptr<ShillProfileClient> shill_profile_client_; scoped_ptr<ShillServiceClient> shill_service_client_; scoped_ptr<GsmSMSClient> gsm_sms_client_; diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h index 1d867e19..d63eefb 100644 --- a/chromeos/dbus/dbus_thread_manager.h +++ b/chromeos/dbus/dbus_thread_manager.h @@ -51,7 +51,6 @@ class SessionManagerClient; class ShillDeviceClient; class ShillIPConfigClient; class ShillManagerClient; -class ShillNetworkClient; class ShillProfileClient; class ShillServiceClient; class SpeechSynthesizerClient; @@ -148,7 +147,6 @@ class CHROMEOS_EXPORT DBusThreadManager { virtual ShillDeviceClient* GetShillDeviceClient() = 0; virtual ShillIPConfigClient* GetShillIPConfigClient() = 0; virtual ShillManagerClient* GetShillManagerClient() = 0; - virtual ShillNetworkClient* GetShillNetworkClient() = 0; virtual ShillProfileClient* GetShillProfileClient() = 0; virtual ShillServiceClient* GetShillServiceClient() = 0; virtual SMSClient* GetSMSClient() = 0; diff --git a/chromeos/dbus/mock_dbus_thread_manager.cc b/chromeos/dbus/mock_dbus_thread_manager.cc index 78fc74a..55e90c0 100644 --- a/chromeos/dbus/mock_dbus_thread_manager.cc +++ b/chromeos/dbus/mock_dbus_thread_manager.cc @@ -17,7 +17,6 @@ #include "chromeos/dbus/mock_shill_device_client.h" #include "chromeos/dbus/mock_shill_ipconfig_client.h" #include "chromeos/dbus/mock_shill_manager_client.h" -#include "chromeos/dbus/mock_shill_network_client.h" #include "chromeos/dbus/mock_shill_profile_client.h" #include "chromeos/dbus/mock_shill_service_client.h" #include "chromeos/dbus/mock_gsm_sms_client.h" @@ -52,7 +51,6 @@ MockDBusThreadManager::MockDBusThreadManager() mock_shill_device_client_(new MockShillDeviceClient), mock_shill_ipconfig_client_(new MockShillIPConfigClient), mock_shill_manager_client_(new MockShillManagerClient), - mock_shill_network_client_(new MockShillNetworkClient), mock_shill_profile_client_(new MockShillProfileClient), mock_shill_service_client_(new MockShillServiceClient), mock_gsm_sms_client_(new MockGsmSMSClient), @@ -90,8 +88,6 @@ MockDBusThreadManager::MockDBusThreadManager() .WillRepeatedly(Return(mock_shill_ipconfig_client())); EXPECT_CALL(*this, GetShillManagerClient()) .WillRepeatedly(Return(mock_shill_manager_client())); - EXPECT_CALL(*this, GetShillNetworkClient()) - .WillRepeatedly(Return(mock_shill_network_client())); EXPECT_CALL(*this, GetShillProfileClient()) .WillRepeatedly(Return(mock_shill_profile_client())); EXPECT_CALL(*this, GetShillServiceClient()) diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h index 053c6d4..be175f6 100644 --- a/chromeos/dbus/mock_dbus_thread_manager.h +++ b/chromeos/dbus/mock_dbus_thread_manager.h @@ -32,7 +32,6 @@ class MockDebugDaemonClient; class MockShillDeviceClient; class MockShillIPConfigClient; class MockShillManagerClient; -class MockShillNetworkClient; class MockShillProfileClient; class MockShillServiceClient; class MockGsmSMSClient; @@ -72,7 +71,6 @@ class MockDBusThreadManager : public DBusThreadManager { MOCK_METHOD0(GetShillDeviceClient, ShillDeviceClient*(void)); MOCK_METHOD0(GetShillIPConfigClient, ShillIPConfigClient*(void)); MOCK_METHOD0(GetShillManagerClient, ShillManagerClient*(void)); - MOCK_METHOD0(GetShillNetworkClient, ShillNetworkClient*(void)); MOCK_METHOD0(GetShillProfileClient, ShillProfileClient*(void)); MOCK_METHOD0(GetShillServiceClient, ShillServiceClient*(void)); MOCK_METHOD0(GetGsmSMSClient, GsmSMSClient*(void)); @@ -132,9 +130,6 @@ class MockDBusThreadManager : public DBusThreadManager { MockShillManagerClient* mock_shill_manager_client() { return mock_shill_manager_client_.get(); } - MockShillNetworkClient* mock_shill_network_client() { - return mock_shill_network_client_.get(); - } MockShillProfileClient* mock_shill_profile_client() { return mock_shill_profile_client_.get(); } @@ -188,7 +183,6 @@ class MockDBusThreadManager : public DBusThreadManager { scoped_ptr<MockShillDeviceClient> mock_shill_device_client_; scoped_ptr<MockShillIPConfigClient> mock_shill_ipconfig_client_; scoped_ptr<MockShillManagerClient> mock_shill_manager_client_; - scoped_ptr<MockShillNetworkClient> mock_shill_network_client_; scoped_ptr<MockShillProfileClient> mock_shill_profile_client_; scoped_ptr<MockShillServiceClient> mock_shill_service_client_; scoped_ptr<MockGsmSMSClient> mock_gsm_sms_client_; diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc index 61e751c..1816bf5 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc @@ -114,12 +114,6 @@ ShillManagerClient* return NULL; } -ShillNetworkClient* - MockDBusThreadManagerWithoutGMock::GetShillNetworkClient() { - NOTIMPLEMENTED(); - return NULL; -} - ShillProfileClient* MockDBusThreadManagerWithoutGMock::GetShillProfileClient() { NOTIMPLEMENTED(); diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h index a9f093e..46d1788 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h @@ -51,7 +51,6 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager { virtual ShillDeviceClient* GetShillDeviceClient() OVERRIDE; virtual ShillIPConfigClient* GetShillIPConfigClient() OVERRIDE; virtual ShillManagerClient* GetShillManagerClient() OVERRIDE; - virtual ShillNetworkClient* GetShillNetworkClient() OVERRIDE; virtual ShillProfileClient* GetShillProfileClient() OVERRIDE; virtual ShillServiceClient* GetShillServiceClient() OVERRIDE; virtual GsmSMSClient* GetGsmSMSClient() OVERRIDE; diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h index eb55a71..263b4b7 100644 --- a/chromeos/dbus/mock_shill_manager_client.h +++ b/chromeos/dbus/mock_shill_manager_client.h @@ -23,6 +23,8 @@ class MockShillManagerClient : public ShillManagerClient { void(ShillPropertyChangedObserver* observer)); MOCK_METHOD1(GetProperties, void(const DictionaryValueCallback& callback)); MOCK_METHOD0(CallGetPropertiesAndBlock, base::DictionaryValue*()); + MOCK_METHOD1(GetNetworksForGeolocation, + void(const DictionaryValueCallback& callback)); MOCK_METHOD4(SetProperty, void(const std::string& name, const base::Value& value, const base::Closure& callback, diff --git a/chromeos/dbus/mock_shill_network_client.cc b/chromeos/dbus/mock_shill_network_client.cc deleted file mode 100644 index 3052f47..0000000 --- a/chromeos/dbus/mock_shill_network_client.cc +++ /dev/null @@ -1,13 +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/dbus/mock_shill_network_client.h" - -namespace chromeos { - -MockShillNetworkClient::MockShillNetworkClient() {} - -MockShillNetworkClient::~MockShillNetworkClient() {} - -} // namespace chromeos diff --git a/chromeos/dbus/mock_shill_network_client.h b/chromeos/dbus/mock_shill_network_client.h deleted file mode 100644 index 28232a0..0000000 --- a/chromeos/dbus/mock_shill_network_client.h +++ /dev/null @@ -1,34 +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_DBUS_MOCK_SHILL_NETWORK_CLIENT_H_ -#define CHROMEOS_DBUS_MOCK_SHILL_NETWORK_CLIENT_H_ - -#include "chromeos/dbus/shill_network_client.h" -#include "chromeos/dbus/shill_property_changed_observer.h" -#include "dbus/object_path.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace chromeos { - -class MockShillNetworkClient : public ShillNetworkClient { - public: - MockShillNetworkClient(); - virtual ~MockShillNetworkClient(); - - MOCK_METHOD2(AddPropertyChangedObserver, - void(const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer)); - MOCK_METHOD2(RemovePropertyChangedObserver, - void(const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer)); - MOCK_METHOD2(GetProperties, void(const dbus::ObjectPath& network_path, - const DictionaryValueCallback& callback)); - MOCK_METHOD1(CallGetPropertiesAndBlock, - base::DictionaryValue*(const dbus::ObjectPath& network_path)); -}; - -} // namespace chromeos - -#endif // CHROMEOS_DBUS_MOCK_SHILL_NETWORK_CLIENT_H_ diff --git a/chromeos/dbus/shill_device_client.cc b/chromeos/dbus/shill_device_client.cc index efde010..e44eca1 100644 --- a/chromeos/dbus/shill_device_client.cc +++ b/chromeos/dbus/shill_device_client.cc @@ -375,8 +375,7 @@ class ShillDeviceClientStubImpl : public ShillDeviceClient, virtual void AddDevice(const std::string& device_path, const std::string& type, - const std::string& object_path, - const std::string& connection_path) OVERRIDE { + const std::string& object_path) OVERRIDE { base::DictionaryValue* properties = GetDeviceProperties(device_path); properties->SetWithoutPathExpansion( flimflam::kTypeProperty, @@ -386,7 +385,7 @@ class ShillDeviceClientStubImpl : public ShillDeviceClient, base::Value::CreateStringValue(object_path)); properties->SetWithoutPathExpansion( flimflam::kDBusConnectionProperty, - base::Value::CreateStringValue(connection_path)); + base::Value::CreateStringValue("/stub")); } virtual void RemoveDevice(const std::string& device_path) OVERRIDE { @@ -397,18 +396,25 @@ class ShillDeviceClientStubImpl : public ShillDeviceClient, stub_devices_.Clear(); } + virtual void SetDeviceProperty(const std::string& device_path, + const std::string& name, + const base::Value& value) { + SetProperty(dbus::ObjectPath(device_path), name, value, + base::Bind(&base::DoNothing), + base::Bind(&ShillDeviceClientStubImpl::ErrorFunction)); + } + private: typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; void SetDefaultProperties() { // Add a wifi device. Note: path matches Manager entry. - AddDevice("stub_wifi_device1", flimflam::kTypeWifi, - "/device/wifi1", "/stub"); + AddDevice("stub_wifi_device1", flimflam::kTypeWifi, "/device/wifi1"); // Add a cellular device. Used in SMS stub. Note: path matches // Manager entry. AddDevice("stub_cellular_device1", flimflam::kTypeCellular, - "/device/cellular1", "/stub"); + "/device/cellular1"); } void PassStubDeviceProperties(const dbus::ObjectPath& device_path, @@ -471,6 +477,11 @@ class ShillDeviceClientStubImpl : public ShillDeviceClient, return *observer_list; } + static void ErrorFunction(const std::string& error_name, + const std::string& error_message) { + LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; + } + // Dictionary of <device_name, Dictionary>. base::DictionaryValue stub_devices_; // Observer list for each device. diff --git a/chromeos/dbus/shill_device_client.h b/chromeos/dbus/shill_device_client.h index 7eb415e..5f7b64d 100644 --- a/chromeos/dbus/shill_device_client.h +++ b/chromeos/dbus/shill_device_client.h @@ -46,10 +46,12 @@ class CHROMEOS_EXPORT ShillDeviceClient { public: virtual void AddDevice(const std::string& device_path, const std::string& type, - const std::string& object_path, - const std::string& connection_path) = 0; + const std::string& object_path) = 0; virtual void RemoveDevice(const std::string& device_path) = 0; virtual void ClearDevices() = 0; + virtual void SetDeviceProperty(const std::string& device_path, + const std::string& name, + const base::Value& value) = 0; protected: ~TestInterface() {} diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc index 6b946a1..38ff9ba 100644 --- a/chromeos/dbus/shill_manager_client.cc +++ b/chromeos/dbus/shill_manager_client.cc @@ -82,6 +82,13 @@ class ShillManagerClientImpl : public ShillManagerClient { return helper_.CallDictionaryValueMethodAndBlock(&method_call); } + virtual void GetNetworksForGeolocation( + const DictionaryValueCallback& callback) OVERRIDE { + dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, + shill::kGetNetworksForGeolocation); + helper_.CallDictionaryValueMethod(&method_call, callback); + } + virtual void SetProperty(const std::string& name, const base::Value& value, const base::Closure& callback, @@ -221,6 +228,17 @@ class ShillManagerClientStubImpl : public ShillManagerClient, return stub_properties_.DeepCopy(); } + virtual void GetNetworksForGeolocation( + const DictionaryValueCallback& callback) OVERRIDE { + if (callback.is_null()) + return; + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind( + &ShillManagerClientStubImpl::PassStubGeoNetworks, + weak_ptr_factory_.GetWeakPtr(), + callback)); + } + virtual void SetProperty(const std::string& name, const base::Value& value, const base::Closure& callback, @@ -328,6 +346,10 @@ class ShillManagerClientStubImpl : public ShillManagerClient, } } + virtual void ResetDevices() OVERRIDE { + stub_properties_.Remove(flimflam::kDevicesProperty, NULL); + } + virtual void AddService(const std::string& service_path, bool add_to_watch_list) OVERRIDE { if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( @@ -401,6 +423,17 @@ class ShillManagerClientStubImpl : public ShillManagerClient, stub_properties_.Clear(); } + virtual void AddGeoNetwork(const std::string& technology, + const base::DictionaryValue& network) OVERRIDE { + base::ListValue* list_value = NULL; + if (!stub_geo_networks_.GetListWithoutPathExpansion( + technology, &list_value)) { + list_value = new base::ListValue; + stub_geo_networks_.Set(technology, list_value); + } + list_value->Append(network.DeepCopy()); + } + private: void AddServiceToWatchList(const std::string& service_path) { if (GetListProperty( @@ -432,6 +465,10 @@ class ShillManagerClientStubImpl : public ShillManagerClient, callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_properties_); } + void PassStubGeoNetworks(const DictionaryValueCallback& callback) const { + callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); + } + void CallNotifyObserversPropertyChanged(const std::string& property, int delay_ms) { // Avoid unnecessary delayed task if we have no observers (e.g. during @@ -467,7 +504,11 @@ class ShillManagerClientStubImpl : public ShillManagerClient, return list_property; } + // Dictionary of property name -> property value base::DictionaryValue stub_properties_; + // Dictionary of technology -> list of property dictionaries + base::DictionaryValue stub_geo_networks_; + ObserverList<ShillPropertyChangedObserver> observer_list_; // Note: This should remain the last member so it'll be destroyed and diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h index fea40da..8afce00 100644 --- a/chromeos/dbus/shill_manager_client.h +++ b/chromeos/dbus/shill_manager_client.h @@ -38,6 +38,7 @@ class CHROMEOS_EXPORT ShillManagerClient { public: virtual void AddDevice(const std::string& device_path) = 0; virtual void RemoveDevice(const std::string& device_path) = 0; + virtual void ResetDevices() = 0; virtual void AddService(const std::string& service_path, bool add_to_watch_list) = 0; virtual void AddServiceAtIndex(const std::string& service_path, @@ -46,6 +47,8 @@ class CHROMEOS_EXPORT ShillManagerClient { virtual void RemoveService(const std::string& service_path) = 0; virtual void AddTechnology(const std::string& type, bool enabled) = 0; virtual void RemoveTechnology(const std::string& type) = 0; + virtual void AddGeoNetwork(const std::string& technology, + const base::DictionaryValue& network) = 0; // Used to reset all properties; does not notify observers. virtual void ClearProperties() = 0; @@ -77,10 +80,15 @@ class CHROMEOS_EXPORT ShillManagerClient { // method call finishes. The caller is responsible to delete the result. // Thie method returns NULL when method call fails. // - // TODO(hashimoto): Refactor CrosGetWifiAccessPoints and remove this method. + // TODO(hashimoto): Refactor blocking calls and remove this method. // crosbug.com/29902 virtual base::DictionaryValue* CallGetPropertiesAndBlock() = 0; + // Calls GetNetworksForGeolocation method. + // |callback| is called after the method call succeeds. + virtual void GetNetworksForGeolocation( + const DictionaryValueCallback& callback) = 0; + // Calls SetProperty method. // |callback| is called after the method call succeeds. virtual void SetProperty(const std::string& name, diff --git a/chromeos/dbus/shill_manager_client_unittest.cc b/chromeos/dbus/shill_manager_client_unittest.cc index 73e4567..a4a241e 100644 --- a/chromeos/dbus/shill_manager_client_unittest.cc +++ b/chromeos/dbus/shill_manager_client_unittest.cc @@ -210,6 +210,56 @@ TEST_F(ShillManagerClientTest, CallGetPropertiesAndBlock) { EXPECT_TRUE(value.Equals(result.get())); } +TEST_F(ShillManagerClientTest, GetNetworksForGeolocation) { + // Create response. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + + dbus::MessageWriter writer(response.get()); + dbus::MessageWriter type_dict_writer(NULL); + writer.OpenArray("{sv}", &type_dict_writer); + dbus::MessageWriter type_entry_writer(NULL); + type_dict_writer.OpenDictEntry(&type_entry_writer); + type_entry_writer.AppendString(flimflam::kTypeWifi); + dbus::MessageWriter variant_writer(NULL); + type_entry_writer.OpenVariant("aa{ss}", &variant_writer); + dbus::MessageWriter wap_list_writer(NULL); + variant_writer.OpenArray("a{ss}", &wap_list_writer); + dbus::MessageWriter property_dict_writer(NULL); + wap_list_writer.OpenArray("{ss}", &property_dict_writer); + dbus::MessageWriter property_entry_writer(NULL); + property_dict_writer.OpenDictEntry(&property_entry_writer); + property_entry_writer.AppendString(shill::kGeoMacAddressProperty); + property_entry_writer.AppendString("01:23:45:67:89:AB"); + property_dict_writer.CloseContainer(&property_entry_writer); + wap_list_writer.CloseContainer(&property_dict_writer); + variant_writer.CloseContainer(&wap_list_writer); + type_entry_writer.CloseContainer(&wap_list_writer); + type_dict_writer.CloseContainer(&type_entry_writer); + writer.CloseContainer(&type_dict_writer); + + + // Create the expected value. + base::DictionaryValue type_dict_value; + base::ListValue* type_entry_value = new base::ListValue; + base::DictionaryValue* property_dict_value = new base::DictionaryValue; + property_dict_value->SetWithoutPathExpansion( + shill::kGeoMacAddressProperty, + base::Value::CreateStringValue("01:23:45:67:89:AB")); + type_entry_value->Append(property_dict_value); + type_dict_value.SetWithoutPathExpansion("wifi", type_entry_value); + + // Set expectations. + PrepareForMethodCall(shill::kGetNetworksForGeolocation, + base::Bind(&ExpectNoArgument), + response.get()); + // Call method. + client_->GetNetworksForGeolocation(base::Bind(&ExpectDictionaryValueResult, + &type_dict_value)); + + // Run the message loop. + message_loop_.RunUntilIdle(); +} + TEST_F(ShillManagerClientTest, SetProperty) { // Create response. scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); diff --git a/chromeos/dbus/shill_network_client.cc b/chromeos/dbus/shill_network_client.cc deleted file mode 100644 index faa399b..0000000 --- a/chromeos/dbus/shill_network_client.cc +++ /dev/null @@ -1,145 +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/dbus/shill_network_client.h" - -#include "base/bind.h" -#include "base/message_loop.h" -#include "base/stl_util.h" -#include "base/values.h" -#include "chromeos/dbus/shill_property_changed_observer.h" -#include "dbus/bus.h" -#include "dbus/message.h" -#include "dbus/object_path.h" -#include "dbus/object_proxy.h" -#include "dbus/values_util.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -namespace chromeos { - -namespace { - -// The ShillNetworkClient implementation. -class ShillNetworkClientImpl : public ShillNetworkClient { - public: - explicit ShillNetworkClientImpl(dbus::Bus* bus) - : bus_(bus), - helpers_deleter_(&helpers_) { - } - - ////////////////////////////////////// - // ShillNetworkClient overrides. - virtual void AddPropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) OVERRIDE { - GetHelper(network_path)->AddPropertyChangedObserver(observer); - } - - virtual void RemovePropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) OVERRIDE { - GetHelper(network_path)->RemovePropertyChangedObserver(observer); - } - - virtual void GetProperties(const dbus::ObjectPath& network_path, - const DictionaryValueCallback& callback) OVERRIDE { - dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface, - flimflam::kGetPropertiesFunction); - GetHelper(network_path)->CallDictionaryValueMethod(&method_call, callback); - } - - virtual base::DictionaryValue* CallGetPropertiesAndBlock( - const dbus::ObjectPath& network_path) OVERRIDE { - dbus::MethodCall method_call(flimflam::kFlimflamNetworkInterface, - flimflam::kGetPropertiesFunction); - return GetHelper(network_path)->CallDictionaryValueMethodAndBlock( - &method_call); - } - - private: - typedef std::map<std::string, ShillClientHelper*> HelperMap; - - // Returns the corresponding ShillClientHelper for the profile. - ShillClientHelper* GetHelper(const dbus::ObjectPath& network_path) { - HelperMap::iterator it = helpers_.find(network_path.value()); - if (it != helpers_.end()) - return it->second; - - // There is no helper for the profile, create it. - dbus::ObjectProxy* object_proxy = - bus_->GetObjectProxy(flimflam::kFlimflamServiceName, network_path); - ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); - helper->MonitorPropertyChanged(flimflam::kFlimflamNetworkInterface); - helpers_.insert(HelperMap::value_type(network_path.value(), helper)); - return helper; - } - - dbus::Bus* bus_; - HelperMap helpers_; - STLValueDeleter<HelperMap> helpers_deleter_; - - DISALLOW_COPY_AND_ASSIGN(ShillNetworkClientImpl); -}; - -// A stub implementation of ShillNetworkClient. -class ShillNetworkClientStubImpl : public ShillNetworkClient { - public: - ShillNetworkClientStubImpl() : weak_ptr_factory_(this) {} - - virtual ~ShillNetworkClientStubImpl() {} - - ///////////////////////////////////// - // ShillNetworkClient overrides. - virtual void AddPropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) OVERRIDE {} - - virtual void RemovePropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) OVERRIDE {} - - virtual void GetProperties(const dbus::ObjectPath& network_path, - const DictionaryValueCallback& callback) OVERRIDE { - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&ShillNetworkClientStubImpl::PassEmptyDictionaryValue, - weak_ptr_factory_.GetWeakPtr(), - callback)); - } - - virtual base::DictionaryValue* CallGetPropertiesAndBlock( - const dbus::ObjectPath& network_path) OVERRIDE { - return new base::DictionaryValue; - } - - private: - void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { - base::DictionaryValue dictionary; - callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); - } - - // Note: This should remain the last member so it'll be destroyed and - // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory<ShillNetworkClientStubImpl> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(ShillNetworkClientStubImpl); -}; - -} // namespace - -ShillNetworkClient::ShillNetworkClient() {} - -ShillNetworkClient::~ShillNetworkClient() {} - -// static -ShillNetworkClient* ShillNetworkClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { - if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillNetworkClientImpl(bus); - DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); - return new ShillNetworkClientStubImpl(); -} - -} // namespace chromeos diff --git a/chromeos/dbus/shill_network_client.h b/chromeos/dbus/shill_network_client.h deleted file mode 100644 index 2221b80..0000000 --- a/chromeos/dbus/shill_network_client.h +++ /dev/null @@ -1,83 +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_DBUS_SHILL_NETWORK_CLIENT_H_ -#define CHROMEOS_DBUS_SHILL_NETWORK_CLIENT_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "chromeos/chromeos_export.h" -#include "chromeos/dbus/dbus_client_implementation_type.h" -#include "chromeos/dbus/shill_client_helper.h" - -namespace base { - -class Value; -class DictionaryValue; - -} // namespace base - -namespace dbus { - -class Bus; -class ObjectPath; - -} // namespace dbus - -namespace chromeos { - -class ShillPropertyChangedObserver; - -// ShillNetworkClient is used to communicate with the Shill Network -// service. All methods should be called from the origin thread which -// initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ShillNetworkClient { - public: - typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; - typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; - - virtual ~ShillNetworkClient(); - - // Factory function, creates a new instance which is owned by the caller. - // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillNetworkClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); - - // Adds a property changed |observer| for the network at |network_path|. - virtual void AddPropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) = 0; - - // Removes a property changed |observer| for the network at |network_path|. - virtual void RemovePropertyChangedObserver( - const dbus::ObjectPath& network_path, - ShillPropertyChangedObserver* observer) = 0; - - // Calls GetProperties method. - // |callback| is called after the method call succeeds. - virtual void GetProperties(const dbus::ObjectPath& network_path, - const DictionaryValueCallback& callback) = 0; - - // DEPRECATED DO NOT USE: Calls GetProperties method and blocks until the - // method call finishes. The caller is responsible to delete the result. - // Thie method returns NULL when method call fails. - // - // TODO(hashimoto): Refactor CrosGetWifiAccessPoints and remove this method. - // crosbug.com/29902 - virtual base::DictionaryValue* CallGetPropertiesAndBlock( - const dbus::ObjectPath& network_path) = 0; - - protected: - // Create() should be used instead. - ShillNetworkClient(); - - private: - DISALLOW_COPY_AND_ASSIGN(ShillNetworkClient); -}; - -} // namespace chromeos - -#endif // CHROMEOS_DBUS_SHILL_NETWORK_CLIENT_H_ diff --git a/chromeos/dbus/shill_network_client_unittest.cc b/chromeos/dbus/shill_network_client_unittest.cc deleted file mode 100644 index 7effd88..0000000 --- a/chromeos/dbus/shill_network_client_unittest.cc +++ /dev/null @@ -1,184 +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 "base/bind.h" -#include "base/values.h" -#include "chromeos/dbus/shill_client_unittest_base.h" -#include "chromeos/dbus/shill_network_client.h" -#include "dbus/message.h" -#include "dbus/values_util.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -using testing::_; -using testing::ByRef; - -namespace chromeos { - -namespace { - -const char kExampleNetworkPath[] = "/foo/bar"; - -} // namespace - -class ShillNetworkClientTest : public ShillClientUnittestBase { - public: - ShillNetworkClientTest() - : ShillClientUnittestBase( - flimflam::kFlimflamNetworkInterface, - dbus::ObjectPath(kExampleNetworkPath)) { - } - - virtual void SetUp() { - ShillClientUnittestBase::SetUp(); - // Create a client with the mock bus. - client_.reset(ShillNetworkClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_)); - // Run the message loop to run the signal connection result callback. - message_loop_.RunUntilIdle(); - } - - virtual void TearDown() { - ShillClientUnittestBase::TearDown(); - } - - protected: - scoped_ptr<ShillNetworkClient> client_; -}; - -TEST_F(ShillNetworkClientTest, PropertyChanged) { - // Create a signal. - const base::FundamentalValue kConnected(true); - dbus::Signal signal(flimflam::kFlimflamNetworkInterface, - flimflam::kMonitorPropertyChanged); - dbus::MessageWriter writer(&signal); - writer.AppendString(flimflam::kConnectedProperty); - dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); - - // Set expectations. - MockPropertyChangeObserver observer; - EXPECT_CALL(observer, - OnPropertyChanged( - flimflam::kConnectedProperty, - ValueEq(ByRef(kConnected)))).Times(1); - - // Add the observer - client_->AddPropertyChangedObserver( - dbus::ObjectPath(kExampleNetworkPath), - &observer); - - // Run the signal callback. - SendPropertyChangedSignal(&signal); - - // Remove the observer. - client_->RemovePropertyChangedObserver( - dbus::ObjectPath(kExampleNetworkPath), - &observer); - - EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0); - - // Run the signal callback again and make sure the observer isn't called. - SendPropertyChangedSignal(&signal); -} - -TEST_F(ShillNetworkClientTest, GetProperties) { - const char kAddress[] = "address"; - const char kName[] = "name"; - const uint8 kSignalStrength = 1; - const uint32 kWifiChannel = 1; - const bool kConnected = true; - - // Create response. - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter array_writer(NULL); - writer.OpenArray("{sv}", &array_writer); - dbus::MessageWriter entry_writer(NULL); - // Append address. - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kAddressProperty); - entry_writer.AppendVariantOfString(kAddress); - array_writer.CloseContainer(&entry_writer); - // Append name. - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kNameProperty); - entry_writer.AppendVariantOfString(kName); - array_writer.CloseContainer(&entry_writer); - // Append signal strength. - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kSignalStrengthProperty); - entry_writer.AppendVariantOfByte(kSignalStrength); - array_writer.CloseContainer(&entry_writer); - // Append Wifi channel. - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kWifiChannelProperty); - entry_writer.AppendVariantOfUint32(kWifiChannel); - array_writer.CloseContainer(&entry_writer); - // Append connected. - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kConnectedProperty); - entry_writer.AppendVariantOfBool(kConnected); - array_writer.CloseContainer(&entry_writer); - writer.CloseContainer(&array_writer); - - // Create the expected value. - base::DictionaryValue value; - value.SetWithoutPathExpansion(flimflam::kAddressProperty, - base::Value::CreateStringValue(kAddress)); - value.SetWithoutPathExpansion(flimflam::kNameProperty, - base::Value::CreateStringValue(kName)); - value.SetWithoutPathExpansion( - flimflam::kSignalStrengthProperty, - base::Value::CreateIntegerValue(kSignalStrength)); - // WiFi.Channel is set as a double because uint32 is larger than int32. - value.SetWithoutPathExpansion(flimflam::kWifiChannelProperty, - base::Value::CreateDoubleValue(kWifiChannel)); - value.SetWithoutPathExpansion(flimflam::kConnectedProperty, - base::Value::CreateBooleanValue(kConnected)); - - // Set expectations. - PrepareForMethodCall(flimflam::kGetPropertiesFunction, - base::Bind(&ExpectNoArgument), - response.get()); - // Call method. - client_->GetProperties(dbus::ObjectPath(kExampleNetworkPath), - base::Bind(&ExpectDictionaryValueResult, &value)); - // Run the message loop. - message_loop_.RunUntilIdle(); -} - -TEST_F(ShillNetworkClientTest, CallGetPropertiesAndBlock) { - const char kName[] = "name"; - - // Create response. - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter array_writer(NULL); - writer.OpenArray("{sv}", &array_writer); - dbus::MessageWriter entry_writer(NULL); - array_writer.OpenDictEntry(&entry_writer); - entry_writer.AppendString(flimflam::kNameProperty); - entry_writer.AppendVariantOfString(kName); - array_writer.CloseContainer(&entry_writer); - writer.CloseContainer(&array_writer); - - // Create the expected value. - base::DictionaryValue value; - value.SetWithoutPathExpansion(flimflam::kNameProperty, - base::Value::CreateStringValue(kName)); - - // Set expectations. - PrepareForMethodCall(flimflam::kGetPropertiesFunction, - base::Bind(&ExpectNoArgument), - response.get()); - // Call method. - scoped_ptr<base::DictionaryValue> result( - client_->CallGetPropertiesAndBlock( - dbus::ObjectPath(kExampleNetworkPath))); - - ASSERT_TRUE(result.get()); - EXPECT_TRUE(result->Equals(&value)); -} - -} // namespace chromeos diff --git a/chromeos/network/cros_network_functions.cc b/chromeos/network/cros_network_functions.cc index 6339bd4..c7d02b1 100644 --- a/chromeos/network/cros_network_functions.cc +++ b/chromeos/network/cros_network_functions.cc @@ -12,7 +12,6 @@ #include "chromeos/dbus/shill_device_client.h" #include "chromeos/dbus/shill_ipconfig_client.h" #include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/dbus/shill_network_client.h" #include "chromeos/dbus/shill_profile_client.h" #include "chromeos/dbus/shill_property_changed_observer.h" #include "chromeos/dbus/shill_service_client.h" @@ -650,92 +649,6 @@ void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) { base::Bind(&DoNothingWithCallStatus)); } -bool CrosGetWifiAccessPoints(WifiAccessPointVector* result) { - scoped_ptr<base::DictionaryValue> manager_properties( - DBusThreadManager::Get()->GetShillManagerClient()-> - CallGetPropertiesAndBlock()); - if (!manager_properties.get()) { - LOG(WARNING) << "Couldn't read managers's properties"; - return false; - } - - base::ListValue* devices = NULL; - if (!manager_properties->GetListWithoutPathExpansion( - flimflam::kDevicesProperty, &devices)) { - LOG(WARNING) << flimflam::kDevicesProperty << " property not found"; - return false; - } - const base::Time now = base::Time::Now(); - bool found_at_least_one_device = false; - result->clear(); - for (size_t i = 0; i < devices->GetSize(); i++) { - std::string device_path; - if (!devices->GetString(i, &device_path)) { - LOG(WARNING) << "Couldn't get devices[" << i << "]"; - continue; - } - scoped_ptr<base::DictionaryValue> device_properties( - DBusThreadManager::Get()->GetShillDeviceClient()-> - CallGetPropertiesAndBlock(dbus::ObjectPath(device_path))); - if (!device_properties.get()) { - LOG(WARNING) << "Couldn't read device's properties " << device_path; - continue; - } - - base::ListValue* networks = NULL; - if (!device_properties->GetListWithoutPathExpansion( - flimflam::kNetworksProperty, &networks)) - continue; // Some devices do not list networks, e.g. ethernet. - - base::Value* device_powered_value = NULL; - bool device_powered = false; - if (device_properties->GetWithoutPathExpansion( - flimflam::kPoweredProperty, &device_powered_value) && - device_powered_value->GetAsBoolean(&device_powered) && - !device_powered) - continue; // Skip devices that are not powered up. - - int scan_interval = 0; - device_properties->GetIntegerWithoutPathExpansion( - flimflam::kScanIntervalProperty, &scan_interval); - - found_at_least_one_device = true; - for (size_t j = 0; j < networks->GetSize(); j++) { - std::string network_path; - if (!networks->GetString(j, &network_path)) { - LOG(WARNING) << "Couldn't get networks[" << j << "]"; - continue; - } - - scoped_ptr<base::DictionaryValue> network_properties( - DBusThreadManager::Get()->GetShillNetworkClient()-> - CallGetPropertiesAndBlock(dbus::ObjectPath(network_path))); - if (!network_properties.get()) { - LOG(WARNING) << "Couldn't read network's properties " << network_path; - continue; - } - - // Using the scan interval as a proxy for approximate age. - // TODO(joth): Replace with actual age, when available from dbus. - const int age_seconds = scan_interval; - WifiAccessPoint ap; - network_properties->GetStringWithoutPathExpansion( - flimflam::kAddressProperty, &ap.mac_address); - network_properties->GetStringWithoutPathExpansion( - flimflam::kNameProperty, &ap.name); - ap.timestamp = now - base::TimeDelta::FromSeconds(age_seconds); - network_properties->GetIntegerWithoutPathExpansion( - flimflam::kSignalStrengthProperty, &ap.signal_strength); - network_properties->GetIntegerWithoutPathExpansion( - flimflam::kWifiChannelProperty, &ap.channel); - result->push_back(ap); - } - } - if (!found_at_least_one_device) - return false; // No powered device found that has a 'Networks' array. - return true; -} - void CrosConfigureService(const base::DictionaryValue& properties) { DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( properties, base::Bind(&DoNothing), diff --git a/chromeos/network/cros_network_functions.h b/chromeos/network/cros_network_functions.h index b964857..5ff93be 100644 --- a/chromeos/network/cros_network_functions.h +++ b/chromeos/network/cros_network_functions.h @@ -253,14 +253,6 @@ CHROMEOS_EXPORT bool CrosListIPConfigsAndBlock( CHROMEOS_EXPORT void CrosRequestIPConfigRefresh( const std::string& ipconfig_path); -// Reads out the results of the last wifi scan. These results are not -// pre-cached in the library, so the call may block whilst the results are -// read over IPC. -// Returns false if an error occurred in reading the results. Note that -// a true return code only indicates the result set was successfully read, -// it does not imply a scan has successfully completed yet. -CHROMEOS_EXPORT bool CrosGetWifiAccessPoints(WifiAccessPointVector* result); - // Configures the network service specified by |properties|. CHROMEOS_EXPORT void CrosConfigureService( const base::DictionaryValue& properties); diff --git a/chromeos/network/cros_network_functions_unittest.cc b/chromeos/network/cros_network_functions_unittest.cc index d224f26..3007639 100644 --- a/chromeos/network/cros_network_functions_unittest.cc +++ b/chromeos/network/cros_network_functions_unittest.cc @@ -10,7 +10,6 @@ #include "chromeos/dbus/mock_shill_device_client.h" #include "chromeos/dbus/mock_shill_ipconfig_client.h" #include "chromeos/dbus/mock_shill_manager_client.h" -#include "chromeos/dbus/mock_shill_network_client.h" #include "chromeos/dbus/mock_shill_profile_client.h" #include "chromeos/dbus/mock_shill_service_client.h" #include "chromeos/network/cros_network_functions.h" @@ -113,8 +112,6 @@ class CrosNetworkFunctionsTest : public testing::Test { mock_dbus_thread_manager->mock_shill_ipconfig_client(); mock_manager_client_ = mock_dbus_thread_manager->mock_shill_manager_client(); - mock_network_client_ = - mock_dbus_thread_manager->mock_shill_network_client(); mock_profile_client_ = mock_dbus_thread_manager->mock_shill_profile_client(); mock_service_client_ = @@ -172,7 +169,6 @@ class CrosNetworkFunctionsTest : public testing::Test { MockShillDeviceClient* mock_device_client_; MockShillIPConfigClient* mock_ipconfig_client_; MockShillManagerClient* mock_manager_client_; - MockShillNetworkClient* mock_network_client_; MockShillProfileClient* mock_profile_client_; MockShillServiceClient* mock_service_client_; MockGsmSMSClient* mock_gsm_sms_client_; @@ -865,70 +861,6 @@ TEST_F(CrosNetworkFunctionsTest, CrosListIPConfigsAndBlock) { EXPECT_EQ(ipconfig_path, result_ipconfig_paths[0]); } -TEST_F(CrosNetworkFunctionsTest, CrosGetWifiAccessPoints) { - const std::string device_path = "/device/path"; - base::ListValue* devices = new base::ListValue; - devices->Append(new base::StringValue(device_path)); - base::DictionaryValue* manager_properties = new base::DictionaryValue; - manager_properties->SetWithoutPathExpansion( - flimflam::kDevicesProperty, devices); - - const int kScanInterval = 42; - const std::string network_path = "/network/path"; - base::ListValue* networks = new base::ListValue; - networks->Append(new base::StringValue(network_path)); - base::DictionaryValue* device_properties = new base::DictionaryValue; - device_properties->SetWithoutPathExpansion( - flimflam::kNetworksProperty, networks); - device_properties->SetWithoutPathExpansion( - flimflam::kPoweredProperty, base::Value::CreateBooleanValue(true)); - device_properties->SetWithoutPathExpansion( - flimflam::kScanIntervalProperty, - base::Value::CreateIntegerValue(kScanInterval)); - - const int kSignalStrength = 10; - const int kWifiChannel = 3; - const std::string address = "address"; - const std::string name = "name"; - const base::Time expected_timestamp = - base::Time::Now() - base::TimeDelta::FromSeconds(kScanInterval); - const base::TimeDelta acceptable_timestamp_range = - base::TimeDelta::FromSeconds(1); - - base::DictionaryValue* network_properties = new base::DictionaryValue; - network_properties->SetWithoutPathExpansion( - flimflam::kAddressProperty, new base::StringValue(address)); - network_properties->SetWithoutPathExpansion( - flimflam::kNameProperty, new base::StringValue(name)); - network_properties->SetWithoutPathExpansion( - flimflam::kSignalStrengthProperty, - base::Value::CreateIntegerValue(kSignalStrength)); - network_properties->SetWithoutPathExpansion( - flimflam::kWifiChannelProperty, - base::Value::CreateIntegerValue(kWifiChannel)); - - // Set expectations. - EXPECT_CALL(*mock_manager_client_, CallGetPropertiesAndBlock()) - .WillOnce(Return(manager_properties)); - EXPECT_CALL(*mock_device_client_, - CallGetPropertiesAndBlock(dbus::ObjectPath(device_path))) - .WillOnce(Return(device_properties)); - EXPECT_CALL(*mock_network_client_, - CallGetPropertiesAndBlock(dbus::ObjectPath(network_path))) - .WillOnce(Return(network_properties)); - - // Call function. - WifiAccessPointVector aps; - ASSERT_TRUE(CrosGetWifiAccessPoints(&aps)); - ASSERT_EQ(1U, aps.size()); - EXPECT_EQ(address, aps[0].mac_address); - EXPECT_EQ(name, aps[0].name); - EXPECT_LE(expected_timestamp - acceptable_timestamp_range, aps[0].timestamp); - EXPECT_GE(expected_timestamp + acceptable_timestamp_range, aps[0].timestamp); - EXPECT_EQ(kSignalStrength, aps[0].signal_strength); - EXPECT_EQ(kWifiChannel, aps[0].channel); -} - TEST_F(CrosNetworkFunctionsTest, CrosConfigureService) { const std::string key1 = "key1"; const std::string string1 = "string1"; diff --git a/chromeos/network/geolocation_handler.cc b/chromeos/network/geolocation_handler.cc new file mode 100644 index 0000000..c08ea14 --- /dev/null +++ b/chromeos/network/geolocation_handler.cc @@ -0,0 +1,174 @@ +// Copyright (c) 2013 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/geolocation_handler.h" + +#include "base/bind.h" +#include "base/string_number_conversions.h" +#include "base/values.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/shill_manager_client.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +static GeolocationHandler* g_geolocation_handler = NULL; + +GeolocationHandler::GeolocationHandler() + : wifi_enabled_(false), + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} + +GeolocationHandler::~GeolocationHandler() { + ShillManagerClient* manager_client = + DBusThreadManager::Get()->GetShillManagerClient(); + if (manager_client) + manager_client->RemovePropertyChangedObserver(this); +} + +void GeolocationHandler::Init() { + ShillManagerClient* manager_client = + DBusThreadManager::Get()->GetShillManagerClient(); + manager_client->GetProperties( + base::Bind(&GeolocationHandler::ManagerPropertiesCallback, + weak_ptr_factory_.GetWeakPtr())); + manager_client->AddPropertyChangedObserver(this); +} + +// static +void GeolocationHandler::Initialize() { + CHECK(!g_geolocation_handler); + g_geolocation_handler = new GeolocationHandler(); + g_geolocation_handler->Init(); +} + +// static +void GeolocationHandler::Shutdown() { + CHECK(g_geolocation_handler); + delete g_geolocation_handler; + g_geolocation_handler = NULL; +} + +// static +GeolocationHandler* GeolocationHandler::Get() { + CHECK(g_geolocation_handler) + << "GeolocationHandler::Get() called before Initialize()"; + return g_geolocation_handler; +} + +bool GeolocationHandler::GetWifiAccessPoints( + WifiAccessPointVector* access_points, int64* age_ms) { + if (!wifi_enabled_) + return false; + // Always request updated access points. + RequestWifiAccessPoints(); + // If no data has been received, return false. + if (geolocation_received_time_.is_null()) + return false; + if (access_points) + *access_points = wifi_access_points_; + if (age_ms) { + base::TimeDelta dtime = base::Time::Now() - geolocation_received_time_; + *age_ms = dtime.InMilliseconds(); + } + return true; +} + +void GeolocationHandler::OnPropertyChanged(const std::string& key, + const base::Value& value) { + HandlePropertyChanged(key, value); +} + +//------------------------------------------------------------------------------ +// Private methods + +void GeolocationHandler::ManagerPropertiesCallback( + DBusMethodCallStatus call_status, + const base::DictionaryValue& properties) { + const base::Value* value = NULL; + if (properties.Get(flimflam::kEnabledTechnologiesProperty, &value) && value) + HandlePropertyChanged(flimflam::kEnabledTechnologiesProperty, *value); +} + +void GeolocationHandler::HandlePropertyChanged(const std::string& key, + const base::Value& value) { + if (key != flimflam::kEnabledTechnologiesProperty) + return; + const base::ListValue* technologies = NULL; + if (!value.GetAsList(&technologies) || !technologies) + return; + bool wifi_was_enabled = wifi_enabled_; + wifi_enabled_ = false; + for (base::ListValue::const_iterator iter = technologies->begin(); + iter != technologies->end(); ++iter) { + std::string technology; + (*iter)->GetAsString(&technology); + if (technology == flimflam::kTypeWifi) { + wifi_enabled_ = true; + break; + } + } + if (!wifi_was_enabled && wifi_enabled_) + RequestWifiAccessPoints(); // Request initial location data. +} + +void GeolocationHandler::RequestWifiAccessPoints() { + DBusThreadManager::Get()->GetShillManagerClient()->GetNetworksForGeolocation( + base::Bind(&GeolocationHandler::GeolocationCallback, + weak_ptr_factory_.GetWeakPtr())); +} + +void GeolocationHandler::GeolocationCallback( + DBusMethodCallStatus call_status, + const base::DictionaryValue& properties) { + if (call_status != DBUS_METHOD_CALL_SUCCESS) { + LOG(ERROR) << "Failed to get Geolocation data: " << call_status; + return; + } + wifi_access_points_.clear(); + if (properties.empty()) + return; // No enabled devices, don't update received time. + + // Dictionary<device_type, entry_list> + for (base::DictionaryValue::Iterator iter(properties); + iter.HasNext(); iter.Advance()) { + const base::ListValue* entry_list = NULL; + if (!iter.value().GetAsList(&entry_list)) { + LOG(WARNING) << "Geolocation dictionary value not a List: " << iter.key(); + continue; + } + // List[Dictionary<key, value_str>] + for (size_t i = 0; i < entry_list->GetSize(); ++i) { + const base::DictionaryValue* entry = NULL; + if (!entry_list->GetDictionary(i, &entry) || !entry) { + LOG(WARNING) << "Geolocation list value not a Dictionary: " << i; + continue; + } + // Docs: developers.google.com/maps/documentation/business/geolocation + WifiAccessPoint wap; + entry->GetString(shill::kGeoMacAddressProperty, &wap.mac_address); + std::string age_str; + if (entry->GetString(shill::kGeoAgeProperty, &age_str)) { + int64 age_ms; + if (base::StringToInt64(age_str, &age_ms)) { + wap.timestamp = + base::Time::Now() - base::TimeDelta::FromMilliseconds(age_ms); + } + } + std::string strength_str; + if (entry->GetString(shill::kGeoSignalStrengthProperty, &strength_str)) + base::StringToInt(strength_str, &wap.signal_strength); + std::string signal_str; + if (entry->GetString(shill::kGeoSignalToNoiseRatioProperty, &signal_str)) + base::StringToInt(signal_str, &wap.signal_to_noise); + std::string channel_str; + if (entry->GetString(shill::kGeoChannelProperty, &channel_str)) + base::StringToInt(channel_str, &wap.channel); + wifi_access_points_.push_back(wap); + } + } + geolocation_received_time_ = base::Time::Now(); +} + +} // namespace chromeos diff --git a/chromeos/network/geolocation_handler.h b/chromeos/network/geolocation_handler.h new file mode 100644 index 0000000..d2ff308 --- /dev/null +++ b/chromeos/network/geolocation_handler.h @@ -0,0 +1,86 @@ +// Copyright (c) 2013 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_GEOLOCATION_HANDLER_H_ +#define CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ + +#include "base/memory/weak_ptr.h" +#include "base/time.h" +#include "chromeos/dbus/dbus_method_call_status.h" +#include "chromeos/dbus/shill_property_changed_observer.h" +#include "chromeos/network/network_util.h" + +namespace base { +class DictionaryValue; +} + +namespace chromeos { + +// This class provices Shill Wifi Access Point data. It currently relies on +// polling because that is the usage model in content::WifiDataProvider. This +// class requests data asynchronously, returning the most recent available data. +// A typical usage pattern, assuming a wifi device is enabeld, is: +// Initialize(); // Makes an initial request +// GetWifiAccessPoints(); // returns true + inital data, requests update +// (Delay some amount of time, ~10s) +// GetWifiAccessPoints(); // returns true + updated data, requests update +// (Delay some amount of time after data changed, ~10s) +// GetWifiAccessPoints(); // returns true + same data, requests update +// (Delay some amount of time after data did not change, ~2 mins) + +class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver { + public: + virtual ~GeolocationHandler(); + + // Manage the global instance. Must be initialized before any calls to Get(). + static void Initialize(); + static void Shutdown(); + static GeolocationHandler* Get(); + + // This sends a request for wifi access point data. If data is already + // available, returns |true|, fills |access_points| with the latest access + // point data, and sets |age_ms| to the time since the last update in MS. + bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms); + + bool wifi_enabled() const { return wifi_enabled_; } + + // ShillPropertyChangedObserver overrides + virtual void OnPropertyChanged(const std::string& key, + const base::Value& value) OVERRIDE; + + private: + friend class GeolocationHandlerTest; + GeolocationHandler(); + void Init(); + + // ShillManagerClient callback + void ManagerPropertiesCallback(DBusMethodCallStatus call_status, + const base::DictionaryValue& properties); + + // Called from OnPropertyChanged or ManagerPropertiesCallback. + void HandlePropertyChanged(const std::string& key, const base::Value& value); + + // Asynchronously request wifi access points from Shill.Manager. + void RequestWifiAccessPoints(); + + // Callback for receiving Geolocation data. + void GeolocationCallback(DBusMethodCallStatus call_status, + const base::DictionaryValue& properties); + + // Wimax enabled state + bool wifi_enabled_; + + // Cached wifi access points and update time + WifiAccessPointVector wifi_access_points_; + base::Time geolocation_received_time_; + + // For Shill client callbacks + base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); +}; + +} // namespace chromeos + +#endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ diff --git a/chromeos/network/geolocation_handler_unittest.cc b/chromeos/network/geolocation_handler_unittest.cc new file mode 100644 index 0000000..dc2cab0 --- /dev/null +++ b/chromeos/network/geolocation_handler_unittest.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2013 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 "base/memory/scoped_ptr.h" +#include "base/message_loop.h" +#include "base/stringprintf.h" +#include "base/values.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/shill_manager_client.h" +#include "chromeos/network/geolocation_handler.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +class GeolocationHandlerTest : public testing::Test { + public: + GeolocationHandlerTest() : manager_test_(NULL) { + } + + virtual ~GeolocationHandlerTest() { + } + + 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_); + geolocation_handler_.reset(new GeolocationHandler()); + geolocation_handler_->Init(); + message_loop_.RunUntilIdle(); + } + + virtual void TearDown() OVERRIDE { + geolocation_handler_.reset(); + DBusThreadManager::Shutdown(); + } + + bool GetWifiAccessPoints() { + return geolocation_handler_->GetWifiAccessPoints( + &wifi_access_points_, NULL); + } + + void AddAccessPoint(int idx) { + base::DictionaryValue properties; + std::string mac_address = + base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", + idx, 0, 0, 0, 0, 0); + std::string channel = StringPrintf("%d", idx); + std::string strength = StringPrintf("%d", idx * 10); + properties.SetStringWithoutPathExpansion( + shill::kGeoMacAddressProperty, mac_address); + properties.SetStringWithoutPathExpansion( + shill::kGeoChannelProperty, channel); + properties.SetStringWithoutPathExpansion( + shill::kGeoSignalStrengthProperty, strength); + manager_test_->AddGeoNetwork(flimflam::kTypeWifi, properties); + message_loop_.RunUntilIdle(); + } + + protected: + MessageLoopForUI message_loop_; + scoped_ptr<GeolocationHandler> geolocation_handler_; + ShillManagerClient::TestInterface* manager_test_; + WifiAccessPointVector wifi_access_points_; + + private: + DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest); +}; + +TEST_F(GeolocationHandlerTest, NoAccessPoints) { + // Inititial call should return false. + EXPECT_FALSE(GetWifiAccessPoints()); + message_loop_.RunUntilIdle(); + // Second call should return false since there are no devices. + EXPECT_FALSE(GetWifiAccessPoints()); +} + +TEST_F(GeolocationHandlerTest, OneAccessPoint) { + // Add an acces point. + AddAccessPoint(1); + message_loop_.RunUntilIdle(); + // Inititial call should return false and request access points. + EXPECT_FALSE(GetWifiAccessPoints()); + message_loop_.RunUntilIdle(); + // Second call should return true since we have an access point. + EXPECT_TRUE(GetWifiAccessPoints()); + ASSERT_EQ(1u, wifi_access_points_.size()); + EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address); + EXPECT_EQ(1, wifi_access_points_[0].channel); +} + +TEST_F(GeolocationHandlerTest, MultipleAccessPoints) { + // Add several acces points. + AddAccessPoint(1); + AddAccessPoint(2); + AddAccessPoint(3); + message_loop_.RunUntilIdle(); + // Inititial call should return false and request access points. + EXPECT_FALSE(GetWifiAccessPoints()); + message_loop_.RunUntilIdle(); + // Second call should return true since we have an access point. + EXPECT_TRUE(GetWifiAccessPoints()); + ASSERT_EQ(3u, wifi_access_points_.size()); + EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address); + EXPECT_EQ(3, wifi_access_points_[2].channel); +} + +} // namespace chromeos diff --git a/chromeos/network/network_device_handler.cc b/chromeos/network/network_device_handler.cc index 6524459..4bff925 100644 --- a/chromeos/network/network_device_handler.cc +++ b/chromeos/network/network_device_handler.cc @@ -9,35 +9,27 @@ #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/shill_device_client.h" #include "chromeos/dbus/shill_manager_client.h" -#include "chromeos/dbus/shill_network_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() - : devices_ready_(false), - weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { -} - NetworkDeviceHandler::~NetworkDeviceHandler() { DBusThreadManager::Get()->GetShillManagerClient()-> RemovePropertyChangedObserver(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::AddObserver(Observer* observer) { observers_.AddObserver(observer); } @@ -46,6 +38,27 @@ 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 @@ -64,6 +77,20 @@ void NetworkDeviceHandler::OnPropertyChanged(const std::string& key, //------------------------------------------------------------------------------ // 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) { @@ -108,14 +135,23 @@ void NetworkDeviceHandler::DevicePropertiesCallback( if (call_status != DBUS_METHOD_CALL_SUCCESS) { LOG(ERROR) << "Failed to get Device properties for " << device_path << ": " << call_status; - DeviceReady(device_path); - return; + } 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; - DeviceReady(device_path); return; } Device& device = devices_[device_path]; @@ -126,82 +162,6 @@ void NetworkDeviceHandler::DevicePropertiesCallback( flimflam::kScanningProperty, &device.scanning); properties.GetIntegerWithoutPathExpansion( flimflam::kScanIntervalProperty, &device.scan_interval); - - if (!device.powered || - (type != flimflam::kTypeWifi && type != flimflam::kTypeWimax)) { - DeviceReady(device_path); - return; - } - - // Get WifiAccessPoint data for each Network property (only for powered - // wifi or wimax devices). - const base::ListValue* networks = NULL; - if (!properties.GetListWithoutPathExpansion( - flimflam::kNetworksProperty, &networks)) { - LOG(WARNING) << "Failed to parse Networks property for " << device_path; - DeviceReady(device_path); - return; - } - - for (size_t i = 0; i < networks->GetSize(); ++i) { - std::string network_path; - if (!networks->GetString(i, &network_path)) { - LOG(WARNING) << "Failed tp parse Networks[" << i << "]" - << " for device: " << device_path; - continue; - } - pending_network_paths_[device_path].insert(network_path); - DBusThreadManager::Get()->GetShillNetworkClient()->GetProperties( - dbus::ObjectPath(device_path), - base::Bind(&NetworkDeviceHandler::NetworkPropertiesCallback, - weak_ptr_factory_.GetWeakPtr(), - device_path, - network_path)); - } -} - -void NetworkDeviceHandler::NetworkPropertiesCallback( - const std::string& device_path, - const std::string& network_path, - DBusMethodCallStatus call_status, - const base::DictionaryValue& properties) { - if (call_status != DBUS_METHOD_CALL_SUCCESS) { - LOG(ERROR) << "Failed to get Network properties for " << network_path - << ", for device: " << device_path << ": " << call_status; - DeviceNetworkReady(device_path, network_path); - return; - } - - // Using the scan interval as a proxy for approximate age. - // TODO(joth): Replace with actual age, when available from dbus. - Device& device = devices_[device_path]; - WifiAccessPoint& wap = device.wifi_access_points[network_path]; - properties.GetStringWithoutPathExpansion( - flimflam::kAddressProperty, &wap.mac_address); - properties.GetStringWithoutPathExpansion( - flimflam::kNameProperty, &wap.name); - int age_seconds = device.scan_interval; - wap.timestamp = base::Time::Now() - base::TimeDelta::FromSeconds(age_seconds); - properties.GetIntegerWithoutPathExpansion( - flimflam::kSignalStrengthProperty, &wap.signal_strength); - properties.GetIntegerWithoutPathExpansion( - flimflam::kWifiChannelProperty, &wap.channel); - DeviceNetworkReady(device_path, network_path); -} - -void NetworkDeviceHandler::DeviceNetworkReady(const std::string& device_path, - const std::string& network_path) { - pending_network_paths_[device_path].erase(network_path); - if (pending_network_paths_[device_path].empty()) - DeviceReady(device_path); -} - -void NetworkDeviceHandler::DeviceReady(const std::string& device_path) { - pending_device_paths_.erase(device_path); - if (pending_device_paths_.empty()) { - devices_ready_ = true; - FOR_EACH_OBSERVER(Observer, observers_, NetworkDevicesUpdated(devices_)); - } } //------------------------------------------------------------------------------ diff --git a/chromeos/network/network_device_handler.h b/chromeos/network/network_device_handler.h index 66109fc..0b90f04 100644 --- a/chromeos/network/network_device_handler.h +++ b/chromeos/network/network_device_handler.h @@ -14,7 +14,6 @@ #include "chromeos/chromeos_export.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/shill_property_changed_observer.h" -#include "chromeos/network/network_util.h" // WifiAccessPoint namespace base { class DictionaryValue; @@ -34,7 +33,6 @@ class CHROMEOS_EXPORT NetworkDeviceHandler bool powered; bool scanning; int scan_interval; - std::map<std::string, WifiAccessPoint> wifi_access_points; }; typedef std::map<std::string, Device> DeviceMap; @@ -49,9 +47,12 @@ class CHROMEOS_EXPORT NetworkDeviceHandler virtual ~Observer() {} }; - NetworkDeviceHandler(); virtual ~NetworkDeviceHandler(); - void Init(); + + // 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); @@ -65,6 +66,10 @@ class CHROMEOS_EXPORT NetworkDeviceHandler 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); @@ -75,9 +80,8 @@ class CHROMEOS_EXPORT NetworkDeviceHandler const std::string& network_path, DBusMethodCallStatus call_status, const base::DictionaryValue& properties); - void DeviceNetworkReady(const std::string& device_path, - const std::string& network_path); - void DeviceReady(const std::string& device_path); + void GetDeviceProperties(const std::string& device_path, + const base::DictionaryValue& properties); // True when the device list is up to date. bool devices_ready_; @@ -88,14 +92,13 @@ class CHROMEOS_EXPORT NetworkDeviceHandler // Map of pending devices. std::set<std::string> pending_device_paths_; - // Map of pending networks per device path. - std::map<std::string, std::set<std::string> > pending_network_paths_; - // Observer list ObserverList<Observer> observers_; // For Shill client callbacks base::WeakPtrFactory<NetworkDeviceHandler> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandler); }; } // namespace chromeos diff --git a/chromeos/network/network_device_handler_unittest.cc b/chromeos/network/network_device_handler_unittest.cc index 5ffd296..589b97a 100644 --- a/chromeos/network/network_device_handler_unittest.cc +++ b/chromeos/network/network_device_handler_unittest.cc @@ -68,7 +68,7 @@ class NetworkDeviceHandlerTest : public testing::Test { void AddDevice(const std::string& type, const std::string& id) { manager_test_->AddDevice(id); - device_test_->AddDevice(id, type, std::string("/device/" + id), "/stub"); + device_test_->AddDevice(id, type, std::string("/device/" + id)); } void RemoveDevice(const std::string& id) { diff --git a/chromeos/network/network_sms_handler_unittest.cc b/chromeos/network/network_sms_handler_unittest.cc index 360755d..62f9f6a 100644 --- a/chromeos/network/network_sms_handler_unittest.cc +++ b/chromeos/network/network_sms_handler_unittest.cc @@ -65,7 +65,7 @@ class NetworkSmsHandlerTest : public testing::Test { DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); ASSERT_TRUE(device_test); device_test->AddDevice("stub_cellular_device2", flimflam::kTypeCellular, - "/org/freedesktop/ModemManager1/stub/0", ":stub.0"); + "/org/freedesktop/ModemManager1/stub/0"); } virtual void TearDown() OVERRIDE { diff --git a/chromeos/network/network_util.h b/chromeos/network/network_util.h index 373e9d9..ce04f98 100644 --- a/chromeos/network/network_util.h +++ b/chromeos/network/network_util.h @@ -36,12 +36,12 @@ struct CHROMEOS_EXPORT SMS { struct CHROMEOS_EXPORT WifiAccessPoint { WifiAccessPoint(); ~WifiAccessPoint(); + std::string ssid; // The ssid of the WiFi node if available. std::string mac_address; // The mac address of the WiFi node. - std::string name; // The SSID of the WiFi node. - base::Time timestamp; // Timestamp when this AP was detected. - int signal_strength; // Radio signal strength measured in dBm. - int signal_to_noise; // Current signal to noise ratio measured in dB. - int channel; // Wifi channel number. + base::Time timestamp; // Timestamp when this AP was detected. + int signal_strength; // Radio signal strength measured in dBm. + int signal_to_noise; // Current signal to noise ratio measured in dB. + int channel; // Wifi channel number. }; typedef std::vector<WifiAccessPoint> WifiAccessPointVector; diff --git a/chromeos/network/shill_property_handler.h b/chromeos/network/shill_property_handler.h index 6b10f79..f90584c 100644 --- a/chromeos/network/shill_property_handler.h +++ b/chromeos/network/shill_property_handler.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ -#define CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ +#ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_ +#define CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_ #include <list> #include <map> @@ -173,4 +173,4 @@ class CHROMEOS_EXPORT ShillPropertyHandler } // namespace internal } // namespace chromeos -#endif // CHROMEOS_NETWORK_NETWORK_STATE_HANDLER_IMPL_H_ +#endif // CHROMEOS_NETWORK_SHILL_PROPERTY_HANDLER_H_ diff --git a/chromeos/network/shill_property_handler_unittest.cc b/chromeos/network/shill_property_handler_unittest.cc index def23f9..9f6e609 100644 --- a/chromeos/network/shill_property_handler_unittest.cc +++ b/chromeos/network/shill_property_handler_unittest.cc @@ -171,7 +171,7 @@ class ShillPropertyHandlerTest : public testing::Test { void AddDevice(const std::string& type, const std::string& id) { ASSERT_TRUE(IsValidType(type)); manager_test_->AddDevice(id); - device_test_->AddDevice(id, type, std::string("/device/" + id), "/stub"); + device_test_->AddDevice(id, type, std::string("/device/" + id)); } void RemoveDevice(const std::string& id) { |