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

Side by Side Diff: dbus/test_service.cc

Issue 8682032: Revert 111479 - chrome: dbus: support asynchronous method replies (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test_service.h" 5 #include "dbus/test_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
11 #include "dbus/exported_object.h" 11 #include "dbus/exported_object.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 13
14 namespace dbus { 14 namespace dbus {
15 15
16 // Echo, SlowEcho, AsyncEcho, BrokenMethod. 16 // Echo, SlowEcho, BrokenMethod.
17 const int TestService::kNumMethodsToExport = 4; 17 const int TestService::kNumMethodsToExport = 3;
18 18
19 TestService::Options::Options() { 19 TestService::Options::Options() {
20 } 20 }
21 21
22 TestService::Options::~Options() { 22 TestService::Options::~Options() {
23 } 23 }
24 24
25 TestService::TestService(const Options& options) 25 TestService::TestService(const Options& options)
26 : base::Thread("TestService"), 26 : base::Thread("TestService"),
27 dbus_thread_message_loop_proxy_(options.dbus_thread_message_loop_proxy), 27 dbus_thread_message_loop_proxy_(options.dbus_thread_message_loop_proxy),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 "org.chromium.TestInterface", 141 "org.chromium.TestInterface",
142 "SlowEcho", 142 "SlowEcho",
143 base::Bind(&TestService::SlowEcho, 143 base::Bind(&TestService::SlowEcho,
144 base::Unretained(this)), 144 base::Unretained(this)),
145 base::Bind(&TestService::OnExported, 145 base::Bind(&TestService::OnExported,
146 base::Unretained(this))); 146 base::Unretained(this)));
147 ++num_methods; 147 ++num_methods;
148 148
149 exported_object_->ExportMethod( 149 exported_object_->ExportMethod(
150 "org.chromium.TestInterface", 150 "org.chromium.TestInterface",
151 "AsyncEcho",
152 base::Bind(&TestService::AsyncEcho,
153 base::Unretained(this)),
154 base::Bind(&TestService::OnExported,
155 base::Unretained(this)));
156 ++num_methods;
157
158 exported_object_->ExportMethod(
159 "org.chromium.TestInterface",
160 "BrokenMethod", 151 "BrokenMethod",
161 base::Bind(&TestService::BrokenMethod, 152 base::Bind(&TestService::BrokenMethod,
162 base::Unretained(this)), 153 base::Unretained(this)),
163 base::Bind(&TestService::OnExported, 154 base::Bind(&TestService::OnExported,
164 base::Unretained(this))); 155 base::Unretained(this)));
165 ++num_methods; 156 ++num_methods;
166 157
167 // Just print an error message as we don't want to crash tests. 158 // Just print an error message as we don't want to crash tests.
168 // Tests will fail at a call to WaitUntilServiceIsStarted(). 159 // Tests will fail at a call to WaitUntilServiceIsStarted().
169 if (num_methods != kNumMethodsToExport) { 160 if (num_methods != kNumMethodsToExport) {
170 LOG(ERROR) << "The number of methods does not match"; 161 LOG(ERROR) << "The number of methods does not match";
171 } 162 }
172 message_loop->Run(); 163 message_loop->Run();
173 } 164 }
174 165
175 void TestService::Echo(MethodCall* method_call, 166 Response* TestService::Echo(MethodCall* method_call) {
176 dbus::ExportedObject::ResponseSender response_sender) {
177 MessageReader reader(method_call); 167 MessageReader reader(method_call);
178 std::string text_message; 168 std::string text_message;
179 if (!reader.PopString(&text_message)) { 169 if (!reader.PopString(&text_message))
180 response_sender.Run(NULL); 170 return NULL;
181 return;
182 }
183 171
184 Response* response = Response::FromMethodCall(method_call); 172 Response* response = Response::FromMethodCall(method_call);
185 MessageWriter writer(response); 173 MessageWriter writer(response);
186 writer.AppendString(text_message); 174 writer.AppendString(text_message);
187 response_sender.Run(response); 175 return response;
188 } 176 }
189 177
190 void TestService::SlowEcho( 178 Response* TestService::SlowEcho(MethodCall* method_call) {
191 MethodCall* method_call,
192 dbus::ExportedObject::ResponseSender response_sender) {
193 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); 179 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms());
194 Echo(method_call, response_sender); 180 return Echo(method_call);
195 } 181 }
196 182
197 void TestService::AsyncEcho( 183 Response* TestService::BrokenMethod(MethodCall* method_call) {
198 MethodCall* method_call, 184 return NULL;
199 dbus::ExportedObject::ResponseSender response_sender) {
200 // Schedule a call to Echo() to send an asynchronous response after we return.
201 message_loop()->PostDelayedTask(FROM_HERE,
202 base::Bind(&TestService::Echo,
203 base::Unretained(this),
204 method_call,
205 response_sender),
206 TestTimeouts::tiny_timeout_ms());
207 }
208
209 void TestService::BrokenMethod(
210 MethodCall* method_call,
211 dbus::ExportedObject::ResponseSender response_sender) {
212 response_sender.Run(NULL);
213 } 185 }
214 186
215 } // namespace dbus 187 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698