зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1438945 - Part 10: RemoteWorkerObserver. r=asuth
--HG-- extra : rebase_source : 4c4b6e7e896e0cc3d297ee0b14fb449ce09361eb
This commit is contained in:
Родитель
c292b31a93
Коммит
db9d439a1d
|
@ -18,12 +18,15 @@ using namespace ipc;
|
|||
namespace dom {
|
||||
|
||||
/* static */ already_AddRefed<RemoteWorkerController>
|
||||
RemoteWorkerController::Create(const RemoteWorkerData& aData)
|
||||
RemoteWorkerController::Create(const RemoteWorkerData& aData,
|
||||
RemoteWorkerObserver* aObserver)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(aObserver);
|
||||
|
||||
RefPtr<RemoteWorkerController> controller = new RemoteWorkerController();
|
||||
RefPtr<RemoteWorkerController> controller =
|
||||
new RemoteWorkerController(aObserver);
|
||||
|
||||
RefPtr<RemoteWorkerManager> manager = RemoteWorkerManager::GetOrCreate();
|
||||
MOZ_ASSERT(manager);
|
||||
|
@ -33,8 +36,9 @@ RemoteWorkerController::Create(const RemoteWorkerData& aData)
|
|||
return controller.forget();
|
||||
}
|
||||
|
||||
RemoteWorkerController::RemoteWorkerController()
|
||||
: mState(ePending)
|
||||
RemoteWorkerController::RemoteWorkerController(RemoteWorkerObserver* aObserver)
|
||||
: mObserver(aObserver)
|
||||
, mState(ePending)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
|
@ -64,9 +68,15 @@ RemoteWorkerController::CreationFailed()
|
|||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(mState == ePending || mState == eTerminated);
|
||||
|
||||
// TODO: maybe notification?
|
||||
if (mState == eTerminated) {
|
||||
MOZ_ASSERT(!mActor);
|
||||
MOZ_ASSERT(mPendingOps.IsEmpty());
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
Shutdown();
|
||||
mObserver->CreationFailed();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -86,7 +96,7 @@ RemoteWorkerController::CreationSucceeded()
|
|||
MOZ_ASSERT(mActor);
|
||||
mState = eReady;
|
||||
|
||||
// TODO: maybe notification?
|
||||
mObserver->CreationSucceeded();
|
||||
|
||||
for (UniquePtr<Op>& op : mPendingOps) {
|
||||
switch (op->mType) {
|
||||
|
@ -138,7 +148,7 @@ RemoteWorkerController::ErrorPropagation(const ErrorValue& aValue)
|
|||
AssertIsOnBackgroundThread();
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
// TODO: error propagation
|
||||
mObserver->ErrorReceived(aValue);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -148,7 +158,7 @@ RemoteWorkerController::WorkerTerminated()
|
|||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(mState == eReady);
|
||||
|
||||
// TODO: worker terminated
|
||||
mObserver->Terminated();
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,24 @@ 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;
|
||||
|
@ -92,7 +110,8 @@ public:
|
|||
NS_INLINE_DECL_REFCOUNTING(RemoteWorkerController)
|
||||
|
||||
static already_AddRefed<RemoteWorkerController>
|
||||
Create(const RemoteWorkerData& aData);
|
||||
Create(const RemoteWorkerData& aData,
|
||||
RemoteWorkerObserver* aObserver);
|
||||
|
||||
void
|
||||
AddWindowID(uint64_t aWindowID);
|
||||
|
@ -119,7 +138,7 @@ public:
|
|||
Thaw();
|
||||
|
||||
private:
|
||||
RemoteWorkerController();
|
||||
explicit RemoteWorkerController(RemoteWorkerObserver* aObserver);
|
||||
~RemoteWorkerController();
|
||||
|
||||
void
|
||||
|
@ -140,14 +159,15 @@ private:
|
|||
void
|
||||
CreationSucceeded();
|
||||
|
||||
RefPtr<RemoteWorkerObserver> mObserver;
|
||||
RefPtr<RemoteWorkerParent> mActor;
|
||||
|
||||
enum {
|
||||
ePending,
|
||||
eReady,
|
||||
eTerminated,
|
||||
} mState;
|
||||
|
||||
RefPtr<RemoteWorkerParent> mActor;
|
||||
|
||||
struct Op {
|
||||
enum Type {
|
||||
eTerminate,
|
||||
|
|
|
@ -51,7 +51,7 @@ SharedWorkerManager::MaybeCreateRemoteWorker(const RemoteWorkerData& aData,
|
|||
AssertIsOnBackgroundThread();
|
||||
|
||||
if (!mRemoteWorkerController) {
|
||||
mRemoteWorkerController = RemoteWorkerController::Create(aData);
|
||||
mRemoteWorkerController = RemoteWorkerController::Create(aData, this);
|
||||
if (NS_WARN_IF(!mRemoteWorkerController)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -188,46 +188,25 @@ SharedWorkerManager::IsSecureContext() const
|
|||
return mIsSecureContext;
|
||||
}
|
||||
|
||||
/* TODO
|
||||
void
|
||||
SharedWorkerManager::BroadcastErrorToActorsOnMainThread(const WorkerErrorReport* aReport,
|
||||
bool aIsErrorEvent)
|
||||
SharedWorkerManager::CreationFailed()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
ErrorValue value;
|
||||
if (aIsErrorEvent) {
|
||||
nsTArray<ErrorDataNote> notes;
|
||||
for (size_t i = 0, len = aReport->mNotes.Length(); i < len; i++) {
|
||||
const WorkerErrorNote& note = aReport->mNotes.ElementAt(i);
|
||||
notes.AppendElement(ErrorDataNote(note.mLineNumber, note.mColumnNumber,
|
||||
note.mMessage, note.mFilename));
|
||||
}
|
||||
|
||||
ErrorData data(aReport->mLineNumber,
|
||||
aReport->mColumnNumber,
|
||||
aReport->mFlags,
|
||||
aReport->mMessage,
|
||||
aReport->mFilename,
|
||||
aReport->mLine,
|
||||
notes);
|
||||
value = data;
|
||||
} else {
|
||||
value = void_t();
|
||||
for (SharedWorkerParent* actor : mActors) {
|
||||
Unused << actor->SendError(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
RefPtr<SharedWorkerManager> self = this;
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
NS_NewRunnableFunction("SharedWorkerManager::BroadcastErrorToActorsOnMainThread",
|
||||
[self, value]() {
|
||||
self->BroadcastErrorToActors(value);
|
||||
});
|
||||
|
||||
mPBackgroundEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
SharedWorkerManager::BroadcastErrorToActors(const ErrorValue& aValue)
|
||||
SharedWorkerManager::CreationSucceeded()
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
void
|
||||
SharedWorkerManager::ErrorReceived(const ErrorValue& aValue)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
|
@ -237,23 +216,7 @@ SharedWorkerManager::BroadcastErrorToActors(const ErrorValue& aValue)
|
|||
}
|
||||
|
||||
void
|
||||
SharedWorkerManager::CloseActorsOnMainThread()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
CloseOnMainThread();
|
||||
|
||||
RefPtr<SharedWorkerManager> self = this;
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
NS_NewRunnableFunction("SharedWorkerManager::CloseActorsOnMainThread",
|
||||
[self]() {
|
||||
self->CloseActors();
|
||||
});
|
||||
|
||||
mPBackgroundEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
SharedWorkerManager::CloseActors()
|
||||
SharedWorkerManager::Terminated()
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
|
@ -262,38 +225,5 @@ SharedWorkerManager::CloseActors()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SharedWorkerManager::FlushReportsToActorsOnMainThread(nsIConsoleReportCollector* aReporter)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
AutoTArray<uint64_t, 10> windowIDs;
|
||||
for (SharedWorkerParent* actor : mActors) {
|
||||
uint64_t windowID = actor->WindowID();
|
||||
if (windowID && !windowIDs.Contains(windowID)) {
|
||||
windowIDs.AppendElement(windowID);
|
||||
}
|
||||
}
|
||||
|
||||
bool reportErrorToBrowserConsole = true;
|
||||
|
||||
// Flush the reports.
|
||||
for (uint32_t index = 0; index < windowIDs.Length(); index++) {
|
||||
aReporter->FlushReportsToConsole(windowIDs[index],
|
||||
nsIConsoleReportCollector::ReportAction::Save);
|
||||
reportErrorToBrowserConsole = false;
|
||||
}
|
||||
|
||||
// Finally report to browser console if there is no any window or shared
|
||||
// worker.
|
||||
if (reportErrorToBrowserConsole) {
|
||||
aReporter->FlushReportsToConsole(0);
|
||||
return;
|
||||
}
|
||||
|
||||
aReporter->ClearConsoleReports();
|
||||
}
|
||||
*/
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef mozilla_dom_SharedWorkerManager_h
|
||||
#define mozilla_dom_SharedWorkerManager_h
|
||||
|
||||
#include "mozilla/dom/RemoteWorkerController.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -17,13 +18,12 @@ namespace dom {
|
|||
|
||||
class MessagePortIdentifier;
|
||||
class RemoteWorkerData;
|
||||
class RemoteWorkerController;
|
||||
class SharedWorkerParent;
|
||||
|
||||
class SharedWorkerManager final
|
||||
class SharedWorkerManager final : public RemoteWorkerObserver
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedWorkerManager);
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedWorkerManager, override);
|
||||
|
||||
// Called on main-thread thread methods
|
||||
|
||||
|
@ -37,6 +37,20 @@ public:
|
|||
const nsAString& aName,
|
||||
nsIPrincipal* aLoadingPrincipal) const;
|
||||
|
||||
// RemoteWorkerObserver
|
||||
|
||||
void
|
||||
CreationFailed() override;
|
||||
|
||||
void
|
||||
CreationSucceeded() override;
|
||||
|
||||
void
|
||||
ErrorReceived(const ErrorValue& aValue) override;
|
||||
|
||||
void
|
||||
Terminated() override;
|
||||
|
||||
// Called on PBackground thread methods
|
||||
|
||||
bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче