chromium/third_party/blink/renderer/core/workers/worker_thread.cc

/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "third_party/blink/renderer/core/workers/worker_thread.h"

#include <limits>
#include <memory>
#include <utility>

#include "base/metrics/histogram_functions.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "third_party/blink/public/common/loader/worker_main_script_load_parameters.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-shared.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/frame/policy_container.h"
#include "third_party/blink/renderer/core/inspector/console_message_storage.h"
#include "third_party/blink/renderer/core/inspector/inspector_issue_storage.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_thread_debugger.h"
#include "third_party/blink/renderer/core/loader/worker_resource_timing_notifier_impl.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/cross_thread_global_scope_creation_params_copier.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_backing_thread.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/worker_resource_timing_notifier.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/worker/non_main_thread_impl.h"
#include "third_party/blink/renderer/platform/scheduler/worker/worker_thread_scheduler.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"

namespace blink {

ExitCode;

namespace {

constexpr base::TimeDelta kForcibleTerminationDelay =;

}  // namespace

base::Lock& WorkerThread::ThreadSetLock() {}

static std::atomic_int g_unique_worker_thread_id(1);

static int GetNextWorkerThreadId() {}

// RefCountedWaitableEvent makes WaitableEvent thread-safe refcounted.
// WorkerThread retains references to the event from both the parent context
// thread and the worker thread with this wrapper. See
// WorkerThread::PerformShutdownOnWorkerThread() for details.
class WorkerThread::RefCountedWaitableEvent
    : public WTF::ThreadSafeRefCounted<RefCountedWaitableEvent> {};

// A class that is passed into V8 Interrupt and via a PostTask. Once both have
// run this object will be destroyed in
// PauseOrFreezeWithInterruptDataOnWorkerThread. The V8 API only takes a raw ptr
// otherwise this could have been done with WTF::Bind and ref counted objects.
class WorkerThread::InterruptData {};

WorkerThread::~WorkerThread() {}

void WorkerThread::Start(
    std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params,
    const std::optional<WorkerBackingThreadStartupData>& thread_startup_data,
    std::unique_ptr<WorkerDevToolsParams> devtools_params) {}

void WorkerThread::EvaluateClassicScript(
    const KURL& script_url,
    const String& source_code,
    std::unique_ptr<Vector<uint8_t>> cached_meta_data,
    const v8_inspector::V8StackTraceId& stack_id) {}

void WorkerThread::FetchAndRunClassicScript(
    const KURL& script_url,
    std::unique_ptr<WorkerMainScriptLoadParameters>
        worker_main_script_load_params,
    std::unique_ptr<WebPolicyContainer> policy_container,
    std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
        outside_settings_object_data,
    WorkerResourceTimingNotifier* outside_resource_timing_notifier,
    const v8_inspector::V8StackTraceId& stack_id) {}

void WorkerThread::FetchAndRunModuleScript(
    const KURL& script_url,
    std::unique_ptr<WorkerMainScriptLoadParameters>
        worker_main_script_load_params,
    std::unique_ptr<WebPolicyContainer> policy_container,
    std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
        outside_settings_object_data,
    WorkerResourceTimingNotifier* outside_resource_timing_notifier,
    network::mojom::CredentialsMode credentials_mode,
    RejectCoepUnsafeNone reject_coep_unsafe_none) {}

void WorkerThread::Pause() {}

void WorkerThread::Freeze(bool is_in_back_forward_cache) {}

void WorkerThread::Resume() {}

void WorkerThread::Terminate() {}

void WorkerThread::TerminateForTesting() {}

void WorkerThread::WillProcessTask(const base::PendingTask& pending_task,
                                   bool was_blocked_or_low_priority) {}

void WorkerThread::DidProcessTask(const base::PendingTask& pending_task) {}

v8::Isolate* WorkerThread::GetIsolate() {}

bool WorkerThread::IsCurrentThread() {}

void WorkerThread::DebuggerTaskStarted() {}

void WorkerThread::DebuggerTaskFinished() {}

WorkerOrWorkletGlobalScope* WorkerThread::GlobalScope() {}

WorkerInspectorController* WorkerThread::GetWorkerInspectorController() {}

unsigned WorkerThread::WorkerThreadCount() {}

HashSet<WorkerThread*>& WorkerThread::InitializingWorkerThreads() {}

HashSet<WorkerThread*>& WorkerThread::WorkerThreads() {}

bool WorkerThread::IsForciblyTerminated() {}

void WorkerThread::WaitForShutdownForTesting() {}

ExitCode WorkerThread::GetExitCodeForTesting() {}

scheduler::WorkerScheduler* WorkerThread::GetScheduler() {}

scoped_refptr<base::SingleThreadTaskRunner> WorkerThread::GetTaskRunner(
    TaskType type) {}

void WorkerThread::ChildThreadStartedOnWorkerThread(WorkerThread* child) {}

void WorkerThread::ChildThreadTerminatedOnWorkerThread(WorkerThread* child) {}

WorkerThread::WorkerThread(WorkerReportingProxy& worker_reporting_proxy)
    :{}

WorkerThread::WorkerThread(WorkerReportingProxy& worker_reporting_proxy,
                           scoped_refptr<base::SingleThreadTaskRunner>
                               parent_thread_default_task_runner)
    :{}

void WorkerThread::ScheduleToTerminateScriptExecution() {}

WorkerThread::TerminationState WorkerThread::ShouldTerminateScriptExecution() {}

void WorkerThread::EnsureScriptExecutionTerminates(ExitCode exit_code) {}

void WorkerThread::InitializeSchedulerOnWorkerThread(
    base::WaitableEvent* waitable_event) {}

void WorkerThread::InitializeOnWorkerThread(
    std::unique_ptr<GlobalScopeCreationParams> global_scope_creation_params,
    const std::optional<WorkerBackingThreadStartupData>& thread_startup_data,
    std::unique_ptr<WorkerDevToolsParams> devtools_params) {}

void WorkerThread::EvaluateClassicScriptOnWorkerThread(
    const KURL& script_url,
    String source_code,
    std::unique_ptr<Vector<uint8_t>> cached_meta_data,
    const v8_inspector::V8StackTraceId& stack_id) {}

void WorkerThread::FetchAndRunClassicScriptOnWorkerThread(
    const KURL& script_url,
    std::unique_ptr<WorkerMainScriptLoadParameters>
        worker_main_script_load_params,
    std::unique_ptr<WebPolicyContainer> policy_container,
    std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
        outside_settings_object,
    WorkerResourceTimingNotifier* outside_resource_timing_notifier,
    const v8_inspector::V8StackTraceId& stack_id) {}

void WorkerThread::FetchAndRunModuleScriptOnWorkerThread(
    const KURL& script_url,
    std::unique_ptr<WorkerMainScriptLoadParameters>
        worker_main_script_load_params,
    std::unique_ptr<WebPolicyContainer> policy_container,
    std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
        outside_settings_object,
    WorkerResourceTimingNotifier* outside_resource_timing_notifier,
    network::mojom::CredentialsMode credentials_mode,
    bool reject_coep_unsafe_none) {}

void WorkerThread::PrepareForShutdownOnWorkerThread() {}

void WorkerThread::PerformShutdownOnWorkerThread() {}

void WorkerThread::SetThreadState(ThreadState next_thread_state) {}

void WorkerThread::SetExitCode(ExitCode exit_code) {}

bool WorkerThread::CheckRequestedToTerminate() {}

void WorkerThread::PauseOrFreeze(mojom::blink::FrameLifecycleState state,
                                 bool is_in_back_forward_cache) {}

void WorkerThread::PauseOrFreezeOnWorkerThread(
    mojom::blink::FrameLifecycleState state,
    bool is_in_back_forward_cache) {}

void WorkerThread::ResumeOnWorkerThread() {}

void WorkerThread::PauseOrFreezeWithInterruptDataOnWorkerThread(
    InterruptData* interrupt_data) {}

void WorkerThread::PauseOrFreezeInsideV8InterruptOnWorkerThread(v8::Isolate*,
                                                                void* data) {}

void WorkerThread::PauseOrFreezeInsidePostTaskOnWorkerThread(
    InterruptData* interrupt_data) {}

}  // namespace blink