summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 08:51:17 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 08:51:17 +0000
commit2632f5046d811f8780484cbaf983f3c9a97c9ea9 (patch)
treeaee09fbc24f1bb9524de64726638ddd3c8f826f3 /chromeos/dbus
parentd2397d877f3cd67b0010abecb451ae390cf789b6 (diff)
downloadchromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.zip
chromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.tar.gz
chromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/dbus_thread_manager.cc8
-rw-r--r--chromeos/dbus/dbus_thread_manager.h2
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.cc4
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.h6
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc6
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.h1
-rw-r--r--chromeos/dbus/mock_shill_manager_client.h2
-rw-r--r--chromeos/dbus/mock_shill_network_client.cc13
-rw-r--r--chromeos/dbus/mock_shill_network_client.h34
-rw-r--r--chromeos/dbus/shill_device_client.cc23
-rw-r--r--chromeos/dbus/shill_device_client.h6
-rw-r--r--chromeos/dbus/shill_manager_client.cc41
-rw-r--r--chromeos/dbus/shill_manager_client.h10
-rw-r--r--chromeos/dbus/shill_manager_client_unittest.cc50
-rw-r--r--chromeos/dbus/shill_network_client.cc145
-rw-r--r--chromeos/dbus/shill_network_client.h83
-rw-r--r--chromeos/dbus/shill_network_client_unittest.cc184
17 files changed, 123 insertions, 495 deletions
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