Implement deviceID attribute for nsICacheEntryInfo. Implement nsCacheSession::EvictEntries().
git-svn-id: svn://10.0.0.236/branches/DISKCACHE2_BRANCH@92057 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
20
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
20
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
@@ -30,6 +30,7 @@
|
||||
#include "nsError.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCache.h"
|
||||
#include "nsCacheDevice.h"
|
||||
|
||||
|
||||
nsCacheEntry::nsCacheEntry(nsCString * key,
|
||||
@@ -71,6 +72,14 @@ nsCacheEntry::Fetched()
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
nsCacheEntry::GetDeviceID()
|
||||
{
|
||||
if (mCacheDevice) return mCacheDevice->GetDeviceID();
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetData(nsISupports **result)
|
||||
{
|
||||
@@ -326,6 +335,17 @@ nsCacheEntryInfo::GetClientID(char ** clientID)
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetDeviceID(char ** deviceID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(deviceID);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*deviceID = nsCRT::strdup(mCacheEntry->GetDeviceID());
|
||||
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetKey(char ** key)
|
||||
{
|
||||
|
||||
2
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
2
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
nsCacheDevice * CacheDevice() { return mCacheDevice;}
|
||||
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;}
|
||||
|
||||
const char * GetDeviceID();
|
||||
|
||||
/**
|
||||
* Data accessors
|
||||
|
||||
@@ -79,6 +79,17 @@ nsCacheEntryDescriptor::GetClientID(char ** result)
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetDeviceID(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = nsCRT::strdup(mCacheEntry->GetDeviceID());
|
||||
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetKey(char ** result)
|
||||
{
|
||||
@@ -86,30 +97,6 @@ nsCacheEntryDescriptor::GetKey(char ** result)
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
|
||||
#if 0
|
||||
nsCString * key;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*result = nsnull;
|
||||
key = mCacheEntry->Key();
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key->BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key->EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
104
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
104
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
@@ -327,7 +327,7 @@ nsCacheService::CreateSession(const char * clientID,
|
||||
{
|
||||
*result = nsnull;
|
||||
|
||||
if (!(mEnableDiskDevice || mEnableMemoryDevice))
|
||||
if ((this == nsnull) || !(mEnableDiskDevice || mEnableMemoryDevice))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCacheSession * session = new nsCacheSession(clientID, storagePolicy, streamBased);
|
||||
@@ -339,7 +339,51 @@ nsCacheService::CreateSession(const char * clientID,
|
||||
}
|
||||
|
||||
|
||||
/* void visitEntries (in nsICacheVisitor visitor); */
|
||||
nsresult
|
||||
nsCacheService::EvictEntriesForSession(nsCacheSession * session)
|
||||
{
|
||||
return EvictEntriesForClient(session->ClientID()->get(),
|
||||
session->StoragePolicy());
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheService::EvictEntriesForClient(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy)
|
||||
{
|
||||
if (this == nsnull) return NS_ERROR_NOT_AVAILABLE;
|
||||
nsAutoLock lock(mCacheServiceLock);
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
printf("### nsCacheService::EvictEntriesForClient(%s, %d)\n",
|
||||
(clientID ? clientID : "nsnull"), storagePolicy);
|
||||
|
||||
if (storagePolicy == nsICache::STORE_ANYWHERE ||
|
||||
storagePolicy == nsICache::STORE_ON_DISK) {
|
||||
|
||||
if (mEnableDiskDevice) {
|
||||
if (!mDiskDevice) {
|
||||
rv = CreateDiskDevice();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rv = mDiskDevice->EvictEntries(clientID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (storagePolicy == nsICache::STORE_ANYWHERE ||
|
||||
storagePolicy == nsICache::STORE_IN_MEMORY) {
|
||||
|
||||
if (mEnableMemoryDevice) {
|
||||
rv = mMemoryDevice->EvictEntries(clientID);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor)
|
||||
{
|
||||
nsAutoLock lock(mCacheServiceLock);
|
||||
@@ -374,31 +418,7 @@ NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor)
|
||||
|
||||
NS_IMETHODIMP nsCacheService::EvictEntries(nsCacheStoragePolicy storagePolicy)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsAutoLock lock(mCacheServiceLock);
|
||||
|
||||
// XXX what should we do about error handling?
|
||||
|
||||
if (storagePolicy == nsICache::STORE_ANYWHERE || storagePolicy == nsICache::STORE_ON_DISK) {
|
||||
if (mEnableDiskDevice) {
|
||||
if (!mDiskDevice) {
|
||||
rv = CreateDiskDevice();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rv = mDiskDevice->EvictEntries(nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (storagePolicy == nsICache::STORE_ANYWHERE || storagePolicy == nsICache::STORE_IN_MEMORY) {
|
||||
if (mEnableMemoryDevice) {
|
||||
rv = mMemoryDevice->EvictEntries(nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return EvictEntriesForClient(nsnull, storagePolicy);
|
||||
}
|
||||
|
||||
|
||||
@@ -715,28 +735,36 @@ nsCacheService::EnsureEntryHasDevice(nsCacheEntry * entry)
|
||||
{
|
||||
nsCacheDevice * device = entry->CacheDevice();
|
||||
if (device) return device;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (entry->IsStreamData() && entry->IsAllowedOnDisk() && mEnableDiskDevice) {
|
||||
// this is the default
|
||||
if (!mDiskDevice) {
|
||||
nsresult rv = CreateDiskDevice();
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
rv = CreateDiskDevice(); // ignore the error (check for mDiskDevice instead)
|
||||
}
|
||||
|
||||
device = mDiskDevice;
|
||||
} else if (mEnableMemoryDevice) {
|
||||
if (mDiskDevice) {
|
||||
entry->MarkBinding(); // XXX
|
||||
rv = mDiskDevice->BindEntry(entry);
|
||||
entry->ClearBinding(); // XXX
|
||||
if (NS_SUCCEEDED(rv))
|
||||
device = mDiskDevice;
|
||||
}
|
||||
}
|
||||
|
||||
// if we can't use mDiskDevice, try mMemoryDevice
|
||||
if (!device && mEnableMemoryDevice) {
|
||||
NS_ASSERTION(entry->IsAllowedInMemory(), "oops.. bad flags");
|
||||
device = mMemoryDevice;
|
||||
|
||||
entry->MarkBinding(); // XXX
|
||||
rv = mMemoryDevice->BindEntry(entry);
|
||||
entry->ClearBinding(); // XXX
|
||||
if (NS_SUCCEEDED(rv))
|
||||
device = mMemoryDevice;
|
||||
}
|
||||
|
||||
if (device == nsnull) return nsnull;
|
||||
|
||||
entry->MarkBinding(); // XXX
|
||||
nsresult rv = device->BindEntry(entry);
|
||||
entry->ClearBinding(); // XXX
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
entry->SetCacheDevice(device);
|
||||
return device;
|
||||
}
|
||||
|
||||
5
mozilla/netwerk/cache/src/nsCacheService.h
vendored
5
mozilla/netwerk/cache/src/nsCacheService.h
vendored
@@ -66,6 +66,11 @@ public:
|
||||
nsICacheListener * listener,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
nsresult EvictEntriesForSession(nsCacheSession * session);
|
||||
|
||||
nsresult EvictEntriesForClient(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy);
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheEntryDescriptor
|
||||
*/
|
||||
|
||||
2
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
2
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
@@ -97,5 +97,5 @@ NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key,
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return nsCacheService::GlobalInstance()->EvictEntriesForSession(this);
|
||||
}
|
||||
|
||||
27
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
27
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
@@ -292,20 +292,16 @@ NS_IMPL_ISUPPORTS1(nsDiskCacheDeviceInfo, nsICacheDeviceInfo);
|
||||
NS_IMETHODIMP nsDiskCacheDeviceInfo::GetDescription(char ** aDescription)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDescription);
|
||||
char* result = nsCRT::strdup("Disk cache device");
|
||||
if (!result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*aDescription = result;
|
||||
return NS_OK;
|
||||
*aDescription = nsCRT::strdup("Disk cache device");
|
||||
return *aDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* readonly attribute string usageReport; */
|
||||
NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(char ** aUsageReport)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aUsageReport);
|
||||
char* result = nsCRT::strdup("disk cache usage report");
|
||||
if (!result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*aUsageReport = result;
|
||||
return NS_OK;
|
||||
*aUsageReport = nsCRT::strdup("disk cache usage report");
|
||||
return *aUsageReport ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long entryCount; */
|
||||
@@ -520,6 +516,13 @@ NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
|
||||
return ClientIDFromCacheKey(nsLiteralCString(mMetaDataFile.mKey), clientID);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(deviceID);
|
||||
*deviceID = nsCRT::strdup(DISK_CACHE_DEVICE_ID);
|
||||
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(char ** clientKey)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientKey);
|
||||
@@ -702,6 +705,10 @@ nsDiskCacheDevice::FindEntry(nsCString * key)
|
||||
// XXX look in entry hashtable first, if not found, then look on
|
||||
// disk, to see if we have a disk cache entry that maches.
|
||||
nsCacheEntry * entry = nsnull;
|
||||
|
||||
// XXX checking the bound hash table should only be a debug check
|
||||
// XXX - the cache service shouldn't bother calling the device
|
||||
// XXX - if the entry is already active (bound or not).
|
||||
nsDiskCacheEntry * diskEntry = mBoundEntries.GetEntry(key->get());
|
||||
if (!diskEntry) {
|
||||
PLDHashNumber hashNumber = nsDiskCacheEntry::Hash(key->get());
|
||||
@@ -921,7 +928,7 @@ nsDiskCacheDevice::EvictEntries(const char * clientID)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRUint32 prefixLength = (clientID ? nsCRT::strlen(clientID) : 0);
|
||||
PRUint32 prefixLength = nsCRT::strlen(clientID);
|
||||
PRUint32 newDataSize = mCacheMap->DataSize();
|
||||
PRUint32 newEntryCount = mCacheMap->EntryCount();
|
||||
|
||||
@@ -1122,7 +1129,7 @@ nsresult nsDiskCacheDevice::openOutputStream(nsIFile * file, nsIOutputStream **
|
||||
return NS_OK;
|
||||
} else {
|
||||
nsCOMPtr<nsITransport> transport;
|
||||
nsresult rv = getTransportForFile(file, nsICache::ACCESS_WRITE, getter_AddRefs(transport));
|
||||
rv = getTransportForFile(file, nsICache::ACCESS_WRITE, getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return transport->OpenOutputStream(0, ULONG_MAX, 0, result);
|
||||
}
|
||||
|
||||
@@ -364,8 +364,8 @@ nsresult
|
||||
nsMemoryCacheDevice::EvictEntries(const char * clientID)
|
||||
{
|
||||
nsCacheEntry * entry;
|
||||
PRUint32 prefixLength = nsCRT::strlen(clientID);
|
||||
|
||||
PRUint32 prefixLength = clientID ? nsCRT::strlen(clientID) : 0;
|
||||
|
||||
PRCList * elem = PR_LIST_HEAD(&mEvictionList);
|
||||
while (elem != &mEvictionList) {
|
||||
entry = (nsCacheEntry *)elem;
|
||||
@@ -382,6 +382,7 @@ nsMemoryCacheDevice::EvictEntries(const char * clientID)
|
||||
EvictEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user