Bug 976608 - applicationCache corrupted due to concurrent updates running (should coalesce), r=jduell

This commit is contained in:
Honza Bambas 2014-07-16 16:16:30 +02:00
Родитель bbcf250ab6
Коммит ef2cb4ed84
6 изменённых файлов: 37 добавлений и 2 удалений

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

@ -50,6 +50,7 @@ NS_IMPL_ISUPPORTS(OfflineCacheUpdateGlue,
//-----------------------------------------------------------------------------
OfflineCacheUpdateGlue::OfflineCacheUpdateGlue()
: mCoalesced(false)
{
LOG(("OfflineCacheUpdateGlue::OfflineCacheUpdateGlue [%p]", this));
}
@ -89,6 +90,9 @@ OfflineCacheUpdateGlue::Schedule()
// Do not use weak reference, we must survive!
mUpdate->AddObserver(this, false);
if (mCoalesced) // already scheduled
return NS_OK;
return mUpdate->Schedule();
}
@ -100,6 +104,14 @@ OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI,
uint32_t aAppID,
bool aInBrowser)
{
nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::EnsureService();
if (service) {
service->FindUpdate(aManifestURI, aAppID, aInBrowser, aCustomProfileDir,
getter_AddRefs(mUpdate));
mCoalesced = !!mUpdate;
}
if (!EnsureUpdate())
return NS_ERROR_NULL_POINTER;
@ -108,6 +120,11 @@ OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI,
if (aDocument)
SetDocument(aDocument);
if (mCoalesced) { // already initialized
LOG(("OfflineCacheUpdateGlue %p coalesced with update %p", this, mUpdate.get()));
return NS_OK;
}
return mUpdate->Init(aManifestURI, aDocumentURI, nullptr, aCustomProfileDir, aAppID, aInBrowser);
}

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

@ -67,6 +67,7 @@ private:
~OfflineCacheUpdateGlue();
nsRefPtr<nsOfflineCacheUpdate> mUpdate;
bool mCoalesced;
/* Document that requested this update */
nsCOMPtr<nsIDOMDocument> mDocument;

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

@ -112,7 +112,7 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
if (!NS_SecurityCompareURIs(manifestURI, documentURI, false))
return NS_ERROR_DOM_SECURITY_ERR;
service->FindUpdate(manifestURI, mAppId, mIsInBrowserElement,
service->FindUpdate(manifestURI, mAppId, mIsInBrowserElement, nullptr,
getter_AddRefs(update));
if (!update) {
update = new nsOfflineCacheUpdate();

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

@ -1994,6 +1994,20 @@ nsOfflineCacheUpdate::IsForGroupID(const nsCSubstring &groupID)
return mGroupID == groupID;
}
bool
nsOfflineCacheUpdate::IsForProfile(nsIFile* aCustomProfileDir)
{
if (!mCustomProfileDir && !aCustomProfileDir)
return true;
if (!mCustomProfileDir || !aCustomProfileDir)
return false;
bool equals;
nsresult rv = mCustomProfileDir->Equals(aCustomProfileDir, &equals);
return NS_SUCCEEDED(rv) && equals;
}
nsresult
nsOfflineCacheUpdate::UpdateFinished(nsOfflineCacheUpdate *aUpdate)
{

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

@ -222,6 +222,7 @@ public:
void SetOwner(nsOfflineCacheUpdateOwner *aOwner);
bool IsForGroupID(const nsCSubstring &groupID);
bool IsForProfile(nsIFile* aCustomProfileDir);
virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
@ -337,6 +338,7 @@ public:
nsresult FindUpdate(nsIURI *aManifestURI,
uint32_t aAppID,
bool aInBrowser,
nsIFile *aCustomProfileDir,
nsOfflineCacheUpdate **aUpdate);
nsresult Schedule(nsIURI *aManifestURI,

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

@ -491,6 +491,7 @@ nsresult
nsOfflineCacheUpdateService::FindUpdate(nsIURI *aManifestURI,
uint32_t aAppID,
bool aInBrowser,
nsIFile *aCustomProfileDir,
nsOfflineCacheUpdate **aUpdate)
{
nsresult rv;
@ -518,7 +519,7 @@ nsOfflineCacheUpdateService::FindUpdate(nsIURI *aManifestURI,
continue;
}
if (update->IsForGroupID(groupID)) {
if (update->IsForGroupID(groupID) && update->IsForProfile(aCustomProfileDir)) {
update.swap(*aUpdate);
return NS_OK;
}