Bug 1231213 - Implement PRemoteWorkerController IPDL protocol and RemoteWorkerController{Parent,Child}. r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D26168

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Perry Jiang 2019-08-13 19:55:59 +00:00
Родитель fe331f45b8
Коммит f133e5ec1a
13 изменённых файлов: 470 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,33 @@
/* 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/. */
include protocol PBackground;
include RemoteWorkerTypes;
include ServiceWorkerOpArgs;
namespace mozilla {
namespace dom {
protocol PRemoteWorkerController {
manager PBackground;
child:
async CreationFailed();
async CreationSucceeded();
async ErrorReceived(ErrorValue aError);
async Terminated();
parent:
async __delete__();
async Shutdown() returns (bool aOk);
};
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -6,6 +6,7 @@
#include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/MessagePortParent.h"
#include "mozilla/dom/RemoteWorkerTypes.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "RemoteWorkerController.h"
#include "RemoteWorkerManager.h"
@ -26,7 +27,7 @@ already_AddRefed<RemoteWorkerController> RemoteWorkerController::Create(
MOZ_ASSERT(aObserver);
RefPtr<RemoteWorkerController> controller =
new RemoteWorkerController(aObserver);
new RemoteWorkerController(aData, aObserver);
RefPtr<RemoteWorkerManager> manager = RemoteWorkerManager::GetOrCreate();
MOZ_ASSERT(manager);
@ -36,8 +37,13 @@ already_AddRefed<RemoteWorkerController> RemoteWorkerController::Create(
return controller.forget();
}
RemoteWorkerController::RemoteWorkerController(RemoteWorkerObserver* aObserver)
: mObserver(aObserver), mState(ePending) {
RemoteWorkerController::RemoteWorkerController(const RemoteWorkerData& aData,
RemoteWorkerObserver* aObserver)
: mObserver(aObserver),
mState(ePending),
mIsServiceWorker(aData.serviceWorkerData().type() ==
OptionalServiceWorkerData::TServiceWorkerData) {
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(XRE_IsParentProcess());
}

Просмотреть файл

@ -80,6 +80,8 @@ namespace dom {
class ErrorValue;
class MessagePortIdentifier;
class RemoteWorkerControllerParent;
class RemoteWorkerData;
class RemoteWorkerManager;
class RemoteWorkerParent;
@ -97,6 +99,7 @@ class RemoteWorkerObserver {
};
class RemoteWorkerController final {
friend class RemoteWorkerControllerParent;
friend class RemoteWorkerManager;
friend class RemoteWorkerParent;
@ -124,7 +127,9 @@ class RemoteWorkerController final {
void Thaw();
private:
explicit RemoteWorkerController(RemoteWorkerObserver* aObserver);
RemoteWorkerController(const RemoteWorkerData& aData,
RemoteWorkerObserver* aObserver);
~RemoteWorkerController();
void SetWorkerActor(RemoteWorkerParent* aActor);
@ -150,6 +155,8 @@ class RemoteWorkerController final {
eTerminated,
} mState;
const bool mIsServiceWorker;
struct Op {
enum Type {
eTerminate,

Просмотреть файл

@ -0,0 +1,111 @@
/* -*- 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/. */
#include "RemoteWorkerControllerChild.h"
#include <utility>
#include "MainThreadUtils.h"
#include "nsError.h"
#include "nsThreadUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Unused.h"
namespace mozilla {
using ipc::IPCResult;
namespace dom {
RemoteWorkerControllerChild::RemoteWorkerControllerChild(
RefPtr<RemoteWorkerObserver> aObserver)
: mObserver(std::move(aObserver)) {
AssertIsOnMainThread();
MOZ_ASSERT(mObserver);
}
void RemoteWorkerControllerChild::ActorDestroy(ActorDestroyReason aReason) {
AssertIsOnMainThread();
mIPCActive = false;
if (NS_WARN_IF(mObserver)) {
mObserver->ErrorReceived(NS_ERROR_DOM_ABORT_ERR);
}
}
IPCResult RemoteWorkerControllerChild::RecvCreationFailed() {
AssertIsOnMainThread();
if (mObserver) {
mObserver->CreationFailed();
}
return IPC_OK();
}
IPCResult RemoteWorkerControllerChild::RecvCreationSucceeded() {
AssertIsOnMainThread();
if (mObserver) {
mObserver->CreationSucceeded();
}
return IPC_OK();
}
IPCResult RemoteWorkerControllerChild::RecvErrorReceived(
const ErrorValue& aError) {
AssertIsOnMainThread();
if (mObserver) {
mObserver->ErrorReceived(aError);
}
return IPC_OK();
}
IPCResult RemoteWorkerControllerChild::RecvTerminated() {
AssertIsOnMainThread();
if (mObserver) {
mObserver->Terminated();
}
return IPC_OK();
}
void RemoteWorkerControllerChild::RevokeObserver(
RemoteWorkerObserver* aObserver) {
AssertIsOnMainThread();
MOZ_ASSERT(aObserver);
MOZ_ASSERT(aObserver == mObserver);
mObserver = nullptr;
}
void RemoteWorkerControllerChild::MaybeSendDelete() {
AssertIsOnMainThread();
if (!mIPCActive) {
return;
}
RefPtr<RemoteWorkerControllerChild> self = this;
SendShutdown()->Then(
GetCurrentThreadSerialEventTarget(), __func__,
[self = std::move(self)](const ShutdownPromise::ResolveOrRejectValue&) {
if (self->mIPCActive) {
Unused << self->Send__delete__(self);
}
});
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- 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_remoteworkercontrollerchild_h__
#define mozilla_dom_remoteworkercontrollerchild_h__
#include "nsISupportsImpl.h"
#include "RemoteWorkerController.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/PRemoteWorkerControllerChild.h"
namespace mozilla {
namespace dom {
class RemoteWorkerControllerChild final : public PRemoteWorkerControllerChild {
friend class PRemoteWorkerControllerChild;
public:
NS_INLINE_DECL_REFCOUNTING(RemoteWorkerControllerChild)
explicit RemoteWorkerControllerChild(RefPtr<RemoteWorkerObserver> aObserver);
void Initialize();
void RevokeObserver(RemoteWorkerObserver* aObserver);
void MaybeSendDelete();
private:
~RemoteWorkerControllerChild() = default;
void ActorDestroy(ActorDestroyReason aReason) override;
mozilla::ipc::IPCResult RecvCreationFailed();
mozilla::ipc::IPCResult RecvCreationSucceeded();
mozilla::ipc::IPCResult RecvErrorReceived(const ErrorValue& aError);
mozilla::ipc::IPCResult RecvTerminated();
RefPtr<RemoteWorkerObserver> mObserver;
bool mIPCActive = true;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_remoteworkercontrollerchild_h__

Просмотреть файл

@ -0,0 +1,127 @@
/* -*- 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/. */
#include "RemoteWorkerControllerParent.h"
#include <utility>
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsThreadUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/BackgroundParent.h"
namespace mozilla {
using namespace ipc;
namespace dom {
RemoteWorkerControllerParent::RemoteWorkerControllerParent(
const RemoteWorkerData& aRemoteWorkerData)
: mRemoteWorkerController(RemoteWorkerController::Create(
aRemoteWorkerData, this, 0 /* random process ID */)) {
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(mRemoteWorkerController);
}
RefPtr<RemoteWorkerParent> RemoteWorkerControllerParent::GetRemoteWorkerParent()
const {
AssertIsOnBackgroundThread();
MOZ_ASSERT(mRemoteWorkerController);
return mRemoteWorkerController->mActor;
}
RemoteWorkerControllerParent::~RemoteWorkerControllerParent() {
AssertIsOnBackgroundThread();
MOZ_ASSERT(!mIPCActive);
MOZ_ASSERT(!mRemoteWorkerController);
}
IPCResult RemoteWorkerControllerParent::RecvShutdown(
ShutdownResolver&& aResolve) {
AssertIsOnBackgroundThread();
MOZ_ASSERT(mIPCActive);
MOZ_ASSERT(mRemoteWorkerController);
mIPCActive = false;
mRemoteWorkerController->Shutdown();
mRemoteWorkerController = nullptr;
aResolve(true);
return IPC_OK();
}
IPCResult RemoteWorkerControllerParent::Recv__delete__() {
AssertIsOnBackgroundThread();
MOZ_ASSERT(!mIPCActive);
MOZ_ASSERT(!mRemoteWorkerController);
return IPC_OK();
}
void RemoteWorkerControllerParent::ActorDestroy(ActorDestroyReason aReason) {
AssertIsOnBackgroundThread();
if (NS_WARN_IF(mIPCActive)) {
mIPCActive = false;
}
if (NS_WARN_IF(mRemoteWorkerController)) {
mRemoteWorkerController->Shutdown();
mRemoteWorkerController = nullptr;
}
}
void RemoteWorkerControllerParent::CreationFailed() {
AssertIsOnBackgroundThread();
if (!mIPCActive) {
return;
}
Unused << SendCreationFailed();
}
void RemoteWorkerControllerParent::CreationSucceeded() {
AssertIsOnBackgroundThread();
if (!mIPCActive) {
return;
}
Unused << SendCreationSucceeded();
}
void RemoteWorkerControllerParent::ErrorReceived(const ErrorValue& aValue) {
AssertIsOnBackgroundThread();
if (!mIPCActive) {
return;
}
Unused << SendErrorReceived(aValue);
}
void RemoteWorkerControllerParent::Terminated() {
AssertIsOnBackgroundThread();
if (!mIPCActive) {
return;
}
Unused << SendTerminated();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- 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_remoteworkercontrollerparent_h__
#define mozilla_dom_remoteworkercontrollerparent_h__
#include <functional>
#include "nsISupportsImpl.h"
#include "RemoteWorkerController.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/PRemoteWorkerControllerParent.h"
namespace mozilla {
namespace dom {
class RemoteWorkerControllerParent final : public PRemoteWorkerControllerParent,
public RemoteWorkerObserver {
friend class PRemoteWorkerControllerParent;
public:
NS_INLINE_DECL_REFCOUNTING(RemoteWorkerControllerParent, override)
explicit RemoteWorkerControllerParent(
const RemoteWorkerData& aRemoteWorkerData);
// Returns the corresponding RemoteWorkerParent (if any).
RefPtr<RemoteWorkerParent> GetRemoteWorkerParent() const;
private:
~RemoteWorkerControllerParent();
mozilla::ipc::IPCResult RecvShutdown(ShutdownResolver&& aResolve);
mozilla::ipc::IPCResult Recv__delete__() override;
void ActorDestroy(ActorDestroyReason aReason) override;
void CreationFailed() override;
void CreationSucceeded() override;
void ErrorReceived(const ErrorValue& aValue) override;
void Terminated() override;
RefPtr<RemoteWorkerController> mRemoteWorkerController;
bool mIPCActive = true;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_remoteworkercontrollerparent_h__

Просмотреть файл

@ -7,6 +7,8 @@
EXPORTS.mozilla.dom += [
'RemoteWorkerChild.h',
'RemoteWorkerController.h',
'RemoteWorkerControllerChild.h',
'RemoteWorkerControllerParent.h',
'RemoteWorkerParent.h',
'RemoteWorkerService.h',
'RemoteWorkerServiceChild.h',
@ -16,6 +18,8 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
'RemoteWorkerChild.cpp',
'RemoteWorkerController.cpp',
'RemoteWorkerControllerChild.cpp',
'RemoteWorkerControllerParent.cpp',
'RemoteWorkerManager.cpp',
'RemoteWorkerParent.cpp',
'RemoteWorkerService.cpp',
@ -29,6 +33,7 @@ LOCAL_INCLUDES += [
IPDL_SOURCES += [
'PRemoteWorker.ipdl',
'PRemoteWorkerController.ipdl',
'PRemoteWorkerService.ipdl',
'RemoteWorkerTypes.ipdlh',
]

Просмотреть файл

@ -35,6 +35,7 @@
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/quota/PQuotaChild.h"
#include "mozilla/dom/RemoteWorkerChild.h"
#include "mozilla/dom/RemoteWorkerControllerChild.h"
#include "mozilla/dom/RemoteWorkerServiceChild.h"
#include "mozilla/dom/SharedWorkerChild.h"
#include "mozilla/dom/StorageIPC.h"
@ -342,6 +343,23 @@ bool BackgroundChildImpl::DeallocPRemoteWorkerChild(
return true;
}
dom::PRemoteWorkerControllerChild*
BackgroundChildImpl::AllocPRemoteWorkerControllerChild(
const dom::RemoteWorkerData& aRemoteWorkerData) {
MOZ_CRASH(
"PRemoteWorkerControllerChild actors must be manually constructed!");
return nullptr;
}
bool BackgroundChildImpl::DeallocPRemoteWorkerControllerChild(
dom::PRemoteWorkerControllerChild* aActor) {
MOZ_ASSERT(aActor);
RefPtr<dom::RemoteWorkerControllerChild> actor =
dont_AddRef(static_cast<dom::RemoteWorkerControllerChild*>(aActor));
return true;
}
dom::PRemoteWorkerServiceChild*
BackgroundChildImpl::AllocPRemoteWorkerServiceChild() {
RefPtr<dom::RemoteWorkerServiceChild> agent =

Просмотреть файл

@ -141,6 +141,13 @@ class BackgroundChildImpl : public PBackgroundChild {
virtual bool DeallocPRemoteWorkerChild(
mozilla::dom::PRemoteWorkerChild* aActor) override;
virtual mozilla::dom::PRemoteWorkerControllerChild*
AllocPRemoteWorkerControllerChild(
const mozilla::dom::RemoteWorkerData& aRemoteWorkerData) override;
virtual bool DeallocPRemoteWorkerControllerChild(
mozilla::dom::PRemoteWorkerControllerChild* aActor) override;
virtual mozilla::dom::PRemoteWorkerServiceChild*
AllocPRemoteWorkerServiceChild() override;

Просмотреть файл

@ -40,6 +40,7 @@
#include "mozilla/dom/quota/ActorsParent.h"
#include "mozilla/dom/simpledb/ActorsParent.h"
#include "mozilla/dom/RemoteWorkerParent.h"
#include "mozilla/dom/RemoteWorkerControllerParent.h"
#include "mozilla/dom/RemoteWorkerServiceParent.h"
#include "mozilla/dom/ReportingHeader.h"
#include "mozilla/dom/SharedWorkerParent.h"
@ -497,6 +498,29 @@ bool BackgroundParentImpl::DeallocPRemoteWorkerParent(
return true;
}
dom::PRemoteWorkerControllerParent*
BackgroundParentImpl::AllocPRemoteWorkerControllerParent(
const dom::RemoteWorkerData& aRemoteWorkerData) {
RefPtr<dom::RemoteWorkerControllerParent> actor =
new dom::RemoteWorkerControllerParent(aRemoteWorkerData);
return actor.forget().take();
}
IPCResult BackgroundParentImpl::RecvPRemoteWorkerControllerConstructor(
dom::PRemoteWorkerControllerParent* aActor,
const dom::RemoteWorkerData& aRemoteWorkerData) {
MOZ_ASSERT(aActor);
return IPC_OK();
}
bool BackgroundParentImpl::DeallocPRemoteWorkerControllerParent(
dom::PRemoteWorkerControllerParent* aActor) {
RefPtr<dom::RemoteWorkerControllerParent> actor =
dont_AddRef(static_cast<dom::RemoteWorkerControllerParent*>(aActor));
return true;
}
mozilla::dom::PRemoteWorkerServiceParent*
BackgroundParentImpl::AllocPRemoteWorkerServiceParent() {
return new mozilla::dom::RemoteWorkerServiceParent();

Просмотреть файл

@ -171,6 +171,17 @@ class BackgroundParentImpl : public PBackgroundParent {
virtual bool DeallocPRemoteWorkerParent(PRemoteWorkerParent* aActor) override;
virtual mozilla::dom::PRemoteWorkerControllerParent*
AllocPRemoteWorkerControllerParent(
const mozilla::dom::RemoteWorkerData& aRemoteWorkerData) override;
virtual mozilla::ipc::IPCResult RecvPRemoteWorkerControllerConstructor(
mozilla::dom::PRemoteWorkerControllerParent* aActor,
const mozilla::dom::RemoteWorkerData& aRemoteWorkerData) override;
virtual bool DeallocPRemoteWorkerControllerParent(
mozilla::dom::PRemoteWorkerControllerParent* aActor) override;
virtual mozilla::dom::PRemoteWorkerServiceParent*
AllocPRemoteWorkerServiceParent() override;

Просмотреть файл

@ -27,6 +27,7 @@ include protocol PIPCBlobInputStream;
include protocol PMediaTransport;
include protocol PPendingIPCBlob;
include protocol PRemoteWorker;
include protocol PRemoteWorkerController;
include protocol PRemoteWorkerService;
include protocol PSharedWorker;
include protocol PTemporaryIPCBlob;
@ -94,6 +95,7 @@ sync protocol PBackground
manages PMediaTransport;
manages PPendingIPCBlob;
manages PRemoteWorker;
manages PRemoteWorkerController;
manages PRemoteWorkerService;
manages PSharedWorker;
manages PTemporaryIPCBlob;
@ -216,6 +218,8 @@ parent:
async PServiceWorker(IPCServiceWorkerDescriptor aDescriptor);
async PRemoteWorkerController(RemoteWorkerData aData);
async PRemoteWorkerService();
async PServiceWorkerContainer();