Track active references in ShillClientHelper (Take 2)
[chromium-blink-merge.git] / chromeos / dbus / shill_manager_client.cc
blobcae9b68d18c97eff85896d4bf87dfd127725e0d9
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/shill_manager_client.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/shill_manager_client_stub.h"
12 #include "chromeos/dbus/shill_property_changed_observer.h"
13 #include "dbus/bus.h"
14 #include "dbus/message.h"
15 #include "dbus/object_path.h"
16 #include "dbus/object_proxy.h"
17 #include "dbus/values_util.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
20 namespace chromeos {
22 namespace {
24 // The ShillManagerClient implementation.
25 class ShillManagerClientImpl : public ShillManagerClient {
26 public:
27 ShillManagerClientImpl() : proxy_(NULL) {}
29 ////////////////////////////////////
30 // ShillManagerClient overrides.
31 virtual void AddPropertyChangedObserver(
32 ShillPropertyChangedObserver* observer) OVERRIDE {
33 helper_->AddPropertyChangedObserver(observer);
36 virtual void RemovePropertyChangedObserver(
37 ShillPropertyChangedObserver* observer) OVERRIDE {
38 helper_->RemovePropertyChangedObserver(observer);
41 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE {
42 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
43 shill::kGetPropertiesFunction);
44 helper_->CallDictionaryValueMethod(&method_call, callback);
47 virtual void GetNetworksForGeolocation(
48 const DictionaryValueCallback& callback) OVERRIDE {
49 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
50 shill::kGetNetworksForGeolocation);
51 helper_->CallDictionaryValueMethod(&method_call, callback);
54 virtual void SetProperty(const std::string& name,
55 const base::Value& value,
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) OVERRIDE {
58 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
59 shill::kSetPropertyFunction);
60 dbus::MessageWriter writer(&method_call);
61 writer.AppendString(name);
62 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
63 helper_->CallVoidMethodWithErrorCallback(&method_call,
64 callback,
65 error_callback);
68 virtual void RequestScan(const std::string& type,
69 const base::Closure& callback,
70 const ErrorCallback& error_callback) OVERRIDE {
71 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
72 shill::kRequestScanFunction);
73 dbus::MessageWriter writer(&method_call);
74 writer.AppendString(type);
75 helper_->CallVoidMethodWithErrorCallback(&method_call,
76 callback,
77 error_callback);
80 virtual void EnableTechnology(
81 const std::string& type,
82 const base::Closure& callback,
83 const ErrorCallback& error_callback) OVERRIDE {
84 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
85 shill::kEnableTechnologyFunction);
86 dbus::MessageWriter writer(&method_call);
87 writer.AppendString(type);
88 helper_->CallVoidMethodWithErrorCallback(&method_call,
89 callback,
90 error_callback);
93 virtual void DisableTechnology(
94 const std::string& type,
95 const base::Closure& callback,
96 const ErrorCallback& error_callback) OVERRIDE {
97 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
98 shill::kDisableTechnologyFunction);
99 dbus::MessageWriter writer(&method_call);
100 writer.AppendString(type);
101 helper_->CallVoidMethodWithErrorCallback(&method_call,
102 callback,
103 error_callback);
106 virtual void ConfigureService(
107 const base::DictionaryValue& properties,
108 const ObjectPathCallback& callback,
109 const ErrorCallback& error_callback) OVERRIDE {
110 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
111 shill::kConfigureServiceFunction);
112 dbus::MessageWriter writer(&method_call);
113 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
114 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
115 callback,
116 error_callback);
119 virtual void ConfigureServiceForProfile(
120 const dbus::ObjectPath& profile_path,
121 const base::DictionaryValue& properties,
122 const ObjectPathCallback& callback,
123 const ErrorCallback& error_callback) OVERRIDE {
124 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
125 shill::kConfigureServiceForProfileFunction);
126 dbus::MessageWriter writer(&method_call);
127 writer.AppendObjectPath(dbus::ObjectPath(profile_path));
128 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
129 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
130 callback,
131 error_callback);
134 virtual void GetService(
135 const base::DictionaryValue& properties,
136 const ObjectPathCallback& callback,
137 const ErrorCallback& error_callback) OVERRIDE {
138 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
139 shill::kGetServiceFunction);
140 dbus::MessageWriter writer(&method_call);
141 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
142 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
143 callback,
144 error_callback);
147 virtual void VerifyDestination(const VerificationProperties& properties,
148 const BooleanCallback& callback,
149 const ErrorCallback& error_callback) OVERRIDE {
150 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
151 shill::kVerifyDestinationFunction);
152 dbus::MessageWriter writer(&method_call);
153 writer.AppendString(properties.certificate);
154 writer.AppendString(properties.public_key);
155 writer.AppendString(properties.nonce);
156 writer.AppendString(properties.signed_data);
157 writer.AppendString(properties.device_serial);
158 writer.AppendString(properties.device_ssid);
159 writer.AppendString(properties.device_bssid);
160 helper_->CallBooleanMethodWithErrorCallback(
161 &method_call, callback, error_callback);
164 virtual void VerifyAndEncryptCredentials(
165 const VerificationProperties& properties,
166 const std::string& service_path,
167 const StringCallback& callback,
168 const ErrorCallback& error_callback) OVERRIDE {
169 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
170 shill::kVerifyAndEncryptCredentialsFunction);
171 dbus::MessageWriter writer(&method_call);
172 writer.AppendString(properties.certificate);
173 writer.AppendString(properties.public_key);
174 writer.AppendString(properties.nonce);
175 writer.AppendString(properties.signed_data);
176 writer.AppendString(properties.device_serial);
177 writer.AppendString(properties.device_ssid);
178 writer.AppendString(properties.device_bssid);
179 writer.AppendObjectPath(dbus::ObjectPath(service_path));
180 helper_->CallStringMethodWithErrorCallback(
181 &method_call, callback, error_callback);
184 virtual void VerifyAndEncryptData(
185 const VerificationProperties& properties,
186 const std::string& data,
187 const StringCallback& callback,
188 const ErrorCallback& error_callback) OVERRIDE {
189 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
190 shill::kVerifyAndEncryptDataFunction);
191 dbus::MessageWriter writer(&method_call);
192 writer.AppendString(properties.certificate);
193 writer.AppendString(properties.public_key);
194 writer.AppendString(properties.nonce);
195 writer.AppendString(properties.signed_data);
196 writer.AppendString(properties.device_serial);
197 writer.AppendString(properties.device_ssid);
198 writer.AppendString(properties.device_bssid);
199 writer.AppendString(data);
200 helper_->CallStringMethodWithErrorCallback(
201 &method_call, callback, error_callback);
204 virtual void ConnectToBestServices(
205 const base::Closure& callback,
206 const ErrorCallback& error_callback) OVERRIDE {
207 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
208 shill::kConnectToBestServicesFunction);
209 helper_->CallVoidMethodWithErrorCallback(&method_call,
210 callback,
211 error_callback);
214 virtual TestInterface* GetTestInterface() OVERRIDE {
215 return NULL;
218 protected:
219 virtual void Init(dbus::Bus* bus) OVERRIDE {
220 proxy_ = bus->GetObjectProxy(shill::kFlimflamServiceName,
221 dbus::ObjectPath(shill::kFlimflamServicePath));
222 helper_.reset(new ShillClientHelper(proxy_));
223 helper_->MonitorPropertyChanged(shill::kFlimflamManagerInterface);
226 private:
227 dbus::ObjectProxy* proxy_;
228 scoped_ptr<ShillClientHelper> helper_;
230 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl);
233 } // namespace
235 ShillManagerClient::ShillManagerClient() {}
237 ShillManagerClient::~ShillManagerClient() {}
239 // static
240 ShillManagerClient* ShillManagerClient::Create(
241 DBusClientImplementationType type) {
242 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
243 return new ShillManagerClientImpl();
244 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
245 return new ShillManagerClientStub();
248 // ShillManagerClient::VerificationProperties implementation.
249 ShillManagerClient::VerificationProperties::VerificationProperties() {
252 ShillManagerClient::VerificationProperties::~VerificationProperties() {
255 } // namespace chromeos