OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/shill_device_client_stub.h" | 5 #include "chromeos/dbus/shill_device_client_stub.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const dbus::ObjectPath& device_path, | 50 const dbus::ObjectPath& device_path, |
51 ShillPropertyChangedObserver* observer){ | 51 ShillPropertyChangedObserver* observer){ |
52 GetObserverList(device_path).RemoveObserver(observer); | 52 GetObserverList(device_path).RemoveObserver(observer); |
53 } | 53 } |
54 | 54 |
55 void ShillDeviceClientStub::GetProperties( | 55 void ShillDeviceClientStub::GetProperties( |
56 const dbus::ObjectPath& device_path, | 56 const dbus::ObjectPath& device_path, |
57 const DictionaryValueCallback& callback){ | 57 const DictionaryValueCallback& callback){ |
58 if (callback.is_null()) | 58 if (callback.is_null()) |
59 return; | 59 return; |
60 MessageLoop::current()->PostTask( | 60 base::MessageLoop::current()->PostTask( |
61 FROM_HERE, | 61 FROM_HERE, |
62 base::Bind(&ShillDeviceClientStub::PassStubDeviceProperties, | 62 base::Bind(&ShillDeviceClientStub::PassStubDeviceProperties, |
63 weak_ptr_factory_.GetWeakPtr(), | 63 weak_ptr_factory_.GetWeakPtr(), |
64 device_path, callback)); | 64 device_path, callback)); |
65 } | 65 } |
66 | 66 |
67 base::DictionaryValue* ShillDeviceClientStub::CallGetPropertiesAndBlock( | 67 base::DictionaryValue* ShillDeviceClientStub::CallGetPropertiesAndBlock( |
68 const dbus::ObjectPath& device_path){ | 68 const dbus::ObjectPath& device_path){ |
69 base::DictionaryValue* device_properties = NULL; | 69 base::DictionaryValue* device_properties = NULL; |
70 stub_devices_.GetDictionaryWithoutPathExpansion( | 70 stub_devices_.GetDictionaryWithoutPathExpansion( |
71 device_path.value(), &device_properties); | 71 device_path.value(), &device_properties); |
72 return device_properties; | 72 return device_properties; |
73 } | 73 } |
74 | 74 |
75 void ShillDeviceClientStub::ProposeScan(const dbus::ObjectPath& device_path, | 75 void ShillDeviceClientStub::ProposeScan(const dbus::ObjectPath& device_path, |
76 const VoidDBusMethodCallback& callback){ | 76 const VoidDBusMethodCallback& callback){ |
77 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 77 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); |
78 } | 78 } |
79 | 79 |
80 void ShillDeviceClientStub::SetProperty(const dbus::ObjectPath& device_path, | 80 void ShillDeviceClientStub::SetProperty(const dbus::ObjectPath& device_path, |
81 const std::string& name, | 81 const std::string& name, |
82 const base::Value& value, | 82 const base::Value& value, |
83 const base::Closure& callback, | 83 const base::Closure& callback, |
84 const ErrorCallback& error_callback){ | 84 const ErrorCallback& error_callback){ |
85 base::DictionaryValue* device_properties = NULL; | 85 base::DictionaryValue* device_properties = NULL; |
86 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { | 86 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { |
87 std::string error_name("org.chromium.flimflam.Error.Failure"); | 87 std::string error_name("org.chromium.flimflam.Error.Failure"); |
88 std::string error_message("Failed"); | 88 std::string error_message("Failed"); |
89 if (!error_callback.is_null()) { | 89 if (!error_callback.is_null()) { |
90 MessageLoop::current()->PostTask(FROM_HERE, | 90 base::MessageLoop::current()->PostTask(FROM_HERE, |
91 base::Bind(error_callback, | 91 base::Bind(error_callback, |
92 error_name, | 92 error_name, |
93 error_message)); | 93 error_message)); |
94 } | 94 } |
95 return; | 95 return; |
96 } | 96 } |
97 device_properties->Set(name, value.DeepCopy()); | 97 device_properties->Set(name, value.DeepCopy()); |
98 MessageLoop::current()->PostTask( | 98 base::MessageLoop::current()->PostTask( |
99 FROM_HERE, | 99 FROM_HERE, |
100 base::Bind(&ShillDeviceClientStub::NotifyObserversPropertyChanged, | 100 base::Bind(&ShillDeviceClientStub::NotifyObserversPropertyChanged, |
101 weak_ptr_factory_.GetWeakPtr(), device_path, name)); | 101 weak_ptr_factory_.GetWeakPtr(), device_path, name)); |
102 if (callback.is_null()) | 102 if (callback.is_null()) |
103 return; | 103 return; |
104 MessageLoop::current()->PostTask(FROM_HERE, callback); | 104 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
105 } | 105 } |
106 | 106 |
107 void ShillDeviceClientStub::ClearProperty( | 107 void ShillDeviceClientStub::ClearProperty( |
108 const dbus::ObjectPath& device_path, | 108 const dbus::ObjectPath& device_path, |
109 const std::string& name, | 109 const std::string& name, |
110 const VoidDBusMethodCallback& callback){ | 110 const VoidDBusMethodCallback& callback){ |
111 base::DictionaryValue* device_properties = NULL; | 111 base::DictionaryValue* device_properties = NULL; |
112 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { | 112 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { |
113 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); | 113 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); |
114 return; | 114 return; |
115 } | 115 } |
116 device_properties->Remove(name, NULL); | 116 device_properties->Remove(name, NULL); |
117 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 117 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); |
118 } | 118 } |
119 | 119 |
120 void ShillDeviceClientStub::AddIPConfig( | 120 void ShillDeviceClientStub::AddIPConfig( |
121 const dbus::ObjectPath& device_path, | 121 const dbus::ObjectPath& device_path, |
122 const std::string& method, | 122 const std::string& method, |
123 const ObjectPathDBusMethodCallback& callback){ | 123 const ObjectPathDBusMethodCallback& callback){ |
124 if (callback.is_null()) | 124 if (callback.is_null()) |
125 return; | 125 return; |
126 MessageLoop::current()->PostTask(FROM_HERE, | 126 base::MessageLoop::current()->PostTask(FROM_HERE, |
127 base::Bind(callback, | 127 base::Bind(callback, |
128 DBUS_METHOD_CALL_SUCCESS, | 128 DBUS_METHOD_CALL_SUCCESS, |
129 dbus::ObjectPath())); | 129 dbus::ObjectPath())); |
130 } | 130 } |
131 | 131 |
132 void ShillDeviceClientStub::RequirePin(const dbus::ObjectPath& device_path, | 132 void ShillDeviceClientStub::RequirePin(const dbus::ObjectPath& device_path, |
133 const std::string& pin, | 133 const std::string& pin, |
134 bool require, | 134 bool require, |
135 const base::Closure& callback, | 135 const base::Closure& callback, |
136 const ErrorCallback& error_callback){ | 136 const ErrorCallback& error_callback){ |
137 if (callback.is_null()) | 137 if (callback.is_null()) |
138 return; | 138 return; |
139 MessageLoop::current()->PostTask(FROM_HERE, callback); | 139 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
140 } | 140 } |
141 | 141 |
142 void ShillDeviceClientStub::EnterPin(const dbus::ObjectPath& device_path, | 142 void ShillDeviceClientStub::EnterPin(const dbus::ObjectPath& device_path, |
143 const std::string& pin, | 143 const std::string& pin, |
144 const base::Closure& callback, | 144 const base::Closure& callback, |
145 const ErrorCallback& error_callback){ | 145 const ErrorCallback& error_callback){ |
146 if (callback.is_null()) | 146 if (callback.is_null()) |
147 return; | 147 return; |
148 MessageLoop::current()->PostTask(FROM_HERE, callback); | 148 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
149 } | 149 } |
150 | 150 |
151 void ShillDeviceClientStub::UnblockPin(const dbus::ObjectPath& device_path, | 151 void ShillDeviceClientStub::UnblockPin(const dbus::ObjectPath& device_path, |
152 const std::string& puk, | 152 const std::string& puk, |
153 const std::string& pin, | 153 const std::string& pin, |
154 const base::Closure& callback, | 154 const base::Closure& callback, |
155 const ErrorCallback& error_callback){ | 155 const ErrorCallback& error_callback){ |
156 if (callback.is_null()) | 156 if (callback.is_null()) |
157 return; | 157 return; |
158 MessageLoop::current()->PostTask(FROM_HERE, callback); | 158 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
159 } | 159 } |
160 | 160 |
161 void ShillDeviceClientStub::ChangePin(const dbus::ObjectPath& device_path, | 161 void ShillDeviceClientStub::ChangePin(const dbus::ObjectPath& device_path, |
162 const std::string& old_pin, | 162 const std::string& old_pin, |
163 const std::string& new_pin, | 163 const std::string& new_pin, |
164 const base::Closure& callback, | 164 const base::Closure& callback, |
165 const ErrorCallback& error_callback){ | 165 const ErrorCallback& error_callback){ |
166 if (callback.is_null()) | 166 if (callback.is_null()) |
167 return; | 167 return; |
168 MessageLoop::current()->PostTask(FROM_HERE, callback); | 168 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
169 } | 169 } |
170 | 170 |
171 void ShillDeviceClientStub::Register(const dbus::ObjectPath& device_path, | 171 void ShillDeviceClientStub::Register(const dbus::ObjectPath& device_path, |
172 const std::string& network_id, | 172 const std::string& network_id, |
173 const base::Closure& callback, | 173 const base::Closure& callback, |
174 const ErrorCallback& error_callback){ | 174 const ErrorCallback& error_callback){ |
175 if (callback.is_null()) | 175 if (callback.is_null()) |
176 return; | 176 return; |
177 MessageLoop::current()->PostTask(FROM_HERE, callback); | 177 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
178 } | 178 } |
179 | 179 |
180 void ShillDeviceClientStub::SetCarrier(const dbus::ObjectPath& device_path, | 180 void ShillDeviceClientStub::SetCarrier(const dbus::ObjectPath& device_path, |
181 const std::string& carrier, | 181 const std::string& carrier, |
182 const base::Closure& callback, | 182 const base::Closure& callback, |
183 const ErrorCallback& error_callback){ | 183 const ErrorCallback& error_callback){ |
184 if (callback.is_null()) | 184 if (callback.is_null()) |
185 return; | 185 return; |
186 MessageLoop::current()->PostTask(FROM_HERE, callback); | 186 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
187 } | 187 } |
188 | 188 |
189 void ShillDeviceClientStub::Reset(const dbus::ObjectPath& device_path, | 189 void ShillDeviceClientStub::Reset(const dbus::ObjectPath& device_path, |
190 const base::Closure& callback, | 190 const base::Closure& callback, |
191 const ErrorCallback& error_callback){ | 191 const ErrorCallback& error_callback){ |
192 if (callback.is_null()) | 192 if (callback.is_null()) |
193 return; | 193 return; |
194 MessageLoop::current()->PostTask(FROM_HERE, callback); | 194 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
195 } | 195 } |
196 | 196 |
197 ShillDeviceClient::TestInterface* ShillDeviceClientStub::GetTestInterface(){ | 197 ShillDeviceClient::TestInterface* ShillDeviceClientStub::GetTestInterface(){ |
198 return this; | 198 return this; |
199 } | 199 } |
200 | 200 |
201 // ShillDeviceClient::TestInterface overrides. | 201 // ShillDeviceClient::TestInterface overrides. |
202 | 202 |
203 void ShillDeviceClientStub::AddDevice(const std::string& device_path, | 203 void ShillDeviceClientStub::AddDevice(const std::string& device_path, |
204 const std::string& type, | 204 const std::string& type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 281 } |
282 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties); | 282 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties); |
283 } | 283 } |
284 | 284 |
285 // Posts a task to run a void callback with status code |status|. | 285 // Posts a task to run a void callback with status code |status|. |
286 void ShillDeviceClientStub::PostVoidCallback( | 286 void ShillDeviceClientStub::PostVoidCallback( |
287 const VoidDBusMethodCallback& callback, | 287 const VoidDBusMethodCallback& callback, |
288 DBusMethodCallStatus status) { | 288 DBusMethodCallStatus status) { |
289 if (callback.is_null()) | 289 if (callback.is_null()) |
290 return; | 290 return; |
291 MessageLoop::current()->PostTask(FROM_HERE, | 291 base::MessageLoop::current()->PostTask(FROM_HERE, |
292 base::Bind(callback, status)); | 292 base::Bind(callback, status)); |
293 } | 293 } |
294 | 294 |
295 void ShillDeviceClientStub::NotifyObserversPropertyChanged( | 295 void ShillDeviceClientStub::NotifyObserversPropertyChanged( |
296 const dbus::ObjectPath& device_path, | 296 const dbus::ObjectPath& device_path, |
297 const std::string& property) { | 297 const std::string& property) { |
298 base::DictionaryValue* dict = NULL; | 298 base::DictionaryValue* dict = NULL; |
299 std::string path = device_path.value(); | 299 std::string path = device_path.value(); |
300 if (!stub_devices_.GetDictionaryWithoutPathExpansion(path, &dict)) { | 300 if (!stub_devices_.GetDictionaryWithoutPathExpansion(path, &dict)) { |
301 LOG(ERROR) << "Notify for unknown service: " << path; | 301 LOG(ERROR) << "Notify for unknown service: " << path; |
(...skipping 26 matching lines...) Expand all Loading... |
328 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 328 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
329 observer_list_.find(device_path); | 329 observer_list_.find(device_path); |
330 if (iter != observer_list_.end()) | 330 if (iter != observer_list_.end()) |
331 return *(iter->second); | 331 return *(iter->second); |
332 PropertyObserverList* observer_list = new PropertyObserverList(); | 332 PropertyObserverList* observer_list = new PropertyObserverList(); |
333 observer_list_[device_path] = observer_list; | 333 observer_list_[device_path] = observer_list; |
334 return *observer_list; | 334 return *observer_list; |
335 } | 335 } |
336 | 336 |
337 } // namespace chromeos | 337 } // namespace chromeos |
OLD | NEW |