Back out bug 1154494 (changeset 94c2f1d254e7 and changeset d1269f811e05) for causing intermittent orange in various service worker tests.

This commit is contained in:
L. David Baron 2015-04-25 15:07:54 -07:00
Родитель 0984efab4d
Коммит b263b5134d
4 изменённых файлов: 40 добавлений и 233 удалений

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

@ -599,7 +599,7 @@ public:
}
void
ComparisonResult(nsresult aStatus, bool aInCacheAndEqual, const nsAString& aNewCacheName) override
ComparisonResult(nsresult aStatus, bool aInCacheAndEqual) override
{
if (NS_WARN_IF(NS_FAILED(aStatus))) {
Fail(NS_ERROR_DOM_TYPE_ERR);
@ -629,6 +629,12 @@ public:
}
nsAutoString cacheName;
rv = serviceWorkerScriptCache::GenerateCacheName(cacheName);
if (NS_WARN_IF(NS_FAILED(rv))) {
Fail(NS_ERROR_DOM_TYPE_ERR);
return;
}
// We have to create a ServiceWorker here simply to ensure there are no
// errors. Ideally we should just pass this worker on to ContinueInstall.
MOZ_ASSERT(!swm->mSetOfScopesBeingUpdated.Contains(mRegistration->mScope));
@ -637,7 +643,7 @@ public:
MOZ_ASSERT(!mUpdateAndInstallInfo);
mUpdateAndInstallInfo =
new ServiceWorkerInfo(mRegistration, mRegistration->mScriptSpec,
aNewCacheName);
cacheName);
nsRefPtr<ServiceWorker> serviceWorker;
rv = swm->CreateServiceWorker(mRegistration->mPrincipal,
mUpdateAndInstallInfo,

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

@ -156,7 +156,7 @@ NS_IMPL_ISUPPORTS(CompareNetwork, nsIStreamLoaderObserver)
// This class gets a cached Response from the CacheStorage and then it calls
// CacheFinished() in the CompareManager.
class CompareCache final : public PromiseNativeHandler
, public nsIStreamLoaderObserver
, public nsIStreamLoaderObserver
{
public:
NS_DECL_ISUPPORTS
@ -173,7 +173,27 @@ public:
nsresult
Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL,
const nsAString& aCacheName);
const nsAString& aCacheName)
{
MOZ_ASSERT(aPrincipal);
AssertIsOnMainThread();
mURL = aURL;
ErrorResult rv;
nsRefPtr<CacheStorage> cacheStorage = CreateCacheStorage(aPrincipal, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.ErrorCode();
}
nsRefPtr<Promise> promise = cacheStorage->Open(aCacheName, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.ErrorCode();
}
promise->AppendNativeHandler(this);
return NS_OK;
}
void
Abort()
@ -220,12 +240,6 @@ public:
return mBuffer;
}
const nsString& URL() const
{
AssertIsOnMainThread();
return mURL;
}
private:
~CompareCache()
{
@ -254,14 +268,13 @@ private:
NS_IMPL_ISUPPORTS(CompareCache, nsIStreamLoaderObserver)
class CompareManager final : public PromiseNativeHandler
class CompareManager final
{
public:
NS_INLINE_DECL_REFCOUNTING(CompareManager, override)
NS_INLINE_DECL_REFCOUNTING(CompareManager)
explicit CompareManager(CompareCallback* aCallback)
: mCallback(aCallback)
, mState(WaitingForOpen)
, mNetworkFinished(false)
, mCacheFinished(false)
, mInCache(false)
@ -276,17 +289,6 @@ public:
AssertIsOnMainThread();
MOZ_ASSERT(aPrincipal);
mURL = aURL;
// Always create a CacheStorage since we want to write the network entry to
// the cache even if there isn't an existing one.
ErrorResult result;
mCacheStorage = CreateCacheStorage(aPrincipal, result);
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
return result.ErrorCode();
}
mCN = new CompareNetwork(this);
nsresult rv = mCN->Initialize(aPrincipal, aURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -295,7 +297,7 @@ public:
if (!aCacheName.IsEmpty()) {
mCC = new CompareCache(this);
rv = mCC->Initialize(aPrincipal, aURL, aCacheName);
mCC->Initialize(aPrincipal, aURL, aCacheName);
if (NS_WARN_IF(NS_FAILED(rv))) {
mCN->Abort();
return rv;
@ -305,13 +307,6 @@ public:
return NS_OK;
}
const nsAString&
URL() const
{
AssertIsOnMainThread();
return mURL;
}
void
NetworkFinished(nsresult aStatus)
{
@ -368,65 +363,6 @@ public:
ComparisonFinished(NS_OK, mCC->Buffer().Equals(mCN->Buffer()));
}
// This class manages 2 promises: 1 is to retrieve Cache object, and 2 is to
// Put the value in the cache. For this reason we have mState to know what
// callback we are handling.
void
ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
{
AssertIsOnMainThread();
MOZ_ASSERT(mCallback);
if (mState == WaitingForOpen) {
if (NS_WARN_IF(!aValue.isObject())) {
Fail(NS_ERROR_FAILURE);
return;
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (NS_WARN_IF(!obj)) {
Fail(NS_ERROR_FAILURE);
return;
}
Cache* cache = nullptr;
nsresult rv = UNWRAP_OBJECT(Cache, obj, cache);
if (NS_WARN_IF(NS_FAILED(rv))) {
Fail(rv);
return;
}
// Just to be safe.
nsRefPtr<Cache> kungfuDeathGrip = cache;
WriteToCache(cache);
return;
}
MOZ_ASSERT(mState == WaitingForPut);
mCallback->ComparisonResult(NS_OK, false /* aIsEqual */, mNewCacheName);
Cleanup();
}
void
RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
{
AssertIsOnMainThread();
if (mState == WaitingForOpen) {
NS_WARNING("Could not open cache.");
} else {
NS_WARNING("Could not write to cache.");
}
Fail(NS_ERROR_FAILURE);
}
CacheStorage*
CacheStorage_()
{
AssertIsOnMainThread();
MOZ_ASSERT(mCacheStorage);
return mCacheStorage;
}
private:
~CompareManager()
{
@ -435,125 +371,23 @@ private:
MOZ_ASSERT(!mCN);
}
void
Fail(nsresult aStatus)
{
AssertIsOnMainThread();
mCallback->ComparisonResult(aStatus, false /* aIsEqual */, EmptyString());
Cleanup();
}
void
Cleanup()
{
AssertIsOnMainThread();
MOZ_ASSERT(mCallback);
mCallback = nullptr;
mCN = nullptr;
mCC = nullptr;
}
void
ComparisonFinished(nsresult aStatus, bool aIsEqual)
{
AssertIsOnMainThread();
MOZ_ASSERT(mCallback);
if (NS_FAILED(aStatus)) {
Fail(aStatus);
return;
}
if (aIsEqual) {
mCallback->ComparisonResult(aStatus, aIsEqual, EmptyString());
Cleanup();
return;
}
// Write to Cache so ScriptLoader reads succeed.
WriteNetworkBufferToNewCache();
}
void
WriteNetworkBufferToNewCache()
{
AssertIsOnMainThread();
MOZ_ASSERT(mCN);
MOZ_ASSERT(mCacheStorage);
MOZ_ASSERT(mNewCacheName.IsEmpty());
ErrorResult result;
result = serviceWorkerScriptCache::GenerateCacheName(mNewCacheName);
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
Fail(result.ErrorCode());
return;
}
nsRefPtr<Promise> cacheOpenPromise = mCacheStorage->Open(mNewCacheName, result);
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
Fail(result.ErrorCode());
return;
}
cacheOpenPromise->AppendNativeHandler(this);
}
void
WriteToCache(Cache* aCache)
{
AssertIsOnMainThread();
MOZ_ASSERT(aCache);
MOZ_ASSERT(mState == WaitingForOpen);
ErrorResult result;
nsCOMPtr<nsIInputStream> body;
result = NS_NewStringInputStream(getter_AddRefs(body), mCN->Buffer());
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
Fail(result.ErrorCode());
return;
}
nsRefPtr<InternalResponse> ir =
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ir->SetBody(body);
nsRefPtr<Response> response = new Response(aCache->GetGlobalObject(), ir);
RequestOrUSVString request;
request.SetAsUSVString().Rebind(URL().Data(), URL().Length());
// For now we have to wait until the Put Promise is fulfilled before we can
// continue since Cache does not yet support starting a read that is being
// written to.
nsRefPtr<Promise> cachePromise = aCache->Put(request, *response, result);
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
Fail(result.ErrorCode());
return;
}
mState = WaitingForPut;
cachePromise->AppendNativeHandler(this);
mCallback->ComparisonResult(aStatus, aIsEqual);
mCallback = nullptr;
mCN = nullptr;
mCC = nullptr;
}
nsRefPtr<CompareCallback> mCallback;
nsRefPtr<CacheStorage> mCacheStorage;
nsRefPtr<CompareNetwork> mCN;
nsRefPtr<CompareCache> mCC;
nsString mURL;
// Only used if the network script has changed and needs to be cached.
nsString mNewCacheName;
enum {
WaitingForOpen,
WaitingForPut
} mState;
bool mNetworkFinished;
bool mCacheFinished;
bool mInCache;
@ -620,27 +454,6 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext
return NS_OK;
}
nsresult
CompareCache::Initialize(nsIPrincipal* aPrincipal, const nsAString& aURL,
const nsAString& aCacheName)
{
MOZ_ASSERT(aPrincipal);
AssertIsOnMainThread();
mURL = aURL;
ErrorResult rv;
nsRefPtr<Promise> promise = mManager->CacheStorage_()->Open(aCacheName, rv);
if (NS_WARN_IF(rv.Failed())) {
MOZ_ASSERT(!rv.IsErrorWithMessage());
return rv.ErrorCode();
}
promise->AppendNativeHandler(this);
return NS_OK;
}
NS_IMETHODIMP
CompareCache::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext,
nsresult aStatus, uint32_t aLen,
@ -715,7 +528,6 @@ CompareCache::ManageCacheResult(JSContext* aCx, JS::Handle<JS::Value> aValue)
CacheQueryOptions params;
nsRefPtr<Promise> promise = cache->Match(request, params, error);
if (NS_WARN_IF(error.Failed())) {
MOZ_ASSERT(!error.IsErrorWithMessage());
mManager->CacheFinished(error.ErrorCode(), false);
return;
}
@ -805,7 +617,6 @@ PurgeCache(nsIPrincipal* aPrincipal, const nsAString& aCacheName)
ErrorResult rv;
nsRefPtr<CacheStorage> cacheStorage = CreateCacheStorage(aPrincipal, rv);
if (NS_WARN_IF(rv.Failed())) {
MOZ_ASSERT(!rv.IsErrorWithMessage());
return rv.ErrorCode();
}
@ -813,7 +624,6 @@ PurgeCache(nsIPrincipal* aPrincipal, const nsAString& aCacheName)
nsRefPtr<Promise> promise =
cacheStorage->Delete(aCacheName, rv);
if (NS_WARN_IF(rv.Failed())) {
MOZ_ASSERT(!rv.IsErrorWithMessage());
return rv.ErrorCode();
}

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

@ -24,16 +24,7 @@ GenerateCacheName(nsAString& aName);
class CompareCallback
{
public:
/*
* If there is an error, ignore aInCacheAndEqual and aNewCacheName.
* On success, if the cached result and network result matched,
* aInCacheAndEqual will be true and no new cache name is passed, otherwise
* use the new cache name to load the ServiceWorker.
*/
virtual void
ComparisonResult(nsresult aStatus,
bool aInCacheAndEqual,
const nsAString& aNewCacheName) = 0;
virtual void ComparisonResult(nsresult aStatus, bool aInCacheAndEqual) = 0;
NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
NS_IMETHOD_(MozExternalRefCountType) Release() = 0;

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

@ -25,7 +25,7 @@
// Verify that the service worker has been correctly updated.
testFrame("periodic/frame.html").then(function(body) {
newSWVersion = parseInt(body);
is(newSWVersion, 2, "Expected correct new version");
todo_is(newSWVersion, "2", "Expected correct new version");
ok(newSWVersion > oldSWVersion,
"The SW should be successfully updated, old: " + oldSWVersion +
", new: " + newSWVersion);
@ -38,7 +38,7 @@
registerSW().then(function() {
return testFrame("periodic/frame.html").then(function(body) {
oldSWVersion = parseInt(body);
is(oldSWVersion, 1, "Expected correct old version");
todo_is(oldSWVersion, "1", "Expected correct old version");
});
}).then(function() {
return navigator.serviceWorker.getRegistration("periodic/foo");