mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Fixes bug 74199 "about:cache-entry needs to know how to deal with
non-stream-based cache entries" r=gordon, sr=mscott
This commit is contained in:
parent
6251aa58fa
commit
c082dc3704
@ -119,7 +119,6 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
mBuffer.Assign("<html>\n<head>\n<title>Information about the Cache Manager</title>\n</head>\n<body>\n");
|
||||
outputStream->Write(mBuffer, mBuffer.Length(), &bytesWritten);
|
||||
|
||||
|
||||
#ifdef MOZ_NEW_CACHE
|
||||
mStream = outputStream;
|
||||
rv = cacheService->VisitEntries(this);
|
||||
@ -153,47 +152,6 @@ nsAboutCache::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
DumpCacheInfo(outputStream, cache);
|
||||
|
||||
DumpCacheEntries(outputStream, cacheManager, cache);
|
||||
/*
|
||||
do {
|
||||
char *key;
|
||||
PRUint32 length;
|
||||
PRBool bMoreEntries = PR_FALSE;
|
||||
|
||||
rv = entryIterator->HasMoreElements(&bMoreEntries);
|
||||
if (!bMoreEntries) break;
|
||||
|
||||
rv = entryIterator->GetNext(getter_AddRefs(item));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
cacheRecord = do_QueryInterface(item);
|
||||
|
||||
cacheEntryCount += 1;
|
||||
cacheRecord->GetStoredContentLength(&length);
|
||||
cacheSize += length;
|
||||
|
||||
buffer.Truncate(0);
|
||||
buffer.AppendInt(cacheEntryCount);
|
||||
buffer.Append(".\t");
|
||||
buffer.AppendInt(length);
|
||||
buffer.Append(" bytes\t");
|
||||
outputStream->Write(buffer, buffer.Length(), &bytesWritten);
|
||||
|
||||
rv = cacheRecord->GetKey(&length, &key);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
outputStream->Write(key, strlen(key), &bytesWritten);
|
||||
outputStream->Write("\n", 1, &bytesWritten);
|
||||
|
||||
nsMemory::Free(key);
|
||||
|
||||
} while(1);
|
||||
|
||||
buffer.Truncate(0);
|
||||
buffer.Append("\nTotal Bytes in Cache: ");
|
||||
buffer.AppendInt(cacheSize);
|
||||
buffer.Append("\n\n");
|
||||
outputStream->Write(buffer, buffer.Length(), &bytesWritten);
|
||||
*/
|
||||
} while(1);
|
||||
#endif
|
||||
|
||||
@ -280,18 +238,23 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
||||
PRUint32 bytesWritten;
|
||||
nsXPIDLCString key;
|
||||
nsXPIDLCString clientID;
|
||||
PRBool streamBased;
|
||||
|
||||
|
||||
rv = entryInfo->GetKey(getter_Copies(key));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = entryInfo->GetClientID(getter_Copies(clientID));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = entryInfo->IsStreamBased(&streamBased);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Generate a about:cache-entry URL for this entry...
|
||||
nsCAutoString url;
|
||||
url += NS_LITERAL_CSTRING("about:cache-entry?client=");
|
||||
url += clientID;
|
||||
url += NS_LITERAL_CSTRING("&sb=");
|
||||
url += streamBased ? "1" : "0";
|
||||
url += NS_LITERAL_CSTRING("&key=");
|
||||
url += key; // key
|
||||
|
||||
@ -351,17 +314,6 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
||||
mBuffer.Append("No last modified time");
|
||||
mBuffer.Append("<br>");
|
||||
|
||||
/*
|
||||
mBuffer.Append("<tt>Last Validated: </tt>");
|
||||
entryInfo->GetLastFetched(&t);
|
||||
if (t) {
|
||||
PrintTimeString(buf, sizeof(buf), t);
|
||||
mBuffer.Append(buf);
|
||||
} else
|
||||
mBuffer.Append("No last validated time");
|
||||
mBuffer.Append("<br>");
|
||||
*/
|
||||
|
||||
// Expires time
|
||||
mBuffer.Append("<tt> "
|
||||
"Expires: </tt>");
|
||||
@ -374,45 +326,6 @@ nsAboutCache::VisitEntry(const char *deviceID,
|
||||
}
|
||||
mBuffer.Append("<br>");
|
||||
|
||||
// Stream based
|
||||
mBuffer.Append("<tt> Stream based: </tt>");
|
||||
PRBool b = PR_TRUE;
|
||||
entryInfo->IsStreamBased(&b);
|
||||
mBuffer.Append(b ? "TRUE" : "FALSE");
|
||||
mBuffer.Append("<br>\n");
|
||||
|
||||
/*
|
||||
// Flags
|
||||
PRBool flag = PR_FALSE, foundFlag = PR_FALSE;
|
||||
mBuffer.Append("<tt> "
|
||||
"Flags: </tt><b>");
|
||||
|
||||
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("</b>none<br>\n");
|
||||
} else {
|
||||
mBuffer.Append("</b><br>\n");
|
||||
}
|
||||
*/
|
||||
|
||||
// Entry is done...
|
||||
mBuffer.Append("</p>\n");
|
||||
|
||||
|
@ -302,9 +302,10 @@ NS_IMETHODIMP
|
||||
nsAboutCacheEntry::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCString clientID, key;
|
||||
nsCAutoString clientID, key;
|
||||
PRBool streamBased = PR_TRUE;
|
||||
|
||||
rv = ParseURI(clientID, key);
|
||||
rv = ParseURI(clientID, streamBased, key);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsICacheService> serv =
|
||||
@ -313,7 +314,7 @@ nsAboutCacheEntry::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
|
||||
|
||||
rv = serv->CreateSession(clientID,
|
||||
nsICache::STORE_ANYWHERE,
|
||||
nsICache::STREAM_BASED,
|
||||
streamBased,
|
||||
getter_AddRefs(mCacheSession));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@ -407,12 +408,10 @@ nsAboutCacheEntry::WriteCacheEntryUnavailable(nsIOutputStream *outputStream,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAboutCacheEntry::ParseURI(nsCString &clientID, nsCString &key)
|
||||
nsAboutCacheEntry::ParseURI(nsCString &clientID, PRBool &streamBased, nsCString &key)
|
||||
{
|
||||
//
|
||||
// about:cache-entry?client=something&key=something-different
|
||||
// ^ ^ ^
|
||||
// a b c
|
||||
// about:cache-entry?client=[string]&sb=[boolean]&key=[string]
|
||||
//
|
||||
nsresult rv;
|
||||
|
||||
@ -426,27 +425,34 @@ nsAboutCacheEntry::ParseURI(nsCString &clientID, nsCString &key)
|
||||
|
||||
nsCAutoString p(path);
|
||||
|
||||
nsReadingIterator<char> begin, end, a, b, c;
|
||||
p.BeginReading(begin);
|
||||
nsReadingIterator<char> i1, i2, i3, end;
|
||||
p.BeginReading(i1);
|
||||
p.EndReading(end);
|
||||
|
||||
if (!FindCharInReadable('?', begin, end))
|
||||
i2 = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("?client="), i1, i2))
|
||||
return NS_ERROR_FAILURE;
|
||||
// i2 points to the start of clientID
|
||||
|
||||
b = begin;
|
||||
a = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("client="), b, a))
|
||||
i1 = i2;
|
||||
i3 = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("&sb="), i1, i3))
|
||||
return NS_ERROR_FAILURE;
|
||||
// now a points to the clientID
|
||||
// i1 points to the end of clientID
|
||||
// i3 points to the start of isStreamBased
|
||||
|
||||
b = a;
|
||||
c = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("&key="), b, c))
|
||||
clientID.Assign(Substring(i2, i1));
|
||||
|
||||
i1 = i3;
|
||||
i2 = end;
|
||||
if (!FindInReadable(NS_LITERAL_CSTRING("&key="), i1, i2))
|
||||
return NS_ERROR_FAILURE;
|
||||
// now c points to the key, and b points to the end of clientID
|
||||
// i1 points to the end of isStreamBased
|
||||
// i2 points to the start of key
|
||||
|
||||
streamBased = FindCharInReadable('1', i3, i1);
|
||||
key.Assign(Substring(i2, end));
|
||||
|
||||
clientID.Assign(Substring(a, b));
|
||||
key.Assign(Substring(c, end));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
private:
|
||||
nsresult WriteCacheEntryDescription(nsIOutputStream *, nsICacheEntryDescriptor *);
|
||||
nsresult WriteCacheEntryUnavailable(nsIOutputStream *, nsresult);
|
||||
nsresult ParseURI(nsCString &, nsCString &);
|
||||
nsresult ParseURI(nsCString &, PRBool &, nsCString &);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIChannel> mStreamChannel;
|
||||
|
Loading…
Reference in New Issue
Block a user