OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_proxy_impl.h" | 5 #include "base/message_loop_proxy_impl.h" |
6 #include "base/threading/thread_restrictions.h" | 6 #include "base/threading/thread_restrictions.h" |
7 | 7 |
8 namespace base { | 8 namespace base { |
9 | 9 |
10 MessageLoopProxyImpl::~MessageLoopProxyImpl() { | 10 MessageLoopProxyImpl::~MessageLoopProxyImpl() { |
(...skipping 22 matching lines...) Expand all Loading... |
33 return PostTaskHelper(from_here, task, 0, false); | 33 return PostTaskHelper(from_here, task, 0, false); |
34 } | 34 } |
35 | 35 |
36 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( | 36 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( |
37 const tracked_objects::Location& from_here, | 37 const tracked_objects::Location& from_here, |
38 Task* task, | 38 Task* task, |
39 int64 delay_ms) { | 39 int64 delay_ms) { |
40 return PostTaskHelper(from_here, task, delay_ms, false); | 40 return PostTaskHelper(from_here, task, delay_ms, false); |
41 } | 41 } |
42 | 42 |
| 43 bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here, |
| 44 const base::Closure& task) { |
| 45 return PostTaskHelper(from_here, task, 0, true); |
| 46 } |
| 47 |
| 48 bool MessageLoopProxyImpl::PostDelayedTask( |
| 49 const tracked_objects::Location& from_here, |
| 50 const base::Closure& task, |
| 51 int64 delay_ms) { |
| 52 return PostTaskHelper(from_here, task, delay_ms, true); |
| 53 } |
| 54 |
| 55 bool MessageLoopProxyImpl::PostNonNestableTask( |
| 56 const tracked_objects::Location& from_here, const base::Closure& task) { |
| 57 return PostTaskHelper(from_here, task, 0, false); |
| 58 } |
| 59 |
| 60 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( |
| 61 const tracked_objects::Location& from_here, |
| 62 const base::Closure& task, |
| 63 int64 delay_ms) { |
| 64 return PostTaskHelper(from_here, task, delay_ms, false); |
| 65 } |
| 66 |
43 bool MessageLoopProxyImpl::BelongsToCurrentThread() { | 67 bool MessageLoopProxyImpl::BelongsToCurrentThread() { |
44 // We shouldn't use MessageLoop::current() since it uses LazyInstance which | 68 // We shouldn't use MessageLoop::current() since it uses LazyInstance which |
45 // may be deleted by ~AtExitManager when a WorkerPool thread calls this | 69 // may be deleted by ~AtExitManager when a WorkerPool thread calls this |
46 // function. | 70 // function. |
47 // http://crbug.com/63678 | 71 // http://crbug.com/63678 |
48 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; | 72 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; |
49 AutoLock lock(message_loop_lock_); | 73 AutoLock lock(message_loop_lock_); |
50 return (target_message_loop_ && | 74 return (target_message_loop_ && |
51 (MessageLoop::current() == target_message_loop_)); | 75 (MessageLoop::current() == target_message_loop_)); |
52 } | 76 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 delay_ms); | 119 delay_ms); |
96 } | 120 } |
97 ret = true; | 121 ret = true; |
98 } | 122 } |
99 } | 123 } |
100 if (!ret) | 124 if (!ret) |
101 delete task; | 125 delete task; |
102 return ret; | 126 return ret; |
103 } | 127 } |
104 | 128 |
| 129 bool MessageLoopProxyImpl::PostTaskHelper( |
| 130 const tracked_objects::Location& from_here, const base::Closure& task, |
| 131 int64 delay_ms, bool nestable) { |
| 132 AutoLock lock(message_loop_lock_); |
| 133 if (target_message_loop_) { |
| 134 if (nestable) { |
| 135 target_message_loop_->PostDelayedTask(from_here, task, delay_ms); |
| 136 } else { |
| 137 target_message_loop_->PostNonNestableDelayedTask(from_here, task, |
| 138 delay_ms); |
| 139 } |
| 140 return true; |
| 141 } |
| 142 return false; |
| 143 } |
| 144 |
105 scoped_refptr<MessageLoopProxy> | 145 scoped_refptr<MessageLoopProxy> |
106 MessageLoopProxy::CreateForCurrentThread() { | 146 MessageLoopProxy::CreateForCurrentThread() { |
107 scoped_refptr<MessageLoopProxy> ret(new MessageLoopProxyImpl()); | 147 scoped_refptr<MessageLoopProxy> ret(new MessageLoopProxyImpl()); |
108 return ret; | 148 return ret; |
109 } | 149 } |
110 | 150 |
111 } // namespace base | 151 } // namespace base |
OLD | NEW |