Bug 1211941 - Let nsICacheStorage.openTruncate impl return an HTTP cache entry write handle, r=michal

This commit is contained in:
Honza Bambas 2016-01-12 07:31:00 +01:00
parent fb064cb435
commit 1a086bb8f8
2 changed files with 10 additions and 7 deletions

View File

@ -60,6 +60,9 @@ public:
void AsyncOpen(nsICacheEntryOpenCallback* aCallback, uint32_t aFlags);
CacheEntryHandle* NewHandle();
// For a new and recreated entry w/o a callback, we need to wrap it
// with a handle to detect writing consumer is gone.
CacheEntryHandle* NewWriteHandle();
public:
uint32_t GetMetadataMemoryConsumption();
@ -240,9 +243,6 @@ private:
nsresult OpenOutputStreamInternal(int64_t offset, nsIOutputStream * *_retval);
// When this entry is new and recreated w/o a callback, we need to wrap it
// with a handle to detect writing consumer is gone.
CacheEntryHandle* NewWriteHandle();
void OnHandleClosed(CacheEntryHandle const* aHandle);
private:

View File

@ -126,17 +126,20 @@ NS_IMETHODIMP CacheStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExt
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<CacheEntryHandle> entry;
RefPtr<CacheEntryHandle> handle;
rv = CacheStorageService::Self()->AddStorageEntry(
this, noRefURI, aIdExtension,
true, // create always
true, // replace any existing one
getter_AddRefs(entry));
getter_AddRefs(handle));
NS_ENSURE_SUCCESS(rv, rv);
// Just open w/o callback, similar to nsICacheEntry.recreate().
entry->Entry()->AsyncOpen(nullptr, OPEN_TRUNCATE);
entry.forget(aCacheEntry);
handle->Entry()->AsyncOpen(nullptr, OPEN_TRUNCATE);
// Return a write handler, consumer is supposed to fill in the entry.
RefPtr<CacheEntryHandle> writeHandle = handle->Entry()->NewWriteHandle();
writeHandle.forget(aCacheEntry);
return NS_OK;
}