Only fsync leveldb's directory when the manifest is being updated.
[chromium-blink-merge.git] / chromeos / dbus / shill_manager_client.cc
bloba1a0438761175b1cbc77f584dea544be65b26385
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/chromeos/chromeos_version.h"
9 #include "base/logging.h"
10 #include "base/message_loop.h"
11 #include "base/values.h"
12 #include "chromeos/dbus/shill_manager_client_stub.h"
13 #include "chromeos/dbus/shill_property_changed_observer.h"
14 #include "dbus/bus.h"
15 #include "dbus/message.h"
16 #include "dbus/object_path.h"
17 #include "dbus/object_proxy.h"
18 #include "dbus/values_util.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h"
21 namespace chromeos {
23 namespace {
25 // Appends a string-to-variant dictionary to the writer.
26 void AppendServicePropertiesDictionary(
27 dbus::MessageWriter* writer,
28 const base::DictionaryValue& dictionary) {
29 dbus::MessageWriter array_writer(NULL);
30 writer->OpenArray("{sv}", &array_writer);
31 for (base::DictionaryValue::Iterator it(dictionary);
32 !it.IsAtEnd();
33 it.Advance()) {
34 dbus::MessageWriter entry_writer(NULL);
35 array_writer.OpenDictEntry(&entry_writer);
36 entry_writer.AppendString(it.key());
37 ShillClientHelper::AppendValueDataAsVariant(&entry_writer, it.value());
38 array_writer.CloseContainer(&entry_writer);
40 writer->CloseContainer(&array_writer);
43 // The ShillManagerClient implementation.
44 class ShillManagerClientImpl : public ShillManagerClient {
45 public:
46 explicit ShillManagerClientImpl(dbus::Bus* bus)
47 : proxy_(bus->GetObjectProxy(
48 flimflam::kFlimflamServiceName,
49 dbus::ObjectPath(flimflam::kFlimflamServicePath))),
50 helper_(bus, proxy_) {
51 helper_.MonitorPropertyChanged(flimflam::kFlimflamManagerInterface);
54 ////////////////////////////////////
55 // ShillManagerClient overrides.
56 virtual void AddPropertyChangedObserver(
57 ShillPropertyChangedObserver* observer) OVERRIDE {
58 helper_.AddPropertyChangedObserver(observer);
61 virtual void RemovePropertyChangedObserver(
62 ShillPropertyChangedObserver* observer) OVERRIDE {
63 helper_.RemovePropertyChangedObserver(observer);
66 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE {
67 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
68 flimflam::kGetPropertiesFunction);
69 helper_.CallDictionaryValueMethod(&method_call, callback);
72 virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE {
73 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
74 flimflam::kGetPropertiesFunction);
75 return helper_.CallDictionaryValueMethodAndBlock(&method_call);
78 virtual void GetNetworksForGeolocation(
79 const DictionaryValueCallback& callback) OVERRIDE {
80 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
81 shill::kGetNetworksForGeolocation);
82 helper_.CallDictionaryValueMethod(&method_call, callback);
85 virtual void SetProperty(const std::string& name,
86 const base::Value& value,
87 const base::Closure& callback,
88 const ErrorCallback& error_callback) OVERRIDE {
89 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
90 flimflam::kSetPropertyFunction);
91 dbus::MessageWriter writer(&method_call);
92 writer.AppendString(name);
93 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
94 helper_.CallVoidMethodWithErrorCallback(&method_call,
95 callback,
96 error_callback);
99 virtual void RequestScan(const std::string& type,
100 const base::Closure& callback,
101 const ErrorCallback& error_callback) OVERRIDE {
102 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
103 flimflam::kRequestScanFunction);
104 dbus::MessageWriter writer(&method_call);
105 writer.AppendString(type);
106 helper_.CallVoidMethodWithErrorCallback(&method_call,
107 callback,
108 error_callback);
111 virtual void EnableTechnology(
112 const std::string& type,
113 const base::Closure& callback,
114 const ErrorCallback& error_callback) OVERRIDE {
115 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
116 flimflam::kEnableTechnologyFunction);
117 dbus::MessageWriter writer(&method_call);
118 writer.AppendString(type);
119 helper_.CallVoidMethodWithErrorCallback(&method_call,
120 callback,
121 error_callback);
124 virtual void DisableTechnology(
125 const std::string& type,
126 const base::Closure& callback,
127 const ErrorCallback& error_callback) OVERRIDE {
128 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
129 flimflam::kDisableTechnologyFunction);
130 dbus::MessageWriter writer(&method_call);
131 writer.AppendString(type);
132 helper_.CallVoidMethodWithErrorCallback(&method_call,
133 callback,
134 error_callback);
137 virtual void ConfigureService(
138 const base::DictionaryValue& properties,
139 const ObjectPathCallback& callback,
140 const ErrorCallback& error_callback) OVERRIDE {
141 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
142 flimflam::kConfigureServiceFunction);
143 dbus::MessageWriter writer(&method_call);
144 AppendServicePropertiesDictionary(&writer, properties);
145 helper_.CallObjectPathMethodWithErrorCallback(&method_call,
146 callback,
147 error_callback);
150 virtual void ConfigureServiceForProfile(
151 const dbus::ObjectPath& profile_path,
152 const base::DictionaryValue& properties,
153 const ObjectPathCallback& callback,
154 const ErrorCallback& error_callback) OVERRIDE {
155 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
156 shill::kConfigureServiceForProfileFunction);
157 dbus::MessageWriter writer(&method_call);
158 writer.AppendObjectPath(dbus::ObjectPath(profile_path));
159 AppendServicePropertiesDictionary(&writer, properties);
160 helper_.CallObjectPathMethodWithErrorCallback(&method_call,
161 callback,
162 error_callback);
165 virtual void GetService(
166 const base::DictionaryValue& properties,
167 const ObjectPathCallback& callback,
168 const ErrorCallback& error_callback) OVERRIDE {
169 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
170 flimflam::kGetServiceFunction);
171 dbus::MessageWriter writer(&method_call);
172 AppendServicePropertiesDictionary(&writer, properties);
173 helper_.CallObjectPathMethodWithErrorCallback(&method_call,
174 callback,
175 error_callback);
178 virtual void VerifyDestination(const VerificationProperties& properties,
179 const BooleanCallback& callback,
180 const ErrorCallback& error_callback) OVERRIDE {
181 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
182 shill::kVerifyDestinationFunction);
183 dbus::MessageWriter writer(&method_call);
184 writer.AppendString(properties.certificate);
185 writer.AppendString(properties.public_key);
186 writer.AppendString(properties.nonce);
187 writer.AppendString(properties.signed_data);
188 writer.AppendString(properties.device_serial);
189 writer.AppendString(properties.device_ssid);
190 writer.AppendString(properties.device_bssid);
191 helper_.CallBooleanMethodWithErrorCallback(
192 &method_call, callback, error_callback);
195 virtual void VerifyAndEncryptCredentials(
196 const VerificationProperties& properties,
197 const std::string& service_path,
198 const StringCallback& callback,
199 const ErrorCallback& error_callback) OVERRIDE {
200 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
201 shill::kVerifyAndEncryptCredentialsFunction);
202 dbus::MessageWriter writer(&method_call);
203 writer.AppendString(properties.certificate);
204 writer.AppendString(properties.public_key);
205 writer.AppendString(properties.nonce);
206 writer.AppendString(properties.signed_data);
207 writer.AppendString(properties.device_serial);
208 writer.AppendString(properties.device_ssid);
209 writer.AppendString(properties.device_bssid);
210 writer.AppendObjectPath(dbus::ObjectPath(service_path));
211 helper_.CallStringMethodWithErrorCallback(
212 &method_call, callback, error_callback);
215 virtual void VerifyAndEncryptData(
216 const VerificationProperties& properties,
217 const std::string& data,
218 const StringCallback& callback,
219 const ErrorCallback& error_callback) OVERRIDE {
220 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
221 shill::kVerifyAndEncryptDataFunction);
222 dbus::MessageWriter writer(&method_call);
223 writer.AppendString(properties.certificate);
224 writer.AppendString(properties.public_key);
225 writer.AppendString(properties.nonce);
226 writer.AppendString(properties.signed_data);
227 writer.AppendString(properties.device_serial);
228 writer.AppendString(properties.device_ssid);
229 writer.AppendString(properties.device_bssid);
230 writer.AppendString(data);
231 helper_.CallStringMethodWithErrorCallback(
232 &method_call, callback, error_callback);
235 virtual void ConnectToBestServices(
236 const base::Closure& callback,
237 const ErrorCallback& error_callback) OVERRIDE {
238 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
239 shill::kConnectToBestServicesFunction);
240 helper_.CallVoidMethodWithErrorCallback(&method_call,
241 callback,
242 error_callback);
245 virtual TestInterface* GetTestInterface() OVERRIDE {
246 return NULL;
249 private:
250 dbus::ObjectProxy* proxy_;
251 ShillClientHelper helper_;
253 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl);
256 } // namespace
258 ShillManagerClient::ShillManagerClient() {}
260 ShillManagerClient::~ShillManagerClient() {}
262 // static
263 ShillManagerClient* ShillManagerClient::Create(
264 DBusClientImplementationType type,
265 dbus::Bus* bus) {
266 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
267 return new ShillManagerClientImpl(bus);
268 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
269 return new ShillManagerClientStub();
272 // ShillManagerClient::VerificationProperties implementation.
273 ShillManagerClient::VerificationProperties::VerificationProperties() {
276 ShillManagerClient::VerificationProperties::~VerificationProperties() {
279 } // namespace chromeos