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/synchronization/waitable_event_watcher.h" | 5 #include "base/synchronization/waitable_event_watcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // No hairpinning - we can't call the delegate directly here. We have to | 160 // No hairpinning - we can't call the delegate directly here. We have to |
161 // enqueue a task on the MessageLoop as normal. | 161 // enqueue a task on the MessageLoop as normal. |
162 current_ml->PostTask(FROM_HERE, callback_); | 162 current_ml->PostTask(FROM_HERE, callback_); |
163 return true; | 163 return true; |
164 } | 164 } |
165 | 165 |
166 message_loop_ = current_ml; | 166 message_loop_ = current_ml; |
167 current_ml->AddDestructionObserver(this); | 167 current_ml->AddDestructionObserver(this); |
168 | 168 |
169 kernel_ = kernel; | 169 kernel_ = kernel; |
170 waiter_ = new AsyncWaiter(current_ml, callback_, cancel_flag_); | 170 waiter_ = new AsyncWaiter(current_ml, callback_, cancel_flag_.get()); |
171 event->Enqueue(waiter_); | 171 event->Enqueue(waiter_); |
172 | 172 |
173 return true; | 173 return true; |
174 } | 174 } |
175 | 175 |
176 void WaitableEventWatcher::StopWatching() { | 176 void WaitableEventWatcher::StopWatching() { |
177 delegate_ = NULL; | 177 delegate_ = NULL; |
178 | 178 |
179 if (message_loop_) { | 179 if (message_loop_) { |
180 message_loop_->RemoveDestructionObserver(this); | 180 message_loop_->RemoveDestructionObserver(this); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // ----------------------------------------------------------------------------- | 261 // ----------------------------------------------------------------------------- |
262 // This is called when the MessageLoop which the callback will be run it is | 262 // This is called when the MessageLoop which the callback will be run it is |
263 // deleted. We need to cancel the callback as if we had been deleted, but we | 263 // deleted. We need to cancel the callback as if we had been deleted, but we |
264 // will still be deleted at some point in the future. | 264 // will still be deleted at some point in the future. |
265 // ----------------------------------------------------------------------------- | 265 // ----------------------------------------------------------------------------- |
266 void WaitableEventWatcher::WillDestroyCurrentMessageLoop() { | 266 void WaitableEventWatcher::WillDestroyCurrentMessageLoop() { |
267 StopWatching(); | 267 StopWatching(); |
268 } | 268 } |
269 | 269 |
270 } // namespace base | 270 } // namespace base |
OLD | NEW |