From 12f9766f28712f8ec3755db4558dba4db5bd8a70 Mon Sep 17 00:00:00 2001 From: "satorux@chromium.org" Date: Sat, 20 Aug 2011 01:07:17 +0000 Subject: Rework TestService using asynchronos API of ExportedObject. This change is to to exercise asynchronos API of ExportedObject. The asynchronos API is implemented on top the synchronos API, hence the synchronos API code is also covered. Along the way, change EndToEndAsyncTest to use the D-Bus thread. Simplified the test code per phajdan.jr's comments as well. TEST=dbus_unittests BUG=90036 Review URL: http://codereview.chromium.org/7671028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97540 0039d316-1c4b-4281-b951-d872f2087c98 --- dbus/exported_object.cc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'dbus/exported_object.cc') diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc index 1793ed2..2ac1ff0 100644 --- a/dbus/exported_object.cc +++ b/dbus/exported_object.cc @@ -36,9 +36,9 @@ ExportedObject::ExportedObject(Bus* bus, service_name_(service_name), object_path_(object_path), object_is_registered_(false), - method_is_called_(false), response_from_method_(NULL), - on_method_is_called_(&method_is_called_lock_) { + on_method_is_called_(false /* manual_reset */, + false /* initially_signaled */) { } ExportedObject::~ExportedObject() { @@ -180,7 +180,6 @@ DBusHandlerResult ExportedObject::HandleMessage( Response* response = NULL; if (bus_->HasDBusThread()) { response_from_method_ = NULL; - method_is_called_ = false; // Post a task to run the method in the origin thread. bus_->PostTaskToOriginThread(FROM_HERE, base::Bind(&ExportedObject::RunMethod, @@ -195,14 +194,11 @@ DBusHandlerResult ExportedObject::HandleMessage( const int kTimeoutSecs = 10; const base::TimeDelta timeout( base::TimeDelta::FromSeconds(kTimeoutSecs)); - const base::Time start_time = base::Time::Now(); - - base::AutoLock auto_lock(method_is_called_lock_); - while (!method_is_called_) { - on_method_is_called_.TimedWait(timeout); - CHECK(base::Time::Now() - start_time < timeout) - << "Method " << absolute_method_name << " timed out"; - } + + const bool signaled = on_method_is_called_.TimedWait(timeout); + // Method not called is a fatal error. The method is likely stuck + // infinitely in the origin thread. No way to stop it from here. + CHECK(signaled) << "Method " << absolute_method_name << " not called"; } response = response_from_method_; } else { @@ -233,9 +229,7 @@ void ExportedObject::RunMethod(MethodCallCallback method_call_callback, MethodCall* method_call) { bus_->AssertOnOriginThread(); - base::AutoLock auto_lock(method_is_called_lock_); response_from_method_ = method_call_callback.Run(method_call); - method_is_called_ = true; on_method_is_called_.Signal(); } -- cgit v1.1