diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 22:28:42 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 22:28:42 +0000 |
commit | b8907a48776fa0141f0addfb62d54a69d1ba306c (patch) | |
tree | 2840c50d775f50563b56075023f5198b0bade21c | |
parent | 791fecafd19065160d0d546e497c8af1d0e1692a (diff) | |
download | chromium_src-b8907a48776fa0141f0addfb62d54a69d1ba306c.zip chromium_src-b8907a48776fa0141f0addfb62d54a69d1ba306c.tar.gz chromium_src-b8907a48776fa0141f0addfb62d54a69d1ba306c.tar.bz2 |
Use MessageLoopProxy for the origin message loop as well.
Inspired by mdm's patch to use the message loop proxy for the D-Bus thread.
Using MessageLoopProxy is a great way to make shutdown safer.
We should use this for the origin message loop as well.
BUG=chromium:90036
TEST=dbus_unittests
Review URL: http://codereview.chromium.org/7847013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100279 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | dbus/bus.cc | 40 | ||||
-rw-r--r-- | dbus/bus.h | 2 |
2 files changed, 31 insertions, 11 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index 5238d51..89918e0 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -180,7 +180,6 @@ Bus::Bus(const Options& options) dbus_thread_message_loop_proxy_(options.dbus_thread_message_loop_proxy), on_shutdown_(false /* manual_reset */, false /* initially_signaled */), connection_(NULL), - origin_loop_(MessageLoop::current()), origin_thread_id_(base::PlatformThread::CurrentId()), async_operations_set_up_(false), shutdown_completed_(false), @@ -188,6 +187,10 @@ Bus::Bus(const Options& options) num_pending_timeouts_(0) { // This is safe to call multiple times. dbus_threads_init_default(); + // The origin message loop is unnecessary if the client uses synchronous + // functions only. + if (MessageLoop::current()) + origin_message_loop_proxy_ = MessageLoop::current()->message_loop_proxy(); } Bus::~Bus() { @@ -560,25 +563,42 @@ void Bus::ProcessAllIncomingDataIfAny() { void Bus::PostTaskToOriginThread(const tracked_objects::Location& from_here, const base::Closure& task) { - origin_loop_->PostTask(from_here, task); + DCHECK(origin_message_loop_proxy_.get()); + if (!origin_message_loop_proxy_->PostTask(from_here, task)) { + LOG(WARNING) << "Failed to post a task to the origin message loop"; + } } void Bus::PostTaskToDBusThread(const tracked_objects::Location& from_here, const base::Closure& task) { - if (dbus_thread_message_loop_proxy_.get()) - dbus_thread_message_loop_proxy_->PostTask(from_here, task); - else - origin_loop_->PostTask(from_here, task); + if (dbus_thread_message_loop_proxy_.get()) { + if (!dbus_thread_message_loop_proxy_->PostTask(from_here, task)) { + LOG(WARNING) << "Failed to post a task to the D-Bus thread message loop"; + } + } else { + DCHECK(origin_message_loop_proxy_.get()); + if (!origin_message_loop_proxy_->PostTask(from_here, task)) { + LOG(WARNING) << "Failed to post a task to the origin message loop"; + } + } } void Bus::PostDelayedTaskToDBusThread( const tracked_objects::Location& from_here, const base::Closure& task, int delay_ms) { - if (dbus_thread_message_loop_proxy_.get()) - dbus_thread_message_loop_proxy_->PostDelayedTask(from_here, task, delay_ms); - else - origin_loop_->PostDelayedTask(from_here, task, delay_ms); + if (dbus_thread_message_loop_proxy_.get()) { + if (!dbus_thread_message_loop_proxy_->PostDelayedTask( + from_here, task, delay_ms)) { + LOG(WARNING) << "Failed to post a task to the D-Bus thread message loop"; + } + } else { + DCHECK(origin_message_loop_proxy_.get()); + if (!origin_message_loop_proxy_->PostDelayedTask( + from_here, task, delay_ms)) { + LOG(WARNING) << "Failed to post a task to the origin message loop"; + } + } } bool Bus::HasDBusThread() { @@ -436,7 +436,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> { base::WaitableEvent on_shutdown_; DBusConnection* connection_; - MessageLoop* origin_loop_; + scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; base::PlatformThreadId origin_thread_id_; std::set<std::string> owned_service_names_; |