Commit 80daef89 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[scheduler] Support base::TaskTraits in blink's BackgroundScheduler

Add PostOnBackgrondThreadWithTraits to the blink's wrapper around
TaskScheduler and add relevant traits to the presubmit whitelist.

We want to allow Blink code to post background tasks with correct
traits but we still need a wrapper to ensure that CrossThreadBind
is used instead of base::Bind.

R=haraken@chromium.org
CC=​leszeks@chromium.org

Change-Id: If5297e1214bb175dee1247754158511811963b55
Reviewed-on: https://chromium-review.googlesource.com/1146658Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577509}
parent cd4ff786
......@@ -39,6 +39,7 @@ include_rules = [
"+base/task/sequence_manager/sequence_manager.h",
"+base/task/sequence_manager/task_queue.h",
"+base/task/sequence_manager/time_domain.h",
"+base/task_scheduler/task_traits.h",
"+base/threading/platform_thread.h",
"+base/threading/sequenced_task_runner_handle.h",
"+base/threading/thread.h",
......
......@@ -11,8 +11,16 @@ namespace blink {
void BackgroundScheduler::PostOnBackgroundThread(const base::Location& location,
CrossThreadClosure closure) {
base::PostTaskWithTraits(location,
{base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
PostOnBackgroundThreadWithTraits(
location, {base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
std::move(closure));
}
void BackgroundScheduler::PostOnBackgroundThreadWithTraits(
const base::Location& location,
const base::TaskTraits& traits,
CrossThreadClosure closure) {
base::PostTaskWithTraits(location, traits,
ConvertToBaseCallback(std::move(closure)));
}
......
......@@ -6,6 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_BACKGROUND_SCHEDULER_H_
#include "base/location.h"
#include "base/sequenced_task_runner.h"
#include "base/task_scheduler/task_traits.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
......@@ -13,14 +15,22 @@ namespace blink {
namespace BackgroundScheduler {
// This is a thin wrapper around base::TaskScheduler to accomodate
// Blink's CrossThreadClosure, which only allows background tasks.
// These are a thin wrapper around base::TaskScheduler to accomodate
// Blink's CrossThreadClosure, which only allows background tasks
// (i.e. tasks which are run off the main thread).
//
// Non-background tasks should be posted using another scheduler, e.g.
// FrameShceduler.
PLATFORM_EXPORT void PostOnBackgroundThread(const base::Location&,
CrossThreadClosure);
PLATFORM_EXPORT void PostOnBackgroundThreadWithTraits(const base::Location&,
const base::TaskTraits&,
CrossThreadClosure);
// TODO(altimin): Expose CreateBackgroundTaskRunnerWithTraits when the
// need arises.
} // namespace BackgroundScheduler
} // namespace blink
......
......@@ -118,6 +118,13 @@ _CONFIG = [
# Base atomic utilities
'base::AtomicSequenceNumber',
# Task traits
'base::TaskTraits',
'base::MayBlock',
'base::TaskPriority',
'base::TaskShutdownBehavior',
'base::WithBaseSyncPrimitives',
# Byte order
'base::ByteSwap',
'base::NetToHost(16|32|64)',
......
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