Bug 405695: Use asciiHost/asciiSpec for offline cache ownership keys. p=Honza Bambas, r=me, sr=biesi

This commit is contained in:
dcamp@mozilla.com 2008-01-22 20:31:50 -08:00
parent d07d06ab57
commit bac18b5c8e
5 changed files with 72 additions and 53 deletions

View File

@ -73,7 +73,7 @@ static const char kMaxEntriesPref[] = "offline.max_site_resources";
#define DEFAULT_MAX_ENTRIES 100
#define MAX_URI_LENGTH 2048
static nsCAutoString gCachedHostPort;
static nsCAutoString gCachedAsciiHost;
static char **gCachedKeys = nsnull;
static PRUint32 gCachedKeysCount = 0;
@ -187,7 +187,7 @@ nsDOMOfflineResourceList::Init()
// Dynamically-managed resources are stored as a separate ownership list
// from the manifest.
rv = mManifestURI->GetSpec(mDynamicOwnerSpec);
rv = mManifestURI->GetAsciiSpec(mDynamicOwnerSpec);
NS_ENSURE_SUCCESS(rv, rv);
mDynamicOwnerSpec.Append("#dynamic");
@ -196,7 +196,7 @@ nsDOMOfflineResourceList::Init()
if (!innerURI)
return NS_ERROR_FAILURE;
rv = innerURI->GetHostPort(mHostPort);
rv = innerURI->GetAsciiHost(mAsciiHost);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheService> serv = do_GetService(NS_CACHESERVICE_CONTRACTID,
@ -383,7 +383,7 @@ nsDOMOfflineResourceList::Remove(const nsAString& aURI)
ClearCachedKeys();
rv = mCacheSession->RemoveOwnedKey(mHostPort, mDynamicOwnerSpec, key);
rv = mCacheSession->RemoveOwnedKey(mAsciiHost, mDynamicOwnerSpec, key);
NS_ENSURE_SUCCESS(rv, rv);
rv = mCacheSession->EvictUnownedEntries();
@ -969,7 +969,7 @@ nsDOMOfflineResourceList::UpdateCompleted(nsIOfflineCacheUpdate *aUpdate)
nsresult
nsDOMOfflineResourceList::GetCacheKey(nsIURI *aURI, nsCString &aKey)
{
nsresult rv = aURI->GetSpec(aKey);
nsresult rv = aURI->GetAsciiSpec(aKey);
NS_ENSURE_SUCCESS(rv, rv);
// url fragments aren't used in cache keys
@ -987,16 +987,16 @@ nsDOMOfflineResourceList::GetCacheKey(nsIURI *aURI, nsCString &aKey)
nsresult
nsDOMOfflineResourceList::CacheKeys()
{
if (gCachedKeys && mHostPort == gCachedHostPort)
if (gCachedKeys && mAsciiHost == gCachedAsciiHost)
return NS_OK;
ClearCachedKeys();
nsresult rv = mCacheSession->GetOwnedKeys(mHostPort, mDynamicOwnerSpec,
nsresult rv = mCacheSession->GetOwnedKeys(mAsciiHost, mDynamicOwnerSpec,
&gCachedKeysCount, &gCachedKeys);
if (NS_SUCCEEDED(rv))
gCachedHostPort = mHostPort;
gCachedAsciiHost = mAsciiHost;
return rv;
}
@ -1010,7 +1010,7 @@ nsDOMOfflineResourceList::ClearCachedKeys()
gCachedKeysCount = 0;
}
gCachedHostPort = "";
gCachedAsciiHost = "";
}

View File

@ -110,7 +110,7 @@ private:
nsCOMPtr<nsIWeakReference> mWindow;
nsCOMPtr<nsIOfflineCacheSession> mCacheSession;
nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
nsCAutoString mHostPort;
nsCAutoString mAsciiHost;
nsCAutoString mDynamicOwnerSpec;
nsCOMArray<nsIDOMEventListener> mCheckingListeners;

View File

@ -113,12 +113,18 @@ clear: function()
true)
.QueryInterface(Ci.nsIOfflineCacheSession);
// Get the asciiHost from the page URL
var locationURI = Cc["@mozilla.org/network/standard-url;1"]
.createInstance(Ci.nsIURI);
locationURI.spec = window.location.href;
var asciiHost = locationURI.asciiHost;
// Clear manifest-owned urls
cacheSession.setOwnedKeys(window.location.host,
cacheSession.setOwnedKeys(asciiHost,
this.getManifestUrl() + "#manifest", 0, []);
// Clear dynamically-owned urls
cacheSession.setOwnedKeys(window.location.host,
cacheSession.setOwnedKeys(asciiHost,
this.getManifestUrl() + "#dynamic", 0, []);
cacheSession.evictUnownedEntries();

View File

@ -80,14 +80,15 @@ interface nsIOfflineCacheSession : nsISupports
/**
* Gets the list of owner URIs associated with a domain.
*
* @param ownerDomain
* @param ownerAsciiDomain
* The domain to query
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param count
* The number of uris returned
* @param uris
* The uris in this domain that own resources
*/
void getOwnerURIs(in ACString ownerDomain,
void getOwnerURIs(in ACString ownerAsciiDomain,
out unsigned long count,
[array, size_is(count)]out string uris);
@ -101,37 +102,41 @@ interface nsIOfflineCacheSession : nsISupports
* an entry is created with this key, it will be owned by the
* domain/URI pair.
*
* @param ownerDomain
* The domain that owns the resources.
* @param ownerURI
* The specific URI that owns the resources. This can be empty if
* no URI specifically owns the resources.
* @param ownerAsciiDomain
* The domain that owns the resources
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param ownerAsciiKey
* The specific key that owns the resources. You may use
* ascii encoded URI spec of the owner - nsIURI.asciiSpec.
* This can be empty if none specifically owns the resources.
* @param count
* The number of keys in keys.
* @param keys
* The keys that the domain/URI pair own. This can be empty to
* clear ownership for the domain/URI pair.
*/
void setOwnedKeys(in ACString ownerDomain,
in ACString ownerURI,
void setOwnedKeys(in ACString ownerAsciiDomain,
in ACString ownerAsciiKey,
in unsigned long count,
[array, size_is(count)]in string keys);
/**
* Gets the list of resources owned by a given domain/URI pair.
*
* @param ownerDomain
* The domain that owns the resources.
* @param ownerURI
* The specific URI that owns the resources. This can be empty
* if no URI specifically owns the resources.
* @param ownerAsciiDomain
* The domain that owns the resources
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param ownerAsciiKey
* The specific key that owns the resources. You may use
* ascii encoded URI spec of the owner - nsIURI.asciiSpec.
* This can be empty if none specifically owns the resources.
* @param count
* The number of keys in keys.
* @param keys
* The keys that the domain/URI pair own.
*/
void getOwnedKeys(in ACString ownerDomain,
in ACString ownerURI,
void getOwnedKeys(in ACString ownerAsciiDomain,
in ACString ownerAsciiKey,
out unsigned long count,
[array, size_is(count)]out string keys);
@ -142,16 +147,18 @@ interface nsIOfflineCacheSession : nsISupports
* an entry is created with this key, it will be owned by the
* domain/URI pair.
*
* @param ownerDomain
* The domain that owns the resources.
* @param ownerURI
* The specific URI that owns the resources. This can be empty
* if no URI specifically owns the resources.
* @param ownerAsciiDomain
* The domain that owns the resources
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param ownerAsciiKey
* The specific key that owns the resources. You may use
* ascii encoded URI spec of the owner - nsIURI.asciiSpec.
* This can be empty if none specifically owns the resources.
* @param key
* The key to add.
*/
void addOwnedKey(in ACString ownerDomain,
in ACString ownerURI,
void addOwnedKey(in ACString ownerAsciiDomain,
in ACString ownerAsciiKey,
in ACString key);
/**
@ -160,38 +167,44 @@ interface nsIOfflineCacheSession : nsISupports
* If the key does not exist, an NS_ERROR_NOT_AVAILABLE exception
* will be thrown.
*
* @param ownerDomain
* The domain that owns the resources.
* @param ownerURI
* The specific URI that owns the resources. This can be empty
* if no URI specifically owns the resources.
* @param ownerAsciiDomain
* The domain that owns the resources
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param ownerAsciiKey
* The specific key that owns the resources. You may use
* ascii encoded URI spec of the owner - nsIURI.asciiSpec.
* This can be empty if none specifically owns the resources.
* @param key The key to remove.
*/
void removeOwnedKey(in ACString ownerDomain,
in ACString ownerURI,
void removeOwnedKey(in ACString ownerAsciiDomain,
in ACString ownerAsciiKey,
in ACString key);
/**
* Checks whether a key is owned by a given domain/URI pair.
*
* @param ownerDomain
* The domain that owns the resources.
* @param ownerURI
* The specific URI that owns the resources. This can be empty
* if no URI specifically owns the resources.
* @param ownerAsciiDomain
* The domain that owns the resources
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
* @param ownerAsciiKey
* The specific key that owns the resources. You may use
* ascii encoded URI spec of the owner - nsIURI.asciiSpec.
* This can be empty if none specifically owns the resources.
* @param key The key to check
*/
boolean keyIsOwned(in ACString ownerDomain,
in ACString ownerURI,
boolean keyIsOwned(in ACString ownerAsciiDomain,
in ACString ownerAsciiKey,
in ACString key);
/**
* Remove all keys owned by a domain, including keys owned by
* a specific URI.
*
* @param domain The domain for which keys should be removed.
* @param ownerAsciiDomain
* The domain for which keys should be removed
* !! IMPORTANT !! : This must be ascii encoded host - nsIURI.asciiHost
*/
void clearKeysOwnedByDomain(in ACString ownerDomain);
void clearKeysOwnedByDomain(in ACString ownerAsciiDomain);
/**
* Evict all entries that are not owned by a domain.

View File

@ -686,12 +686,12 @@ nsOfflineCacheUpdate::Init(PRBool aPartialUpdate,
mManifestURI = aManifestURI;
rv = mManifestURI->GetHostPort(mUpdateDomain);
rv = mManifestURI->GetAsciiHost(mUpdateDomain);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString manifestSpec;
rv = mManifestURI->GetSpec(manifestSpec);
rv = mManifestURI->GetAsciiSpec(manifestSpec);
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 ref = manifestSpec.FindChar('#');