[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/run_loop.h" |
| 6 | |
| 7 | #include "base/bind.h" |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 8 | #include "base/callback.h" |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 9 | #include "base/lazy_instance.h" |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 10 | #include "base/single_thread_task_runner.h" |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 11 | #include "base/threading/thread_local.h" |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 12 | #include "base/threading/thread_task_runner_handle.h" |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 17 | namespace { |
| 18 | |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 19 | LazyInstance<ThreadLocalPointer<RunLoop::Delegate>>::Leaky tls_delegate = |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 20 | LAZY_INSTANCE_INITIALIZER; |
| 21 | |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 22 | // Runs |closure| immediately if this is called on |task_runner|, otherwise |
| 23 | // forwards |closure| to it. |
| 24 | void ProxyToTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner, |
| 25 | OnceClosure closure) { |
| 26 | if (task_runner->RunsTasksInCurrentSequence()) { |
| 27 | std::move(closure).Run(); |
| 28 | return; |
| 29 | } |
| 30 | task_runner->PostTask(FROM_HERE, std::move(closure)); |
| 31 | } |
| 32 | |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 33 | } // namespace |
| 34 | |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 35 | RunLoop::Delegate::Delegate() { |
| 36 | // The Delegate can be created on another thread. It is only bound in |
| 37 | // RegisterDelegateForCurrentThread(). |
| 38 | DETACH_FROM_THREAD(bound_thread_checker_); |
| 39 | } |
| 40 | |
| 41 | RunLoop::Delegate::~Delegate() { |
| 42 | DCHECK_CALLED_ON_VALID_THREAD(bound_thread_checker_); |
| 43 | // A RunLoop::Delegate may be destroyed before it is bound, if so it may still |
| 44 | // be on its creation thread (e.g. a Thread that fails to start) and |
| 45 | // shouldn't disrupt that thread's state. |
| 46 | if (bound_) |
| 47 | tls_delegate.Get().Set(nullptr); |
| 48 | } |
| 49 | |
Gabriel Charette | e2b632b | 2017-08-02 03:52:16 | [diff] [blame] | 50 | bool RunLoop::Delegate::Client::ShouldQuitWhenIdle() const { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 51 | DCHECK_CALLED_ON_VALID_THREAD(outer_->bound_thread_checker_); |
| 52 | DCHECK(outer_->bound_); |
Gabriel Charette | e2b632b | 2017-08-02 03:52:16 | [diff] [blame] | 53 | return outer_->active_run_loops_.top()->quit_when_idle_received_; |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | bool RunLoop::Delegate::Client::IsNested() const { |
| 57 | DCHECK_CALLED_ON_VALID_THREAD(outer_->bound_thread_checker_); |
| 58 | DCHECK(outer_->bound_); |
| 59 | return outer_->active_run_loops_.size() > 1; |
| 60 | } |
| 61 | |
| 62 | RunLoop::Delegate::Client::Client(Delegate* outer) : outer_(outer) {} |
| 63 | |
Gabriel Charette | 0592c3a | 2017-07-26 12:02:04 | [diff] [blame] | 64 | // static |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 65 | RunLoop::Delegate::Client* RunLoop::RegisterDelegateForCurrentThread( |
| 66 | Delegate* delegate) { |
| 67 | // Bind |delegate| to this thread. |
| 68 | DCHECK(!delegate->bound_); |
| 69 | DCHECK_CALLED_ON_VALID_THREAD(delegate->bound_thread_checker_); |
| 70 | |
| 71 | // There can only be one RunLoop::Delegate per thread. |
| 72 | DCHECK(!tls_delegate.Get().Get()); |
| 73 | tls_delegate.Get().Set(delegate); |
| 74 | delegate->bound_ = true; |
| 75 | |
| 76 | return &delegate->client_interface_; |
| 77 | } |
| 78 | |
Gabriel Charette | 3ff403e | 2017-08-07 04:22:48 | [diff] [blame] | 79 | RunLoop::RunLoop(Type type) |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 80 | : delegate_(tls_delegate.Get().Get()), |
Gabriel Charette | 3ff403e | 2017-08-07 04:22:48 | [diff] [blame] | 81 | type_(type), |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 82 | origin_task_runner_(ThreadTaskRunnerHandle::Get()), |
| 83 | weak_factory_(this) { |
Gabriel Charette | e2b632b | 2017-08-02 03:52:16 | [diff] [blame] | 84 | DCHECK(delegate_) << "A RunLoop::Delegate must be bound to this thread prior " |
| 85 | "to using RunLoop."; |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 86 | DCHECK(origin_task_runner_); |
Gabriel Charette | 3ff403e | 2017-08-07 04:22:48 | [diff] [blame] | 87 | |
| 88 | DCHECK(IsNestingAllowedOnCurrentThread() || |
| 89 | type_ != Type::kNestableTasksAllowed); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 92 | RunLoop::~RunLoop() { |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 93 | // TODO(gab): Fix bad usage and enable this check, http://crbug.com/715235. |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 94 | // DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void RunLoop::Run() { |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 98 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 99 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 100 | if (!BeforeRun()) |
| 101 | return; |
vadimt | 12f0f7d | 2014-09-15 19:19:38 | [diff] [blame] | 102 | |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 103 | // It is okay to access this RunLoop from another sequence while Run() is |
| 104 | // active as this RunLoop won't touch its state until after that returns (if |
| 105 | // the RunLoop's state is accessed while processing Run(), it will be re-bound |
| 106 | // to the accessing sequence for the remainder of that Run() -- accessing from |
| 107 | // multiple sequences is still disallowed). |
| 108 | DETACH_FROM_SEQUENCE(sequence_checker_); |
| 109 | |
Gabriel Charette | b030a4a | 2017-10-26 01:04:40 | [diff] [blame^] | 110 | DCHECK_EQ(this, delegate_->active_run_loops_.top()); |
| 111 | const bool application_tasks_allowed = |
| 112 | delegate_->active_run_loops_.size() == 1U || |
| 113 | type_ == Type::kNestableTasksAllowed; |
| 114 | delegate_->Run(application_tasks_allowed); |
vadimt | 12f0f7d | 2014-09-15 19:19:38 | [diff] [blame] | 115 | |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 116 | // Rebind this RunLoop to the current thread after Run(). |
| 117 | DETACH_FROM_SEQUENCE(sequence_checker_); |
| 118 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 119 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 120 | AfterRun(); |
| 121 | } |
| 122 | |
| 123 | void RunLoop::RunUntilIdle() { |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 124 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 125 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 126 | quit_when_idle_received_ = true; |
| 127 | Run(); |
| 128 | } |
| 129 | |
| 130 | void RunLoop::Quit() { |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 131 | // Thread-safe. |
| 132 | |
| 133 | // This can only be hit if run_loop->Quit() is called directly (QuitClosure() |
| 134 | // proxies through ProxyToTaskRunner() as it can only deref its WeakPtr on |
| 135 | // |origin_task_runner_|). |
| 136 | if (!origin_task_runner_->RunsTasksInCurrentSequence()) { |
tzik | 0c100dc | 2017-06-26 06:13:17 | [diff] [blame] | 137 | origin_task_runner_->PostTask( |
| 138 | FROM_HERE, base::BindOnce(&RunLoop::Quit, Unretained(this))); |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 139 | return; |
| 140 | } |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 141 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 142 | quit_called_ = true; |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 143 | if (running_ && delegate_->active_run_loops_.top() == this) { |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 144 | // This is the inner-most RunLoop, so quit now. |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 145 | delegate_->Quit(); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
fdoray | a4f28ec | 2016-06-10 00:08:58 | [diff] [blame] | 149 | void RunLoop::QuitWhenIdle() { |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 150 | // Thread-safe. |
| 151 | |
| 152 | // This can only be hit if run_loop->QuitWhenIdle() is called directly |
| 153 | // (QuitWhenIdleClosure() proxies through ProxyToTaskRunner() as it can only |
| 154 | // deref its WeakPtr on |origin_task_runner_|). |
| 155 | if (!origin_task_runner_->RunsTasksInCurrentSequence()) { |
| 156 | origin_task_runner_->PostTask( |
tzik | 0c100dc | 2017-06-26 06:13:17 | [diff] [blame] | 157 | FROM_HERE, base::BindOnce(&RunLoop::QuitWhenIdle, Unretained(this))); |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
fdoray | a4f28ec | 2016-06-10 00:08:58 | [diff] [blame] | 161 | quit_when_idle_received_ = true; |
| 162 | } |
| 163 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 164 | base::Closure RunLoop::QuitClosure() { |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 165 | // TODO(gab): Fix bad usage and enable this check, http://crbug.com/715235. |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 166 | // DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 167 | |
| 168 | // Need to use ProxyToTaskRunner() as WeakPtrs vended from |
| 169 | // |weak_factory_| may only be accessed on |origin_task_runner_|. |
| 170 | // TODO(gab): It feels wrong that QuitClosure() is bound to a WeakPtr. |
| 171 | return base::Bind(&ProxyToTaskRunner, origin_task_runner_, |
| 172 | base::Bind(&RunLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 173 | } |
| 174 | |
fdoray | a365860 | 2016-06-10 18:23:15 | [diff] [blame] | 175 | base::Closure RunLoop::QuitWhenIdleClosure() { |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 176 | // TODO(gab): Fix bad usage and enable this check, http://crbug.com/715235. |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 177 | // DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 178 | |
| 179 | // Need to use ProxyToTaskRunner() as WeakPtrs vended from |
| 180 | // |weak_factory_| may only be accessed on |origin_task_runner_|. |
| 181 | // TODO(gab): It feels wrong that QuitWhenIdleClosure() is bound to a WeakPtr. |
| 182 | return base::Bind( |
| 183 | &ProxyToTaskRunner, origin_task_runner_, |
| 184 | base::Bind(&RunLoop::QuitWhenIdle, weak_factory_.GetWeakPtr())); |
fdoray | a365860 | 2016-06-10 18:23:15 | [diff] [blame] | 185 | } |
| 186 | |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 187 | // static |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 188 | bool RunLoop::IsRunningOnCurrentThread() { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 189 | Delegate* delegate = tls_delegate.Get().Get(); |
| 190 | return delegate && !delegate->active_run_loops_.empty(); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // static |
| 194 | bool RunLoop::IsNestedOnCurrentThread() { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 195 | Delegate* delegate = tls_delegate.Get().Get(); |
| 196 | return delegate && delegate->active_run_loops_.size() > 1; |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // static |
| 200 | void RunLoop::AddNestingObserverOnCurrentThread(NestingObserver* observer) { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 201 | Delegate* delegate = tls_delegate.Get().Get(); |
| 202 | DCHECK(delegate); |
| 203 | CHECK(delegate->allow_nesting_); |
| 204 | delegate->nesting_observers_.AddObserver(observer); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // static |
| 208 | void RunLoop::RemoveNestingObserverOnCurrentThread(NestingObserver* observer) { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 209 | Delegate* delegate = tls_delegate.Get().Get(); |
| 210 | DCHECK(delegate); |
| 211 | CHECK(delegate->allow_nesting_); |
| 212 | delegate->nesting_observers_.RemoveObserver(observer); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // static |
| 216 | bool RunLoop::IsNestingAllowedOnCurrentThread() { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 217 | return tls_delegate.Get().Get()->allow_nesting_; |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // static |
| 221 | void RunLoop::DisallowNestingOnCurrentThread() { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 222 | tls_delegate.Get().Get()->allow_nesting_ = false; |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 223 | } |
| 224 | |
Gabriel Charette | 0592c3a | 2017-07-26 12:02:04 | [diff] [blame] | 225 | // static |
| 226 | void RunLoop::QuitCurrentDeprecated() { |
| 227 | DCHECK(IsRunningOnCurrentThread()); |
| 228 | tls_delegate.Get().Get()->active_run_loops_.top()->Quit(); |
| 229 | } |
| 230 | |
| 231 | // static |
| 232 | void RunLoop::QuitCurrentWhenIdleDeprecated() { |
| 233 | DCHECK(IsRunningOnCurrentThread()); |
| 234 | tls_delegate.Get().Get()->active_run_loops_.top()->QuitWhenIdle(); |
| 235 | } |
| 236 | |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 237 | #if DCHECK_IS_ON() |
| 238 | RunLoop::ScopedDisallowRunningForTesting::ScopedDisallowRunningForTesting() |
| 239 | : current_delegate_(tls_delegate.Get().Get()), |
| 240 | previous_run_allowance_( |
| 241 | current_delegate_ ? current_delegate_->allow_running_for_testing_ |
| 242 | : false) { |
| 243 | if (current_delegate_) |
| 244 | current_delegate_->allow_running_for_testing_ = false; |
| 245 | } |
| 246 | |
| 247 | RunLoop::ScopedDisallowRunningForTesting::~ScopedDisallowRunningForTesting() { |
| 248 | DCHECK_EQ(current_delegate_, tls_delegate.Get().Get()); |
| 249 | if (current_delegate_) |
| 250 | current_delegate_->allow_running_for_testing_ = previous_run_allowance_; |
| 251 | } |
| 252 | #else // DCHECK_IS_ON() |
| 253 | // Defined out of line so that the compiler doesn't inline these and realize |
| 254 | // the scope has no effect and then throws an "unused variable" warning in |
| 255 | // non-dcheck builds. |
| 256 | RunLoop::ScopedDisallowRunningForTesting::ScopedDisallowRunningForTesting() = |
| 257 | default; |
| 258 | RunLoop::ScopedDisallowRunningForTesting::~ScopedDisallowRunningForTesting() = |
| 259 | default; |
| 260 | #endif // DCHECK_IS_ON() |
| 261 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 262 | bool RunLoop::BeforeRun() { |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 263 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 264 | |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 265 | #if DCHECK_IS_ON() |
Gabriel Charette | a4497505 | 2017-08-21 23:14:04 | [diff] [blame] | 266 | DCHECK(delegate_->allow_running_for_testing_) |
| 267 | << "RunLoop::Run() isn't allowed in the scope of a " |
| 268 | "ScopedDisallowRunningForTesting. Hint: if mixing " |
| 269 | "TestMockTimeTaskRunners on same thread, use TestMockTimeTaskRunner's " |
| 270 | "API instead of RunLoop to drive individual task runners."; |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 271 | DCHECK(!run_called_); |
| 272 | run_called_ = true; |
gab | cf5e4ce | 2017-05-19 22:56:57 | [diff] [blame] | 273 | #endif // DCHECK_IS_ON() |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 274 | |
| 275 | // Allow Quit to be called before Run. |
| 276 | if (quit_called_) |
| 277 | return false; |
| 278 | |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 279 | auto& active_run_loops_ = delegate_->active_run_loops_; |
| 280 | active_run_loops_.push(this); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 281 | |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 282 | const bool is_nested = active_run_loops_.size() > 1; |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 283 | |
| 284 | if (is_nested) { |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 285 | CHECK(delegate_->allow_nesting_); |
| 286 | for (auto& observer : delegate_->nesting_observers_) |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 287 | observer.OnBeginNestedRunLoop(); |
Gabriel Charette | 3ff403e | 2017-08-07 04:22:48 | [diff] [blame] | 288 | if (type_ == Type::kNestableTasksAllowed) |
| 289 | delegate_->EnsureWorkScheduled(); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 290 | } |
jamescook | aacdfd0 | 2016-04-28 00:50:03 | [diff] [blame] | 291 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 292 | running_ = true; |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | void RunLoop::AfterRun() { |
gab | 980a5271 | 2017-05-18 16:20:16 | [diff] [blame] | 297 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 298 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 299 | running_ = false; |
| 300 | |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 301 | auto& active_run_loops_ = delegate_->active_run_loops_; |
| 302 | DCHECK_EQ(active_run_loops_.top(), this); |
| 303 | active_run_loops_.pop(); |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 304 | |
| 305 | RunLoop* previous_run_loop = |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 306 | active_run_loops_.empty() ? nullptr : active_run_loops_.top(); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 307 | |
Gabriel Charette | e2b632b | 2017-08-02 03:52:16 | [diff] [blame] | 308 | // Execute deferred Quit, if any: |
gab | 7af9dc0 | 2017-05-05 13:38:54 | [diff] [blame] | 309 | if (previous_run_loop && previous_run_loop->quit_called_) |
gab | 27355196 | 2017-05-18 06:01:10 | [diff] [blame] | 310 | delegate_->Quit(); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | } // namespace base |