diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-12 01:10:52 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-12 01:10:52 +0000 |
commit | 54e0612d52deedf7a0f0a0f9a65aa5ab0bc67947 (patch) | |
tree | 833a3338270b76161bf0b9cac20add41a9c3f9a5 | |
parent | a2be2f11f1e87ccdbbdf3be2d6164e74b4d115fd (diff) | |
download | chromium_src-54e0612d52deedf7a0f0a0f9a65aa5ab0bc67947.zip chromium_src-54e0612d52deedf7a0f0a0f9a65aa5ab0bc67947.tar.gz chromium_src-54e0612d52deedf7a0f0a0f9a65aa5ab0bc67947.tar.bz2 |
Introduce task_runner() accessors for both base::Thread and base::MessageLoop
This is so that callers can code against a TaskRunner interface
directly, rather than converting message_loop_proxy() into a TaskRunner.
BUG=391045
Review URL: https://codereview.chromium.org/389653005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282767 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/message_loop/message_loop.h | 7 | ||||
-rw-r--r-- | base/threading/thread.h | 22 |
2 files changed, 24 insertions, 5 deletions
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h index a65fbf5..330bde6 100644 --- a/base/message_loop/message_loop.h +++ b/base/message_loop/message_loop.h @@ -295,10 +295,17 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { const std::string& thread_name() const { return thread_name_; } // Gets the message loop proxy associated with this message loop. + // + // NOTE: Deprecated; prefer task_runner() and the TaskRunner interfaces scoped_refptr<MessageLoopProxy> message_loop_proxy() { return message_loop_proxy_; } + // Gets the TaskRunner associated with this message loop. + scoped_refptr<SingleThreadTaskRunner> task_runner() { + return message_loop_proxy_; + } + // Enables or disables the recursive task processing. This happens in the case // of recursive message loops. Some unwanted message loop may occurs when // using common controls or printer functions. By default, recursive task diff --git a/base/threading/thread.h b/base/threading/thread.h index 9d446dd..a0a3005 100644 --- a/base/threading/thread.h +++ b/base/threading/thread.h @@ -138,15 +138,27 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { // MessageLoop* message_loop() const { return message_loop_; } - // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's - // PostTask methods to execute code on the thread. This only returns - // non-NULL after a successful call to Start. After Stop has been called, - // this will return NULL. Callers can hold on to this even after the thread - // is gone. + // Returns a MessageLoopProxy for this thread. Use the MessageLoopProxy's + // PostTask methods to execute code on the thread. Returns NULL if the thread + // is not running (e.g. before Start or after Stop have been called). Callers + // can hold on to this even after the thread is gone; in this situation, + // attempts to PostTask() will fail. + // + // Note: This method is deprecated. Callers should call task_runner() instead + // and use the TaskRunner interfaces for safely interfacing with the Thread. scoped_refptr<MessageLoopProxy> message_loop_proxy() const { return message_loop_ ? message_loop_->message_loop_proxy() : NULL; } + // Returns a TaskRunner for this thread. Use the TaskRunner's PostTask + // methods to execute code on the thread. Returns NULL if the thread is not + // running (e.g. before Start or after Stop have been called). Callers can + // hold on to this even after the thread is gone; in this situation, attempts + // to PostTask() will fail. + scoped_refptr<SingleThreadTaskRunner> task_runner() const { + return message_loop_proxy(); + } + // Returns the name of this thread (for display in debugger too). const std::string& thread_name() const { return name_; } |