| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 : MessageLoop(type, MessagePumpFactoryCallback()) { | 126 : MessageLoop(type, MessagePumpFactoryCallback()) { |
| 127 BindToCurrentThread(); | 127 BindToCurrentThread(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) | 130 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) |
| 131 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { | 131 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { |
| 132 BindToCurrentThread(); | 132 BindToCurrentThread(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 MessageLoop::~MessageLoop() { | 135 MessageLoop::~MessageLoop() { |
| 136 // current() could be NULL if this message loop is destructed before it is | 136 // If |pump_| is non-null, this message loop has been bound and should be the |
| 137 // bound to a thread. | 137 // current one on this thread. Otherwise, this loop is being destructed before |
| 138 DCHECK(current() == this || !current()); | 138 // it was bound to a thread, so a different message loop (or no loop at all) |
| 139 // may be current. |
| 140 DCHECK((pump_ && current() == this) || (!pump_ && current() != this)); |
| 139 | 141 |
| 140 // iOS just attaches to the loop, it doesn't Run it. | 142 // iOS just attaches to the loop, it doesn't Run it. |
| 141 // TODO(stuartmorgan): Consider wiring up a Detach(). | 143 // TODO(stuartmorgan): Consider wiring up a Detach(). |
| 142 #if !defined(OS_IOS) | 144 #if !defined(OS_IOS) |
| 143 DCHECK(!run_loop_); | 145 DCHECK(!run_loop_); |
| 144 #endif | 146 #endif |
| 145 | 147 |
| 146 #if defined(OS_WIN) | 148 #if defined(OS_WIN) |
| 147 if (in_high_res_mode_) | 149 if (in_high_res_mode_) |
| 148 Time::ActivateHighResolutionTimer(false); | 150 Time::ActivateHighResolutionTimer(false); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 170 | 172 |
| 171 thread_task_runner_handle_.reset(); | 173 thread_task_runner_handle_.reset(); |
| 172 | 174 |
| 173 // Tell the incoming queue that we are dying. | 175 // Tell the incoming queue that we are dying. |
| 174 incoming_task_queue_->WillDestroyCurrentMessageLoop(); | 176 incoming_task_queue_->WillDestroyCurrentMessageLoop(); |
| 175 incoming_task_queue_ = NULL; | 177 incoming_task_queue_ = NULL; |
| 176 unbound_task_runner_ = NULL; | 178 unbound_task_runner_ = NULL; |
| 177 task_runner_ = NULL; | 179 task_runner_ = NULL; |
| 178 | 180 |
| 179 // OK, now make it so that no one can find us. | 181 // OK, now make it so that no one can find us. |
| 180 lazy_tls_ptr.Pointer()->Set(NULL); | 182 if (current() == this) |
| 183 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 181 } | 184 } |
| 182 | 185 |
| 183 // static | 186 // static |
| 184 MessageLoop* MessageLoop::current() { | 187 MessageLoop* MessageLoop::current() { |
| 185 // TODO(darin): sadly, we cannot enable this yet since people call us even | 188 // TODO(darin): sadly, we cannot enable this yet since people call us even |
| 186 // when they have no intention of using us. | 189 // when they have no intention of using us. |
| 187 // DCHECK(loop) << "Ouch, did you forget to initialize me?"; | 190 // DCHECK(loop) << "Ouch, did you forget to initialize me?"; |
| 188 return lazy_tls_ptr.Pointer()->Get(); | 191 return lazy_tls_ptr.Pointer()->Get(); |
| 189 } | 192 } |
| 190 | 193 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 persistent, | 757 persistent, |
| 755 mode, | 758 mode, |
| 756 controller, | 759 controller, |
| 757 delegate); | 760 delegate); |
| 758 } | 761 } |
| 759 #endif | 762 #endif |
| 760 | 763 |
| 761 #endif // !defined(OS_NACL_SFI) | 764 #endif // !defined(OS_NACL_SFI) |
| 762 | 765 |
| 763 } // namespace base | 766 } // namespace base |
| OLD | NEW |