Bug 1037447 - Introduce nsICacheEntry nsICacheStorage.openTruncate(URL, idEnhance), r=michal

This commit is contained in:
Honza Bambas 2014-07-16 16:16:30 +02:00
parent 91997e8450
commit bbcf250ab6
6 changed files with 81 additions and 1 deletions

View File

@ -84,6 +84,12 @@ NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(nsIURI *aURI,
return NS_OK;
}
NS_IMETHODIMP AppCacheStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExtension,
nsICacheEntry **aCacheEntry)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP AppCacheStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension,
bool *aResult)
{

View File

@ -105,6 +105,33 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI,
}
NS_IMETHODIMP CacheStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExtension,
nsICacheEntry **aCacheEntry)
{
if (!CacheStorageService::Self())
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsIURI> noRefURI;
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<CacheEntryHandle> entry;
rv = CacheStorageService::Self()->AddStorageEntry(
this, noRefURI, aIdExtension,
true, // create always
true, // replace any existing one
getter_AddRefs(entry));
NS_ENSURE_SUCCESS(rv, rv);
// Just open w/o callback, similar to nsICacheEntry.recreate().
entry->Entry()->AsyncOpen(nullptr, OPEN_TRUNCATE);
entry.forget(aCacheEntry);
return NS_OK;
}
NS_IMETHODIMP CacheStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension,
bool *aResult)
{

View File

@ -944,6 +944,12 @@ NS_IMETHODIMP _OldStorage::AsyncOpenURI(nsIURI *aURI,
return NS_OK;
}
NS_IMETHODIMP _OldStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExtension,
nsICacheEntry **aCacheEntry)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension,
bool *aResult)
{

View File

@ -5,6 +5,7 @@
#include "nsISupports.idl"
interface nsIURI;
interface nsICacheEntry;
interface nsICacheEntryOpenCallback;
interface nsICacheEntryDoomCallback;
interface nsICacheStorageVisitor;
@ -14,7 +15,7 @@ interface nsICacheStorageVisitor;
* in-mem+on-disk, in-mem+on-disk+app-cache or just a specific
* app-cache storage.
*/
[scriptable, uuid(d9006881-a536-4ce3-bc48-e7f94b40a690)]
[scriptable, uuid(35d104a6-d252-4fd4-8a56-3c14657cad3b)]
interface nsICacheStorage : nsISupports
{
/**
@ -77,6 +78,21 @@ interface nsICacheStorage : nsISupports
in uint32_t aFlags,
in nsICacheEntryOpenCallback aCallback);
/**
* Immediately opens a new and empty cache entry in the storage, any existing
* entries are immediately doomed. This is similar to the recreate() method
* on nsICacheEntry.
*
* Storage may not implement this method and throw NS_ERROR_NOT_IMPLEMENTED.
* In that case consumer must use asyncOpen with OPEN_TRUNCATE flag and get
* the new entry via a callback.
*
* @param aURI @see asyncOpenURI
* @param aIdExtension @see asyncOpenURI
*/
nsICacheEntry openTruncate(in nsIURI aURI,
in ACString aIdExtension);
/**
* Synchronously check on existance of an entry. In case of disk entries
* this uses information from the cache index. When the index data are not

View File

@ -0,0 +1,24 @@
function run_test()
{
do_get_profile();
if (!newCacheBackEndUsed()) {
do_check_true(true, "This test doesn't run when the old cache back end is used since the behavior is different");
return;
}
var storage = getCacheStorage("disk");
var entry = storage.openTruncate(createURI("http://new1/"), "");
do_check_true(!!entry);
// Fill the entry, and when done, check it's content
(new OpenCallback(NEW, "meta", "data", function() {
asyncOpenCacheEntry("http://new1/", "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
new OpenCallback(NORMAL, "meta", "data", function() {
finish_cache2_test();
})
);
})).onCacheEntryAvailable(entry, true, null, 0);
do_test_pending();
}

View File

@ -26,6 +26,7 @@ support-files =
[test_cache2-01c-basic-hasmeta-only.js]
[test_cache2-01d-basic-not-wanted.js]
[test_cache2-01e-basic-bypass-if-busy.js]
[test_cache2-01f-basic-openTruncate.js]
[test_cache2-02-open-non-existing.js]
[test_cache2-03-oncacheentryavail-throws.js]
[test_cache2-04-oncacheentryavail-throws2x.js]