Bug 396222 - "let clients track the offline cache usage for a domain" [p=dcamp@mozilla.com (Dave Camp) / honzab@allpeers.com (Honza Bambas) r+sr=biesi r=dcamp a1.9=schrep]

This commit is contained in:
reed@reedloden.com 2008-02-07 01:04:30 -08:00
Родитель 0424cb53da
Коммит 31ad11b473
6 изменённых файлов: 72 добавлений и 1 удалений

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

@ -63,7 +63,7 @@
* the domain.
*/
[scriptable, uuid(de7875e5-a7e2-4d8d-ad01-807ef55ef8c0)]
[scriptable, uuid(3a33e268-4175-4440-a933-89d461c86c5f)]
interface nsIOfflineCacheSession : nsISupports
{
/**
@ -206,6 +206,13 @@ interface nsIOfflineCacheSession : nsISupports
*/
void clearKeysOwnedByDomain(in ACString ownerAsciiDomain);
/**
* Get the number of bytes used in the cache by a domain.
*
* @param domain The domain to check.
*/
unsigned long getDomainUsage(in ACString ownerDomain);
/**
* Evict all entries that are not owned by a domain.
*/

20
netwerk/cache/src/nsCacheService.cpp поставляемый
Просмотреть файл

@ -1013,6 +1013,26 @@ nsresult nsCacheService::ClearOfflineKeysOwnedByDomain(nsCacheSession * session,
#endif
}
nsresult nsCacheService::GetOfflineDomainUsage(nsCacheSession * session,
const nsACString & domain,
PRUint32 * usage)
{
#ifdef NECKO_OFFLINE_CACHE
if (session->StoragePolicy() != nsICache::STORE_OFFLINE)
return NS_ERROR_NOT_AVAILABLE;
if (!gService->mOfflineDevice) {
nsresult rv = gService->CreateOfflineDevice();
if (NS_FAILED(rv)) return rv;
}
return gService->mOfflineDevice->GetDomainUsage(session->ClientID()->get(),
domain,
usage);
#else // !NECKO_OFFLINE_CACHE
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
nsresult nsCacheService::EvictUnownedOfflineEntries(nsCacheSession * session)
{
#ifdef NECKO_OFFLINE_CACHE

3
netwerk/cache/src/nsCacheService.h поставляемый
Просмотреть файл

@ -136,6 +136,9 @@ public:
static nsresult ClearOfflineKeysOwnedByDomain(nsCacheSession * session,
const nsACString & domain);
static nsresult GetOfflineDomainUsage(nsCacheSession * session,
const nsACString & domain,
PRUint32 * usage);
static nsresult EvictUnownedOfflineEntries(nsCacheSession * session);

6
netwerk/cache/src/nsCacheSession.cpp поставляемый
Просмотреть файл

@ -192,6 +192,12 @@ NS_IMETHODIMP nsCacheSession::ClearKeysOwnedByDomain(const nsACString & domain)
return nsCacheService::ClearOfflineKeysOwnedByDomain(this, domain);
}
NS_IMETHODIMP nsCacheSession::GetDomainUsage(const nsACString & domain,
PRUint32 *usage)
{
return nsCacheService::GetOfflineDomainUsage(this, domain, usage);
}
NS_IMETHODIMP nsCacheSession::EvictUnownedEntries()
{
return nsCacheService::EvictUnownedOfflineEntries(this);

31
netwerk/cache/src/nsDiskCacheDeviceSQL.cpp поставляемый
Просмотреть файл

@ -779,6 +779,7 @@ nsOfflineCacheDevice::Init()
statement (aStatement), sql (aSql) {}
} prepared[] = {
StatementSql ( mStatement_CacheSize, "SELECT Sum(DataSize) from moz_cache;" ),
StatementSql ( mStatement_DomainSize, "SELECT Sum(moz_cache.DataSize) FROM moz_cache INNER JOIN moz_cache_owners ON moz_cache.ClientID=moz_cache_owners.ClientID AND moz_cache.Key = moz_cache_owners.Key WHERE moz_cache.ClientID=? AND moz_cache_owners.Domain=?;" ),
StatementSql ( mStatement_EntryCount, "SELECT count(*) from moz_cache;" ),
StatementSql ( mStatement_UpdateEntry, "UPDATE moz_cache SET MetaData = ?, Flags = ?, DataSize = ?, FetchCount = ?, LastFetched = ?, LastModified = ?, ExpirationTime = ? WHERE ClientID = ? AND Key = ?;" ),
StatementSql ( mStatement_UpdateEntrySize, "UPDATE moz_cache SET DataSize = ? WHERE ClientID = ? AND Key = ?;" ),
@ -1480,6 +1481,36 @@ nsOfflineCacheDevice::ClearKeysOwnedByDomain(const char *clientID,
return statement->Execute();
}
nsresult
nsOfflineCacheDevice::GetDomainUsage(const char *clientID,
const nsACString &domain,
PRUint32 *usage)
{
LOG(("nsOfflineCacheDevice::GetDomainUsage [cid=%s]\n", clientID));
*usage = 0;
AutoResetStatement statement(mStatement_DomainSize);
nsresult rv;
rv = statement->BindUTF8StringParameter(0, nsDependentCString(clientID));
NS_ENSURE_SUCCESS(rv, rv);
rv = statement->BindUTF8StringParameter(1, domain);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasRows;
rv = statement->ExecuteStep(&hasRows);
NS_ENSURE_SUCCESS(rv, rv);
if (!hasRows)
return NS_OK;
*usage = statement->AsInt32(0);
return NS_OK;
}
nsresult
nsOfflineCacheDevice::EvictUnownedEntries(const char *clientID)
{

4
netwerk/cache/src/nsDiskCacheDeviceSQL.h поставляемый
Просмотреть файл

@ -143,6 +143,9 @@ public:
nsresult ClearKeysOwnedByDomain(const char *clientID,
const nsACString &ownerDomain);
nsresult GetDomainUsage(const char *clientID,
const nsACString &ownerDomain,
PRUint32 *usage);
nsresult EvictUnownedEntries(const char *clientID);
nsresult CreateTemporaryClientID(nsACString &clientID);
@ -179,6 +182,7 @@ private:
nsRefPtr<nsOfflineCacheEvictionFunction> mEvictionFunction;
nsCOMPtr<mozIStorageStatement> mStatement_CacheSize;
nsCOMPtr<mozIStorageStatement> mStatement_DomainSize;
nsCOMPtr<mozIStorageStatement> mStatement_EntryCount;
nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntry;
nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntrySize;