diff --git a/netwerk/protocol/about/src/nsAboutCache.cpp b/netwerk/protocol/about/src/nsAboutCache.cpp index 943601d2f7f7..0cdb4ef1c8ff 100644 --- a/netwerk/protocol/about/src/nsAboutCache.cpp +++ b/netwerk/protocol/about/src/nsAboutCache.cpp @@ -116,10 +116,14 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result) rv = storageStream->GetOutputStream(0, getter_AddRefs(outputStream)); if (NS_FAILED(rv)) return rv; - mBuffer.Assign("\n\nInformation about the Cache Manager\n\n\n"); + mBuffer.Assign("\n\nInformation about the Cache Service\n\n\n"); + outputStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); #ifdef MOZ_NEW_CACHE + rv = ParseURI(aURI, mDeviceID); + if (NS_FAILED(rv)) return rv; + mStream = outputStream; rv = cacheService->VisitEntries(this); if (NS_FAILED(rv)) return rv; @@ -185,47 +189,60 @@ nsAboutCache::VisitDevice(const char *deviceID, PRUint32 bytesWritten, value; nsXPIDLCString str; - // Write out the Cache Name - deviceInfo->GetDescription(getter_Copies(str)); + *visitEntries = PR_FALSE; - mBuffer.Assign("

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


\n"); + if (mDeviceID.IsEmpty() || mDeviceID.Equals(deviceID)) { - // Write out cache info - - mBuffer.Append("\n\n"); - deviceInfo->GetUsageReport(getter_Copies(str)); - mBuffer.Append("\n\n"); + // Write out the Cache Name + deviceInfo->GetDescription(getter_Copies(str)); - mBuffer.Append("\n\n"); - value = 0; - deviceInfo->GetEntryCount(&value); - mBuffer.Append("\n\n"); + mBuffer.Assign("

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


\n"); - mBuffer.Append("\n\n"); - value = 0; - deviceInfo->GetMaximumSize(&value); - mBuffer.Append("\n\n"); + // Write out cache info - 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(" Bytes
\n\n"); + deviceInfo->GetUsageReport(getter_Copies(str)); + mBuffer.Append("\n\n"); - mBuffer.Append("
Usage report:"); + mBuffer.Append(str); + mBuffer.Append("
\n
\n"); + mBuffer.Append("\nNumber of entries:\n"); + value = 0; + deviceInfo->GetEntryCount(&value); + mBuffer.Append(""); + mBuffer.AppendInt(value); + mBuffer.Append("\n\n"); - mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); + mBuffer.Append("\nMaximum storage size:\n"); + value = 0; + deviceInfo->GetMaximumSize(&value); + mBuffer.Append(""); + mBuffer.AppendInt(value); + mBuffer.Append("\n\n"); + + mBuffer.Append("\nStorage in use:\n"); + mBuffer.Append(""); + value = 0; + deviceInfo->GetTotalSize(&value); + mBuffer.AppendInt(value); + mBuffer.Append(" Bytes\n\n"); + + mBuffer.Append("\n"); + + if (mDeviceID.IsEmpty()) { + mBuffer.Append("\nList Cache Entries\n"); + } else { + *visitEntries = PR_TRUE; + } + + mBuffer.Append("
\n"); + mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); + } - *visitEntries = PR_TRUE; return NS_OK; } @@ -259,28 +276,22 @@ nsAboutCache::VisitEntry(const char *deviceID, url += key; // key // Entry start... - mBuffer.Assign("

\n"); + mBuffer.Assign("

\n"); // URI - mBuffer.Append("       " - "    Key: "); + mBuffer.Append("       " + "    Key: "); mBuffer.Append(""); mBuffer.Append(key); mBuffer.Append("
\n"); - // Client - mBuffer.Append("       " - " Client: "); - mBuffer.Append(clientID); - mBuffer.Append("
\n"); - // Content length PRUint32 length = 0; entryInfo->GetDataSize(&length); - mBuffer.Append("     Data size: "); + mBuffer.Append("     Data size: "); mBuffer.AppendInt(length); mBuffer.Append(" Bytes
\n"); @@ -288,24 +299,16 @@ nsAboutCache::VisitEntry(const char *deviceID, PRInt32 fetchCount = 0; entryInfo->GetFetchCount(&fetchCount); - mBuffer.Append("   Fetch count: "); + mBuffer.Append("   Fetch count: "); mBuffer.AppendInt(fetchCount); mBuffer.Append("
\n"); - // Last modified time + // vars for reporting time char buf[255]; PRUint32 t; - mBuffer.Append("  Last Fetched: "); - entryInfo->GetLastFetched(&t); - if (t) { - PrintTimeString(buf, sizeof(buf), t); - mBuffer.Append(buf); - } else - mBuffer.Append("No last fetched time"); - mBuffer.Append("
"); - - mBuffer.Append(" Last Modified: "); + // Last modified time + mBuffer.Append(" Last Modified: "); entryInfo->GetLastModified(&t); if (t) { PrintTimeString(buf, sizeof(buf), t); @@ -315,8 +318,8 @@ nsAboutCache::VisitEntry(const char *deviceID, mBuffer.Append("
"); // Expires time - mBuffer.Append("       " - "Expires: "); + mBuffer.Append("       " + "Expires: "); entryInfo->GetExpirationTime(&t); if (t) { PrintTimeString(buf, sizeof(buf), t); @@ -327,7 +330,7 @@ nsAboutCache::VisitEntry(const char *deviceID, mBuffer.Append("
"); // Entry is done... - mBuffer.Append("

\n"); + mBuffer.Append("

\n"); mStream->Write(mBuffer, mBuffer.Length(), &bytesWritten); @@ -335,6 +338,35 @@ nsAboutCache::VisitEntry(const char *deviceID, return NS_OK; } + +nsresult +nsAboutCache::ParseURI(nsIURI * uri, nsCString &deviceID) +{ + // + // about:cache[?device=string] + // + nsresult rv; + + deviceID.Truncate(); + + nsXPIDLCString path; + rv = uri->GetPath(getter_Copies(path)); + if (NS_FAILED(rv)) return rv; + + nsCAutoString p(path); + + nsReadingIterator start, valueStart, end; + p.BeginReading(start); + p.EndReading(end); + + valueStart = end; + if (!FindInReadable(NS_LITERAL_CSTRING("?device="), start, valueStart)) + return NS_OK; + + deviceID.Assign(Substring(valueStart, end)); + return NS_OK; +} + #else void nsAboutCache::DumpCacheInfo(nsIOutputStream *aStream, nsINetDataCache *aCache) @@ -553,4 +585,6 @@ nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) return rv; } + + //////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/protocol/about/src/nsAboutCache.h b/netwerk/protocol/about/src/nsAboutCache.h index 7a3bac5ec6d1..7d6323ddcdca 100644 --- a/netwerk/protocol/about/src/nsAboutCache.h +++ b/netwerk/protocol/about/src/nsAboutCache.h @@ -56,7 +56,10 @@ public: protected: #ifdef MOZ_NEW_CACHE + nsresult ParseURI(nsIURI * uri, nsCString &deviceID); + nsCOMPtr mStream; + nsCString mDeviceID; #else void DumpCacheInfo(nsIOutputStream *aStream, nsINetDataCache *aCache); diff --git a/netwerk/protocol/about/src/nsAboutCacheEntry.cpp b/netwerk/protocol/about/src/nsAboutCacheEntry.cpp index df8eb185f4f8..3de13b72754c 100644 --- a/netwerk/protocol/about/src/nsAboutCacheEntry.cpp +++ b/netwerk/protocol/about/src/nsAboutCacheEntry.cpp @@ -30,6 +30,7 @@ #include "nsICacheEntryDescriptor.h" #include "nsIStorageStream.h" #include "nsNetUtil.h" +#include "prtime.h" //----------------------------------------------------------------------------- // nsISupports implementation @@ -329,6 +330,22 @@ nsAboutCacheEntry::AsyncOpen(nsIStreamListener *listener, nsISupports *context) // helper methods //----------------------------------------------------------------------------- +static PRTime SecondsToPRTime(PRUint32 t_sec) +{ + PRTime t_usec, usec_per_sec; + LL_I2L(t_usec, t_sec); + LL_I2L(usec_per_sec, PR_USEC_PER_SEC); + LL_MUL(t_usec, t_usec, usec_per_sec); + return t_usec; +} +static void PrintTimeString(char *buf, PRUint32 bufsize, PRUint32 t_sec) +{ + PRExplodedTime et; + PRTime t_usec = SecondsToPRTime(t_sec); + PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et); + PR_FormatTime(buf, bufsize, "%c", &et); +} + #define TD_RIGHT_ALIGN "" #define APPEND_ROW(label, value) \ @@ -372,23 +389,85 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream, buffer.Append(str); buffer.Append(""); - // Since meta data enumeration is not hooked up yet, let's just look for some - // well known (HTTP) meta data tags. - str = 0; - descriptor->GetMetaDataElement("request-time", getter_Copies(str)); - if (str) - APPEND_ROW("request-time", str); + // temp vars for reporting + char timeBuf[255]; + PRUint32 u = 0; + PRInt32 i = 0; + nsCAutoString s; - str = 0; - descriptor->GetMetaDataElement("response-time", getter_Copies(str)); - if (str) - APPEND_ROW("response-time", str); + // Fetch Count + s.Truncate(); + descriptor->GetFetchCount(&i); + s.AppendInt(i); + APPEND_ROW("fetch count", s); + // Last Fetched + descriptor->GetLastFetched(&u); + if (u) { + PrintTimeString(timeBuf, sizeof(timeBuf), u); + APPEND_ROW("last fetched", timeBuf); + } else { + APPEND_ROW("last fetched", "No last fetch time"); + } + + // Last Modified + descriptor->GetLastModified(&u); + if (u) { + PrintTimeString(timeBuf, sizeof(timeBuf), u); + APPEND_ROW("last modified", timeBuf); + } else { + APPEND_ROW("last modified", "No last modified time"); + } + + // Expiration Time + descriptor->GetExpirationTime(&u); + if (u) { + PrintTimeString(timeBuf, sizeof(timeBuf), u); + APPEND_ROW("expires", timeBuf); + } else { + APPEND_ROW("expires", "No expiration time"); + } + + // Data Size + s.Truncate(); + descriptor->GetDataSize(&u); + s.AppendInt((PRInt32)u); // XXX nsICacheEntryInfo interfaces should be fixed. + APPEND_ROW("Data size", s); + + // Storage Policy + + // XXX Stream Based? + + // XXX Cache Device + // File on disk + + // Security Info str = 0; - descriptor->GetMetaDataElement("http-headers", getter_Copies(str)); - if (str) - APPEND_ROW("http-headers", str); + nsCOMPtr securityInfo; + descriptor->GetSecurityInfo(getter_AddRefs(securityInfo)); + if (securityInfo) { + APPEND_ROW("Security", "This is a secure document."); + } else { + APPEND_ROW("Security", + "This document does not have any security info associated with it."); + } + + buffer.Append(""); + // Meta Data + // let's just look for some well known (HTTP) meta data tags, for now. + buffer.Append("
"); + + // Client ID + str = 0; + descriptor->GetClientID(getter_Copies(str)); + if (str) APPEND_ROW("Client", str); + + + mBuffer = &buffer; // make it available for VisitMetaDataElement() + descriptor->VisitMetaData(this); + mBuffer = nsnull; + buffer.Append("
"); @@ -456,4 +535,25 @@ nsAboutCacheEntry::ParseURI(nsCString &clientID, PRBool &streamBased, nsCString return NS_OK; } + +//----------------------------------------------------------------------------- +// nsICacheMetaDataVisitor implementation +//----------------------------------------------------------------------------- + +NS_IMETHODIMP +nsAboutCacheEntry::VisitMetaDataElement(const char * key, + const char * value, + PRBool * keepGoing) +{ + mBuffer->Append(""); + mBuffer->Append(key); + mBuffer->Append(":\n
");
+    mBuffer->Append(value);
+    mBuffer->Append("
\n"); + + *keepGoing = PR_TRUE; + return NS_OK; +} + #endif // MOZ_NEW_CACHE + diff --git a/netwerk/protocol/about/src/nsAboutCacheEntry.h b/netwerk/protocol/about/src/nsAboutCacheEntry.h index 9b1555ed80f9..222c192f9d35 100644 --- a/netwerk/protocol/about/src/nsAboutCacheEntry.h +++ b/netwerk/protocol/about/src/nsAboutCacheEntry.h @@ -30,6 +30,7 @@ #include "nsIChannel.h" #include "nsICacheListener.h" #include "nsICacheSession.h" +#include "nsICacheEntryDescriptor.h" #include "nsIStreamListener.h" #include "nsCOMPtr.h" #include "nsString.h" @@ -39,6 +40,7 @@ class nsICacheEntryDescriptor; class nsAboutCacheEntry : public nsIAboutModule , public nsIChannel , public nsICacheListener + , public nsICacheMetaDataVisitor { public: NS_DECL_ISUPPORTS @@ -46,8 +48,12 @@ public: NS_DECL_NSIREQUEST NS_DECL_NSICHANNEL NS_DECL_NSICACHELISTENER + NS_DECL_NSICACHEMETADATAVISITOR + + nsAboutCacheEntry() + : mBuffer(nsnull) + { NS_INIT_ISUPPORTS(); } - nsAboutCacheEntry() { NS_INIT_ISUPPORTS(); } virtual ~nsAboutCacheEntry() {} private: @@ -60,6 +66,7 @@ private: nsCOMPtr mListener; nsCOMPtr mListenerContext; nsCOMPtr mCacheSession; + nsCString * mBuffer; }; #define NS_ABOUT_CACHE_ENTRY_MODULE_CID \