Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: dbus/exported_object.cc

Issue 8637002: chrome: dbus: support asynchronous method replies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix style nits Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 iter->second.Run(method_call.get(),
229 // complete. 229 base::Bind(&ExportedObject::SendResponse,
230 // |response| will be deleted in OnMethodCompleted(). 230 this,
231 Response* response = iter->second.Run(method_call.get()); 231 start_time,
232 OnMethodCompleted(method_call.release(), response, start_time); 232 method_call.release()));
233 } 233 }
234 234
235 // 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
236 // time from OnMethodCompleted() asynchronously. 236 // time from OnMethodCompleted() asynchronously.
237 return DBUS_HANDLER_RESULT_HANDLED; 237 return DBUS_HANDLER_RESULT_HANDLED;
238 } 238 }
239 239
240 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, 240 void ExportedObject::RunMethod(MethodCallCallback method_call_callback,
241 MethodCall* method_call, 241 MethodCall* method_call,
242 base::TimeTicks start_time) { 242 base::TimeTicks start_time) {
243 bus_->AssertOnOriginThread(); 243 bus_->AssertOnOriginThread();
244 method_call_callback.Run(method_call,
245 base::Bind(&ExportedObject::SendResponse,
246 this,
247 start_time,
248 method_call));
249 }
244 250
245 Response* response = method_call_callback.Run(method_call); 251 void ExportedObject::SendResponse(base::TimeTicks start_time,
246 bus_->PostTaskToDBusThread(FROM_HERE, 252 MethodCall* method_call,
247 base::Bind(&ExportedObject::OnMethodCompleted, 253 Response* response) {
248 this, 254 DCHECK(method_call);
249 method_call, 255 if (bus_->HasDBusThread()) {
250 response, 256 bus_->PostTaskToDBusThread(FROM_HERE,
251 start_time)); 257 base::Bind(&ExportedObject::OnMethodCompleted,
258 this,
259 method_call,
260 response,
261 start_time));
262 } else {
263 OnMethodCompleted(method_call, response, start_time);
264 }
252 } 265 }
253 266
254 void ExportedObject::OnMethodCompleted(MethodCall* method_call, 267 void ExportedObject::OnMethodCompleted(MethodCall* method_call,
255 Response* response, 268 Response* response,
256 base::TimeTicks start_time) { 269 base::TimeTicks start_time) {
257 bus_->AssertOnDBusThread(); 270 bus_->AssertOnDBusThread();
258 scoped_ptr<MethodCall> method_call_deleter(method_call); 271 scoped_ptr<MethodCall> method_call_deleter(method_call);
259 scoped_ptr<Response> response_deleter(response); 272 scoped_ptr<Response> response_deleter(response);
260 273
261 // Record if the method call is successful, or not. 1 if successful. 274 // Record if the method call is successful, or not. 1 if successful.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return self->HandleMessage(connection, raw_message); 311 return self->HandleMessage(connection, raw_message);
299 } 312 }
300 313
301 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, 314 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection,
302 void* user_data) { 315 void* user_data) {
303 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); 316 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data);
304 return self->OnUnregistered(connection); 317 return self->OnUnregistered(connection);
305 } 318 }
306 319
307 } // namespace dbus 320 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/exported_object.h ('k') | dbus/test_service.h » ('j') | dbus/test_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698