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.h" | 5 #include "base/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 299 |
300 void MessageLoop::QuitNow() { | 300 void MessageLoop::QuitNow() { |
301 DCHECK_EQ(this, current()); | 301 DCHECK_EQ(this, current()); |
302 if (state_) { | 302 if (state_) { |
303 pump_->Quit(); | 303 pump_->Quit(); |
304 } else { | 304 } else { |
305 NOTREACHED() << "Must be inside Run to call Quit"; | 305 NOTREACHED() << "Must be inside Run to call Quit"; |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
| 309 // This is a complete hack just for the proof of concept. Really, we want |
| 310 // to modify PendingTask to understand base::Closure. |
| 311 class ClosureTaskAdapter : public Task { |
| 312 public: |
| 313 explicit ClosureTaskAdapter(const tracked_objects::Location& from_here, |
| 314 base::Closure c) |
| 315 : closure_(c) { |
| 316 closure_.tracked()->SetBirthPlace(from_here); |
| 317 } |
| 318 |
| 319 virtual void Run() { |
| 320 closure_(); |
| 321 } |
| 322 |
| 323 private: |
| 324 base::Closure closure_; |
| 325 }; |
| 326 |
| 327 void MessageLoop::PostClosure( |
| 328 const tracked_objects::Location& from_here, base::Closure closure) { |
| 329 // The wrapping of Closure in Task will screw up task tracking...that will be |
| 330 // fixed if we correctly refactor message loop's PendingTask. |
| 331 PostTask_Helper(from_here, new ClosureTaskAdapter(from_here, closure), 0, |
| 332 true); |
| 333 } |
| 334 |
309 void MessageLoop::PostTask( | 335 void MessageLoop::PostTask( |
310 const tracked_objects::Location& from_here, Task* task) { | 336 const tracked_objects::Location& from_here, Task* task) { |
311 PostTask_Helper(from_here, task, 0, true); | 337 PostTask_Helper(from_here, task, 0, true); |
312 } | 338 } |
313 | 339 |
314 void MessageLoop::PostDelayedTask( | 340 void MessageLoop::PostDelayedTask( |
315 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { | 341 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
316 PostTask_Helper(from_here, task, delay_ms, true); | 342 PostTask_Helper(from_here, task, delay_ms, true); |
317 } | 343 } |
318 | 344 |
| 345 void MessageLoop::PostDelayedClosure( |
| 346 const tracked_objects::Location& from_here, base::Closure closure, |
| 347 int64 delay_ms) { |
| 348 // The wrapping of Closure in Task will screw up task tracking...that will be |
| 349 // fixed if we correctly refactor message loop's PendingTask. |
| 350 PostTask_Helper(from_here, new ClosureTaskAdapter(from_here, closure), |
| 351 delay_ms, true); |
| 352 } |
| 353 |
319 void MessageLoop::PostNonNestableTask( | 354 void MessageLoop::PostNonNestableTask( |
320 const tracked_objects::Location& from_here, Task* task) { | 355 const tracked_objects::Location& from_here, Task* task) { |
321 PostTask_Helper(from_here, task, 0, false); | 356 PostTask_Helper(from_here, task, 0, false); |
322 } | 357 } |
323 | 358 |
324 void MessageLoop::PostNonNestableDelayedTask( | 359 void MessageLoop::PostNonNestableDelayedTask( |
325 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { | 360 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
326 PostTask_Helper(from_here, task, delay_ms, false); | 361 PostTask_Helper(from_here, task, delay_ms, false); |
327 } | 362 } |
328 | 363 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 Watcher *delegate) { | 737 Watcher *delegate) { |
703 return pump_libevent()->WatchFileDescriptor( | 738 return pump_libevent()->WatchFileDescriptor( |
704 fd, | 739 fd, |
705 persistent, | 740 persistent, |
706 static_cast<base::MessagePumpLibevent::Mode>(mode), | 741 static_cast<base::MessagePumpLibevent::Mode>(mode), |
707 controller, | 742 controller, |
708 delegate); | 743 delegate); |
709 } | 744 } |
710 | 745 |
711 #endif | 746 #endif |
OLD | NEW |