diff --git a/netwerk/protocol/about/src/Makefile.in b/netwerk/protocol/about/src/Makefile.in index 7b02b317fe3f..c3842ef92b22 100644 --- a/netwerk/protocol/about/src/Makefile.in +++ b/netwerk/protocol/about/src/Makefile.in @@ -47,3 +47,6 @@ override NO_STATIC_LIB= include $(topsrcdir)/config/rules.mk +ifdef MOZ_NEW_CACHE +CPPFLAGS += -DMOZ_NEW_CACHE +endif diff --git a/netwerk/protocol/about/src/nsAboutCache.cpp b/netwerk/protocol/about/src/nsAboutCache.cpp index 3d44f476f885..2d2ec9bd8697 100644 --- a/netwerk/protocol/about/src/nsAboutCache.cpp +++ b/netwerk/protocol/about/src/nsAboutCache.cpp @@ -19,6 +19,7 @@ * * Contributor(s): * Henrik Gemal + * Darin Fisher */ #include "nsAboutCache.h" @@ -33,11 +34,19 @@ #include "nsNetUtil.h" #include "prtime.h" +#ifdef MOZ_NEW_CACHE +#include "nsICacheService.h" +#else #include "nsICachedNetData.h" #include "nsINetDataCacheRecord.h" +#endif +#ifdef MOZ_NEW_CACHE +NS_IMPL_ISUPPORTS2(nsAboutCache, nsIAboutModule, nsICacheVisitor) +#else NS_IMPL_ISUPPORTS1(nsAboutCache, nsIAboutModule) +#endif NS_IMETHODIMP nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) @@ -68,8 +77,13 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) } */ // Get the cache manager service +#ifdef MOZ_NEW_CACHE + NS_WITH_SERVICE(nsICacheService, cacheService, + NS_CACHESERVICE_CONTRACTID, &rv); +#else NS_WITH_SERVICE(nsINetDataCacheManager, cacheManager, NS_NETWORK_CACHE_MANAGER_CONTRACTID, &rv); +#endif if (NS_FAILED(rv)) return rv; nsCOMPtr storageStream; @@ -87,6 +101,9 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) outputStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); +#ifdef MOZ_NEW_CACHE + mStream = outputStream; +#else nsCOMPtr moduleIterator; nsCOMPtr entryIterator; @@ -157,6 +174,7 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) outputStream->Write(buffer, buffer.Length(), &bytesWritten); */ } while(1); +#endif mBuffer.Assign("\n\n"); outputStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); @@ -178,6 +196,202 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) return rv; } +#ifdef MOZ_NEW_CACHE + +NS_IMETHODIMP +nsAboutCache::VisitDevice(const char *deviceID, + nsICacheDeviceInfo *deviceInfo, + PRBool *visitEntries) +{ + PRUint32 bytesWritten, value; + nsXPIDLCString str; + + // Write out the Cache Name + deviceInfo->GetDescription(getter_Copies(str)); + + mBuffer.Assign("

"); + mBuffer.Append(str); + mBuffer.Append("

\n"); + + // Write out cache info + + mBuffer.Append("\n\n"); + deviceInfo->GetUsageReport(getter_Copies(str)); + mBuffer.Assign("\n\n"); + + mBuffer.Append("\n\n"); + value = 0; + deviceInfo->GetEntryCount(&value); + mBuffer.Append("\n\n"); + + mBuffer.Append("\n\n"); + value = 0; + deviceInfo->GetMaximumSize(&value); + mBuffer.Append("\n\n"); + + mBuffer.Append("\n\n"); + mBuffer.Append("\n\n"); + + mBuffer.Append("
Usage report:"); + mBuffer.Append(str); + mBuffer.Append("
Number of entries:"); + mBuffer.AppendInt(value); + mBuffer.Append("
Maximum storage size:"); + mBuffer.AppendInt(value); + mBuffer.Append("
Storage in use:"); + value = 0; + deviceInfo->GetTotalSize(&value); + mBuffer.AppendInt(value); + mBuffer.Append(" KB
\n
\n"); + + mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); + + *visitEntries = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsAboutCache::VisitEntry(const char *deviceID, + const char *clientID, + nsICacheEntryInfo *entryInfo, + PRBool *visitNext) +{ + PRUint32 bytesWritten; + nsXPIDLCString str; + + // Entry start... + mBuffer.Assign("

\n"); + + // URI + mBuffer.Append("       " + "    URL: "); + entryInfo->GetKey(getter_Copies(str)); + mBuffer.Append(""); + mBuffer.Append(str); + mBuffer.Append("
\n"); + + // Client + mBuffer.Append("       " + " Client: "); + entryInfo->GetClientID(getter_Copies(str)); + mBuffer.Append(str); + mBuffer.Append("
\n"); + + // Content length + PRUint32 length = 0; + entryInfo->GetDataSize(&length); + + mBuffer.Append("     Data size: "); + mBuffer.AppendInt(length); + mBuffer.Append("
\n"); + + // Number of accesses + PRInt32 fetchCount = 0; + entryInfo->GetFetchCount(&fetchCount); + + mBuffer.Append("   Fetch count: "); + mBuffer.AppendInt(fetchCount); + mBuffer.Append("
\n"); + + // Last modified time + char buf[255]; + PRExplodedTime et; + PRTime t; + + mBuffer.Append("  Last Fetched: "); + entryInfo->GetLastFetched(&t); + if (LL_NE(t, LL_ZERO)) { + PR_ExplodeTime(t, PR_LocalTimeParameters, &et); + PR_FormatTime(buf, sizeof(buf), "%c", &et); + mBuffer.Append(buf); + } else + mBuffer.Append("No last fetched time"); + mBuffer.Append("
"); + + mBuffer.Append(" Last Modified: "); + entryInfo->GetLastModified(&t); + if (LL_NE(t, LL_ZERO)) { + PR_ExplodeTime(t, PR_LocalTimeParameters, &et); + PR_FormatTime(buf, sizeof(buf), "%c", &et); + mBuffer.Append(buf); + } else + mBuffer.Append("No last modified time"); + mBuffer.Append("
"); + + mBuffer.Append("Last Validated: "); + entryInfo->GetLastFetched(&t); + if (LL_NE(t, LL_ZERO)) { + PR_ExplodeTime(t, PR_LocalTimeParameters, &et); + PR_FormatTime(buf, sizeof(buf), "%c", &et); + mBuffer.Append(buf); + } else + mBuffer.Append("No last validated time"); + mBuffer.Append("
"); + + // Expires time + mBuffer.Append("       " + "Expires: "); + entryInfo->GetExpirationTime(&t); + if (LL_NE(t, LL_ZERO)) { + PR_ExplodeTime(t, PR_LocalTimeParameters, &et); + PR_FormatTime(buf, sizeof(buf), "%c", &et); + mBuffer.Append(buf); + } else { + mBuffer.Append("No expiration time"); + } + mBuffer.Append("
"); + + // Stream based + mBuffer.Append("  Stream based: "); + PRBool b = PR_TRUE; + entryInfo->GetStreamBased(&b); + mBuffer.Append(b ? "TRUE" : "FALSE"); + mBuffer.Append("
\n"); + + /* + // Flags + PRBool flag = PR_FALSE, foundFlag = PR_FALSE; + mBuffer.Append("         " + "Flags: "); + + flag = PR_FALSE; + entry->GetPartialFlag(&flag); + if (flag) { + mBuffer.Append("PARTIAL "); + foundFlag = PR_TRUE; + } + flag = PR_FALSE; + entry->GetUpdateInProgress(&flag); + if (flag) { + mBuffer.Append("UPDATE_IN_PROGRESS "); + foundFlag = PR_TRUE; + } + flag = PR_FALSE; + entry->GetInUse(&flag); + if (flag) { + mBuffer.Append("IN_USE"); + foundFlag = PR_TRUE; + } + + if (!foundFlag) { + mBuffer.Append("none
\n"); + } else { + mBuffer.Append("
\n"); + } + */ + + // Entry is done... + mBuffer.Append("

\n"); + + mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); + + *visitNext = PR_TRUE; + return NS_OK; +} + +#else void nsAboutCache::DumpCacheInfo(nsIOutputStream *aStream, nsINetDataCache *aCache) { @@ -380,6 +594,8 @@ nsresult nsAboutCache::DumpCacheEntries(nsIOutputStream *aStream, return NS_OK; } +#endif /* MOZ_NEW_CACHE */ + NS_METHOD nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) diff --git a/netwerk/protocol/about/src/nsAboutCache.h b/netwerk/protocol/about/src/nsAboutCache.h index dc4b39a6a7ae..b302b3ad8482 100644 --- a/netwerk/protocol/about/src/nsAboutCache.h +++ b/netwerk/protocol/about/src/nsAboutCache.h @@ -28,15 +28,25 @@ #include "nsString.h" #include "nsIOutputStream.h" +#ifdef MOZ_NEW_CACHE +#include "nsICacheVisitor.h" +#include "nsCOMPtr.h" +#else #include "nsINetDataCacheManager.h" #include "nsINetDataCache.h" +#endif class nsAboutCache : public nsIAboutModule +#ifdef MOZ_NEW_CACHE + , public nsICacheVisitor +#endif { public: NS_DECL_ISUPPORTS - NS_DECL_NSIABOUTMODULE +#ifdef MOZ_NEW_CACHE + NS_DECL_NSICACHEVISITOR +#endif nsAboutCache() { NS_INIT_REFCNT(); } virtual ~nsAboutCache() {} @@ -45,6 +55,9 @@ public: Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); protected: +#ifdef MOZ_NEW_CACHE + nsCOMPtr mStream; +#else void DumpCacheInfo(nsIOutputStream *aStream, nsINetDataCache *aCache); @@ -57,6 +70,7 @@ protected: nsresult DumpCacheEntries(nsIOutputStream *aStream, nsINetDataCacheManager *aCacheMgr, nsINetDataCache *aCache); +#endif nsCString mBuffer; }; @@ -68,4 +82,4 @@ protected: {0x9b, 0xe2, 0x00, 0xe0, 0x98, 0x72, 0xa4, 0x16} \ } -#endif // nsAboutCache_h__ +#endif /* !defined(nsAboutCache_h__) */