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

Unified Diff: dbus/test_service.cc

Issue 8728020: chrome: dbus: support asynchronous method replies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: dbus/test_service.cc
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
index b0207b0e7e9afb14ae4cd1033766855f12b3cdff..ea8e3601b0f12a1f414f7f972bcb0441794f8dd9 100644
--- a/dbus/test_service.cc
+++ b/dbus/test_service.cc
@@ -13,8 +13,8 @@
namespace dbus {
-// Echo, SlowEcho, BrokenMethod.
-const int TestService::kNumMethodsToExport = 3;
+// Echo, SlowEcho, AsyncEcho, BrokenMethod.
+const int TestService::kNumMethodsToExport = 4;
TestService::Options::Options() {
}
@@ -148,6 +148,15 @@ void TestService::Run(MessageLoop* message_loop) {
exported_object_->ExportMethod(
"org.chromium.TestInterface",
+ "AsyncEcho",
+ base::Bind(&TestService::AsyncEcho,
+ base::Unretained(this)),
+ base::Bind(&TestService::OnExported,
+ base::Unretained(this)));
+ ++num_methods;
+
+ exported_object_->ExportMethod(
+ "org.chromium.TestInterface",
"BrokenMethod",
base::Bind(&TestService::BrokenMethod,
base::Unretained(this)),
@@ -163,25 +172,44 @@ void TestService::Run(MessageLoop* message_loop) {
message_loop->Run();
}
-Response* TestService::Echo(MethodCall* method_call) {
+void TestService::Echo(MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
MessageReader reader(method_call);
std::string text_message;
- if (!reader.PopString(&text_message))
- return NULL;
+ if (!reader.PopString(&text_message)) {
+ response_sender.Run(NULL);
+ return;
+ }
Response* response = Response::FromMethodCall(method_call);
MessageWriter writer(response);
writer.AppendString(text_message);
- return response;
+ response_sender.Run(response);
}
-Response* TestService::SlowEcho(MethodCall* method_call) {
+void TestService::SlowEcho(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms());
- return Echo(method_call);
+ Echo(method_call, response_sender);
+}
+
+void TestService::AsyncEcho(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ // Schedule a call to Echo() to send an asynchronous response after we return.
+ message_loop()->PostDelayedTask(FROM_HERE,
+ base::Bind(&TestService::Echo,
+ base::Unretained(this),
+ method_call,
+ response_sender),
+ TestTimeouts::tiny_timeout_ms());
}
-Response* TestService::BrokenMethod(MethodCall* method_call) {
- return NULL;
+void TestService::BrokenMethod(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ response_sender.Run(NULL);
}
} // namespace dbus

Powered by Google App Engine
This is Rietveld 408576698