This patch implements the PRemoteWorkerDebugger binding. We are trying to keep the same logic debugger registration/unregistration to minimize the difference between the local debugger(the debugger on the content process main thread) The registration logic is After constructing a Worker, we start the debugger registration and block the parent thread until the registration is complete. Blocking the parent thread because we don't want to dispatch the ComplieScriptRunnable() and any other DebuggeeRunnables before the debugger is ready. Blocking the parent thread also forbids the IPC that we might not be able to handle during the debugger registration, such as SharedWorkerTerminateOpArgs which can terminate a "Pending" worker. After RemoteWorkerDebuggerManagerChild::SendRegister() is called, we use mRemoteDebuggerBindingCondVar to block the parent thread. After registration is done in the parent process, RemoteWorkerDebugger receives the RegistrationDone() on the WorkerThread, then calling mRemoteWorkerDebuggerBindingCondVar.Notify to unblock the parent thread. However, To ensure the message can be sent immediately after RemoteWorkerDebuggerParent binding, RemoteWorkerDebuggerChild binding needs to be completed in the Worker thread before calling RemoteWorkerDebuggerManagerChild::SendRegister(), so we wait for the child binding to complete in EnableRemoteDebugger(). RemoteWorkerDebuggerChild binding happens on the Worker thread when needed. The time points are the start of WorkerThreadPrimaryRunnable::Run() and WorkerPrivate::ThawInternal(). So when the Worker starts to run the event loops, we create the RemoteWorkerDebuggerChild and bind it to the child Endpoint. We then notify the parent thread that the child binding is done to start remote debugger registration on the parent process. Through this implementation, the remote debugger mechanism has similar logic to the local debugger and can be used by all types of Workers. Depends on D231682 Differential Revision: https://phabricator.services.mozilla.com/D230260
51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_dom_WorkerEventTarget_h
|
|
#define mozilla_dom_WorkerEventTarget_h
|
|
|
|
#include "nsISerialEventTarget.h"
|
|
#include "mozilla/Mutex.h"
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
|
|
|
namespace mozilla::dom {
|
|
|
|
class WorkerEventTarget final : public nsISerialEventTarget {
|
|
public:
|
|
// The WorkerEventTarget supports different dispatch behaviors:
|
|
//
|
|
// * Hybrid targets will attempt to dispatch as a normal runnable,
|
|
// but fallback to a control runnable if that fails. This is
|
|
// often necessary for code that wants normal dispatch order, but
|
|
// also needs to execute while the worker is shutting down (possibly
|
|
// with a holder in place.)
|
|
//
|
|
// * ControlOnly targets will simply dispatch a control runnable.
|
|
//
|
|
// * DebuggerOnly targets will simply dispatch a debugger runnable.
|
|
enum class Behavior : uint8_t { Hybrid, ControlOnly, DebuggerOnly };
|
|
|
|
private:
|
|
mozilla::Mutex mMutex;
|
|
CheckedUnsafePtr<WorkerPrivate> mWorkerPrivate MOZ_GUARDED_BY(mMutex);
|
|
const Behavior mBehavior MOZ_GUARDED_BY(mMutex);
|
|
|
|
~WorkerEventTarget() = default;
|
|
|
|
public:
|
|
WorkerEventTarget(WorkerPrivate* aWorkerPrivate, Behavior aBehavior);
|
|
|
|
void ForgetWorkerPrivate(WorkerPrivate* aWorkerPrivate);
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSIEVENTTARGET
|
|
NS_DECL_NSISERIALEVENTTARGET
|
|
};
|
|
|
|
} // namespace mozilla::dom
|
|
|
|
#endif // mozilla_dom_WorkerEventTarget_h
|