forked from mirrors/gecko-dev
Backed out changeset 6f25a7e73fe2 (bug 1231213) Backed out changeset 5e88c3855fb6 (bug 1231213) Backed out changeset a78d7b3e44af (bug 1231213) Backed out changeset eb7f3a9b0a42 (bug 1231213) Backed out changeset 87575a180ad5 (bug 1231213) Backed out changeset 4e8369314e87 (bug 1231213) Backed out changeset 039c34bc043c (bug 1231213) Backed out changeset 0528ab68d94e (bug 1231213) Backed out changeset 670e7d61d95c (bug 1231213) Backed out changeset d61b9d65bd0a (bug 1231213) Backed out changeset 9042ea694d40 (bug 1231213) Backed out changeset bc0607e0d50b (bug 1231213) Backed out changeset 196ee18781cb (bug 1231213) Backed out changeset 4b588dec466b (bug 1231213) Backed out changeset be6031a6fca7 (bug 1231213) Backed out changeset 12e04c22f52f (bug 1231213) Backed out changeset fd146f327f2d (bug 1231213) Backed out changeset f2af7b66f50d (bug 1231213) Backed out changeset 71d93fc98d3f (bug 1231213) Backed out changeset 280271806864 (bug 1231213) Backed out changeset ca4e828345a2 (bug 1231213) Backed out changeset e41b984510ad (bug 1231213)
198 lines
6.6 KiB
C++
198 lines
6.6 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_RemoteWorkerController_h
|
|
#define mozilla_dom_RemoteWorkerController_h
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
/* Here's a graph about this remote workers are spawned.
|
|
*
|
|
* _________________________________ | ________________________________
|
|
* | | | | |
|
|
* | Parent process | IPC | Creation of Process X |
|
|
* | PBackground thread | | | |
|
|
* | | | | [RemoteWorkerService::Init()] |
|
|
* | | | | | |
|
|
* | | | | | (1) |
|
|
* | [RemoteWorkerManager:: (2) | | | V |
|
|
* | RegisterActor()]<-------- [new RemoteWorkerServiceChild] |
|
|
* | | | | |
|
|
* | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | |________________________________|
|
|
* | | |
|
|
* | new SharedWorker/ServiceWorker | |
|
|
* | | ^ | IPC
|
|
* | (3) | (4)| |
|
|
* | V | | |
|
|
* | [RemoteWorkerController:: | |
|
|
* | | Create(data)] | |
|
|
* | | (5) | |
|
|
* | V | |
|
|
* | [RemoteWorkerManager::Launch()] | |
|
|
* | | | IPC _____________________________
|
|
* | | (6) | | | |
|
|
* | | | | Selected content process |
|
|
* | V | (7) | |
|
|
* | [SendPRemoteWorkerConstructor()]--------->[new RemoteWorkerChild()] |
|
|
* | | | | | | |
|
|
* | | (8) | | | | |
|
|
* | V | | | V |
|
|
* | [RemoteWorkerController-> | | | RemoteWorkerChild->Exec() |
|
|
* | | SetControllerActor()] | | |_____________________________|
|
|
* | (9) | | IPC
|
|
* | V | |
|
|
* | [RemoteWorkerObserver-> | |
|
|
* | CreationCompleted()] | |
|
|
* |_________________________________| |
|
|
* |
|
|
*
|
|
* 1. When a new process starts, it creates a RemoteWorkerService singleton.
|
|
* This service creates a new thread (Worker Launcher) and from there, it
|
|
* starts a PBackground RemoteWorkerServiceChild actor.
|
|
* 2. On the parent process, PBackground thread, RemoteWorkerServiceParent
|
|
* actors are registered into the RemoteWorkerManager service.
|
|
*
|
|
* 3. At some point, a SharedWorker or a ServiceWorker must be executed.
|
|
* RemoteWorkerController::Create() is used to start the launching. This
|
|
* method must be called on the parent process, on the PBackground thread.
|
|
* 4. RemoteWorkerController object is immediately returned to the caller. Any
|
|
* operation done with this controller object will be stored in a queue,
|
|
* until the launching is correctly executed.
|
|
* 5. RemoteWorkerManager has the list of active RemoteWorkerServiceParent
|
|
* actors. From them, it picks one.
|
|
* In case we don't have any content process to select, a new one is
|
|
* spawned. If this happens, the operation is suspended until a new
|
|
* RemoteWorkerServiceParent is registered.
|
|
* 6. RemoteWorkerServiceParent is used to create a RemoteWorkerParent.
|
|
* 7. RemoteWorkerChild is created on a selected process and it executes the
|
|
* WorkerPrivate.
|
|
* 8. The RemoteWorkerParent actor is passed to the RemoteWorkerController.
|
|
* 9. RemoteWorkerController now is ready to continue and it called
|
|
* RemoteWorkerObserver to inform that the operation is completed.
|
|
* In case there were pending operations, they are now executed.
|
|
*/
|
|
|
|
class ErrorValue;
|
|
class MessagePortIdentifier;
|
|
class RemoteWorkerManager;
|
|
class RemoteWorkerParent;
|
|
|
|
class RemoteWorkerObserver {
|
|
public:
|
|
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
|
|
|
virtual void CreationFailed() = 0;
|
|
|
|
virtual void CreationSucceeded() = 0;
|
|
|
|
virtual void ErrorReceived(const ErrorValue& aValue) = 0;
|
|
|
|
virtual void Terminated() = 0;
|
|
};
|
|
|
|
class RemoteWorkerController final {
|
|
friend class RemoteWorkerManager;
|
|
friend class RemoteWorkerParent;
|
|
|
|
public:
|
|
NS_INLINE_DECL_REFCOUNTING(RemoteWorkerController)
|
|
|
|
static already_AddRefed<RemoteWorkerController> Create(
|
|
const RemoteWorkerData& aData, RemoteWorkerObserver* aObserver,
|
|
base::ProcessId = 0);
|
|
|
|
void AddWindowID(uint64_t aWindowID);
|
|
|
|
void RemoveWindowID(uint64_t aWindowID);
|
|
|
|
void AddPortIdentifier(const MessagePortIdentifier& aPortIdentifier);
|
|
|
|
void Terminate();
|
|
|
|
void Suspend();
|
|
|
|
void Resume();
|
|
|
|
void Freeze();
|
|
|
|
void Thaw();
|
|
|
|
private:
|
|
explicit RemoteWorkerController(RemoteWorkerObserver* aObserver);
|
|
~RemoteWorkerController();
|
|
|
|
void SetWorkerActor(RemoteWorkerParent* aActor);
|
|
|
|
void ErrorPropagation(const ErrorValue& aValue);
|
|
|
|
void WorkerTerminated();
|
|
|
|
void ForgetActorAndTerminate();
|
|
|
|
void Shutdown();
|
|
|
|
void CreationFailed();
|
|
|
|
void CreationSucceeded();
|
|
|
|
RefPtr<RemoteWorkerObserver> mObserver;
|
|
RefPtr<RemoteWorkerParent> mActor;
|
|
|
|
enum {
|
|
ePending,
|
|
eReady,
|
|
eTerminated,
|
|
} mState;
|
|
|
|
struct Op {
|
|
enum Type {
|
|
eTerminate,
|
|
eSuspend,
|
|
eResume,
|
|
eFreeze,
|
|
eThaw,
|
|
ePortIdentifier,
|
|
eAddWindowID,
|
|
eRemoveWindowID,
|
|
};
|
|
|
|
explicit Op(Type aType, uint64_t aWindowID = 0)
|
|
: mType(aType), mWindowID(aWindowID), mCompleted(false) {
|
|
MOZ_COUNT_CTOR(Op);
|
|
}
|
|
|
|
explicit Op(const MessagePortIdentifier& aPortIdentifier)
|
|
: mType(ePortIdentifier),
|
|
mPortIdentifier(aPortIdentifier),
|
|
mCompleted(false) {
|
|
MOZ_COUNT_CTOR(Op);
|
|
}
|
|
|
|
// This object cannot be copied.
|
|
Op(Op const&) = delete;
|
|
Op& operator=(Op const&) = delete;
|
|
|
|
~Op();
|
|
|
|
void Completed() { mCompleted = true; }
|
|
|
|
Type mType;
|
|
|
|
MessagePortIdentifier mPortIdentifier;
|
|
uint64_t mWindowID;
|
|
bool mCompleted;
|
|
};
|
|
|
|
nsTArray<UniquePtr<Op>> mPendingOps;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_dom_RemoteWorkerController_h
|