| 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/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/tracked_objects.h" |
| 8 | 9 |
| 9 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 10 #include "base/message_loop/message_pump_dispatcher.h" | 11 #include "base/message_loop/message_pump_dispatcher.h" |
| 11 #endif | 12 #endif |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 RunLoop::RunLoop() | 16 RunLoop::RunLoop() |
| 16 : loop_(MessageLoop::current()), | 17 : loop_(MessageLoop::current()), |
| 17 previous_run_loop_(NULL), | 18 previous_run_loop_(NULL), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 weak_factory_(this) { | 40 weak_factory_(this) { |
| 40 } | 41 } |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 RunLoop::~RunLoop() { | 44 RunLoop::~RunLoop() { |
| 44 } | 45 } |
| 45 | 46 |
| 46 void RunLoop::Run() { | 47 void RunLoop::Run() { |
| 47 if (!BeforeRun()) | 48 if (!BeforeRun()) |
| 48 return; | 49 return; |
| 49 loop_->RunHandler(); | 50 { |
| 51 // Use task stopwatch to exclude the loop run time from the current task, if |
| 52 // any. |
| 53 tracked_objects::TaskStopwatch stopwatch; |
| 54 stopwatch.Start(); |
| 55 loop_->RunHandler(); |
| 56 stopwatch.Stop(); |
| 57 } |
| 50 AfterRun(); | 58 AfterRun(); |
| 51 } | 59 } |
| 52 | 60 |
| 53 void RunLoop::RunUntilIdle() { | 61 void RunLoop::RunUntilIdle() { |
| 54 quit_when_idle_received_ = true; | 62 quit_when_idle_received_ = true; |
| 55 Run(); | 63 Run(); |
| 56 } | 64 } |
| 57 | 65 |
| 58 void RunLoop::Quit() { | 66 void RunLoop::Quit() { |
| 59 quit_called_ = true; | 67 quit_called_ = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 89 | 97 |
| 90 // Pop RunLoop stack: | 98 // Pop RunLoop stack: |
| 91 loop_->run_loop_ = previous_run_loop_; | 99 loop_->run_loop_ = previous_run_loop_; |
| 92 | 100 |
| 93 // Execute deferred QuitNow, if any: | 101 // Execute deferred QuitNow, if any: |
| 94 if (previous_run_loop_ && previous_run_loop_->quit_called_) | 102 if (previous_run_loop_ && previous_run_loop_->quit_called_) |
| 95 loop_->QuitNow(); | 103 loop_->QuitNow(); |
| 96 } | 104 } |
| 97 | 105 |
| 98 } // namespace base | 106 } // namespace base |
| OLD | NEW |