OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop/message_loop_proxy_impl.h" | 5 #include "base/message_loop/message_loop_proxy_impl.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/incoming_task_queue.h" | 9 #include "base/message_loop/incoming_task_queue.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 MessageLoopProxyImpl::MessageLoopProxyImpl( | 15 // static |
16 scoped_refptr<IncomingTaskQueue> incoming_queue) | 16 MessageLoopProxyImpl* MessageLoopProxyImpl::Create( |
17 : incoming_queue_(incoming_queue), | 17 scoped_refptr<IncomingTaskQueue> incoming_queue) { |
18 valid_thread_id_(PlatformThread::CurrentId()) { | 18 return new MessageLoopProxyImpl(incoming_queue, false /* lazy_init */); |
19 } | |
20 | |
21 // static | |
22 MessageLoopProxyImpl* MessageLoopProxyImpl::CreateForLazyInit( | |
23 scoped_refptr<IncomingTaskQueue> incoming_queue) { | |
24 return new MessageLoopProxyImpl(incoming_queue, true /* lazy_init */); | |
19 } | 25 } |
20 | 26 |
21 bool MessageLoopProxyImpl::PostDelayedTask( | 27 bool MessageLoopProxyImpl::PostDelayedTask( |
22 const tracked_objects::Location& from_here, | 28 const tracked_objects::Location& from_here, |
23 const base::Closure& task, | 29 const base::Closure& task, |
24 base::TimeDelta delay) { | 30 base::TimeDelta delay) { |
25 DCHECK(!task.is_null()) << from_here.ToString(); | 31 DCHECK(!task.is_null()) << from_here.ToString(); |
26 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, true); | 32 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, true); |
27 } | 33 } |
28 | 34 |
29 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( | 35 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( |
30 const tracked_objects::Location& from_here, | 36 const tracked_objects::Location& from_here, |
31 const base::Closure& task, | 37 const base::Closure& task, |
32 base::TimeDelta delay) { | 38 base::TimeDelta delay) { |
33 DCHECK(!task.is_null()) << from_here.ToString(); | 39 DCHECK(!task.is_null()) << from_here.ToString(); |
34 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, false); | 40 return incoming_queue_->AddToIncomingQueue(from_here, task, delay, false); |
35 } | 41 } |
36 | 42 |
37 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { | 43 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { |
38 return valid_thread_id_ == PlatformThread::CurrentId(); | 44 return valid_thread_id_ == PlatformThread::CurrentId(); |
39 } | 45 } |
40 | 46 |
47 void MessageLoopProxyImpl::LazyInit() { | |
48 DCHECK_EQ(kInvalidThreadId, valid_thread_id_); | |
49 valid_thread_id_ = PlatformThread::CurrentId(); | |
50 } | |
51 | |
52 MessageLoopProxyImpl::MessageLoopProxyImpl( | |
53 scoped_refptr<IncomingTaskQueue> incoming_queue, | |
54 bool lazy_init) | |
rvargas (doing something else)
2015/03/26 02:19:27
Maybe it's better to remove this argument and set
kinuko
2015/04/13 02:02:59
Removed.
| |
55 : incoming_queue_(incoming_queue), | |
56 valid_thread_id_(lazy_init ? kInvalidThreadId | |
57 : PlatformThread::CurrentId()) { | |
58 } | |
59 | |
41 MessageLoopProxyImpl::~MessageLoopProxyImpl() { | 60 MessageLoopProxyImpl::~MessageLoopProxyImpl() { |
42 } | 61 } |
43 | 62 |
44 } // namespace internal | 63 } // namespace internal |
45 | 64 |
46 scoped_refptr<MessageLoopProxy> | 65 scoped_refptr<MessageLoopProxy> |
47 MessageLoopProxy::current() { | 66 MessageLoopProxy::current() { |
48 MessageLoop* cur_loop = MessageLoop::current(); | 67 MessageLoop* cur_loop = MessageLoop::current(); |
49 if (!cur_loop) | 68 if (!cur_loop) |
50 return NULL; | 69 return NULL; |
51 return cur_loop->message_loop_proxy(); | 70 return cur_loop->message_loop_proxy(); |
52 } | 71 } |
53 | 72 |
54 } // namespace base | 73 } // namespace base |
OLD | NEW |