OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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() { |
11 AutoLock lock(message_loop_lock_); | |
12 // If the target message loop still exists, the d'tor WILL execute on the | |
13 // target loop. | |
14 if (target_message_loop_) { | |
15 DCHECK(MessageLoop::current() == target_message_loop_); | |
16 MessageLoop::current()->RemoveDestructionObserver(this); | |
17 } | |
18 } | 11 } |
19 | 12 |
20 // MessageLoopProxy implementation | 13 // MessageLoopProxy implementation |
21 bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here, | 14 bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here, |
22 Task* task) { | 15 Task* task) { |
23 return PostTaskHelper(from_here, task, 0, true); | 16 return PostTaskHelper(from_here, task, 0, true); |
24 } | 17 } |
25 | 18 |
26 bool MessageLoopProxyImpl::PostDelayedTask( | 19 bool MessageLoopProxyImpl::PostDelayedTask( |
27 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { | 20 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 target_message_loop_->DeleteSoon(FROM_HERE, this); | 88 target_message_loop_->DeleteSoon(FROM_HERE, this); |
96 delete_later = true; | 89 delete_later = true; |
97 } | 90 } |
98 } | 91 } |
99 if (!delete_later) | 92 if (!delete_later) |
100 delete this; | 93 delete this; |
101 } | 94 } |
102 | 95 |
103 MessageLoopProxyImpl::MessageLoopProxyImpl() | 96 MessageLoopProxyImpl::MessageLoopProxyImpl() |
104 : target_message_loop_(MessageLoop::current()) { | 97 : target_message_loop_(MessageLoop::current()) { |
105 target_message_loop_->AddDestructionObserver(this); | |
106 } | 98 } |
107 | 99 |
108 bool MessageLoopProxyImpl::PostTaskHelper( | 100 bool MessageLoopProxyImpl::PostTaskHelper( |
109 const tracked_objects::Location& from_here, Task* task, int64 delay_ms, | 101 const tracked_objects::Location& from_here, Task* task, int64 delay_ms, |
110 bool nestable) { | 102 bool nestable) { |
111 bool ret = false; | 103 bool ret = false; |
112 { | 104 { |
113 AutoLock lock(message_loop_lock_); | 105 AutoLock lock(message_loop_lock_); |
114 if (target_message_loop_) { | 106 if (target_message_loop_) { |
115 if (nestable) { | 107 if (nestable) { |
(...skipping 20 matching lines...) Expand all Loading... |
136 } else { | 128 } else { |
137 target_message_loop_->PostNonNestableDelayedTask(from_here, task, | 129 target_message_loop_->PostNonNestableDelayedTask(from_here, task, |
138 delay_ms); | 130 delay_ms); |
139 } | 131 } |
140 return true; | 132 return true; |
141 } | 133 } |
142 return false; | 134 return false; |
143 } | 135 } |
144 | 136 |
145 scoped_refptr<MessageLoopProxy> | 137 scoped_refptr<MessageLoopProxy> |
146 MessageLoopProxy::CreateForCurrentThread() { | 138 MessageLoopProxy::current() { |
147 scoped_refptr<MessageLoopProxy> ret(new MessageLoopProxyImpl()); | 139 MessageLoop* cur_loop = MessageLoop::current(); |
148 return ret; | 140 if (!cur_loop) |
| 141 return NULL; |
| 142 return cur_loop->message_loop_proxy(); |
149 } | 143 } |
150 | 144 |
151 } // namespace base | 145 } // namespace base |
OLD | NEW |