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

Unified Diff: dbus/test_service.cc

Issue 125673003: dbus: Add comments about the right way to expose methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/test_service.cc
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
index 5f5950162ec95493ed86176cfcbf5cc93101ef73..21a885d0b67fa4a4ede39046fb3d8116cb26ecac 100644
--- a/dbus/test_service.cc
+++ b/dbus/test_service.cc
@@ -38,7 +38,7 @@ TestService::TestService(const Options& options)
: base::Thread("TestService"),
request_ownership_options_(options.request_ownership_options),
dbus_task_runner_(options.dbus_task_runner),
- on_all_methods_exported_(false, false),
+ on_name_obtained_(false, false),
num_exported_methods_(0) {
}
@@ -54,8 +54,8 @@ bool TestService::StartService() {
bool TestService::WaitUntilServiceIsStarted() {
const base::TimeDelta timeout(TestTimeouts::action_max_timeout());
- // Wait until all methods are exported.
- return on_all_methods_exported_.TimedWait(timeout);
+ // Wait until the ownership of the service name is obtained.
+ return on_name_obtained_.TimedWait(timeout);
}
void TestService::ShutdownAndBlock() {
@@ -138,6 +138,8 @@ void TestService::OnOwnership(base::Callback<void(bool)> callback,
has_ownership_ = success;
LOG_IF(ERROR, !success) << "Failed to own: " << service_name;
callback.Run(success);
+
+ on_name_obtained_.Signal();
}
void TestService::OnExported(const std::string& interface_name,
@@ -152,8 +154,15 @@ void TestService::OnExported(const std::string& interface_name,
}
++num_exported_methods_;
- if (num_exported_methods_ == kNumMethodsToExport)
- on_all_methods_exported_.Signal();
+ if (num_exported_methods_ == kNumMethodsToExport) {
+ // As documented in exported_object.h, the service name should be
+ // requested after all methods are exposed.
+ bus_->RequestOwnership("org.chromium.TestService",
+ request_ownership_options_,
+ base::Bind(&TestService::OnOwnership,
+ base::Unretained(this),
+ base::Bind(&EmptyCallback)));
+ }
}
void TestService::Run(base::MessageLoop* message_loop) {
@@ -163,12 +172,6 @@ void TestService::Run(base::MessageLoop* message_loop) {
bus_options.dbus_task_runner = dbus_task_runner_;
bus_ = new Bus(bus_options);
- bus_->RequestOwnership("org.chromium.TestService",
- request_ownership_options_,
- base::Bind(&TestService::OnOwnership,
- base::Unretained(this),
- base::Bind(&EmptyCallback)));
-
exported_object_ = bus_->GetExportedObject(
ObjectPath("/org/chromium/TestObject"));
« 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