Commit 458f348d authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

ios: Add NonNestable TaskTrait

Turns out we'll need it afterall since some ios code
uses NonNestable tasks, e.g. indirectly via DeleteSoon.

Bug: 867421, 878356
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I77c0161b083c987f48b0f3270490e8feee241b18
Reviewed-on: https://chromium-review.googlesource.com/1216564Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590269}
parent f677c141
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
namespace web { namespace web {
// Tasks with this trait will not be executed inside a nested RunLoop.
//
// Note: This should rarely be required. Drivers of nested loops should instead
// make sure to be reentrant when allowing nested application tasks (also rare).
//
// TODO(crbug.com/876272): Investigate removing this trait -- and any logic for
// deferred tasks in MessageLoop.
struct NonNestable {};
// TaskTraits for running tasks on a WebThread. // TaskTraits for running tasks on a WebThread.
// //
// These traits enable the use of the //base/task/post_task.h APIs to post tasks // These traits enable the use of the //base/task/post_task.h APIs to post tasks
...@@ -33,6 +42,7 @@ class WebTaskTraitsExtension { ...@@ -33,6 +42,7 @@ class WebTaskTraitsExtension {
struct ValidTrait { struct ValidTrait {
ValidTrait(WebThread::ID) {} ValidTrait(WebThread::ID) {}
ValidTrait(NonNestable) {}
}; };
template < template <
...@@ -42,25 +52,37 @@ class WebTaskTraitsExtension { ...@@ -42,25 +52,37 @@ class WebTaskTraitsExtension {
constexpr WebTaskTraitsExtension(ArgTypes... args) constexpr WebTaskTraitsExtension(ArgTypes... args)
: web_thread_(base::trait_helpers::GetValueFromArgList( : web_thread_(base::trait_helpers::GetValueFromArgList(
base::trait_helpers::RequiredEnumArgGetter<WebThread::ID>(), base::trait_helpers::RequiredEnumArgGetter<WebThread::ID>(),
args...)),
nestable_(!base::trait_helpers::GetValueFromArgList(
base::trait_helpers::BooleanArgGetter<NonNestable>(),
args...)) {} args...)) {}
constexpr base::TaskTraitsExtensionStorage Serialize() const { constexpr base::TaskTraitsExtensionStorage Serialize() const {
static_assert(4 == sizeof(WebTaskTraitsExtension), static_assert(8 == sizeof(WebTaskTraitsExtension),
"Update Serialize() and Parse() when changing " "Update Serialize() and Parse() when changing "
"WebTaskTraitsExtension"); "WebTaskTraitsExtension");
return {kExtensionId, {static_cast<uint8_t>(web_thread_)}}; return {
kExtensionId,
{static_cast<uint8_t>(web_thread_), static_cast<uint8_t>(nestable_)}};
} }
static const WebTaskTraitsExtension Parse( static const WebTaskTraitsExtension Parse(
const base::TaskTraitsExtensionStorage& extension) { const base::TaskTraitsExtensionStorage& extension) {
return WebTaskTraitsExtension( return WebTaskTraitsExtension(static_cast<WebThread::ID>(extension.data[0]),
static_cast<WebThread::ID>(extension.data[0])); static_cast<bool>(extension.data[1]));
} }
constexpr WebThread::ID web_thread() const { return web_thread_; } constexpr WebThread::ID web_thread() const { return web_thread_; }
// Returns true if tasks with these traits may run in a nested RunLoop.
constexpr bool nestable() const { return nestable_; }
private: private:
WebTaskTraitsExtension(WebThread::ID web_thread, bool nestable)
: web_thread_(web_thread), nestable_(nestable) {}
WebThread::ID web_thread_; WebThread::ID web_thread_;
bool nestable_;
}; };
template <class... ArgTypes, template <class... ArgTypes,
......
...@@ -159,8 +159,9 @@ class WebThreadTaskExecutor : public base::TaskExecutor { ...@@ -159,8 +159,9 @@ class WebThreadTaskExecutor : public base::TaskExecutor {
const base::TaskTraits& traits, const base::TaskTraits& traits,
base::OnceClosure task, base::OnceClosure task,
base::TimeDelta delay) override { base::TimeDelta delay) override {
return PostTaskHelper(GetWebThreadIdentifier(traits), from_here, return PostTaskHelper(
std::move(task), delay, true); GetWebThreadIdentifier(traits), from_here, std::move(task), delay,
traits.GetExtension<WebTaskTraitsExtension>().nestable());
} }
scoped_refptr<base::TaskRunner> CreateTaskRunnerWithTraits( scoped_refptr<base::TaskRunner> CreateTaskRunnerWithTraits(
......
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