blob: 88e491d62507160d6fa38762fcfd32d90122655d [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/base/static_sequence/static_sequence.h"
#include "base/task/thread_pool.h"
namespace util {
namespace internal {
StaticTaskRunnerHolder::StaticTaskRunnerHolder(base::TaskTraits traits)
: traits_(traits), initialized_(false) {}
StaticTaskRunnerHolder::~StaticTaskRunnerHolder() = default;
void StaticTaskRunnerHolder::WillDestroyCurrentMessageLoop() {
initialized_ = false;
task_runner_ = nullptr;
}
const scoped_refptr<base::SequencedTaskRunner>& StaticTaskRunnerHolder::Get() {
if (!initialized_) {
task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(traits_);
base::CurrentThread::Get().AddDestructionObserver(this);
initialized_ = true;
}
return task_runner_;
}
} // namespace internal
} // namespace util