2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/thread_helper.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void SignalEvent(CefRefPtr<CefWaitableEvent> event) {
|
2016-01-19 21:09:01 +01:00
|
|
|
event->Signal();
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:56:02 +01:00
|
|
|
void WaitForThread(CefThreadId thread_id, int64 delay_ms) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(thread_id, base::BindOnce(SignalEvent, event), delay_ms);
|
2016-11-15 22:18:41 +01:00
|
|
|
event->Wait();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 18:56:02 +01:00
|
|
|
void WaitForThread(CefRefPtr<CefTaskRunner> task_runner, int64 delay_ms) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2016-11-15 18:56:02 +01:00
|
|
|
task_runner->PostDelayedTask(
|
2021-06-19 21:54:45 +02:00
|
|
|
CefCreateClosureTask(base::BindOnce(SignalEvent, event)), delay_ms);
|
2016-11-15 22:18:41 +01:00
|
|
|
event->Wait();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunOnThread(CefThreadId thread_id,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::OnceClosure test_impl,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event) {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!CefCurrentlyOn(thread_id)) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(thread_id, base::BindOnce(RunOnThread, thread_id,
|
|
|
|
std::move(test_impl), event));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
std::move(test_impl).Run();
|
2016-01-19 21:09:01 +01:00
|
|
|
SignalEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunOnThreadAsync(
|
|
|
|
CefThreadId thread_id,
|
2021-06-19 21:54:45 +02:00
|
|
|
base::OnceCallback<void(CefRefPtr<CefWaitableEvent>)> test_impl,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event) {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!CefCurrentlyOn(thread_id)) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(thread_id, base::BindOnce(RunOnThreadAsync, thread_id,
|
|
|
|
std::move(test_impl), event));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
std::move(test_impl).Run(event);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|