Commit e4d30f28 authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Add TaskType to EventTarget::EnqueueAsyncEvent

Events and task sources are orthogonal things, and it would not make
sense to determine a task source (task type) from an event. This CL adds
a TaskType argument to specify the task source explicitly.

Bug: 846618
Change-Id: I2c3c5d51e8d94ee12905bc8b850162f10433ad76
Reviewed-on: https://chromium-review.googlesource.com/1114529Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570360}
parent 648ee420
...@@ -42,8 +42,6 @@ class CORE_EXPORT EventQueue final ...@@ -42,8 +42,6 @@ class CORE_EXPORT EventQueue final
USING_GARBAGE_COLLECTED_MIXIN(EventQueue); USING_GARBAGE_COLLECTED_MIXIN(EventQueue);
public: public:
// TODO(hajimehoshi): TaskType should be determined based on an event instead
// of specifying here.
static EventQueue* Create(ExecutionContext*, TaskType); static EventQueue* Create(ExecutionContext*, TaskType);
~EventQueue(); ~EventQueue();
......
...@@ -870,17 +870,15 @@ void EventTarget::RemoveAllEventListeners() { ...@@ -870,17 +870,15 @@ void EventTarget::RemoveAllEventListeners() {
} }
} }
void EventTarget::EnqueueAsyncEvent(Event* event) { void EventTarget::EnqueueAsyncEvent(Event* event, TaskType task_type) {
ExecutionContext* context = GetExecutionContext(); ExecutionContext* context = GetExecutionContext();
if (!context) if (!context)
return; return;
probe::AsyncTaskScheduled(context, event->type(), event); probe::AsyncTaskScheduled(context, event->type(), event);
// TODO(hajimehoshi): Specify better task type based on the event. context->GetTaskRunner(task_type)->PostTask(
context->GetTaskRunner(TaskType::kInternalDefault) FROM_HERE,
->PostTask( WTF::Bind(&EventTarget::DispatchAsyncEvent, WrapPersistent(this),
FROM_HERE, WrapPersistent(event), WrapPersistent(context)));
WTF::Bind(&EventTarget::DispatchAsyncEvent, WrapPersistent(this),
WrapPersistent(event), WrapPersistent(context)));
} }
void EventTarget::DispatchAsyncEvent(Event* event, ExecutionContext* context) { void EventTarget::DispatchAsyncEvent(Event* event, ExecutionContext* context) {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/add_event_listener_options_resolved.h" #include "third_party/blink/renderer/core/dom/events/add_event_listener_options_resolved.h"
#include "third_party/blink/renderer/core/dom/events/event_dispatch_result.h" #include "third_party/blink/renderer/core/dom/events/event_dispatch_result.h"
...@@ -154,7 +155,7 @@ class CORE_EXPORT EventTarget : public ScriptWrappable { ...@@ -154,7 +155,7 @@ class CORE_EXPORT EventTarget : public ScriptWrappable {
DispatchEventResult DispatchEvent(Event*); DispatchEventResult DispatchEvent(Event*);
void EnqueueAsyncEvent(Event*); void EnqueueAsyncEvent(Event*, TaskType);
// dispatchEventForBindings is intended to only be called from // dispatchEventForBindings is intended to only be called from
// javascript originated calls. This method will validate and may adjust // javascript originated calls. This method will validate and may adjust
......
...@@ -460,7 +460,7 @@ void WebPluginContainerImpl::EnqueueMessageEvent( ...@@ -460,7 +460,7 @@ void WebPluginContainerImpl::EnqueueMessageEvent(
const WebDOMMessageEvent& event) { const WebDOMMessageEvent& event) {
if (!element_->GetExecutionContext()) if (!element_->GetExecutionContext())
return; return;
element_->EnqueueAsyncEvent(event); element_->EnqueueAsyncEvent(event, TaskType::kInternalDefault);
} }
void WebPluginContainerImpl::Invalidate() { void WebPluginContainerImpl::Invalidate() {
......
...@@ -1427,11 +1427,12 @@ void ContentSecurityPolicy::DispatchViolationEvents( ...@@ -1427,11 +1427,12 @@ void ContentSecurityPolicy::DispatchViolationEvents(
if (execution_context_->IsDocument()) { if (execution_context_->IsDocument()) {
Document* document = ToDocument(execution_context_); Document* document = ToDocument(execution_context_);
if (element && element->isConnected() && element->GetDocument() == document) if (element && element->isConnected() && element->GetDocument() == document)
element->EnqueueAsyncEvent(event); element->EnqueueAsyncEvent(event, TaskType::kInternalDefault);
else else
document->EnqueueAsyncEvent(event); document->EnqueueAsyncEvent(event, TaskType::kInternalDefault);
} else if (execution_context_->IsWorkerGlobalScope()) { } else if (execution_context_->IsWorkerGlobalScope()) {
ToWorkerGlobalScope(execution_context_)->EnqueueAsyncEvent(event); ToWorkerGlobalScope(execution_context_)
->EnqueueAsyncEvent(event, TaskType::kInternalDefault);
} }
} }
......
...@@ -339,12 +339,12 @@ Document* LocalDOMWindow::InstallNewDocument(const String& mime_type, ...@@ -339,12 +339,12 @@ Document* LocalDOMWindow::InstallNewDocument(const String& mime_type,
} }
void LocalDOMWindow::EnqueueWindowEvent(Event* event) { void LocalDOMWindow::EnqueueWindowEvent(Event* event) {
EnqueueAsyncEvent(event); EnqueueAsyncEvent(event, TaskType::kInternalDefault);
} }
void LocalDOMWindow::EnqueueDocumentEvent(Event* event) { void LocalDOMWindow::EnqueueDocumentEvent(Event* event) {
if (document_) if (document_)
document_->EnqueueAsyncEvent(event); document_->EnqueueAsyncEvent(event, TaskType::kInternalDefault);
} }
void LocalDOMWindow::DispatchWindowLoadEvent() { void LocalDOMWindow::DispatchWindowLoadEvent() {
......
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