Commit 54e0612d authored by rsleevi@chromium.org's avatar rsleevi@chromium.org

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
parent a2be2f11
......@@ -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
......
......@@ -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_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment