OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "dbus/exported_object.h" | 5 #include "dbus/exported_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 const base::TimeTicks start_time = base::TimeTicks::Now(); | 217 const base::TimeTicks start_time = base::TimeTicks::Now(); |
218 if (bus_->HasDBusThread()) { | 218 if (bus_->HasDBusThread()) { |
219 // Post a task to run the method in the origin thread. | 219 // Post a task to run the method in the origin thread. |
220 bus_->PostTaskToOriginThread(FROM_HERE, | 220 bus_->PostTaskToOriginThread(FROM_HERE, |
221 base::Bind(&ExportedObject::RunMethod, | 221 base::Bind(&ExportedObject::RunMethod, |
222 this, | 222 this, |
223 iter->second, | 223 iter->second, |
224 method_call.release(), | 224 method_call.release(), |
225 start_time)); | 225 start_time)); |
226 } else { | 226 } else { |
227 // If the D-Bus thread is not used, just call the method directly. We | 227 // If the D-Bus thread is not used, just call the method directly. |
228 // don't need the complicated logic to wait for the method call to be | 228 MethodCall* released_method_call = method_call.release(); |
229 // complete. | 229 iter->second.Run(released_method_call, |
230 // |response| will be deleted in OnMethodCompleted(). | 230 base::Bind(&ExportedObject::SendResponse, |
231 Response* response = iter->second.Run(method_call.get()); | 231 this, |
232 OnMethodCompleted(method_call.release(), response, start_time); | 232 start_time, |
| 233 released_method_call)); |
233 } | 234 } |
234 | 235 |
235 // It's valid to say HANDLED here, and send a method response at a later | 236 // It's valid to say HANDLED here, and send a method response at a later |
236 // time from OnMethodCompleted() asynchronously. | 237 // time from OnMethodCompleted() asynchronously. |
237 return DBUS_HANDLER_RESULT_HANDLED; | 238 return DBUS_HANDLER_RESULT_HANDLED; |
238 } | 239 } |
239 | 240 |
240 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, | 241 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, |
241 MethodCall* method_call, | 242 MethodCall* method_call, |
242 base::TimeTicks start_time) { | 243 base::TimeTicks start_time) { |
243 bus_->AssertOnOriginThread(); | 244 bus_->AssertOnOriginThread(); |
| 245 method_call_callback.Run(method_call, |
| 246 base::Bind(&ExportedObject::SendResponse, |
| 247 this, |
| 248 start_time, |
| 249 method_call)); |
| 250 } |
244 | 251 |
245 Response* response = method_call_callback.Run(method_call); | 252 void ExportedObject::SendResponse(base::TimeTicks start_time, |
246 bus_->PostTaskToDBusThread(FROM_HERE, | 253 MethodCall* method_call, |
247 base::Bind(&ExportedObject::OnMethodCompleted, | 254 Response* response) { |
248 this, | 255 DCHECK(method_call); |
249 method_call, | 256 if (bus_->HasDBusThread()) { |
250 response, | 257 bus_->PostTaskToDBusThread(FROM_HERE, |
251 start_time)); | 258 base::Bind(&ExportedObject::OnMethodCompleted, |
| 259 this, |
| 260 method_call, |
| 261 response, |
| 262 start_time)); |
| 263 } else { |
| 264 OnMethodCompleted(method_call, response, start_time); |
| 265 } |
252 } | 266 } |
253 | 267 |
254 void ExportedObject::OnMethodCompleted(MethodCall* method_call, | 268 void ExportedObject::OnMethodCompleted(MethodCall* method_call, |
255 Response* response, | 269 Response* response, |
256 base::TimeTicks start_time) { | 270 base::TimeTicks start_time) { |
257 bus_->AssertOnDBusThread(); | 271 bus_->AssertOnDBusThread(); |
258 scoped_ptr<MethodCall> method_call_deleter(method_call); | 272 scoped_ptr<MethodCall> method_call_deleter(method_call); |
259 scoped_ptr<Response> response_deleter(response); | 273 scoped_ptr<Response> response_deleter(response); |
260 | 274 |
261 // Record if the method call is successful, or not. 1 if successful. | 275 // Record if the method call is successful, or not. 1 if successful. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return self->HandleMessage(connection, raw_message); | 312 return self->HandleMessage(connection, raw_message); |
299 } | 313 } |
300 | 314 |
301 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, | 315 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, |
302 void* user_data) { | 316 void* user_data) { |
303 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); | 317 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); |
304 return self->OnUnregistered(connection); | 318 return self->OnUnregistered(connection); |
305 } | 319 } |
306 | 320 |
307 } // namespace dbus | 321 } // namespace dbus |
OLD | NEW |