diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 03:31:34 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 03:31:34 +0000 |
commit | 2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd (patch) | |
tree | 9bae18a794cacca3aa2164deca4e6460815f20b9 /chrome/browser/chrome_thread.cc | |
parent | ad3d7273dff93e5107a947c05c6a47c35ea7eea7 (diff) | |
download | chromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.zip chromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.tar.gz chromium_src-2cbac9eb5be45ba99a37b28eb1dbf306ee3e67cd.tar.bz2 |
Created a MessageLoopProxy interface. This provides a thread-safe refcounted interface to the Post* methods
of a message loop. This class can outlive the target message loop. Changed ChromeThread to vend an implementation of this proxy.
BUG=None
TEST=ChromeThread unit-tests modified.
Review URL: http://codereview.chromium.org/1800008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chrome_thread.cc')
-rw-r--r-- | chrome/browser/chrome_thread.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/chrome/browser/chrome_thread.cc b/chrome/browser/chrome_thread.cc index 300c2f6..6421a79 100644 --- a/chrome/browser/chrome_thread.cc +++ b/chrome/browser/chrome_thread.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chrome_thread.h" #include "base/message_loop.h" +#include "base/message_loop_proxy.h" // Friendly names for the well-known threads. static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { @@ -19,6 +20,44 @@ static const char* chrome_thread_names[ChromeThread::ID_COUNT] = { #endif }; +// An implementation of MessageLoopProxy to be used in conjunction +// with ChromeThread. +class ChromeThreadMessageLoopProxy : public MessageLoopProxy { + public: + explicit ChromeThreadMessageLoopProxy(ChromeThread::ID identifier) + : id_(identifier) { + } + + // MessageLoopProxy implementation. + virtual bool PostTask(const tracked_objects::Location& from_here, + Task* task) { + return ChromeThread::PostTask(id_, from_here, task); + } + + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + Task* task, int64 delay_ms) { + return ChromeThread::PostDelayedTask(id_, from_here, task, delay_ms); + } + + virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, + Task* task) { + return ChromeThread::PostNonNestableTask(id_, from_here, task); + } + + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + Task* task, + int64 delay_ms) { + return ChromeThread::PostNonNestableDelayedTask(id_, from_here, task, + delay_ms); + } + + private: + ChromeThread::ID id_; + DISALLOW_COPY_AND_ASSIGN(ChromeThreadMessageLoopProxy); +}; + + Lock ChromeThread::lock_; ChromeThread* ChromeThread::chrome_threads_[ID_COUNT]; @@ -122,6 +161,14 @@ bool ChromeThread::GetCurrentThreadIdentifier(ID* identifier) { } // static +scoped_refptr<MessageLoopProxy> ChromeThread::GetMessageLoopProxyForThread( + ID identifier) { + scoped_refptr<MessageLoopProxy> proxy = + new ChromeThreadMessageLoopProxy(identifier); + return proxy; +} + +// static bool ChromeThread::PostTaskHelper( ID identifier, const tracked_objects::Location& from_here, |