diff --git a/netwerk/cache/src/Makefile.in b/netwerk/cache/src/Makefile.in index e65994b8a363..46fcfefa5864 100644 --- a/netwerk/cache/src/Makefile.in +++ b/netwerk/cache/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = nkcache -LIBRARY_NAME = nkcachemgr_s +LIBRARY_NAME = nkcacheservice_s REQUIRES = xpcom necko pref js EXPORTS = \ @@ -38,7 +38,9 @@ CPPSRCS = \ nsCacheEntry.cpp \ nsCacheEntryDescriptor.cpp \ nsCacheMetaData.cpp \ + nsCacheModule.cpp \ nsCacheService.cpp \ + nsCacheSession.cpp \ nsDiskCacheDevice.cpp \ nsMemoryCacheDevice.cpp \ $(NULL) diff --git a/netwerk/cache/src/nsCacheDevice.h b/netwerk/cache/src/nsCacheDevice.h index 05561ab1426d..d24f407269bc 100644 --- a/netwerk/cache/src/nsCacheDevice.h +++ b/netwerk/cache/src/nsCacheDevice.h @@ -26,6 +26,8 @@ #include "nspr.h" #include "nsError.h" +#include "nsITransport.h" +#include "nsCacheEntry.h" class nsCacheEntry; @@ -33,25 +35,20 @@ class nsCacheEntry; class nsCacheDevice { public: - nsCacheDevice(PRUint32 deviceID) : mDeviceID(deviceID){} virtual ~nsCacheDevice() = 0; - //** decide on strings or ints for IDs - virtual PRUint32 GetDeviceID(void) { return mDeviceID; } + virtual const char * GetDeviceID(void) = 0; virtual nsresult ActivateEntryIfFound( nsCacheEntry * entry ) = 0; virtual nsresult DeactivateEntry( nsCacheEntry * entry ) = 0; - virtual nsresult BindEntry( nsCacheEntry * entry ) = 0; - //** need to define stream factory methods + virtual nsresult GetTransportForEntry( nsCacheEntry * entry, + nsITransport **transport ) = 0; + + virtual nsresult OnDataSizeChanged( nsCacheEntry * entry ) = 0; //** need to define methods for enumerating entries - - //** need notification methods for size changes on non-streamBased entries - -protected: - PRUint32 mDeviceID; }; #endif // _nsCacheDevice_h_ diff --git a/netwerk/cache/src/nsCacheEntry.cpp b/netwerk/cache/src/nsCacheEntry.cpp index c8d64dc36fe6..d1dd74249536 100644 --- a/netwerk/cache/src/nsCacheEntry.cpp +++ b/netwerk/cache/src/nsCacheEntry.cpp @@ -116,17 +116,17 @@ nsCacheEntry::CommonOpen(nsCacheRequest * request, PRUint32 *accessGranted) if (!IsInitialized()) { // brand new, unbound entry - NS_ASSERTION(request->mAccessRequested & nsICacheService::WRITE, + NS_ASSERTION(request->mAccessRequested & nsICache::ACCESS_WRITE, "new cache entry for READ-ONLY request"); if (request->mStreamBased) MarkStreamBased(); mFetchCount = 1; MarkInitialized(); - *accessGranted = request->mAccessRequested & ~nsICacheService::WRITE; + *accessGranted = request->mAccessRequested & ~nsICache::ACCESS_WRITE; return rv; } if (IsStreamData() != request->mStreamBased) { - *accessGranted = nsICacheService::NO_ACCESS; + *accessGranted = nsICache::ACCESS_NONE; return request->mStreamBased ? NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM; } @@ -136,7 +136,7 @@ nsCacheEntry::CommonOpen(nsCacheRequest * request, PRUint32 *accessGranted) *accessGranted = request->mAccessRequested; } else { // nth request for existing, bound entry - *accessGranted = request->mAccessRequested & ~nsICacheService::WRITE; + *accessGranted = request->mAccessRequested & ~nsICache::ACCESS_WRITE; if (!IsValid()) rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION; } diff --git a/netwerk/cache/src/nsCacheEntry.h b/netwerk/cache/src/nsCacheEntry.h index c531a1f47d1d..704156b3867b 100644 --- a/netwerk/cache/src/nsCacheEntry.h +++ b/netwerk/cache/src/nsCacheEntry.h @@ -59,8 +59,8 @@ public: void GetKey( nsCString ** key) { if (key) *key = mKey; } - void GetFetchCount( PRUint32 * result) { if (result) *result = mFetchCount; } - void SetFetchCount( PRUint32 count) { mFetchCount = count; } + void GetFetchCount( PRInt32 * result) { if (result) *result = mFetchCount; } + void SetFetchCount( PRInt32 count) { mFetchCount = count; } void GetLastFetched( PRTime * result) { if (result) *result = mLastFetched; } void SetLastFetched( PRTime lastFetched) diff --git a/netwerk/cache/src/nsCacheEntryDescriptor.cpp b/netwerk/cache/src/nsCacheEntryDescriptor.cpp index ab31373bd2ff..066a6baaa830 100644 --- a/netwerk/cache/src/nsCacheEntryDescriptor.cpp +++ b/netwerk/cache/src/nsCacheEntryDescriptor.cpp @@ -91,7 +91,7 @@ nsCacheEntryDescriptor::GetKey(char ** result) /* readonly attribute unsigned long fetchCount; */ NS_IMETHODIMP -nsCacheEntryDescriptor::GetFetchCount(PRUint32 *fetchCount) +nsCacheEntryDescriptor::GetFetchCount(PRInt32 *fetchCount) { if (!fetchCount) return NS_ERROR_NULL_POINTER; mCacheEntry->GetFetchCount(fetchCount); @@ -165,40 +165,14 @@ nsCacheEntryDescriptor::GetAccessGranted(PRUint32 *accessGranted) /* attribute unsigned long storageFlags; */ NS_IMETHODIMP -nsCacheEntryDescriptor::GetStorageFlags(PRUint32 *storageFlags) +nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *policy) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP -nsCacheEntryDescriptor::SetStorageFlags(PRUint32 storageFlags) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute boolean allowInMemory; */ -NS_IMETHODIMP -nsCacheEntryDescriptor::GetAllowInMemory(PRBool *aAllowInMemory) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCacheEntryDescriptor::SetAllowInMemory(PRBool aAllowInMemory) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute boolean allowOnDisk; */ -NS_IMETHODIMP -nsCacheEntryDescriptor::GetAllowOnDisk(PRBool *aAllowOnDisk) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCacheEntryDescriptor::SetAllowOnDisk(PRBool aAllowOnDisk) +nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -217,19 +191,6 @@ nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status) return NS_ERROR_NOT_IMPLEMENTED; } -/* void truncateExistingData (in unsigned long newLength); */ -NS_IMETHODIMP -nsCacheEntryDescriptor::TruncateExistingData(PRUint32 newLength) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void appendToExistingData (); */ -NS_IMETHODIMP -nsCacheEntryDescriptor::AppendToExistingData() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} /* void markValid (); */ NS_IMETHODIMP diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index 8e8415359944..b42c0d7fc4b1 100644 --- a/netwerk/cache/src/nsCacheService.cpp +++ b/netwerk/cache/src/nsCacheService.cpp @@ -143,6 +143,19 @@ nsCacheService::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) return rv; } +/* nsICacheSession createSession (in string clientID, in long storagePolicy, in boolean streamBased); */ +NS_IMETHODIMP nsCacheService::CreateSession(const char *clientID, PRInt32 storagePolicy, PRBool streamBased, nsICacheSession **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +/* void visitEntries (in nsICacheVisitor visitor); */ +NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + nsresult nsCacheService::CommonOpenCacheEntry(const char *clientID, const char *clientKey, @@ -170,7 +183,7 @@ nsCacheService::CommonOpenCacheEntry(const char *clientID, const char *clientKey } -NS_IMETHODIMP +nsresult nsCacheService::OpenCacheEntry(const char *clientID, const char *clientKey, PRUint32 accessRequested, PRBool streamBased, nsICacheEntryDescriptor **result) @@ -197,7 +210,7 @@ nsCacheService::OpenCacheEntry(const char *clientID, const char *clientKey, } -NS_IMETHODIMP +nsresult nsCacheService::AsyncOpenCacheEntry(const char * clientID, const char * key, PRUint32 accessRequested, PRBool streamBased, nsICacheListener *listener) @@ -219,7 +232,6 @@ nsCacheService::AsyncOpenCacheEntry(const char * clientID, const char * key, return rv; } - nsresult nsCacheService::ActivateEntry(nsCacheRequest * request, nsCacheEntry ** result) @@ -241,7 +253,7 @@ nsCacheService::ActivateEntry(nsCacheRequest * request, nsCacheEntry *entry = mActiveEntries.GetEntry(request->mKey); // doom existing entry if we are processing a FORCE-WRITE - if (entry && (request->mAccessRequested == nsICacheService::WRITE)) { + if (entry && (request->mAccessRequested == nsICache::ACCESS_WRITE)) { entry->Doom(); } @@ -259,7 +271,7 @@ nsCacheService::ActivateEntry(nsCacheRequest * request, rv = SearchCacheDevices(entry, &device); if ((rv == NS_ERROR_CACHE_KEY_NOT_FOUND) && - !(request->mAccessRequested & nsICacheService::WRITE)) { + !(request->mAccessRequested & nsICache::ACCESS_WRITE)) { // this was a READ-ONLY request, deallocate entry //** dealloc entry, call listener with error, etc. *result = nsnull; @@ -305,37 +317,6 @@ nsCacheService::SearchActiveEntries(const nsCString * key) } -NS_IMETHODIMP -nsCacheService::EnumerateDeviceIDs(nsISimpleEnumerator **_retval) -{ - if (!mCacheServiceLock) - return NS_ERROR_NOT_INITIALIZED; - - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NS_IMETHODIMP -nsCacheService::EnumerateClientIDs(nsISimpleEnumerator **_retval) -{ - if (!mCacheServiceLock) - return NS_ERROR_NOT_INITIALIZED; - - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NS_IMETHODIMP -nsCacheService::EnumerateEntries(const char *deviceID, const char *clientID, - nsISimpleEnumerator **_retval) -{ - if (!mCacheServiceLock) - return NS_ERROR_NOT_INITIALIZED; - - return NS_ERROR_NOT_IMPLEMENTED; -} - - /* * nsCacheClientHashTable diff --git a/netwerk/cache/src/nsCacheService.h b/netwerk/cache/src/nsCacheService.h index 914068be5d31..83d986b6322f 100644 --- a/netwerk/cache/src/nsCacheService.h +++ b/netwerk/cache/src/nsCacheService.h @@ -127,6 +127,14 @@ private: PRUint32 accessRequested, PRBool streamBased, nsCacheRequest **request, nsCacheEntry **entry); + nsresult OpenCacheEntry(const char *clientID, const char *clientKey, + PRUint32 accessRequested, PRBool streamBased, + nsICacheEntryDescriptor **result); + + nsresult AsyncOpenCacheEntry(const char * clientID, const char * key, + PRUint32 accessRequested, PRBool streamBased, + nsICacheListener *listener); + /** * Data Members */ diff --git a/netwerk/cache/src/nsDiskCacheDevice.cpp b/netwerk/cache/src/nsDiskCacheDevice.cpp index 67830f1b3b1d..2e8c0a8529c0 100644 --- a/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -26,7 +26,6 @@ nsDiskCacheDevice::nsDiskCacheDevice() - : nsCacheDevice(kDiskCacheID) { } @@ -61,6 +60,13 @@ nsDiskCacheDevice::Create(nsCacheDevice **result) } +const char * +nsDiskCacheDevice::GetDeviceID() +{ + return "disk"; +} + + nsresult nsDiskCacheDevice::ActivateEntryIfFound(nsCacheEntry * entry) { @@ -81,6 +87,17 @@ nsDiskCacheDevice::BindEntry(nsCacheEntry * entry) return NS_ERROR_NOT_IMPLEMENTED; } -//** need stream factory methods +nsresult +nsDiskCacheDevice::GetTransportForEntry( nsCacheEntry * entry, + nsITransport **transport ) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult +nsDiskCacheDevice::OnDataSizeChanged( nsCacheEntry * entry ) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} //** need methods for enumerating entries diff --git a/netwerk/cache/src/nsDiskCacheDevice.h b/netwerk/cache/src/nsDiskCacheDevice.h index 1a9f31d3605f..9068eb67deb7 100644 --- a/netwerk/cache/src/nsDiskCacheDevice.h +++ b/netwerk/cache/src/nsDiskCacheDevice.h @@ -39,10 +39,16 @@ public: static nsresult Create(nsCacheDevice **result); + virtual const char * GetDeviceID(void); virtual nsresult ActivateEntryIfFound( nsCacheEntry * entry ); virtual nsresult DeactivateEntry( nsCacheEntry * entry ); virtual nsresult BindEntry( nsCacheEntry * entry ); + virtual nsresult GetTransportForEntry( nsCacheEntry * entry, + nsITransport **transport ); + + virtual nsresult OnDataSizeChanged( nsCacheEntry * entry ); + private: }; diff --git a/netwerk/cache/src/nsMemoryCacheDevice.cpp b/netwerk/cache/src/nsMemoryCacheDevice.cpp index 55b7ca948980..2463c4ad729d 100644 --- a/netwerk/cache/src/nsMemoryCacheDevice.cpp +++ b/netwerk/cache/src/nsMemoryCacheDevice.cpp @@ -26,7 +26,6 @@ nsMemoryCacheDevice::nsMemoryCacheDevice() - : nsCacheDevice(kMemoryCacheID) { } @@ -66,6 +65,13 @@ nsMemoryCacheDevice::Create(nsCacheDevice **result) } +const char * +nsMemoryCacheDevice::GetDeviceID() +{ + return "memory"; +} + + nsresult nsMemoryCacheDevice::ActivateEntryIfFound(nsCacheEntry * entry) { @@ -112,8 +118,17 @@ nsMemoryCacheDevice::BindEntry(nsCacheEntry * entry) return NS_ERROR_NOT_IMPLEMENTED; } -//** need stream factory methods +nsresult +nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry, + nsITransport **transport ) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult +nsMemoryCacheDevice::OnDataSizeChanged( nsCacheEntry * entry ) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} //** need methods for enumerating entries - -//** need notification methods for size changes on non-streamBased entries (for eviction)