Change cache interfaces to use ACString for the key. Bug 277627, r+sr=darin.

This commit is contained in:
bryner%brianryner.com 2005-01-13 03:25:28 +00:00
Родитель ca8fdc6596
Коммит 6c4ea68040
26 изменённых файлов: 56 добавлений и 58 удалений

Просмотреть файл

@ -116,7 +116,7 @@ nsresult NeckoCacheHelper::ExistsInCache(const nsACString& inURI, PRBool* outExi
NS_ASSERTION(mCacheSession, "No cache session");
nsCOMPtr<nsICacheEntryDescriptor> entryDesc;
nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc));
nsresult rv = mCacheSession->OpenCacheEntry(inURI, nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc));
*outExists = NS_SUCCEEDED(rv) && (entryDesc != NULL);
return NS_OK;
@ -127,7 +127,7 @@ nsresult NeckoCacheHelper::PutInCache(const nsACString& inURI, PRUint32 inExpira
NS_ASSERTION(mCacheSession, "No cache session");
nsCOMPtr<nsICacheEntryDescriptor> entryDesc;
nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_WRITE, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc));
nsresult rv = mCacheSession->OpenCacheEntry(inURI, nsICache::ACCESS_WRITE, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc));
if (NS_FAILED(rv) || !entryDesc) return rv;
nsCacheAccessMode accessMode;

Просмотреть файл

@ -309,7 +309,7 @@ nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
// open a cache entry for this channel...
PRBool delayed = PR_FALSE;
nsresult rv = OpenCacheEntry(spec.get(), nsICache::ACCESS_READ, &delayed);
nsresult rv = OpenCacheEntry(spec, nsICache::ACCESS_READ, &delayed);
if (NS_FAILED(rv)) {
LOG(("nsWyciwygChannel::OpenCacheEntry failed [rv=%x]\n", rv));
return rv;
@ -346,7 +346,7 @@ nsWyciwygChannel::WriteToCacheEntry(const nsAString &aData)
nsCAutoString spec;
rv = mURI->GetAsciiSpec(spec);
if (NS_FAILED(rv)) return rv;
rv = OpenCacheEntry(spec.get(), nsICache::ACCESS_WRITE);
rv = OpenCacheEntry(spec, nsICache::ACCESS_WRITE);
if (NS_FAILED(rv)) return rv;
}
@ -511,7 +511,7 @@ nsWyciwygChannel::OnStopRequest(nsIRequest *request, nsISupports *ctx, nsresult
//////////////////////////////////////////////////////////////////////////////
nsresult
nsWyciwygChannel::OpenCacheEntry(const char * aCacheKey,
nsWyciwygChannel::OpenCacheEntry(const nsACString & aCacheKey,
nsCacheAccessMode aAccessMode,
PRBool * aDelayFlag)
{

Просмотреть файл

@ -82,7 +82,7 @@ public:
protected:
nsresult ReadFromCache();
nsresult OpenCacheEntry(const char * aCacheKey, nsCacheAccessMode aWriteAccess, PRBool * aDelayFlag = nsnull);
nsresult OpenCacheEntry(const nsACString & aCacheKey, nsCacheAccessMode aWriteAccess, PRBool * aDelayFlag = nsnull);
nsresult mStatus;
PRBool mIsPending;

Просмотреть файл

@ -7934,7 +7934,7 @@ nsresult nsImapMockChannel::OpenCacheEntry()
nsCAutoString cacheKey;
cacheKey.AppendInt(uidValidity, 16);
cacheKey.Append(urlSpec);
return cacheSession->AsyncOpenCacheEntry(cacheKey.get(), nsICache::ACCESS_READ_WRITE, this);
return cacheSession->AsyncOpenCacheEntry(cacheKey, nsICache::ACCESS_READ_WRITE, this);
}
nsresult nsImapMockChannel::ReadFromMemCache(nsICacheEntryDescriptor *entry)

Просмотреть файл

@ -1154,7 +1154,7 @@ mime_image_begin(const char *image_url, const char *content_type,
// we may need to convert the image_url into just a part url - in any case,
// it has to be the same as what imglib will be asking imap for later
// on so that we'll find this in the memory cache.
rv = memCacheSession->OpenCacheEntry(image_url, nsICache::ACCESS_READ_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
rv = memCacheSession->OpenCacheEntry(nsDependentCString(image_url), nsICache::ACCESS_READ_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
nsCacheAccessMode access;
if (entry)
{

Просмотреть файл

@ -920,7 +920,7 @@ nsresult nsNNTPProtocol::OpenCacheEntry()
char * anchor = (char *)strrchr(urlSpec.BeginWriting(), '?');
if (anchor)
*anchor = '\0';
return cacheSession->AsyncOpenCacheEntry(urlSpec.get(), nsICache::ACCESS_READ_WRITE, this);
return cacheSession->AsyncOpenCacheEntry(urlSpec, nsICache::ACCESS_READ_WRITE, this);
}
NS_IMETHODIMP nsNNTPProtocol::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)

Просмотреть файл

@ -194,7 +194,7 @@ PRBool imgCache::Put(nsIURI *aKey, imgRequest *request, nsICacheEntryDescriptor
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec.get(), nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;
@ -244,7 +244,7 @@ PRBool imgCache::Get(nsIURI *aKey, PRBool *aHasExpired, imgRequest **aRequest, n
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec.get(), nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;
@ -306,7 +306,7 @@ PRBool imgCache::Remove(nsIURI *aKey)
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec.get(), nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;

6
netwerk/cache/public/nsICacheSession.idl поставляемый
Просмотреть файл

@ -46,7 +46,7 @@
interface nsICacheEntryDescriptor;
interface nsICacheListener;
[scriptable, uuid(b4b419ad-28b7-4d25-9988-20fa98505a19)]
[scriptable, uuid(ae9e84b5-3e2d-457e-8fcd-5bbd2a8b832e)]
interface nsICacheSession : nsISupports
{
/**
@ -71,7 +71,7 @@ interface nsICacheSession : nsISupports
* return NS_ERROR_CACHE_WAIT_FOR_VALIDATION rather than block when another
* descriptor has been given WRITE access but hasn't validated the entry yet.
*/
nsICacheEntryDescriptor openCacheEntry(in string key,
nsICacheEntryDescriptor openCacheEntry(in ACString key,
in nsCacheAccessMode accessRequested,
in boolean blockingMode);
@ -80,7 +80,7 @@ interface nsICacheSession : nsISupports
* Instead, the listener will be notified when the descriptor is
* available.
*/
void asyncOpenCacheEntry(in string key,
void asyncOpenCacheEntry(in ACString key,
in nsCacheAccessMode accessRequested,
in nsICacheListener listener);

4
netwerk/cache/public/nsICacheVisitor.idl поставляемый
Просмотреть файл

@ -109,7 +109,7 @@ interface nsICacheDeviceInfo : nsISupports
};
[scriptable, uuid(72c64022-1dd2-11b2-b3a5-b8b859e0a1b2)]
[scriptable, uuid(fab51c92-95c3-4468-b317-7de4d7588254)]
interface nsICacheEntryInfo : nsISupports
{
/**
@ -125,7 +125,7 @@ interface nsICacheEntryInfo : nsISupports
/**
* Get the key identifying the cache entry.
*/
readonly attribute string key;
readonly attribute ACString key;
/**
* Get the number of times the cache entry has been opened.

7
netwerk/cache/src/nsCache.cpp поставляемый
Просмотреть файл

@ -131,10 +131,9 @@ ClientIDFromCacheKey(const nsACString& key, char ** result)
nsresult
ClientKeyFromCacheKey(const nsACString& key, char ** result)
ClientKeyFromCacheKey(const nsCString& key, nsACString &result)
{
nsresult rv = NS_OK;
*result = nsnull;
nsReadingIterator<char> start;
key.BeginReading(start);
@ -144,11 +143,11 @@ ClientKeyFromCacheKey(const nsACString& key, char ** result)
if (FindCharInReadable(':', start, end)) {
++start; // advance past clientID ':' delimiter
*result = ToNewCString( Substring(start, end));
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
result.Assign(Substring(start, end));
} else {
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
rv = NS_ERROR_UNEXPECTED;
result.Truncate(0);
}
return rv;
}

2
netwerk/cache/src/nsCache.h поставляемый
Просмотреть файл

@ -83,7 +83,7 @@ extern PRTime PRTimeFromSeconds(PRUint32 seconds);
extern nsresult ClientIDFromCacheKey(const nsACString& key, char ** result);
extern nsresult ClientKeyFromCacheKey(const nsACString& key, char ** result);
extern nsresult ClientKeyFromCacheKey(const nsCString& key, nsACString &result);
#endif // _nsCache_h

3
netwerk/cache/src/nsCacheEntry.cpp поставляемый
Просмотреть файл

@ -305,9 +305,8 @@ nsCacheEntryInfo::GetDeviceID(char ** deviceID)
NS_IMETHODIMP
nsCacheEntryInfo::GetKey(char ** key)
nsCacheEntryInfo::GetKey(nsACString &key)
{
NS_ENSURE_ARG_POINTER(key);
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
return ClientKeyFromCacheKey(*mCacheEntry->Key(), key);

Просмотреть файл

@ -94,9 +94,8 @@ nsCacheEntryDescriptor::GetDeviceID(char ** result)
NS_IMETHODIMP
nsCacheEntryDescriptor::GetKey(char ** result)
nsCacheEntryDescriptor::GetKey(nsACString &result)
{
NS_ENSURE_ARG_POINTER(result);
nsAutoLock lock(nsCacheService::ServiceLock());
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;

4
netwerk/cache/src/nsCacheService.cpp поставляемый
Просмотреть файл

@ -726,7 +726,7 @@ nsCacheService::CreateMemoryDevice()
nsresult
nsCacheService::CreateRequest(nsCacheSession * session,
const char * clientKey,
const nsACString & clientKey,
nsCacheAccessMode accessRequested,
PRBool blockingMode,
nsICacheListener * listener,
@ -849,7 +849,7 @@ nsCacheService::ProcessRequest(nsCacheRequest * request,
nsresult
nsCacheService::OpenCacheEntry(nsCacheSession * session,
const char * key,
const nsACString & key,
nsCacheAccessMode accessRequested,
PRBool blockingMode,
nsICacheListener * listener,

4
netwerk/cache/src/nsCacheService.h поставляемый
Просмотреть файл

@ -83,7 +83,7 @@ public:
* Methods called by nsCacheSession
*/
static nsresult OpenCacheEntry(nsCacheSession * session,
const char * key,
const nsACString & key,
nsCacheAccessMode accessRequested,
PRBool blockingMode,
nsICacheListener * listener,
@ -159,7 +159,7 @@ private:
nsresult CreateMemoryDevice();
nsresult CreateRequest(nsCacheSession * session,
const char * clientKey,
const nsACString & clientKey,
nsCacheAccessMode accessRequested,
PRBool blockingMode,
nsICacheListener * listener,

4
netwerk/cache/src/nsCacheSession.cpp поставляемый
Просмотреть файл

@ -84,7 +84,7 @@ NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(PRBool doomEntriesIfExpire
NS_IMETHODIMP
nsCacheSession::OpenCacheEntry(const char * key,
nsCacheSession::OpenCacheEntry(const nsACString & key,
nsCacheAccessMode accessRequested,
PRBool blockingMode,
nsICacheEntryDescriptor ** result)
@ -100,7 +100,7 @@ nsCacheSession::OpenCacheEntry(const char * key,
}
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key,
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const nsACString & key,
nsCacheAccessMode accessRequested,
nsICacheListener *listener)
{

6
netwerk/cache/src/nsDiskCacheDeviceSQL.cpp поставляемый
Просмотреть файл

@ -465,10 +465,10 @@ nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
}
NS_IMETHODIMP
nsDiskCacheEntryInfo::GetKey(char ** clientKey)
nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
{
*clientKey = nsCRT::strdup(mRec->key);
return *clientKey ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
clientKey.Assign(mRec->key);
return NS_OK;
}
NS_IMETHODIMP

3
netwerk/cache/src/nsDiskCacheEntry.cpp поставляемый
Просмотреть файл

@ -177,9 +177,8 @@ NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
}
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(char ** clientKey)
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
{
NS_ENSURE_ARG_POINTER(clientKey);
return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->mKeyStart), clientKey);
}

Просмотреть файл

@ -224,11 +224,11 @@ nsAboutCache::VisitEntry(const char *deviceID,
{
nsresult rv;
PRUint32 bytesWritten;
nsXPIDLCString key;
nsCAutoString key;
nsXPIDLCString clientID;
PRBool streamBased;
rv = entryInfo->GetKey(getter_Copies(key));
rv = entryInfo->GetKey(key);
if (NS_FAILED(rv)) return rv;
rv = entryInfo->GetClientID(getter_Copies(clientID));
@ -244,7 +244,7 @@ nsAboutCache::VisitEntry(const char *deviceID,
url.AppendLiteral("&amp;sb=");
url += streamBased ? '1' : '0';
url.AppendLiteral("&amp;key=");
char* escapedKey = nsEscapeHTML(key);
char* escapedKey = nsEscapeHTML(key.get());
url += escapedKey; // key
// Entry start...

Просмотреть файл

@ -343,7 +343,7 @@ nsAboutCacheEntry::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
mListener = listener;
mListenerContext = context;
return mCacheSession->AsyncOpenCacheEntry(key.get(), nsICache::ACCESS_READ, this);
return mCacheSession->AsyncOpenCacheEntry(key, nsICache::ACCESS_READ, this);
}
@ -384,9 +384,9 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream,
nsCString buffer;
PRUint32 n;
nsXPIDLCString str;
nsCAutoString str;
rv = descriptor->GetKey(getter_Copies(str));
rv = descriptor->GetKey(str);
if (NS_FAILED(rv)) return rv;
buffer.SetCapacity(4096);
@ -405,7 +405,7 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream,
uri->SchemeIs("javascript", &isJS);
uri->SchemeIs("data", &isData);
}
char* escapedStr = nsEscapeHTML(str);
char* escapedStr = nsEscapeHTML(str.get());
if (NS_SUCCEEDED(rv) && !(isJS || isData)) {
buffer.AppendLiteral("<a href=\"");
buffer.Append(escapedStr);
@ -497,9 +497,9 @@ nsAboutCacheEntry::WriteCacheEntryDescription(nsIOutputStream *outputStream,
// let's just look for some well known (HTTP) meta data tags, for now.
// Client ID
str.Truncate();
descriptor->GetClientID(getter_Copies(str));
if (!str.IsEmpty()) APPEND_ROW("Client", str);
nsXPIDLCString str2;
descriptor->GetClientID(getter_Copies(str2));
if (!str2.IsEmpty()) APPEND_ROW("Client", str2);
mBuffer = &buffer; // make it available for VisitMetaDataElement()

Просмотреть файл

@ -360,7 +360,7 @@ nsFTPChannel::AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
nsCAutoString cacheKey;
GenerateCacheKey(cacheKey);
rv = mCacheSession->AsyncOpenCacheEntry(cacheKey.get(),
rv = mCacheSession->AsyncOpenCacheEntry(cacheKey,
accessRequested,
this);
if (NS_SUCCEEDED(rv))

Просмотреть файл

@ -1206,11 +1206,11 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
// we'll try to synchronously open the cache entry... however, it may be
// in use and not yet validated, in which case we'll try asynchronously
// opening the cache entry.
rv = session->OpenCacheEntry(cacheKey.get(), accessRequested, PR_FALSE,
rv = session->OpenCacheEntry(cacheKey, accessRequested, PR_FALSE,
getter_AddRefs(mCacheEntry));
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
// access to the cache entry has been denied
rv = session->AsyncOpenCacheEntry(cacheKey.get(), accessRequested, this);
rv = session->AsyncOpenCacheEntry(cacheKey, accessRequested, this);
if (NS_FAILED(rv)) return rv;
// we'll have to wait for the cache entry
*delayed = PR_TRUE;

Просмотреть файл

@ -112,16 +112,18 @@ TestMemoryObjectCache()
// Test ACCESS_READ for non-existent entry
printf("\nTest ACCESS_READ:\n");
rv = session->OpenCacheEntry("non-existent entry",
rv = session->OpenCacheEntry(NS_LITERAL_CSTRING("non-existent entry"),
nsICache::ACCESS_READ,
nsICache::BLOCKING,
getter_AddRefs(descriptor));
if (rv != NS_ERROR_CACHE_KEY_NOT_FOUND)
printf("OpenCacheEntry(ACCESS_READ) returned: %x for non-existent entry\n", rv);
NS_NAMED_LITERAL_CSTRING(cacheKey, "http://www.mozilla.org/somekey");
// Test creating new entry
printf("\nTest ACCESS_READ_WRITE:\n");
rv = session->OpenCacheEntry("http://www.mozilla.org/somekey",
rv = session->OpenCacheEntry(cacheKey,
nsICache::ACCESS_READ_WRITE,
nsICache::BLOCKING,
getter_AddRefs(descriptor));
@ -142,7 +144,7 @@ TestMemoryObjectCache()
// Test refetching entry
rv = session->OpenCacheEntry("http://www.mozilla.org/somekey",
rv = session->OpenCacheEntry(cacheKey,
nsICache::ACCESS_READ_WRITE,
nsICache::BLOCKING,
getter_AddRefs(descriptor));
@ -167,7 +169,7 @@ TestMemoryObjectCache()
// Test ACCESS_WRITE entry
printf("\nTest ACCESS_WRITE:\n");
rv = session->OpenCacheEntry("http://www.mozilla.org/somekey",
rv = session->OpenCacheEntry(cacheKey,
nsICache::ACCESS_WRITE,
nsICache::BLOCKING,
getter_AddRefs(descriptor));

Просмотреть файл

@ -167,7 +167,7 @@ nsresult TestMCTransport(const char *filename)
&session);
if (NS_FAILED(rv)) return rv;
rv = session->OpenCacheEntry(filename,
rv = session->OpenCacheEntry(nsDependentCString(filename),
nsICache::ACCESS_READ_WRITE,
nsICache::BLOCKING,
&desc);

Просмотреть файл

@ -353,7 +353,7 @@ nsSound::GetSoundFromCache(nsIURI* inURI, nsISupports** outSound)
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = cacheSession->OpenCacheEntry(uriSpec.get(), nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
rv = cacheSession->OpenCacheEntry(uriSpec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
#ifdef SOUND_DEBUG
printf("Got sound from cache with rv %ld\n", rv);
@ -385,7 +385,7 @@ nsSound::PutSoundInCache(nsIChannel* inChannel, PRUint32 inDataSize, nsISupports
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = cacheSession->OpenCacheEntry(uriSpec.get(), nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
rv = cacheSession->OpenCacheEntry(uriSpec, nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
#ifdef SOUND_DEBUG
printf("Put sound in cache with rv %ld\n", rv);
#endif

Просмотреть файл

@ -4136,7 +4136,7 @@ nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
return NS_RDF_NO_VALUE;
}
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = mCacheSession->OpenCacheEntry(path.get(), nsICache::ACCESS_READ,
rv = mCacheSession->OpenCacheEntry(path, nsICache::ACCESS_READ,
nsICache::NON_BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || (!entry))
{