| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop/message_loop_proxy_impl.h" | |
| 6 | |
| 7 #include "base/location.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/message_loop/incoming_task_queue.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 | |
| 12 namespace base { | |
| 13 namespace internal { | |
| 14 | |
| 15 MessageLoopProxyImpl::MessageLoopProxyImpl( | |
| 16 scoped_refptr<IncomingTaskQueue> incoming_queue) | |
| 17 : incoming_queue_(incoming_queue), | |
| 18 valid_thread_id_(kInvalidThreadId) { | |
| 19 } | |
| 20 | |
| 21 void MessageLoopProxyImpl::BindToCurrentThread() { | |
| 22 AutoLock lock(valid_thread_id_lock_); | |
| 23 DCHECK_EQ(kInvalidThreadId, valid_thread_id_); | |
| 24 valid_thread_id_ = PlatformThread::CurrentId(); | |
| 25 } | |
| 26 | |
| 27 bool MessageLoopProxyImpl::PostDelayedTask( | |
| 28 const tracked_objects::Location& from_here, | |
| 29 const base::Closure& task, | |
| 30 base::TimeDelta delay) { | |
| 31 DCHECK(!task.is_null()) << from_here.ToString(); | |
| 32 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, true); | |
| 33 } | |
| 34 | |
| 35 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( | |
| 36 const tracked_objects::Location& from_here, | |
| 37 const base::Closure& task, | |
| 38 base::TimeDelta delay) { | |
| 39 DCHECK(!task.is_null()) << from_here.ToString(); | |
| 40 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, false); | |
| 41 } | |
| 42 | |
| 43 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { | |
| 44 AutoLock lock(valid_thread_id_lock_); | |
| 45 return valid_thread_id_ == PlatformThread::CurrentId(); | |
| 46 } | |
| 47 | |
| 48 MessageLoopProxyImpl::~MessageLoopProxyImpl() { | |
| 49 } | |
| 50 | |
| 51 } // namespace internal | |
| 52 | |
| 53 scoped_refptr<MessageLoopProxy> | |
| 54 MessageLoopProxy::current() { | |
| 55 MessageLoop* cur_loop = MessageLoop::current(); | |
| 56 if (!cur_loop) | |
| 57 return NULL; | |
| 58 return cur_loop->message_loop_proxy(); | |
| 59 } | |
| 60 | |
| 61 } // namespace base | |
| OLD | NEW |