Bug 1418074 - Get rid of friend classes in WorkerFetchResolver, r=bkelly

This commit is contained in:
Andrea Marchesini 2017-12-22 10:05:48 +01:00
Родитель 359a45f9a9
Коммит d3e4e6067c
1 изменённых файлов: 60 добавлений и 28 удалений

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

@ -164,14 +164,11 @@ private:
class WorkerFetchResolver final : public FetchDriverObserver
{
friend class MainThreadFetchRunnable;
friend class WorkerDataAvailableRunnable;
friend class WorkerFetchResponseEndBase;
friend class WorkerFetchResponseEndRunnable;
friend class WorkerFetchResponseRunnable;
// Thread-safe:
RefPtr<PromiseWorkerProxy> mPromiseProxy;
RefPtr<AbortSignalProxy> mSignalProxy;
// Touched only on the worker thread.
RefPtr<FetchObserver> mFetchObserver;
public:
@ -223,6 +220,31 @@ public:
return mSignalProxy->GetSignalForTargetThread();
}
PromiseWorkerProxy*
PromiseProxy() const
{
MOZ_ASSERT(NS_IsMainThread());
return mPromiseProxy;
}
Promise*
WorkerPromise(WorkerPrivate* aWorkerPrivate) const
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
return mPromiseProxy->WorkerPromise();
}
FetchObserver*
GetFetchObserver(WorkerPrivate* aWorkerPrivate) const
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
return mFetchObserver;
}
void
OnResponseAvailableInternal(InternalResponse* aResponse) override;
@ -235,6 +257,22 @@ public:
void
OnDataAvailable() override;
void
Shutdown(WorkerPrivate* aWorkerPrivate)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
mPromiseProxy->CleanUp();
mFetchObserver = nullptr;
if (mSignalProxy) {
mSignalProxy->Shutdown();
mSignalProxy = nullptr;
}
}
private:
WorkerFetchResolver(PromiseWorkerProxy* aProxy,
AbortSignalProxy* aSignalProxy,
@ -329,7 +367,7 @@ public:
{
AssertIsOnMainThread();
RefPtr<FetchDriver> fetch;
RefPtr<PromiseWorkerProxy> proxy = mResolver->mPromiseProxy;
RefPtr<PromiseWorkerProxy> proxy = mResolver->PromiseProxy();
{
// Acquire the proxy mutex while getting data from the WorkerPrivate...
@ -561,11 +599,13 @@ public:
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
RefPtr<Promise> promise = mResolver->mPromiseProxy->WorkerPromise();
RefPtr<Promise> promise = mResolver->WorkerPromise(aWorkerPrivate);
RefPtr<FetchObserver> fetchObserver =
mResolver->GetFetchObserver(aWorkerPrivate);
if (mInternalResponse->Type() != ResponseType::Error) {
if (mResolver->mFetchObserver) {
mResolver->mFetchObserver->SetState(FetchState::Complete);
if (fetchObserver) {
fetchObserver->SetState(FetchState::Complete);
}
RefPtr<nsIGlobalObject> global = aWorkerPrivate->GlobalScope();
@ -574,8 +614,8 @@ public:
mResolver->GetAbortSignalForTargetThread());
promise->MaybeResolve(response);
} else {
if (mResolver->mFetchObserver) {
mResolver->mFetchObserver->SetState(FetchState::Errored);
if (fetchObserver) {
fetchObserver->SetState(FetchState::Errored);
}
ErrorResult result;
@ -603,9 +643,12 @@ public:
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
if (mResolver->mFetchObserver &&
mResolver->mFetchObserver->State() == FetchState::Requesting) {
mResolver->mFetchObserver->SetState(FetchState::Responding);
RefPtr<FetchObserver> fetchObserver =
mResolver->GetFetchObserver(aWorkerPrivate);
if (fetchObserver &&
fetchObserver->State() == FetchState::Requesting) {
fetchObserver->SetState(FetchState::Responding);
}
return true;
@ -627,17 +670,7 @@ public:
void
WorkerRunInternal(WorkerPrivate* aWorkerPrivate)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
mResolver->mPromiseProxy->CleanUp();
mResolver->mFetchObserver = nullptr;
if (mResolver->mSignalProxy) {
mResolver->mSignalProxy->Shutdown();
mResolver->mSignalProxy = nullptr;
}
mResolver->Shutdown(aWorkerPrivate);
}
};
@ -660,8 +693,7 @@ public:
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{
if (mReason == FetchDriverObserver::eAborted) {
RefPtr<Promise> promise = mResolver->mPromiseProxy->WorkerPromise();
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
mResolver->WorkerPromise(aWorkerPrivate)->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}
WorkerRunInternal(aWorkerPrivate);