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. | 227 // If the D-Bus thread is not used, just call the method directly. We |
228 MethodCall* released_method_call = method_call.release(); | 228 // don't need the complicated logic to wait for the method call to be |
229 iter->second.Run(released_method_call, | 229 // complete. |
230 base::Bind(&ExportedObject::SendResponse, | 230 // |response| will be deleted in OnMethodCompleted(). |
231 this, | 231 Response* response = iter->second.Run(method_call.get()); |
232 start_time, | 232 OnMethodCompleted(method_call.release(), response, start_time); |
233 released_method_call)); | |
234 } | 233 } |
235 | 234 |
236 // It's valid to say HANDLED here, and send a method response at a later | 235 // It's valid to say HANDLED here, and send a method response at a later |
237 // time from OnMethodCompleted() asynchronously. | 236 // time from OnMethodCompleted() asynchronously. |
238 return DBUS_HANDLER_RESULT_HANDLED; | 237 return DBUS_HANDLER_RESULT_HANDLED; |
239 } | 238 } |
240 | 239 |
241 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, | 240 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, |
242 MethodCall* method_call, | 241 MethodCall* method_call, |
243 base::TimeTicks start_time) { | 242 base::TimeTicks start_time) { |
244 bus_->AssertOnOriginThread(); | 243 bus_->AssertOnOriginThread(); |
245 method_call_callback.Run(method_call, | |
246 base::Bind(&ExportedObject::SendResponse, | |
247 this, | |
248 start_time, | |
249 method_call)); | |
250 } | |
251 | 244 |
252 void ExportedObject::SendResponse(base::TimeTicks start_time, | 245 Response* response = method_call_callback.Run(method_call); |
253 MethodCall* method_call, | 246 bus_->PostTaskToDBusThread(FROM_HERE, |
254 Response* response) { | 247 base::Bind(&ExportedObject::OnMethodCompleted, |
255 DCHECK(method_call); | 248 this, |
256 if (bus_->HasDBusThread()) { | 249 method_call, |
257 bus_->PostTaskToDBusThread(FROM_HERE, | 250 response, |
258 base::Bind(&ExportedObject::OnMethodCompleted, | 251 start_time)); |
259 this, | |
260 method_call, | |
261 response, | |
262 start_time)); | |
263 } else { | |
264 OnMethodCompleted(method_call, response, start_time); | |
265 } | |
266 } | 252 } |
267 | 253 |
268 void ExportedObject::OnMethodCompleted(MethodCall* method_call, | 254 void ExportedObject::OnMethodCompleted(MethodCall* method_call, |
269 Response* response, | 255 Response* response, |
270 base::TimeTicks start_time) { | 256 base::TimeTicks start_time) { |
271 bus_->AssertOnDBusThread(); | 257 bus_->AssertOnDBusThread(); |
272 scoped_ptr<MethodCall> method_call_deleter(method_call); | 258 scoped_ptr<MethodCall> method_call_deleter(method_call); |
273 scoped_ptr<Response> response_deleter(response); | 259 scoped_ptr<Response> response_deleter(response); |
274 | 260 |
275 // Record if the method call is successful, or not. 1 if successful. | 261 // 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... |
312 return self->HandleMessage(connection, raw_message); | 298 return self->HandleMessage(connection, raw_message); |
313 } | 299 } |
314 | 300 |
315 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, | 301 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, |
316 void* user_data) { | 302 void* user_data) { |
317 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); | 303 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); |
318 return self->OnUnregistered(connection); | 304 return self->OnUnregistered(connection); |
319 } | 305 } |
320 | 306 |
321 } // namespace dbus | 307 } // namespace dbus |
OLD | NEW |