diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/base/run_loop.cc | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) | |
download | qtwebengine-chromium-552906b0f222c5d5dd11b9fd73829d510980461a.tar.gz |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/base/run_loop.cc')
-rw-r--r-- | chromium/base/run_loop.cc | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/chromium/base/run_loop.cc b/chromium/base/run_loop.cc index e96eb7c4369..234e3fdc47b 100644 --- a/chromium/base/run_loop.cc +++ b/chromium/base/run_loop.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/callback.h" #include "base/cancelable_callback.h" -#include "base/message_loop/message_loop.h" #include "base/no_destructor.h" #include "base/single_thread_task_runner.h" #include "base/threading/thread_local.h" @@ -34,49 +33,18 @@ void ProxyToTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner, task_runner->PostTask(FROM_HERE, std::move(closure)); } -ThreadLocalPointer<RunLoop::ScopedRunTimeoutForTest>& -ScopedRunTimeoutForTestTLS() { - static NoDestructor<ThreadLocalPointer<RunLoop::ScopedRunTimeoutForTest>> tls; +ThreadLocalPointer<const RunLoop::RunLoopTimeout>& RunLoopTimeoutTLS() { + static NoDestructor<ThreadLocalPointer<const RunLoop::RunLoopTimeout>> tls; return *tls; } -void OnRunTimeout(RunLoop* run_loop, OnceClosure on_timeout) { +void OnRunLoopTimeout(RunLoop* run_loop, OnceClosure on_timeout) { run_loop->Quit(); std::move(on_timeout).Run(); } } // namespace -RunLoop::ScopedRunTimeoutForTest::ScopedRunTimeoutForTest( - TimeDelta timeout, - RepeatingClosure on_timeout) - : timeout_(timeout), - on_timeout_(std::move(on_timeout)), - nested_timeout_(ScopedRunTimeoutForTestTLS().Get()) { - DCHECK_GT(timeout_, TimeDelta()); - DCHECK(on_timeout_); - ScopedRunTimeoutForTestTLS().Set(this); -} - -RunLoop::ScopedRunTimeoutForTest::~ScopedRunTimeoutForTest() { - ScopedRunTimeoutForTestTLS().Set(nested_timeout_); -} - -// static -const RunLoop::ScopedRunTimeoutForTest* -RunLoop::ScopedRunTimeoutForTest::Current() { - return ScopedRunTimeoutForTestTLS().Get(); -} - -RunLoop::ScopedDisableRunTimeoutForTest::ScopedDisableRunTimeoutForTest() - : nested_timeout_(ScopedRunTimeoutForTestTLS().Get()) { - ScopedRunTimeoutForTestTLS().Set(nullptr); -} - -RunLoop::ScopedDisableRunTimeoutForTest::~ScopedDisableRunTimeoutForTest() { - ScopedRunTimeoutForTestTLS().Set(nested_timeout_); -} - RunLoop::Delegate::Delegate() { // The Delegate can be created on another thread. It is only bound in // RegisterDelegateForCurrentThread(). @@ -137,16 +105,16 @@ void RunLoop::Run() { if (!BeforeRun()) return; - // If there is a ScopedRunTimeoutForTest active then set the timeout. + // If there is a RunLoopTimeout active then set the timeout. // TODO(crbug.com/905412): Use real-time for Run() timeouts so that they // can be applied even in tests which mock TimeTicks::Now(). CancelableOnceClosure cancelable_timeout; - ScopedRunTimeoutForTest* run_timeout = ScopedRunTimeoutForTestTLS().Get(); + const RunLoopTimeout* run_timeout = GetTimeoutForCurrentThread(); if (run_timeout) { cancelable_timeout.Reset( - BindOnce(&OnRunTimeout, Unretained(this), run_timeout->on_timeout())); - ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, cancelable_timeout.callback(), run_timeout->timeout()); + BindOnce(&OnRunLoopTimeout, Unretained(this), run_timeout->on_timeout)); + origin_task_runner_->PostDelayedTask( + FROM_HERE, cancelable_timeout.callback(), run_timeout->timeout); } DCHECK_EQ(this, delegate_->active_run_loops_.top()); @@ -303,6 +271,20 @@ RunLoop::ScopedDisallowRunningForTesting::~ScopedDisallowRunningForTesting() = default; #endif // DCHECK_IS_ON() +RunLoop::RunLoopTimeout::RunLoopTimeout() = default; + +RunLoop::RunLoopTimeout::~RunLoopTimeout() = default; + +// static +void RunLoop::SetTimeoutForCurrentThread(const RunLoopTimeout* timeout) { + RunLoopTimeoutTLS().Set(timeout); +} + +// static +const RunLoop::RunLoopTimeout* RunLoop::GetTimeoutForCurrentThread() { + return RunLoopTimeoutTLS().Get(); +} + bool RunLoop::BeforeRun() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |