Bug 1132141 - Update storage when ServiceWorker registration fails. r=baku

This commit is contained in:
Nikhil Marathe 2015-02-11 10:51:32 -08:00
parent 9190583d2e
commit aafb36075f
2 changed files with 34 additions and 9 deletions

View File

@ -422,7 +422,7 @@ public:
const nsMainThreadPtrHandle<nsISupports> aJob)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
, mJob(aJob)
{
{
AssertIsOnMainThread();
}
@ -2689,4 +2689,36 @@ ServiceWorkerManager::MaybeRemoveRegistration(ServiceWorkerRegistrationInfo* aRe
}
}
void
ServiceWorkerManager::RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration)
{
MOZ_ASSERT(aRegistration);
MOZ_ASSERT(!aRegistration->IsControllingDocuments());
MOZ_ASSERT(mServiceWorkerRegistrationInfos.Contains(aRegistration->mScope));
ServiceWorkerManager::RemoveScope(mOrderedScopes, aRegistration->mScope);
// Hold a ref since the hashtable may be the last ref.
nsRefPtr<ServiceWorkerRegistrationInfo> reg;
mServiceWorkerRegistrationInfos.Remove(aRegistration->mScope,
getter_AddRefs(reg));
MOZ_ASSERT(reg);
// All callers should be either from a job in which case the actor is
// available, or from MaybeStopControlling(), in which case, this will only be
// called if a valid registration is found. If a valid registration exists,
// it means the actor is available since the original map of registrations is
// populated by it, and any new registrations wait until the actor is
// available before proceeding (See ServiceWorkerRegisterJob::Start).
MOZ_ASSERT(mActor);
PrincipalInfo principalInfo;
if (NS_WARN_IF(NS_FAILED(PrincipalToPrincipalInfo(reg->mPrincipal,
&principalInfo)))) {
//XXXnsm I can't think of any other reason a stored principal would fail to
//convert.
NS_WARNING("Unable to unregister serviceworker due to possible OOM");
return;
}
mActor->SendUnregisterServiceWorker(principalInfo, NS_ConvertUTF8toUTF16(reg->mScope));
}
END_WORKERS_NAMESPACE

View File

@ -352,14 +352,7 @@ public:
CreateNewRegistration(const nsCString& aScope, nsIPrincipal* aPrincipal);
void
RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration)
{
MOZ_ASSERT(aRegistration);
MOZ_ASSERT(!aRegistration->IsControllingDocuments());
MOZ_ASSERT(mServiceWorkerRegistrationInfos.Contains(aRegistration->mScope));
ServiceWorkerManager::RemoveScope(mOrderedScopes, aRegistration->mScope);
mServiceWorkerRegistrationInfos.Remove(aRegistration->mScope);
}
RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration);
ServiceWorkerJobQueue*
GetOrCreateJobQueue(const nsCString& aScope)