Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / chromeos / dbus / shill_device_client.cc
blob64fef54d0b31fa71352a831deed75d19223a72f5
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_device_client.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.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 ShillDeviceClient implementation.
25 class ShillDeviceClientImpl : public ShillDeviceClient {
26 public:
27 ShillDeviceClientImpl()
28 : bus_(NULL) {
31 ~ShillDeviceClientImpl() override {
32 for (HelperMap::iterator iter = helpers_.begin();
33 iter != helpers_.end(); ++iter) {
34 // This *should* never happen, yet we're getting crash reports that
35 // seem to imply that it does happen sometimes. Adding CHECKs here
36 // so we can determine more accurately where the problem lies.
37 // See: http://crbug.com/170541
38 CHECK(iter->second) << "NULL Helper found in helper list.";
39 delete iter->second;
41 helpers_.clear();
44 ///////////////////////////////////////
45 // ShillDeviceClient overrides.
46 void AddPropertyChangedObserver(
47 const dbus::ObjectPath& device_path,
48 ShillPropertyChangedObserver* observer) override {
49 GetHelper(device_path)->AddPropertyChangedObserver(observer);
52 void RemovePropertyChangedObserver(
53 const dbus::ObjectPath& device_path,
54 ShillPropertyChangedObserver* observer) override {
55 GetHelper(device_path)->RemovePropertyChangedObserver(observer);
58 void GetProperties(const dbus::ObjectPath& device_path,
59 const DictionaryValueCallback& callback) override {
60 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
61 shill::kGetPropertiesFunction);
62 GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback);
65 void ProposeScan(const dbus::ObjectPath& device_path,
66 const VoidDBusMethodCallback& callback) override {
67 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
68 shill::kProposeScanFunction);
69 GetHelper(device_path)->CallVoidMethod(&method_call, callback);
72 void SetProperty(const dbus::ObjectPath& device_path,
73 const std::string& name,
74 const base::Value& value,
75 const base::Closure& callback,
76 const ErrorCallback& error_callback) override {
77 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
78 shill::kSetPropertyFunction);
79 dbus::MessageWriter writer(&method_call);
80 writer.AppendString(name);
81 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
82 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call,
83 callback,
84 error_callback);
87 void ClearProperty(const dbus::ObjectPath& device_path,
88 const std::string& name,
89 const VoidDBusMethodCallback& callback) override {
90 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
91 shill::kClearPropertyFunction);
92 dbus::MessageWriter writer(&method_call);
93 writer.AppendString(name);
94 GetHelper(device_path)->CallVoidMethod(&method_call, callback);
97 void AddIPConfig(const dbus::ObjectPath& device_path,
98 const std::string& method,
99 const ObjectPathDBusMethodCallback& callback) override {
100 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
101 shill::kAddIPConfigFunction);
102 dbus::MessageWriter writer(&method_call);
103 writer.AppendString(method);
104 GetHelper(device_path)->CallObjectPathMethod(&method_call, callback);
107 void RequirePin(const dbus::ObjectPath& device_path,
108 const std::string& pin,
109 bool require,
110 const base::Closure& callback,
111 const ErrorCallback& error_callback) override {
112 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
113 shill::kRequirePinFunction);
114 dbus::MessageWriter writer(&method_call);
115 writer.AppendString(pin);
116 writer.AppendBool(require);
117 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
118 &method_call, callback, error_callback);
121 void EnterPin(const dbus::ObjectPath& device_path,
122 const std::string& pin,
123 const base::Closure& callback,
124 const ErrorCallback& error_callback) override {
125 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
126 shill::kEnterPinFunction);
127 dbus::MessageWriter writer(&method_call);
128 writer.AppendString(pin);
129 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
130 &method_call, callback, error_callback);
133 void UnblockPin(const dbus::ObjectPath& device_path,
134 const std::string& puk,
135 const std::string& pin,
136 const base::Closure& callback,
137 const ErrorCallback& error_callback) override {
138 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
139 shill::kUnblockPinFunction);
140 dbus::MessageWriter writer(&method_call);
141 writer.AppendString(puk);
142 writer.AppendString(pin);
143 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
144 &method_call, callback, error_callback);
147 void ChangePin(const dbus::ObjectPath& device_path,
148 const std::string& old_pin,
149 const std::string& new_pin,
150 const base::Closure& callback,
151 const ErrorCallback& error_callback) override {
152 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
153 shill::kChangePinFunction);
154 dbus::MessageWriter writer(&method_call);
155 writer.AppendString(old_pin);
156 writer.AppendString(new_pin);
157 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
158 &method_call, callback, error_callback);
161 void Register(const dbus::ObjectPath& device_path,
162 const std::string& network_id,
163 const base::Closure& callback,
164 const ErrorCallback& error_callback) override {
165 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
166 shill::kRegisterFunction);
167 dbus::MessageWriter writer(&method_call);
168 writer.AppendString(network_id);
169 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
170 &method_call, callback, error_callback);
173 void SetCarrier(const dbus::ObjectPath& device_path,
174 const std::string& carrier,
175 const base::Closure& callback,
176 const ErrorCallback& error_callback) override {
177 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
178 shill::kSetCarrierFunction);
179 dbus::MessageWriter writer(&method_call);
180 writer.AppendString(carrier);
181 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
182 &method_call, callback, error_callback);
185 void Reset(const dbus::ObjectPath& device_path,
186 const base::Closure& callback,
187 const ErrorCallback& error_callback) override {
188 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
189 shill::kResetFunction);
190 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
191 &method_call, callback, error_callback);
194 void PerformTDLSOperation(const dbus::ObjectPath& device_path,
195 const std::string& operation,
196 const std::string& peer,
197 const StringCallback& callback,
198 const ErrorCallback& error_callback) override {
199 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
200 shill::kPerformTDLSOperationFunction);
201 dbus::MessageWriter writer(&method_call);
202 writer.AppendString(operation);
203 writer.AppendString(peer);
204 GetHelper(device_path)->CallStringMethodWithErrorCallback(
205 &method_call, callback, error_callback);
208 void AddWakeOnPacketConnection(
209 const dbus::ObjectPath& device_path,
210 const net::IPEndPoint& ip_endpoint,
211 const base::Closure& callback,
212 const ErrorCallback& error_callback) override {
213 if (ip_endpoint.address().empty()) {
214 LOG(ERROR) << "AddWakeOnPacketConnection: null address";
215 return;
217 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
218 shill::kAddWakeOnPacketConnectionFunction);
219 dbus::MessageWriter writer(&method_call);
220 writer.AppendString(ip_endpoint.ToStringWithoutPort());
221 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call,
222 callback,
223 error_callback);
226 void RemoveWakeOnPacketConnection(
227 const dbus::ObjectPath& device_path,
228 const net::IPEndPoint& ip_endpoint,
229 const base::Closure& callback,
230 const ErrorCallback& error_callback) override {
231 if (ip_endpoint.address().empty()) {
232 LOG(ERROR) << "RemoveWakeOnPacketConnection: null address";
233 return;
235 dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
236 shill::kRemoveWakeOnPacketConnectionFunction);
237 dbus::MessageWriter writer(&method_call);
238 writer.AppendString(ip_endpoint.ToStringWithoutPort());
239 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call,
240 callback,
241 error_callback);
244 void RemoveAllWakeOnPacketConnections(
245 const dbus::ObjectPath& device_path,
246 const base::Closure& callback,
247 const ErrorCallback& error_callback) override {
248 dbus::MethodCall method_call(
249 shill::kFlimflamDeviceInterface,
250 shill::kRemoveAllWakeOnPacketConnectionsFunction);
251 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call,
252 callback,
253 error_callback);
256 TestInterface* GetTestInterface() override { return NULL; }
258 protected:
259 void Init(dbus::Bus* bus) override { bus_ = bus; }
261 private:
262 typedef std::map<std::string, ShillClientHelper*> HelperMap;
264 // Returns the corresponding ShillClientHelper for the profile.
265 ShillClientHelper* GetHelper(const dbus::ObjectPath& device_path) {
266 HelperMap::iterator it = helpers_.find(device_path.value());
267 if (it != helpers_.end()) {
268 CHECK(it->second) << "Found a NULL helper in the list.";
269 return it->second;
272 // There is no helper for the profile, create it.
273 dbus::ObjectProxy* object_proxy =
274 bus_->GetObjectProxy(shill::kFlimflamServiceName, device_path);
275 ShillClientHelper* helper = new ShillClientHelper(object_proxy);
276 CHECK(helper) << "Unable to create Shill client helper.";
277 helper->MonitorPropertyChanged(shill::kFlimflamDeviceInterface);
278 helpers_.insert(HelperMap::value_type(device_path.value(), helper));
279 return helper;
282 dbus::Bus* bus_;
283 HelperMap helpers_;
285 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientImpl);
288 } // namespace
290 ShillDeviceClient::ShillDeviceClient() {}
292 ShillDeviceClient::~ShillDeviceClient() {}
294 // static
295 ShillDeviceClient* ShillDeviceClient::Create() {
296 return new ShillDeviceClientImpl();
299 } // namespace chromeos