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

Unified Diff: dbus/bus.cc

Issue 7830009: Add Bus::ShutdownOnDBusThreadAndBlock() and remove bus::Shutdown() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
« dbus/bus.h ('K') | « dbus/bus.h ('k') | dbus/bus_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/bus.cc
diff --git a/dbus/bus.cc b/dbus/bus.cc
index 1b766acd0f7a787b1f17da1fbb7c8f517b8f57ad..4fc846348979b7f7505fa0570d160c8775d8051e 100644
--- a/dbus/bus.cc
+++ b/dbus/bus.cc
@@ -14,6 +14,7 @@
#include "base/stl_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
+#include "base/time.h"
#include "dbus/exported_object.h"
#include "dbus/object_proxy.h"
#include "dbus/scoped_dbus_error.h"
@@ -178,11 +179,13 @@ Bus::Bus(const Options& options)
: bus_type_(options.bus_type),
connection_type_(options.connection_type),
dbus_thread_(options.dbus_thread),
+ on_shutdown_(false /* manual_reset */, false /* initially_signaled */),
connection_(NULL),
origin_loop_(MessageLoop::current()),
origin_thread_id_(base::PlatformThread::CurrentId()),
dbus_thread_id_(base::kInvalidThreadId),
async_operations_set_up_(false),
+ shutdown_completed_(false),
num_pending_watches_(0),
num_pending_timeouts_(0) {
if (dbus_thread_) {
@@ -299,13 +302,15 @@ void Bus::ShutdownAndBlock() {
}
// Private connection should be closed.
- if (connection_ && connection_type_ == PRIVATE) {
- dbus_connection_close(connection_);
+ if (connection_) {
+ if (connection_type_ == PRIVATE)
+ dbus_connection_close(connection_);
+ // dbus_connection_close() won't unref.
+ dbus_connection_unref(connection_);
}
- // dbus_connection_close() won't unref.
- dbus_connection_unref(connection_);
connection_ = NULL;
+ shutdown_completed_ = true;
}
void Bus::Shutdown(OnShutdownCallback callback) {
@@ -316,6 +321,22 @@ void Bus::Shutdown(OnShutdownCallback callback) {
callback));
}
+void Bus::ShutdownAndBlockWithDBusThread() {
+ AssertOnOriginThread();
+ DCHECK(dbus_thread_);
+
+ PostTaskToDBusThread(FROM_HERE, base::Bind(
+ &Bus::ShutdownAndBlockWithDBusThreadInternal,
+ this));
+
+ // Wait until the shutdown is complete on the D-Bus thread.
+ // The shutdown should not hang, but set timeout just in case.
+ const int kTimeoutSecs = 3;
+ const base::TimeDelta timeout(base::TimeDelta::FromSeconds(kTimeoutSecs));
+ const bool signaled = on_shutdown_.TimedWait(timeout);
+ LOG_IF(ERROR, !signaled) << "Failed to shutdown the bus";
+}
+
bool Bus::RequestOwnership(const std::string& service_name) {
DCHECK(connection_);
// dbus_bus_request_name() is a blocking call.
@@ -542,6 +563,13 @@ void Bus::ShutdownInternal(OnShutdownCallback callback) {
PostTaskToOriginThread(FROM_HERE, callback);
}
+void Bus::ShutdownAndBlockWithDBusThreadInternal() {
+ AssertOnDBusThread();
+
+ ShutdownAndBlock();
+ on_shutdown_.Signal();
+}
+
void Bus::ProcessAllIncomingDataIfAny() {
AssertOnDBusThread();
« dbus/bus.h ('K') | « dbus/bus.h ('k') | dbus/bus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698