merge inbound to m-c

This commit is contained in:
Wes Kocher 2014-05-05 19:12:08 -07:00
commit 2468456ad0
2 changed files with 22 additions and 40 deletions

View File

@ -7,6 +7,7 @@
#include "CacheStorageService.h"
#include "CacheObserver.h"
#include "CacheFileUtils.h"
#include "CacheIndex.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
@ -305,24 +306,35 @@ bool CacheEntry::Load(bool aTruncate, bool aPriority)
MOZ_ASSERT(!mFile);
nsresult rv;
nsAutoCString fileKey;
rv = HashingKeyWithStorage(fileKey);
if (!aTruncate && NS_SUCCEEDED(rv)) {
// Check the index right now to know we have or have not the entry
// as soon as possible.
CacheIndex::EntryStatus status;
if (NS_SUCCEEDED(CacheIndex::HasEntry(fileKey, &status)) &&
status == CacheIndex::DOES_NOT_EXIST) {
LOG((" entry doesn't exist according information from the index, truncating"));
aTruncate = true;
}
}
mFile = new CacheFile();
BackgroundOp(Ops::REGISTER);
bool directLoad = aTruncate || !mUseDisk;
if (directLoad)
mFileStatus = NS_OK;
else
mLoadStart = TimeStamp::Now();
mFile = new CacheFile();
BackgroundOp(Ops::REGISTER);
{
mozilla::MutexAutoUnlock unlock(mLock);
nsresult rv;
nsAutoCString fileKey;
rv = HashingKeyWithStorage(fileKey);
LOG((" performing load, file=%p", mFile.get()));
if (NS_SUCCEEDED(rv)) {
rv = mFile->Init(fileKey,
@ -847,8 +859,6 @@ bool CacheEntry::IsReferenced() const
bool CacheEntry::IsFileDoomed()
{
mozilla::MutexAutoLock lock(mLock);
if (NS_SUCCEEDED(mFileStatus)) {
return mFile->IsDoomed();
}

View File

@ -8,7 +8,6 @@
#include "CacheFileChunk.h"
#include "CacheFileInputStream.h"
#include "CacheFileOutputStream.h"
#include "CacheIndex.h"
#include "nsThreadUtils.h"
#include "mozilla/DebugOnly.h"
#include <algorithm>
@ -237,33 +236,8 @@ CacheFile::Init(const nsACString &aKey,
mMetadata = new CacheFileMetadata(mOpenAsMemoryOnly, mKey);
mReady = true;
mDataSize = mMetadata->Offset();
}
else {
} else {
flags = CacheFileIOManager::CREATE;
// Have a look into index and change to CREATE_NEW when we are sure
// that the entry does not exist.
CacheIndex::EntryStatus status;
rv = CacheIndex::HasEntry(mKey, &status);
if (status == CacheIndex::DOES_NOT_EXIST) {
LOG(("CacheFile::Init() - Forcing CREATE_NEW flag since we don't have"
" this entry according to index"));
flags = CacheFileIOManager::CREATE_NEW;
// make sure we can use this entry immediately
mMetadata = new CacheFileMetadata(mOpenAsMemoryOnly, mKey);
mReady = true;
mDataSize = mMetadata->Offset();
// Notify callback now and don't store it in mListener, no further
// operation can change the result.
nsRefPtr<NotifyCacheFileListenerEvent> ev;
ev = new NotifyCacheFileListenerEvent(aCallback, NS_OK, true);
rv = NS_DispatchToCurrentThread(ev);
NS_ENSURE_SUCCESS(rv, rv);
aCallback = nullptr;
}
}
if (aPriority)
@ -1554,8 +1528,6 @@ CacheFile::DataSize(int64_t* aSize)
bool
CacheFile::IsDoomed()
{
CacheFileAutoLock lock(this);
if (!mHandle)
return false;