Update V8 to version 4.6.54.
[chromium-blink-merge.git] / chromeos / dbus / shill_manager_client.cc
blob46179a90546679227e330f8822d93d033bdabc69
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_property_changed_observer.h"
12 #include "dbus/bus.h"
13 #include "dbus/message.h"
14 #include "dbus/object_path.h"
15 #include "dbus/object_proxy.h"
16 #include "dbus/values_util.h"
17 #include "net/base/ip_endpoint.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 void AddPropertyChangedObserver(
32 ShillPropertyChangedObserver* observer) override {
33 helper_->AddPropertyChangedObserver(observer);
36 void RemovePropertyChangedObserver(
37 ShillPropertyChangedObserver* observer) override {
38 helper_->RemovePropertyChangedObserver(observer);
41 void GetProperties(const DictionaryValueCallback& callback) override {
42 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
43 shill::kGetPropertiesFunction);
44 helper_->CallDictionaryValueMethod(&method_call, callback);
47 void GetNetworksForGeolocation(
48 const DictionaryValueCallback& callback) override {
49 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
50 shill::kGetNetworksForGeolocation);
51 helper_->CallDictionaryValueMethod(&method_call, callback);
54 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 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 void EnableTechnology(const std::string& type,
81 const base::Closure& callback,
82 const ErrorCallback& error_callback) override {
83 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
84 shill::kEnableTechnologyFunction);
85 dbus::MessageWriter writer(&method_call);
86 writer.AppendString(type);
87 helper_->CallVoidMethodWithErrorCallback(&method_call,
88 callback,
89 error_callback);
92 void DisableTechnology(const std::string& type,
93 const base::Closure& callback,
94 const ErrorCallback& error_callback) override {
95 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
96 shill::kDisableTechnologyFunction);
97 dbus::MessageWriter writer(&method_call);
98 writer.AppendString(type);
99 helper_->CallVoidMethodWithErrorCallback(&method_call,
100 callback,
101 error_callback);
104 void ConfigureService(const base::DictionaryValue& properties,
105 const ObjectPathCallback& callback,
106 const ErrorCallback& error_callback) override {
107 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
108 shill::kConfigureServiceFunction);
109 dbus::MessageWriter writer(&method_call);
110 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
111 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
112 callback,
113 error_callback);
116 void ConfigureServiceForProfile(
117 const dbus::ObjectPath& profile_path,
118 const base::DictionaryValue& properties,
119 const ObjectPathCallback& callback,
120 const ErrorCallback& error_callback) override {
121 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
122 shill::kConfigureServiceForProfileFunction);
123 dbus::MessageWriter writer(&method_call);
124 writer.AppendObjectPath(dbus::ObjectPath(profile_path));
125 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
126 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
127 callback,
128 error_callback);
131 void GetService(const base::DictionaryValue& properties,
132 const ObjectPathCallback& callback,
133 const ErrorCallback& error_callback) override {
134 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
135 shill::kGetServiceFunction);
136 dbus::MessageWriter writer(&method_call);
137 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties);
138 helper_->CallObjectPathMethodWithErrorCallback(&method_call,
139 callback,
140 error_callback);
143 void VerifyDestination(const VerificationProperties& properties,
144 const BooleanCallback& callback,
145 const ErrorCallback& error_callback) override {
146 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
147 shill::kVerifyDestinationFunction);
148 dbus::MessageWriter writer(&method_call);
149 writer.AppendString(properties.certificate);
150 writer.AppendString(properties.public_key);
151 writer.AppendString(properties.nonce);
152 writer.AppendString(properties.signed_data);
153 writer.AppendString(properties.device_serial);
154 writer.AppendString(properties.device_ssid);
155 writer.AppendString(properties.device_bssid);
156 helper_->CallBooleanMethodWithErrorCallback(
157 &method_call, callback, error_callback);
160 void VerifyAndEncryptCredentials(
161 const VerificationProperties& properties,
162 const std::string& service_path,
163 const StringCallback& callback,
164 const ErrorCallback& error_callback) override {
165 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
166 shill::kVerifyAndEncryptCredentialsFunction);
167 dbus::MessageWriter writer(&method_call);
168 writer.AppendString(properties.certificate);
169 writer.AppendString(properties.public_key);
170 writer.AppendString(properties.nonce);
171 writer.AppendString(properties.signed_data);
172 writer.AppendString(properties.device_serial);
173 writer.AppendString(properties.device_ssid);
174 writer.AppendString(properties.device_bssid);
175 writer.AppendObjectPath(dbus::ObjectPath(service_path));
176 helper_->CallStringMethodWithErrorCallback(
177 &method_call, callback, error_callback);
180 void VerifyAndEncryptData(const VerificationProperties& properties,
181 const std::string& data,
182 const StringCallback& callback,
183 const ErrorCallback& error_callback) override {
184 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
185 shill::kVerifyAndEncryptDataFunction);
186 dbus::MessageWriter writer(&method_call);
187 writer.AppendString(properties.certificate);
188 writer.AppendString(properties.public_key);
189 writer.AppendString(properties.nonce);
190 writer.AppendString(properties.signed_data);
191 writer.AppendString(properties.device_serial);
192 writer.AppendString(properties.device_ssid);
193 writer.AppendString(properties.device_bssid);
194 writer.AppendString(data);
195 helper_->CallStringMethodWithErrorCallback(
196 &method_call, callback, error_callback);
199 void ConnectToBestServices(const base::Closure& callback,
200 const ErrorCallback& error_callback) override {
201 dbus::MethodCall method_call(shill::kFlimflamManagerInterface,
202 shill::kConnectToBestServicesFunction);
203 helper_->CallVoidMethodWithErrorCallback(&method_call,
204 callback,
205 error_callback);
208 TestInterface* GetTestInterface() override { return NULL; }
210 protected:
211 void Init(dbus::Bus* bus) override {
212 proxy_ = bus->GetObjectProxy(shill::kFlimflamServiceName,
213 dbus::ObjectPath(shill::kFlimflamServicePath));
214 helper_.reset(new ShillClientHelper(proxy_));
215 helper_->MonitorPropertyChanged(shill::kFlimflamManagerInterface);
218 private:
219 dbus::ObjectProxy* proxy_;
220 scoped_ptr<ShillClientHelper> helper_;
222 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl);
225 } // namespace
227 ShillManagerClient::ShillManagerClient() {}
229 ShillManagerClient::~ShillManagerClient() {}
231 // static
232 ShillManagerClient* ShillManagerClient::Create() {
233 return new ShillManagerClientImpl();
236 // ShillManagerClient::VerificationProperties implementation.
237 ShillManagerClient::VerificationProperties::VerificationProperties() {
240 ShillManagerClient::VerificationProperties::~VerificationProperties() {
243 } // namespace chromeos