Commit 10463110 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

[DevTools] Put worker initalization params to WorkerDevToolsParams

This simple struct is being used to initialize DevTools in workers.

Bug: 882467
Change-Id: I4d7fa582913b3be9a8466de24d727289a34f6ce0
Reviewed-on: https://chromium-review.googlesource.com/c/1308073
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604495}
parent f5beba8b
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/events/message_event.h" #include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h" #include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h" #include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h" #include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
...@@ -105,8 +106,8 @@ void WebSharedWorkerImpl::TerminateWorkerThread() { ...@@ -105,8 +106,8 @@ void WebSharedWorkerImpl::TerminateWorkerThread() {
} }
if (worker_thread_) { if (worker_thread_) {
worker_thread_->Terminate(); worker_thread_->Terminate();
if (DevToolsAgent* agent = DevToolsAgent::From(shadow_page_->GetDocument())) DevToolsAgent::WorkerThreadTerminated(shadow_page_->GetDocument(),
agent->ChildWorkerThreadTerminated(worker_thread_.get()); worker_thread_.get());
} }
} }
...@@ -350,8 +351,11 @@ void WebSharedWorkerImpl::ContinueOnScriptLoaderFinished() { ...@@ -350,8 +351,11 @@ void WebSharedWorkerImpl::ContinueOnScriptLoaderFinished() {
thread_startup_data.atomics_wait_mode = thread_startup_data.atomics_wait_mode =
WorkerBackingThreadStartupData::AtomicsWaitMode::kAllow; WorkerBackingThreadStartupData::AtomicsWaitMode::kAllow;
auto devtools_params = DevToolsAgent::WorkerThreadCreated(
document, GetWorkerThread(), script_response_url);
GetWorkerThread()->Start(std::move(global_scope_creation_params), GetWorkerThread()->Start(std::move(global_scope_creation_params),
thread_startup_data, DevToolsAgent::From(document), thread_startup_data, std::move(devtools_params),
parent_execution_context_task_runners_); parent_execution_context_task_runners_);
// TODO(nhiroki): Support module workers (https://crbug.com/680046). // TODO(nhiroki): Support module workers (https://crbug.com/680046).
GetWorkerThread()->EvaluateClassicScript(script_response_url, source_code, GetWorkerThread()->EvaluateClassicScript(script_response_url, source_code,
......
...@@ -99,6 +99,7 @@ blink_core_sources("inspector") { ...@@ -99,6 +99,7 @@ blink_core_sources("inspector") {
"thread_debugger.h", "thread_debugger.h",
"v8_inspector_string.cc", "v8_inspector_string.cc",
"v8_inspector_string.h", "v8_inspector_string.h",
"worker_devtools_params.h",
"worker_inspector_controller.cc", "worker_inspector_controller.cc",
"worker_inspector_controller.h", "worker_inspector_controller.h",
"worker_thread_debugger.cc", "worker_thread_debugger.cc",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "third_party/blink/renderer/core/inspector/devtools_session.h" #include "third_party/blink/renderer/core/inspector/devtools_session.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h" #include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/inspector/inspector_task_runner.h" #include "third_party/blink/renderer/core/inspector/inspector_task_runner.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h" #include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
...@@ -23,8 +24,9 @@ ...@@ -23,8 +24,9 @@
namespace blink { namespace blink {
// static namespace {
DevToolsAgent* DevToolsAgent::From(ExecutionContext* execution_context) {
DevToolsAgent* DevToolsAgentFromContext(ExecutionContext* execution_context) {
if (!execution_context) if (!execution_context)
return nullptr; return nullptr;
if (auto* scope = DynamicTo<WorkerGlobalScope>(execution_context)) { if (auto* scope = DynamicTo<WorkerGlobalScope>(execution_context)) {
...@@ -45,6 +47,8 @@ DevToolsAgent* DevToolsAgent::From(ExecutionContext* execution_context) { ...@@ -45,6 +47,8 @@ DevToolsAgent* DevToolsAgent::From(ExecutionContext* execution_context) {
return nullptr; return nullptr;
} }
} // namespace
DevToolsAgent::DevToolsAgent( DevToolsAgent::DevToolsAgent(
Client* client, Client* client,
InspectedFrames* inspected_frames, InspectedFrames* inspected_frames,
...@@ -130,29 +134,40 @@ void DevToolsAgent::ReportChildWorkers(bool report, bool wait_for_debugger) { ...@@ -130,29 +134,40 @@ void DevToolsAgent::ReportChildWorkers(bool report, bool wait_for_debugger) {
ReportChildWorker(std::move(it.value)); ReportChildWorker(std::move(it.value));
} }
void DevToolsAgent::ChildWorkerThreadCreated( // static
std::unique_ptr<WorkerDevToolsParams> DevToolsAgent::WorkerThreadCreated(
ExecutionContext* parent_context,
WorkerThread* worker_thread, WorkerThread* worker_thread,
const KURL& url, const KURL& url) {
mojom::blink::DevToolsAgentRequest& agent_request, auto result = std::make_unique<WorkerDevToolsParams>();
mojom::blink::DevToolsAgentHostPtrInfo& host_ptr_info, result->devtools_worker_token = base::UnguessableToken::Create();
bool& wait_for_debugger) {
DevToolsAgent* agent = DevToolsAgentFromContext(parent_context);
if (!agent)
return result;
auto data = std::make_unique<WorkerData>(); auto data = std::make_unique<WorkerData>();
data->url = url; data->url = url;
agent_request = mojo::MakeRequest(&data->agent_ptr); result->agent_request = mojo::MakeRequest(&data->agent_ptr);
data->host_request = mojo::MakeRequest(&host_ptr_info); data->host_request = mojo::MakeRequest(&result->agent_host_ptr_info);
data->devtools_worker_token = worker_thread->GetDevToolsWorkerToken(); data->devtools_worker_token = result->devtools_worker_token;
data->waiting_for_debugger = pause_child_workers_on_start_; data->waiting_for_debugger = agent->pause_child_workers_on_start_;
wait_for_debugger = pause_child_workers_on_start_; result->wait_for_debugger = agent->pause_child_workers_on_start_;
if (report_child_workers_) { if (agent->report_child_workers_) {
ReportChildWorker(std::move(data)); agent->ReportChildWorker(std::move(data));
} else { } else {
unreported_child_worker_threads_.insert(worker_thread, std::move(data)); agent->unreported_child_worker_threads_.insert(worker_thread,
std::move(data));
} }
return result;
} }
void DevToolsAgent::ChildWorkerThreadTerminated(WorkerThread* worker_thread) { // static
unreported_child_worker_threads_.erase(worker_thread); void DevToolsAgent::WorkerThreadTerminated(ExecutionContext* parent_context,
WorkerThread* worker_thread) {
if (DevToolsAgent* agent = DevToolsAgentFromContext(parent_context))
agent->unreported_child_worker_threads_.erase(worker_thread);
} }
void DevToolsAgent::ReportChildWorker(std::unique_ptr<WorkerData> data) { void DevToolsAgent::ReportChildWorker(std::unique_ptr<WorkerData> data) {
......
...@@ -25,6 +25,7 @@ class ExecutionContext; ...@@ -25,6 +25,7 @@ class ExecutionContext;
class InspectedFrames; class InspectedFrames;
class InspectorTaskRunner; class InspectorTaskRunner;
class WorkerThread; class WorkerThread;
struct WorkerDevToolsParams;
class CORE_EXPORT DevToolsAgent class CORE_EXPORT DevToolsAgent
: public GarbageCollectedFinalized<DevToolsAgent>, : public GarbageCollectedFinalized<DevToolsAgent>,
...@@ -40,7 +41,13 @@ class CORE_EXPORT DevToolsAgent ...@@ -40,7 +41,13 @@ class CORE_EXPORT DevToolsAgent
virtual void DebuggerTaskFinished() = 0; virtual void DebuggerTaskFinished() = 0;
}; };
static DevToolsAgent* From(ExecutionContext*); static std::unique_ptr<WorkerDevToolsParams> WorkerThreadCreated(
ExecutionContext* parent_context,
WorkerThread*,
const KURL&);
static void WorkerThreadTerminated(ExecutionContext* parent_context,
WorkerThread*);
DevToolsAgent(Client*, DevToolsAgent(Client*,
InspectedFrames*, InspectedFrames*,
CoreProbeSink*, CoreProbeSink*,
...@@ -56,12 +63,6 @@ class CORE_EXPORT DevToolsAgent ...@@ -56,12 +63,6 @@ class CORE_EXPORT DevToolsAgent
void BindRequest(mojom::blink::DevToolsAgentHostAssociatedPtrInfo, void BindRequest(mojom::blink::DevToolsAgentHostAssociatedPtrInfo,
mojom::blink::DevToolsAgentAssociatedRequest, mojom::blink::DevToolsAgentAssociatedRequest,
scoped_refptr<base::SingleThreadTaskRunner>); scoped_refptr<base::SingleThreadTaskRunner>);
void ChildWorkerThreadCreated(WorkerThread*,
const KURL&,
mojom::blink::DevToolsAgentRequest&,
mojom::blink::DevToolsAgentHostPtrInfo&,
bool& wait_for_debugger);
void ChildWorkerThreadTerminated(WorkerThread*);
virtual void Trace(blink::Visitor*); virtual void Trace(blink::Visitor*);
private: private:
......
// Copyright 2018 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_WORKER_DEVTOOLS_PARAMS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_WORKER_DEVTOOLS_PARAMS_H_
#include "base/unguessable_token.h"
#include "third_party/blink/public/web/devtools_agent.mojom-blink.h"
namespace blink {
struct CORE_EXPORT WorkerDevToolsParams {
mojom::blink::DevToolsAgentRequest agent_request;
mojom::blink::DevToolsAgentHostPtrInfo agent_host_ptr_info;
bool wait_for_debugger = false;
base::UnguessableToken devtools_worker_token;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_WORKER_DEVTOOLS_PARAMS_H_
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "third_party/blink/renderer/core/inspector/inspector_network_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_network_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h" #include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/inspector/protocol/Protocol.h" #include "third_party/blink/renderer/core/inspector/protocol/Protocol.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h" #include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h" #include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
...@@ -54,13 +55,12 @@ namespace blink { ...@@ -54,13 +55,12 @@ namespace blink {
WorkerInspectorController* WorkerInspectorController::Create( WorkerInspectorController* WorkerInspectorController::Create(
WorkerThread* thread, WorkerThread* thread,
scoped_refptr<InspectorTaskRunner> inspector_task_runner, scoped_refptr<InspectorTaskRunner> inspector_task_runner,
mojom::blink::DevToolsAgentRequest agent_request, std::unique_ptr<WorkerDevToolsParams> devtools_params) {
mojom::blink::DevToolsAgentHostPtrInfo host_ptr_info) {
WorkerThreadDebugger* debugger = WorkerThreadDebugger* debugger =
WorkerThreadDebugger::From(thread->GetIsolate()); WorkerThreadDebugger::From(thread->GetIsolate());
return debugger ? new WorkerInspectorController( return debugger ? new WorkerInspectorController(
thread, debugger, std::move(inspector_task_runner), thread, debugger, std::move(inspector_task_runner),
std::move(agent_request), std::move(host_ptr_info)) std::move(devtools_params))
: nullptr; : nullptr;
} }
...@@ -68,15 +68,14 @@ WorkerInspectorController::WorkerInspectorController( ...@@ -68,15 +68,14 @@ WorkerInspectorController::WorkerInspectorController(
WorkerThread* thread, WorkerThread* thread,
WorkerThreadDebugger* debugger, WorkerThreadDebugger* debugger,
scoped_refptr<InspectorTaskRunner> inspector_task_runner, scoped_refptr<InspectorTaskRunner> inspector_task_runner,
mojom::blink::DevToolsAgentRequest agent_request, std::unique_ptr<WorkerDevToolsParams> devtools_params)
mojom::blink::DevToolsAgentHostPtrInfo host_ptr_info)
: debugger_(debugger), : debugger_(debugger),
thread_(thread), thread_(thread),
inspected_frames_(nullptr), inspected_frames_(nullptr),
probe_sink_(new CoreProbeSink()) { probe_sink_(new CoreProbeSink()) {
probe_sink_->addInspectorTraceEvents(new InspectorTraceEvents()); probe_sink_->addInspectorTraceEvents(new InspectorTraceEvents());
if (auto* scope = DynamicTo<WorkerGlobalScope>(thread->GlobalScope())) { if (auto* scope = DynamicTo<WorkerGlobalScope>(thread->GlobalScope())) {
worker_devtools_token_ = thread->GetDevToolsWorkerToken(); worker_devtools_token_ = devtools_params->devtools_worker_token;
parent_devtools_token_ = scope->GetParentDevToolsToken(); parent_devtools_token_ = scope->GetParentDevToolsToken();
url_ = scope->Url(); url_ = scope->Url();
worker_thread_id_ = thread->GetPlatformThreadId(); worker_thread_id_ = thread->GetPlatformThreadId();
...@@ -88,7 +87,8 @@ WorkerInspectorController::WorkerInspectorController( ...@@ -88,7 +87,8 @@ WorkerInspectorController::WorkerInspectorController(
agent_ = new DevToolsAgent(this, inspected_frames_.Get(), probe_sink_.Get(), agent_ = new DevToolsAgent(this, inspected_frames_.Get(), probe_sink_.Get(),
std::move(inspector_task_runner), std::move(inspector_task_runner),
std::move(io_task_runner)); std::move(io_task_runner));
agent_->BindRequest(std::move(host_ptr_info), std::move(agent_request), agent_->BindRequest(std::move(devtools_params->agent_host_ptr_info),
std::move(devtools_params->agent_request),
thread->GetTaskRunner(TaskType::kInternalInspector)); thread->GetTaskRunner(TaskType::kInternalInspector));
} }
TraceEvent::AddEnabledStateObserver(this); TraceEvent::AddEnabledStateObserver(this);
......
...@@ -50,6 +50,7 @@ class CoreProbeSink; ...@@ -50,6 +50,7 @@ class CoreProbeSink;
class InspectedFrames; class InspectedFrames;
class WorkerThread; class WorkerThread;
class WorkerThreadDebugger; class WorkerThreadDebugger;
struct WorkerDevToolsParams;
class WorkerInspectorController final class WorkerInspectorController final
: public GarbageCollectedFinalized<WorkerInspectorController>, : public GarbageCollectedFinalized<WorkerInspectorController>,
...@@ -60,8 +61,7 @@ class WorkerInspectorController final ...@@ -60,8 +61,7 @@ class WorkerInspectorController final
static WorkerInspectorController* Create( static WorkerInspectorController* Create(
WorkerThread*, WorkerThread*,
scoped_refptr<InspectorTaskRunner>, scoped_refptr<InspectorTaskRunner>,
mojom::blink::DevToolsAgentRequest, std::unique_ptr<WorkerDevToolsParams>);
mojom::blink::DevToolsAgentHostPtrInfo);
~WorkerInspectorController() override; ~WorkerInspectorController() override;
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
...@@ -74,8 +74,7 @@ class WorkerInspectorController final ...@@ -74,8 +74,7 @@ class WorkerInspectorController final
WorkerInspectorController(WorkerThread*, WorkerInspectorController(WorkerThread*,
WorkerThreadDebugger*, WorkerThreadDebugger*,
scoped_refptr<InspectorTaskRunner>, scoped_refptr<InspectorTaskRunner>,
mojom::blink::DevToolsAgentRequest, std::unique_ptr<WorkerDevToolsParams>);
mojom::blink::DevToolsAgentHostPtrInfo);
// Thread::TaskObserver implementation. // Thread::TaskObserver implementation.
void WillProcessTask(const base::PendingTask&) override; void WillProcessTask(const base::PendingTask&) override;
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/devtools_agent.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h" #include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
...@@ -88,9 +90,11 @@ void ThreadedMessagingProxyBase::InitializeWorkerThread( ...@@ -88,9 +90,11 @@ void ThreadedMessagingProxyBase::InitializeWorkerThread(
worker_thread_ = CreateWorkerThread(); worker_thread_ = CreateWorkerThread();
auto devtools_params = DevToolsAgent::WorkerThreadCreated(
execution_context_.Get(), worker_thread_.get(), script_url);
worker_thread_->Start(std::move(global_scope_creation_params), worker_thread_->Start(std::move(global_scope_creation_params),
thread_startup_data, thread_startup_data, std::move(devtools_params),
DevToolsAgent::From(execution_context_.Get()),
GetParentExecutionContextTaskRunners()); GetParentExecutionContextTaskRunners());
if (auto* scope = DynamicTo<WorkerGlobalScope>(*execution_context_)) { if (auto* scope = DynamicTo<WorkerGlobalScope>(*execution_context_)) {
...@@ -144,8 +148,8 @@ void ThreadedMessagingProxyBase::WorkerThreadTerminated() { ...@@ -144,8 +148,8 @@ void ThreadedMessagingProxyBase::WorkerThreadTerminated() {
parent_thread = scope->GetThread(); parent_thread = scope->GetThread();
std::unique_ptr<WorkerThread> child_thread = std::move(worker_thread_); std::unique_ptr<WorkerThread> child_thread = std::move(worker_thread_);
if (child_thread) { if (child_thread) {
if (DevToolsAgent* agent = DevToolsAgent::From(execution_context_.Get())) DevToolsAgent::WorkerThreadTerminated(execution_context_.Get(),
agent->ChildWorkerThreadTerminated(child_thread.get()); child_thread.get());
} }
// If the parent Worker/Worklet object was already destroyed, this will // If the parent Worker/Worklet object was already destroyed, this will
...@@ -168,8 +172,8 @@ void ThreadedMessagingProxyBase::TerminateGlobalScope() { ...@@ -168,8 +172,8 @@ void ThreadedMessagingProxyBase::TerminateGlobalScope() {
if (!worker_thread_) if (!worker_thread_)
return; return;
worker_thread_->Terminate(); worker_thread_->Terminate();
if (DevToolsAgent* agent = DevToolsAgent::From(execution_context_.Get())) DevToolsAgent::WorkerThreadTerminated(execution_context_.Get(),
agent->ChildWorkerThreadTerminated(worker_thread_.get()); worker_thread_.get());
} }
ExecutionContext* ThreadedMessagingProxyBase::GetExecutionContext() const { ExecutionContext* ThreadedMessagingProxyBase::GetExecutionContext() const {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/inspector/console_message_storage.h" #include "third_party/blink/renderer/core/inspector/console_message_storage.h"
#include "third_party/blink/renderer/core/inspector/inspector_task_runner.h" #include "third_party/blink/renderer/core/inspector/inspector_task_runner.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h" #include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h" #include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
...@@ -123,12 +124,13 @@ WorkerThread::~WorkerThread() { ...@@ -123,12 +124,13 @@ WorkerThread::~WorkerThread() {
void WorkerThread::Start( void WorkerThread::Start(
std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params, std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params,
const base::Optional<WorkerBackingThreadStartupData>& thread_startup_data, const base::Optional<WorkerBackingThreadStartupData>& thread_startup_data,
DevToolsAgent* devtools_agent, std::unique_ptr<WorkerDevToolsParams> devtools_params,
ParentExecutionContextTaskRunners* parent_execution_context_task_runners) { ParentExecutionContextTaskRunners* parent_execution_context_task_runners) {
DCHECK_CALLED_ON_VALID_THREAD(parent_thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(parent_thread_checker_);
DCHECK(!parent_execution_context_task_runners_); DCHECK(!parent_execution_context_task_runners_);
parent_execution_context_task_runners_ = parent_execution_context_task_runners_ =
parent_execution_context_task_runners; parent_execution_context_task_runners;
devtools_worker_token_ = devtools_params->devtools_worker_token;
// Synchronously initialize the per-global-scope scheduler to prevent someone // Synchronously initialize the per-global-scope scheduler to prevent someone
// from posting a task to the thread before the scheduler is ready. // from posting a task to the thread before the scheduler is ready.
...@@ -143,24 +145,12 @@ void WorkerThread::Start( ...@@ -143,24 +145,12 @@ void WorkerThread::Start(
inspector_task_runner_ = inspector_task_runner_ =
InspectorTaskRunner::Create(GetTaskRunner(TaskType::kInternalInspector)); InspectorTaskRunner::Create(GetTaskRunner(TaskType::kInternalInspector));
bool wait_for_debugger = false;
mojom::blink::DevToolsAgentRequest devtools_agent_request;
mojom::blink::DevToolsAgentHostPtrInfo devtools_agent_host_ptr_info;
if (devtools_agent) {
devtools_agent->ChildWorkerThreadCreated(
this, global_scope_creation_params->script_url.Copy(),
devtools_agent_request, devtools_agent_host_ptr_info,
wait_for_debugger);
}
GetWorkerBackingThread().BackingThread().PostTask( GetWorkerBackingThread().BackingThread().PostTask(
FROM_HERE, FROM_HERE,
CrossThreadBind(&WorkerThread::InitializeOnWorkerThread, CrossThreadBind(
CrossThreadUnretained(this), &WorkerThread::InitializeOnWorkerThread, CrossThreadUnretained(this),
WTF::Passed(std::move(global_scope_creation_params)), WTF::Passed(std::move(global_scope_creation_params)),
thread_startup_data, wait_for_debugger, thread_startup_data, WTF::Passed(std::move(devtools_params))));
WTF::Passed(std::move(devtools_agent_request)),
WTF::Passed(std::move(devtools_agent_host_ptr_info))));
} }
void WorkerThread::EvaluateClassicScript( void WorkerThread::EvaluateClassicScript(
...@@ -362,7 +352,6 @@ WorkerThread::WorkerThread(WorkerReportingProxy& worker_reporting_proxy) ...@@ -362,7 +352,6 @@ WorkerThread::WorkerThread(WorkerReportingProxy& worker_reporting_proxy)
: time_origin_(CurrentTimeTicks()), : time_origin_(CurrentTimeTicks()),
worker_thread_id_(GetNextWorkerThreadId()), worker_thread_id_(GetNextWorkerThreadId()),
forcible_termination_delay_(kForcibleTerminationDelay), forcible_termination_delay_(kForcibleTerminationDelay),
devtools_worker_token_(base::UnguessableToken::Create()),
worker_reporting_proxy_(worker_reporting_proxy), worker_reporting_proxy_(worker_reporting_proxy),
shutdown_event_(RefCountedWaitableEvent::Create()) { shutdown_event_(RefCountedWaitableEvent::Create()) {
MutexLocker lock(ThreadSetMutex()); MutexLocker lock(ThreadSetMutex());
...@@ -431,10 +420,9 @@ void WorkerThread::InitializeSchedulerOnWorkerThread( ...@@ -431,10 +420,9 @@ void WorkerThread::InitializeSchedulerOnWorkerThread(
void WorkerThread::InitializeOnWorkerThread( void WorkerThread::InitializeOnWorkerThread(
std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params, std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params,
const base::Optional<WorkerBackingThreadStartupData>& thread_startup_data, const base::Optional<WorkerBackingThreadStartupData>& thread_startup_data,
bool wait_for_debugger, std::unique_ptr<WorkerDevToolsParams> devtools_params) {
mojom::blink::DevToolsAgentRequest devtools_agent_request,
mojom::blink::DevToolsAgentHostPtrInfo devtools_agent_host_ptr_info) {
DCHECK(IsCurrentThread()); DCHECK(IsCurrentThread());
bool wait_for_debugger = devtools_params->wait_for_debugger;
{ {
MutexLocker lock(mutex_); MutexLocker lock(mutex_);
DCHECK_EQ(ThreadState::kNotStarted, thread_state_); DCHECK_EQ(ThreadState::kNotStarted, thread_state_);
...@@ -455,8 +443,7 @@ void WorkerThread::InitializeOnWorkerThread( ...@@ -455,8 +443,7 @@ void WorkerThread::InitializeOnWorkerThread(
worker_reporting_proxy_.DidCreateWorkerGlobalScope(GlobalScope()); worker_reporting_proxy_.DidCreateWorkerGlobalScope(GlobalScope());
worker_inspector_controller_ = WorkerInspectorController::Create( worker_inspector_controller_ = WorkerInspectorController::Create(
this, inspector_task_runner_, std::move(devtools_agent_request), this, inspector_task_runner_, std::move(devtools_params));
std::move(devtools_agent_host_ptr_info));
// Since context initialization below may fail, we should notify debugger // Since context initialization below may fail, we should notify debugger
// about the new worker thread separately, so that it can resolve it by id // about the new worker thread separately, so that it can resolve it by id
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "third_party/blink/public/platform/web_thread_type.h" #include "third_party/blink/public/platform/web_thread_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/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/inspector/devtools_agent.h"
#include "third_party/blink/renderer/core/workers/parent_execution_context_task_runners.h" #include "third_party/blink/renderer/core/workers/parent_execution_context_task_runners.h"
#include "third_party/blink/renderer/core/workers/worker_backing_thread_startup_data.h" #include "third_party/blink/renderer/core/workers/worker_backing_thread_startup_data.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
...@@ -62,6 +61,7 @@ class WorkerOrWorkletGlobalScope; ...@@ -62,6 +61,7 @@ class WorkerOrWorkletGlobalScope;
class WorkerReportingProxy; class WorkerReportingProxy;
struct CrossThreadFetchClientSettingsObjectData; struct CrossThreadFetchClientSettingsObjectData;
struct GlobalScopeCreationParams; struct GlobalScopeCreationParams;
struct WorkerDevToolsParams;
// WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism
// can access the lower thread infrastructure via an implementation of this // can access the lower thread infrastructure via an implementation of this
...@@ -100,7 +100,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver { ...@@ -100,7 +100,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver {
// (https://crbug.com/710364) // (https://crbug.com/710364)
void Start(std::unique_ptr<GlobalScopeCreationParams>, void Start(std::unique_ptr<GlobalScopeCreationParams>,
const base::Optional<WorkerBackingThreadStartupData>&, const base::Optional<WorkerBackingThreadStartupData>&,
DevToolsAgent*, std::unique_ptr<WorkerDevToolsParams>,
ParentExecutionContextTaskRunners*); ParentExecutionContextTaskRunners*);
// Posts a task to evaluate a top-level classic script on the worker thread. // Posts a task to evaluate a top-level classic script on the worker thread.
...@@ -278,9 +278,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver { ...@@ -278,9 +278,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver {
void InitializeOnWorkerThread( void InitializeOnWorkerThread(
std::unique_ptr<GlobalScopeCreationParams>, std::unique_ptr<GlobalScopeCreationParams>,
const base::Optional<WorkerBackingThreadStartupData>&, const base::Optional<WorkerBackingThreadStartupData>&,
bool wait_for_debugger, std::unique_ptr<WorkerDevToolsParams>) LOCKS_EXCLUDED(mutex_);
mojom::blink::DevToolsAgentRequest,
mojom::blink::DevToolsAgentHostPtrInfo) LOCKS_EXCLUDED(mutex_);
void EvaluateClassicScriptOnWorkerThread( void EvaluateClassicScriptOnWorkerThread(
const KURL& script_url, const KURL& script_url,
...@@ -314,7 +312,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver { ...@@ -314,7 +312,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver {
TimeDelta forcible_termination_delay_; TimeDelta forcible_termination_delay_;
scoped_refptr<InspectorTaskRunner> inspector_task_runner_; scoped_refptr<InspectorTaskRunner> inspector_task_runner_;
const base::UnguessableToken devtools_worker_token_; base::UnguessableToken devtools_worker_token_;
int debugger_task_counter_ GUARDED_BY(mutex_) = 0; int debugger_task_counter_ GUARDED_BY(mutex_) = 0;
WorkerReportingProxy& worker_reporting_proxy_; WorkerReportingProxy& worker_reporting_proxy_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h"
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/inspector_task_runner.h" #include "third_party/blink/renderer/core/inspector/inspector_task_runner.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
...@@ -397,11 +398,15 @@ TEST_F(WorkerThreadTest, Terminate_WhileDebuggerTaskIsRunningOnInitialization) { ...@@ -397,11 +398,15 @@ TEST_F(WorkerThreadTest, Terminate_WhileDebuggerTaskIsRunningOnInitialization) {
std::make_unique<WorkerSettings>(Settings::Create().get()), std::make_unique<WorkerSettings>(Settings::Create().get()),
kV8CacheOptionsDefault, nullptr /* worklet_module_responses_map */); kV8CacheOptionsDefault, nullptr /* worklet_module_responses_map */);
// Specify PauseOnWorkerStart::kPause so that the worker thread can pause // Set wait_for_debugger so that the worker thread can pause
// on initialization to run debugger tasks. // on initialization to run debugger tasks.
auto devtools_params = std::make_unique<WorkerDevToolsParams>();
devtools_params->wait_for_debugger = true;
worker_thread_->Start(std::move(global_scope_creation_params), worker_thread_->Start(std::move(global_scope_creation_params),
WorkerBackingThreadStartupData::CreateDefault(), WorkerBackingThreadStartupData::CreateDefault(),
nullptr, ParentExecutionContextTaskRunners::Create()); std::move(devtools_params),
ParentExecutionContextTaskRunners::Create());
// Used to wait for worker thread termination in a debugger task on the // Used to wait for worker thread termination in a debugger task on the
// worker thread. // worker thread.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/parent_execution_context_task_runners.h" #include "third_party/blink/renderer/core/workers/parent_execution_context_task_runners.h"
...@@ -100,7 +101,8 @@ class WorkerThreadForTest : public WorkerThread { ...@@ -100,7 +101,8 @@ class WorkerThreadForTest : public WorkerThread {
kV8CacheOptionsDefault, nullptr /* worklet_module_responses_map */); kV8CacheOptionsDefault, nullptr /* worklet_module_responses_map */);
Start(std::move(creation_params), Start(std::move(creation_params),
WorkerBackingThreadStartupData::CreateDefault(), nullptr, WorkerBackingThreadStartupData::CreateDefault(),
std::make_unique<WorkerDevToolsParams>(),
parent_execution_context_task_runners); parent_execution_context_task_runners);
EvaluateClassicScript(script_url, source, nullptr /* cached_meta_data */, EvaluateClassicScript(script_url, source, nullptr /* cached_meta_data */,
v8_inspector::V8StackTraceId()); v8_inspector::V8StackTraceId());
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_cache_options.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
...@@ -85,7 +86,8 @@ class AnimationWorkletGlobalScopeTest : public PageTestBase { ...@@ -85,7 +86,8 @@ class AnimationWorkletGlobalScopeTest : public PageTestBase {
OriginTrialContext::GetTokens(document).get(), OriginTrialContext::GetTokens(document).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap), kV8CacheOptionsDefault, new WorkletModuleResponsesMap),
base::nullopt, nullptr, ParentExecutionContextTaskRunners::Create()); base::nullopt, std::make_unique<WorkerDevToolsParams>(),
ParentExecutionContextTaskRunners::Create());
return thread; return thread;
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "third_party/blink/renderer/core/execution_context/security_context.h" #include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h" #include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h" #include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
...@@ -228,8 +229,8 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() { ...@@ -228,8 +229,8 @@ void WebEmbeddedWorkerImpl::TerminateWorkerContext() {
return; return;
} }
worker_thread_->Terminate(); worker_thread_->Terminate();
if (DevToolsAgent* agent = DevToolsAgent::From(shadow_page_->GetDocument())) DevToolsAgent::WorkerThreadTerminated(shadow_page_->GetDocument(),
agent->ChildWorkerThreadTerminated(worker_thread_.get()); worker_thread_.get());
} }
void WebEmbeddedWorkerImpl::ResumeAfterDownload() { void WebEmbeddedWorkerImpl::ResumeAfterDownload() {
...@@ -451,12 +452,15 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() { ...@@ -451,12 +452,15 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() {
ServiceWorkerGlobalScopeProxy::Create(*this, *worker_context_client_), ServiceWorkerGlobalScopeProxy::Create(*this, *worker_context_client_),
std::move(installed_scripts_manager_), std::move(cache_storage_info_)); std::move(installed_scripts_manager_), std::move(cache_storage_info_));
auto devtools_params = DevToolsAgent::WorkerThreadCreated(
document, worker_thread_.get(), worker_start_data_.script_url);
// We have a dummy document here for loading but it doesn't really represent // We have a dummy document here for loading but it doesn't really represent
// the document/frame of associated document(s) for this worker. Here we // the document/frame of associated document(s) for this worker. Here we
// populate the task runners with default task runners of the main thread. // populate the task runners with default task runners of the main thread.
worker_thread_->Start(std::move(global_scope_creation_params), worker_thread_->Start(std::move(global_scope_creation_params),
WorkerBackingThreadStartupData::CreateDefault(), WorkerBackingThreadStartupData::CreateDefault(),
DevToolsAgent::From(document), std::move(devtools_params),
ParentExecutionContextTaskRunners::Create()); ParentExecutionContextTaskRunners::Create());
// > Switching on job’s worker type, run these substeps with the following // > Switching on job’s worker type, run these substeps with the following
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h" #include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/messaging/message_channel.h" #include "third_party/blink/renderer/core/messaging/message_channel.h"
#include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
...@@ -76,7 +77,8 @@ class AudioWorkletGlobalScopeTest : public PageTestBase { ...@@ -76,7 +77,8 @@ class AudioWorkletGlobalScopeTest : public PageTestBase {
OriginTrialContext::GetTokens(document).get(), OriginTrialContext::GetTokens(document).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap), kV8CacheOptionsDefault, new WorkletModuleResponsesMap),
base::nullopt, nullptr, ParentExecutionContextTaskRunners::Create()); base::nullopt, std::make_unique<WorkerDevToolsParams>(),
ParentExecutionContextTaskRunners::Create());
return thread; return thread;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h" #include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
...@@ -60,7 +61,8 @@ class AudioWorkletThreadTest : public PageTestBase { ...@@ -60,7 +61,8 @@ class AudioWorkletThreadTest : public PageTestBase {
OriginTrialContext::GetTokens(document).get(), OriginTrialContext::GetTokens(document).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap), kV8CacheOptionsDefault, new WorkletModuleResponsesMap),
base::nullopt, nullptr, ParentExecutionContextTaskRunners::Create()); base::nullopt, std::make_unique<WorkerDevToolsParams>(),
ParentExecutionContextTaskRunners::Create());
return thread; return thread;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h" #include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
...@@ -74,7 +75,8 @@ class AnimationAndPaintWorkletThreadTest : public PageTestBase { ...@@ -74,7 +75,8 @@ class AnimationAndPaintWorkletThreadTest : public PageTestBase {
OriginTrialContext::GetTokens(document).get(), OriginTrialContext::GetTokens(document).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap), kV8CacheOptionsDefault, new WorkletModuleResponsesMap),
base::nullopt, nullptr, ParentExecutionContextTaskRunners::Create()); base::nullopt, std::make_unique<WorkerDevToolsParams>(),
ParentExecutionContextTaskRunners::Create());
return thread; return thread;
} }
......
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