| Index: base/message_loop_proxy.cc
|
| diff --git a/base/message_loop_proxy.cc b/base/message_loop_proxy.cc
|
| index 755564b9c5d915d71e2fc46f335ec8428db3c769..e771c16839519ae4484cdfed8049ae595e3d7ae1 100644
|
| --- a/base/message_loop_proxy.cc
|
| +++ b/base/message_loop_proxy.cc
|
| @@ -4,14 +4,107 @@
|
|
|
| #include "base/message_loop_proxy.h"
|
|
|
| -#include "base/bind.h"
|
| +#include "base/location.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/threading/thread_restrictions.h"
|
|
|
| namespace base {
|
|
|
| -MessageLoopProxy::MessageLoopProxy() {
|
| +scoped_refptr<MessageLoopProxy>
|
| +MessageLoopProxy::current() {
|
| + MessageLoop* cur_loop = MessageLoop::current();
|
| + if (!cur_loop)
|
| + return NULL;
|
| + return cur_loop->message_loop_proxy();
|
| +}
|
| +
|
| +// This function will be removed later in the fixing of CR Bug #108171.
|
| +bool MessageLoopProxy::PostDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + int64 delay_ms) {
|
| + return PostDelayedTask(
|
| + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
|
| +}
|
| +
|
| +bool MessageLoopProxy::PostDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) {
|
| + return PostTaskHelper(from_here, task, delay, true);
|
| +}
|
| +
|
| +bool MessageLoopProxy::RunsTasksOnCurrentThread() const {
|
| + // We shouldn't use MessageLoop::current() since it uses LazyInstance which
|
| + // may be deleted by ~AtExitManager when a WorkerPool thread calls this
|
| + // function.
|
| + // http://crbug.com/63678
|
| + base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
|
| + AutoLock lock(message_loop_lock_);
|
| + return (target_message_loop_ &&
|
| + (MessageLoop::current() == target_message_loop_));
|
| +}
|
| +
|
| +// This function will be removed later in the fixing of CR Bug #108171.
|
| +bool MessageLoopProxy::PostNonNestableDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + int64 delay_ms) {
|
| + return PostNonNestableDelayedTask(
|
| + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
|
| +}
|
| +
|
| +bool MessageLoopProxy::PostNonNestableDelayedTask(
|
| + const tracked_objects::Location& from_here,
|
| + const base::Closure& task,
|
| + base::TimeDelta delay) {
|
| + return PostTaskHelper(from_here, task, delay, false);
|
| +}
|
| +
|
| +void MessageLoopProxy::OnDestruct() const {
|
| + // We shouldn't use MessageLoop::current() since it uses LazyInstance which
|
| + // may be deleted by ~AtExitManager when a WorkerPool thread calls this
|
| + // function.
|
| + // http://crbug.com/63678
|
| + base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
|
| + bool delete_later = false;
|
| + {
|
| + AutoLock lock(message_loop_lock_);
|
| + if (target_message_loop_ &&
|
| + (MessageLoop::current() != target_message_loop_)) {
|
| + target_message_loop_->DeleteSoon(FROM_HERE, this);
|
| + delete_later = true;
|
| + }
|
| + }
|
| + if (!delete_later)
|
| + delete this;
|
| +}
|
| +
|
| +MessageLoopProxy::MessageLoopProxy()
|
| + : target_message_loop_(MessageLoop::current()) {
|
| }
|
|
|
| MessageLoopProxy::~MessageLoopProxy() {
|
| }
|
|
|
| +void MessageLoopProxy::WillDestroyCurrentMessageLoop() {
|
| + AutoLock lock(message_loop_lock_);
|
| + target_message_loop_ = NULL;
|
| +}
|
| +
|
| +bool MessageLoopProxy::PostTaskHelper(
|
| + const tracked_objects::Location& from_here, const base::Closure& task,
|
| + base::TimeDelta delay, bool nestable) {
|
| + AutoLock lock(message_loop_lock_);
|
| + if (target_message_loop_) {
|
| + if (nestable) {
|
| + target_message_loop_->PostDelayedTask(from_here, task, delay);
|
| + } else {
|
| + target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay);
|
| + }
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| } // namespace base
|
|
|