Commit 8ec76b32 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

Make Thread's task queue TimeDomain configurable

Adds a field to Thread::Options to allow the task queue time domain to
be configured, to enable Thread users to test task posting functionality
using synthetic time.

Bug: 1034758
Change-Id: I9b301f98e856a86045a12bab6e25569d4ef9b330
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020480Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735444}
parent 2f617fec
...@@ -50,14 +50,16 @@ class SequenceManagerThreadDelegate : public Thread::Delegate { ...@@ -50,14 +50,16 @@ class SequenceManagerThreadDelegate : public Thread::Delegate {
public: public:
explicit SequenceManagerThreadDelegate( explicit SequenceManagerThreadDelegate(
MessagePumpType message_pump_type, MessagePumpType message_pump_type,
OnceCallback<std::unique_ptr<MessagePump>()> message_pump_factory) OnceCallback<std::unique_ptr<MessagePump>()> message_pump_factory,
sequence_manager::TimeDomain* time_domain)
: sequence_manager_( : sequence_manager_(
sequence_manager::internal::SequenceManagerImpl::CreateUnbound( sequence_manager::internal::SequenceManagerImpl::CreateUnbound(
sequence_manager::SequenceManager::Settings::Builder() sequence_manager::SequenceManager::Settings::Builder()
.SetMessagePumpType(message_pump_type) .SetMessagePumpType(message_pump_type)
.Build())), .Build())),
default_task_queue_(sequence_manager_->CreateTaskQueue( default_task_queue_(sequence_manager_->CreateTaskQueue(
sequence_manager::TaskQueue::Spec("default_tq"))), sequence_manager::TaskQueue::Spec("default_tq")
.SetTimeDomain(time_domain))),
message_pump_factory_(std::move(message_pump_factory)) { message_pump_factory_(std::move(message_pump_factory)) {
sequence_manager_->SetDefaultTaskRunner(default_task_queue_->task_runner()); sequence_manager_->SetDefaultTaskRunner(default_task_queue_->task_runner());
} }
...@@ -158,15 +160,18 @@ bool Thread::StartWithOptions(const Options& options) { ...@@ -158,15 +160,18 @@ bool Thread::StartWithOptions(const Options& options) {
if (options.delegate) { if (options.delegate) {
DCHECK(!options.message_pump_factory); DCHECK(!options.message_pump_factory);
DCHECK(!options.task_queue_time_domain_);
delegate_ = WrapUnique(options.delegate); delegate_ = WrapUnique(options.delegate);
} else if (options.message_pump_factory) { } else if (options.message_pump_factory) {
delegate_ = std::make_unique<SequenceManagerThreadDelegate>( delegate_ = std::make_unique<SequenceManagerThreadDelegate>(
MessagePumpType::CUSTOM, options.message_pump_factory); MessagePumpType::CUSTOM, options.message_pump_factory,
options.task_queue_time_domain_);
} else { } else {
delegate_ = std::make_unique<SequenceManagerThreadDelegate>( delegate_ = std::make_unique<SequenceManagerThreadDelegate>(
options.message_pump_type, options.message_pump_type,
BindOnce([](MessagePumpType type) { return MessagePump::Create(type); }, BindOnce([](MessagePumpType type) { return MessagePump::Create(type); },
options.message_pump_type)); options.message_pump_type),
options.task_queue_time_domain_);
} }
start_event_.Reset(); start_event_.Reset();
......
...@@ -27,6 +27,9 @@ namespace base { ...@@ -27,6 +27,9 @@ namespace base {
class MessagePump; class MessagePump;
class RunLoop; class RunLoop;
namespace sequence_manager {
class TimeDomain;
}
// IMPORTANT: Instead of creating a base::Thread, consider using // IMPORTANT: Instead of creating a base::Thread, consider using
// base::Create(Sequenced|SingleThread)TaskRunner(). // base::Create(Sequenced|SingleThread)TaskRunner().
...@@ -91,6 +94,10 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -91,6 +94,10 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// Specifies timer slack for thread message loop. // Specifies timer slack for thread message loop.
TimerSlack timer_slack = TIMER_SLACK_NONE; TimerSlack timer_slack = TIMER_SLACK_NONE;
// The time domain to be used by the task queue. This is not compatible with
// a non-null |delegate|.
sequence_manager::TimeDomain* task_queue_time_domain_ = nullptr;
// Used to create the MessagePump for the MessageLoop. The callback is Run() // Used to create the MessagePump for the MessageLoop. The callback is Run()
// on the thread. If message_pump_factory.is_null(), then a MessagePump // on the thread. If message_pump_factory.is_null(), then a MessagePump
// appropriate for |message_pump_type| is created. Setting this forces the // appropriate for |message_pump_type| is created. Setting this forces the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment