This commit is contained in:
Michal Novotny 2010-06-21 20:14:58 -07:00
Родитель e33497cdb2
Коммит da56414e71
8 изменённых файлов: 355 добавлений и 169 удалений

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

@ -54,6 +54,7 @@ class nsCacheRequest : public PRCList
private:
friend class nsCacheService;
friend class nsCacheEntry;
friend class nsProcessRequestEvent;
nsCacheRequest( nsCString * key,
nsICacheListener * listener,

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

@ -614,6 +614,45 @@ nsCacheProfilePrefObserver::MemoryCacheCapacity()
return capacity;
}
/******************************************************************************
* nsProcessRequestEvent
*****************************************************************************/
class nsProcessRequestEvent : public nsRunnable {
public:
nsProcessRequestEvent(nsCacheRequest *aRequest)
{
mRequest = aRequest;
}
NS_IMETHOD Run()
{
nsresult rv;
NS_ASSERTION(mRequest->mListener,
"Sync OpenCacheEntry() posted to background thread!");
nsCacheServiceAutoLock lock;
rv = nsCacheService::gService->ProcessRequest(mRequest,
PR_FALSE,
nsnull);
// Don't delete the request if it was queued
if (rv != NS_ERROR_CACHE_WAIT_FOR_VALIDATION)
delete mRequest;
return NS_OK;
}
protected:
virtual ~nsProcessRequestEvent() {}
private:
nsCacheRequest *mRequest;
};
/******************************************************************************
* nsCacheService
*****************************************************************************/
@ -681,8 +720,13 @@ nsCacheService::Init()
CACHE_LOG_INIT();
nsresult rv = NS_NewThread(getter_AddRefs(mCacheIOThread));
if (NS_FAILED(rv)) {
NS_WARNING("Can't create cache IO thread");
}
// initialize hashtable for active cache entries
nsresult rv = mActiveEntries.Init();
rv = mActiveEntries.Init();
if (NS_FAILED(rv)) return rv;
// create profile/preference observer
@ -735,6 +779,11 @@ nsCacheService::Shutdown()
LogCacheStatistics();
#endif
}
if (mCacheIOThread) {
mCacheIOThread->Shutdown();
mCacheIOThread = nsnull;
}
}
@ -947,6 +996,17 @@ NS_IMETHODIMP nsCacheService::EvictEntries(nsCacheStoragePolicy storagePolicy)
return EvictEntriesForClient(nsnull, storagePolicy);
}
NS_IMETHODIMP nsCacheService::GetCacheIOTarget(nsIEventTarget * *aCacheIOTarget)
{
nsCacheServiceAutoLock lock;
if (!mCacheIOThread)
return NS_ERROR_NOT_AVAILABLE;
NS_ADDREF(*aCacheIOTarget = mCacheIOThread);
return NS_OK;
}
/**
* Internal Methods
*/
@ -1235,11 +1295,28 @@ nsCacheService::OpenCacheEntry(nsCacheSession * session,
CACHE_LOG_DEBUG(("Created request %p\n", request));
rv = gService->ProcessRequest(request, PR_TRUE, result);
// Process the request on the background thread if we are on the main thread
// and the the request is asynchronous
if (NS_IsMainThread() && listener && gService->mCacheIOThread) {
nsCOMPtr<nsIRunnable> ev =
new nsProcessRequestEvent(request);
if (ev) {
rv = gService->mCacheIOThread->Dispatch(ev, NS_DISPATCH_NORMAL);
} else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
// delete requests that have completed
if (!(listener && (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION)))
delete request;
// delete request if we didn't post the event
if (NS_FAILED(rv))
delete request;
}
else {
rv = gService->ProcessRequest(request, PR_TRUE, result);
// delete requests that have completed
if (!(listener && (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION)))
delete request;
}
return rv;
}
@ -1779,7 +1856,7 @@ nsCacheService::ReleaseObject_Locked(nsISupports * obj,
NS_ASSERTION(gService->mLockedThread == PR_GetCurrentThread(), "oops");
PRBool isCur;
if (!target || NS_SUCCEEDED(target->IsOnCurrentThread(&isCur)) && isCur) {
if (!target || (NS_SUCCEEDED(target->IsOnCurrentThread(&isCur)) && isCur)) {
gService->mDoomedObjects.AppendElement(obj);
} else {
NS_ProxyRelease(target, obj);

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

@ -166,6 +166,7 @@ public:
private:
friend class nsCacheServiceAutoLock;
friend class nsOfflineCacheDevice;
friend class nsProcessRequestEvent;
/**
* Internal Methods
@ -245,6 +246,8 @@ private:
PRThread * mLockedThread; // The thread holding mLock
#endif
nsCOMPtr<nsIThread> mCacheIOThread;
nsTArray<nsISupports*> mDoomedObjects;
PRBool mInitialized;

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

@ -47,8 +47,9 @@ interface nsISimpleEnumerator;
interface nsICacheListener;
interface nsICacheSession;
interface nsICacheVisitor;
interface nsIEventTarget;
[scriptable, uuid(de114eb4-29fc-4959-b2f7-2d03eb9bc771)]
[scriptable, uuid(14dbe1e9-f3bc-45af-92f4-2c574fcd4e39)]
interface nsICacheService : nsISupports
{
/**
@ -87,6 +88,11 @@ interface nsICacheService : nsISupports
* everything.
*/
void evictEntries(in nsCacheStoragePolicy storagePolicy);
/**
* Event target which is used for I/O operations
*/
readonly attribute nsIEventTarget cacheIOTarget;
};
%{C++

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

@ -105,6 +105,8 @@ nsHttpChannel::nsHttpChannel()
, mCacheAccess(0)
, mPostID(0)
, mRequestTime(0)
, mOnCacheEntryAvailableCallback(nsnull)
, mAsyncCacheOpen(PR_FALSE)
, mStartPos(LL_MAXUINT)
, mPendingAsyncCallOnResume(nsnull)
, mSuspendCount(0)
@ -274,8 +276,6 @@ nsHttpChannel::Connect(PRBool firstTime)
// true when called from AsyncOpen
if (firstTime) {
PRBool delayed = PR_FALSE;
// are we offline?
PRBool offline = gIOService->IsOffline();
if (offline)
@ -290,7 +290,7 @@ nsHttpChannel::Connect(PRBool firstTime)
}
// open a cache entry for this channel...
rv = OpenCacheEntry(offline, &delayed);
rv = OpenCacheEntry();
if (NS_FAILED(rv)) {
LOG(("OpenCacheEntry failed [rv=%x]\n", rv));
@ -314,7 +314,7 @@ nsHttpChannel::Connect(PRBool firstTime)
if (NS_FAILED(rv)) return rv;
}
if (NS_SUCCEEDED(rv) && delayed)
if (NS_SUCCEEDED(rv) && mAsyncCacheOpen)
return NS_OK;
}
@ -1645,11 +1645,11 @@ IsSubRangeRequest(nsHttpRequestHead &aRequestHead)
}
nsresult
nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
nsHttpChannel::OpenCacheEntry()
{
nsresult rv;
*delayed = PR_FALSE;
mAsyncCacheOpen = PR_FALSE;
mLoadedFromApplicationCache = PR_FALSE;
LOG(("nsHttpChannel::OpenCacheEntry [this=%p]", this));
@ -1685,23 +1685,10 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
GenerateCacheKey(mPostID, cacheKey);
// Get a cache session with appropriate storage policy
nsCacheStoragePolicy storagePolicy = DetermineStoragePolicy();
// Set the desired cache access mode accordingly...
nsCacheAccessMode accessRequested;
if (offline || (mLoadFlags & INHIBIT_CACHING)) {
// If we have been asked to bypass the cache and not write to the
// cache, then don't use the cache at all. Unless we're actually
// offline, which takes precedence over BYPASS_LOCAL_CACHE.
if (BYPASS_LOCAL_CACHE(mLoadFlags) && !offline)
return NS_ERROR_NOT_AVAILABLE;
accessRequested = nsICache::ACCESS_READ;
}
else if (BYPASS_LOCAL_CACHE(mLoadFlags))
accessRequested = nsICache::ACCESS_WRITE; // replace cache entry
else
accessRequested = nsICache::ACCESS_READ_WRITE; // normal browsing
rv = DetermineCacheAccess(&accessRequested);
if NS_FAILED(rv) return rv;
if (!mApplicationCache && mInheritApplicationCache) {
// Pick up an application cache from the notification
@ -1730,10 +1717,6 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
nsCOMPtr<nsICacheSession> session;
// Will be set to true if we've found the right session, but need
// to open the cache entry asynchronously.
PRBool waitingForValidation = PR_FALSE;
// If we have an application cache, we check it first.
if (mApplicationCache) {
nsCAutoString appCacheClientID;
@ -1749,107 +1732,217 @@ nsHttpChannel::OpenCacheEntry(PRBool offline, PRBool *delayed)
getter_AddRefs(session));
NS_ENSURE_SUCCESS(rv, rv);
// 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.
//
// We open with ACCESS_READ only, because we don't want to
// overwrite the offline cache entry non-atomically.
// ACCESS_READ will prevent us from writing to the offline
// cache as a normal cache entry.
rv = session->OpenCacheEntry(cacheKey,
nsICache::ACCESS_READ, PR_FALSE,
getter_AddRefs(mCacheEntry));
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
accessRequested = nsICache::ACCESS_READ;
waitingForValidation = PR_TRUE;
rv = NS_OK;
if (mLoadFlags & LOAD_BYPASS_LOCAL_CACHE_IF_BUSY) {
// must use synchronous open for LOAD_BYPASS_LOCAL_CACHE_IF_BUSY
rv = session->OpenCacheEntry(cacheKey,
nsICache::ACCESS_READ, PR_FALSE,
getter_AddRefs(mCacheEntry));
if (NS_SUCCEEDED(rv)) {
mCacheEntry->GetAccessGranted(&mCacheAccess);
LOG(("nsHttpChannel::OpenCacheEntry [this=%p grantedAccess=%d]",
this, mCacheAccess));
mLoadedFromApplicationCache = PR_TRUE;
return NS_OK;
} else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
LOG(("bypassing local cache since it is busy\n"));
// Don't try to load normal cache entry
return NS_ERROR_NOT_AVAILABLE;
}
} else {
mOnCacheEntryAvailableCallback =
&nsHttpChannel::OnOfflineCacheEntryAvailable;
// We open with ACCESS_READ only, because we don't want to
// overwrite the offline cache entry non-atomically.
// ACCESS_READ will prevent us from writing to the offline
// cache as a normal cache entry.
rv = session->AsyncOpenCacheEntry(cacheKey,
nsICache::ACCESS_READ,
this);
if (NS_SUCCEEDED(rv)) {
mAsyncCacheOpen = PR_TRUE;
return NS_OK;
}
}
if (NS_FAILED(rv) && !mCacheForOfflineUse && !mFallbackChannel) {
// Check for namespace match.
nsCOMPtr<nsIApplicationCacheNamespace> namespaceEntry;
rv = mApplicationCache->GetMatchingNamespace
(cacheKey, getter_AddRefs(namespaceEntry));
// sync or async opening failed
return OnOfflineCacheEntryAvailable(nsnull, nsICache::ACCESS_NONE,
rv, PR_TRUE);
}
return OpenNormalCacheEntry(PR_TRUE);
}
nsresult
nsHttpChannel::OnOfflineCacheEntryAvailable(nsICacheEntryDescriptor *aEntry,
nsCacheAccessMode aAccess,
nsresult aEntryStatus,
PRBool aIsSync)
{
nsresult rv;
if (NS_SUCCEEDED(aEntryStatus)) {
// We successfully opened an offline cache session and the entry,
// so indicate we will load from the offline cache.
mLoadedFromApplicationCache = PR_TRUE;
mCacheEntry = aEntry;
mCacheAccess = aAccess;
}
if (mCanceled && NS_FAILED(mStatus)) {
LOG(("channel was canceled [this=%p status=%x]\n", this, mStatus));
return mStatus;
}
if (NS_SUCCEEDED(aEntryStatus))
// Called from OnCacheEntryAvailable, advance to the next state
return Connect(PR_FALSE);
if (!mCacheForOfflineUse && !mFallbackChannel) {
nsCAutoString cacheKey;
GenerateCacheKey(mPostID, cacheKey);
// Check for namespace match.
nsCOMPtr<nsIApplicationCacheNamespace> namespaceEntry;
rv = mApplicationCache->GetMatchingNamespace
(cacheKey, getter_AddRefs(namespaceEntry));
if (NS_FAILED(rv) && !aIsSync)
return Connect(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 namespaceType = 0;
if (!namespaceEntry ||
NS_FAILED(namespaceEntry->GetItemType(&namespaceType)) ||
(namespaceType &
(nsIApplicationCacheNamespace::NAMESPACE_FALLBACK |
nsIApplicationCacheNamespace::NAMESPACE_OPPORTUNISTIC |
nsIApplicationCacheNamespace::NAMESPACE_BYPASS)) == 0) {
// When loading from an application cache, only items
// on the whitelist or matching a
// fallback/opportunistic namespace should hit the
// network...
mLoadFlags |= LOAD_ONLY_FROM_CACHE;
// ... and if there were an application cache entry,
// we would have found it earlier.
return aIsSync ? NS_ERROR_CACHE_KEY_NOT_FOUND : Connect(PR_FALSE);
}
if (namespaceType &
nsIApplicationCacheNamespace::NAMESPACE_FALLBACK) {
rv = namespaceEntry->GetData(mFallbackKey);
if (NS_FAILED(rv) && !aIsSync)
return Connect(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 namespaceType = 0;
if (!namespaceEntry ||
NS_FAILED(namespaceEntry->GetItemType(&namespaceType)) ||
(namespaceType &
(nsIApplicationCacheNamespace::NAMESPACE_FALLBACK |
nsIApplicationCacheNamespace::NAMESPACE_OPPORTUNISTIC |
nsIApplicationCacheNamespace::NAMESPACE_BYPASS)) == 0) {
// When loading from an application cache, only items
// on the whitelist or matching a
// fallback/opportunistic namespace should hit the
// network...
mLoadFlags |= LOAD_ONLY_FROM_CACHE;
// ... and if there were an application cache entry,
// we would have found it earlier.
return NS_ERROR_CACHE_KEY_NOT_FOUND;
}
if (namespaceType &
nsIApplicationCacheNamespace::NAMESPACE_FALLBACK) {
rv = namespaceEntry->GetData(mFallbackKey);
NS_ENSURE_SUCCESS(rv, rv);
}
if ((namespaceType &
nsIApplicationCacheNamespace::NAMESPACE_OPPORTUNISTIC) &&
mLoadFlags & LOAD_DOCUMENT_URI) {
// Document loads for items in an opportunistic namespace
// should be placed in the offline cache.
nsCString clientID;
mApplicationCache->GetClientID(clientID);
mCacheForOfflineUse = !clientID.IsEmpty();
SetOfflineCacheClientID(clientID);
mCachingOpportunistically = PR_TRUE;
}
}
else if (NS_SUCCEEDED(rv)) {
// We successfully opened an offline cache session and the entry,
// now indiciate we load from the offline cache.
mLoadedFromApplicationCache = PR_TRUE;
if ((namespaceType &
nsIApplicationCacheNamespace::NAMESPACE_OPPORTUNISTIC) &&
mLoadFlags & LOAD_DOCUMENT_URI) {
// Document loads for items in an opportunistic namespace
// should be placed in the offline cache.
nsCString clientID;
mApplicationCache->GetClientID(clientID);
mCacheForOfflineUse = !clientID.IsEmpty();
SetOfflineCacheClientID(clientID);
mCachingOpportunistically = PR_TRUE;
}
}
if (!mCacheEntry && !waitingForValidation) {
rv = gHttpHandler->GetCacheSession(storagePolicy,
getter_AddRefs(session));
if (NS_FAILED(rv)) return rv;
return OpenNormalCacheEntry(aIsSync);
}
nsresult
nsHttpChannel::OpenNormalCacheEntry(PRBool aIsSync)
{
NS_ASSERTION(!mCacheEntry, "We have already mCacheEntry");
nsresult rv;
nsCAutoString cacheKey;
GenerateCacheKey(mPostID, cacheKey);
nsCacheStoragePolicy storagePolicy = DetermineStoragePolicy();
nsCOMPtr<nsICacheSession> session;
rv = gHttpHandler->GetCacheSession(storagePolicy,
getter_AddRefs(session));
if (NS_FAILED(rv)) return rv;
nsCacheAccessMode accessRequested;
rv = DetermineCacheAccess(&accessRequested);
if NS_FAILED(rv) return rv;
if (mLoadFlags & LOAD_BYPASS_LOCAL_CACHE_IF_BUSY) {
if (!aIsSync) {
// Unexpected state: we were called from OnCacheEntryAvailable(),
// so LOAD_BYPASS_LOCAL_CACHE_IF_BUSY shouldn't be set. Unless
// somebody altered mLoadFlags between OpenCacheEntry() and
// OnCacheEntryAvailable()...
NS_WARNING(
"OpenNormalCacheEntry() called from OnCacheEntryAvailable() "
"when LOAD_BYPASS_LOCAL_CACHE_IF_BUSY was specified");
}
// must use synchronous open for LOAD_BYPASS_LOCAL_CACHE_IF_BUSY
rv = session->OpenCacheEntry(cacheKey, accessRequested, PR_FALSE,
getter_AddRefs(mCacheEntry));
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
waitingForValidation = PR_TRUE;
rv = NS_OK;
if (NS_SUCCEEDED(rv)) {
mCacheEntry->GetAccessGranted(&mCacheAccess);
LOG(("nsHttpChannel::OpenCacheEntry [this=%p grantedAccess=%d]",
this, mCacheAccess));
}
else if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) {
LOG(("bypassing local cache since it is busy\n"));
rv = NS_ERROR_NOT_AVAILABLE;
}
}
else {
mOnCacheEntryAvailableCallback =
&nsHttpChannel::OnNormalCacheEntryAvailable;
rv = session->AsyncOpenCacheEntry(cacheKey, accessRequested, this);
if (NS_SUCCEEDED(rv)) {
mAsyncCacheOpen = PR_TRUE;
return NS_OK;
}
if (NS_FAILED(rv)) return rv;
}
if (waitingForValidation) {
// access to the cache entry has been denied (because the
// cache entry is probably in use by another channel).
if (mLoadFlags & LOAD_BYPASS_LOCAL_CACHE_IF_BUSY) {
LOG(("bypassing local cache since it is busy\n"));
return NS_ERROR_NOT_AVAILABLE;
}
rv = session->AsyncOpenCacheEntry(cacheKey, accessRequested, this);
if (NS_FAILED(rv)) return rv;
// we'll have to wait for the cache entry
*delayed = PR_TRUE;
}
else if (NS_SUCCEEDED(rv)) {
mCacheEntry->GetAccessGranted(&mCacheAccess);
LOG(("nsHttpChannel::OpenCacheEntry [this=%p grantedAccess=%d]", this, mCacheAccess));
}
if (!aIsSync)
// Called from OnCacheEntryAvailable, advance to the next state
rv = Connect(PR_FALSE);
return rv;
}
nsresult
nsHttpChannel::OnNormalCacheEntryAvailable(nsICacheEntryDescriptor *aEntry,
nsCacheAccessMode aAccess,
nsresult aEntryStatus,
PRBool aIsSync)
{
NS_ASSERTION(!aIsSync, "aIsSync should be false");
if (NS_SUCCEEDED(aEntryStatus)) {
mCacheEntry = aEntry;
mCacheAccess = aAccess;
}
if (mCanceled && NS_FAILED(mStatus)) {
LOG(("channel was canceled [this=%p status=%x]\n", this, mStatus));
return mStatus;
}
if ((mLoadFlags & LOAD_ONLY_FROM_CACHE) && NS_FAILED(aEntryStatus))
// if this channel is only allowed to pull from the cache, then
// we must fail if we were unable to open a cache entry.
return NS_ERROR_DOCUMENT_NOT_CACHED;
// advance to the next state...
return Connect(PR_FALSE);
}
nsresult
nsHttpChannel::OpenOfflineCacheEntryForWriting()
@ -2683,20 +2776,26 @@ nsHttpChannel::InstallCacheListener(PRUint32 offset)
do_CreateInstance(kStreamListenerTeeCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventTarget> cacheIOTarget;
serv->GetCacheIOTarget(getter_AddRefs(cacheIOTarget));
nsCacheStoragePolicy policy;
rv = mCacheEntry->GetStoragePolicy(&policy);
if (!gHttpHandler->mCacheWriteThread ||
NS_FAILED(rv) ||
policy == nsICache::STORE_ON_DISK_AS_FILE) {
LOG(("nsHttpChannel::InstallCacheListener sync tee %p\n", tee.get()));
if (NS_FAILED(rv) || policy == nsICache::STORE_ON_DISK_AS_FILE ||
!cacheIOTarget) {
LOG(("nsHttpChannel::InstallCacheListener sync tee %p rv=%x policy=%d "
"cacheIOTarget=%p", tee.get(), rv, policy, cacheIOTarget.get()));
rv = tee->Init(mListener, out, nsnull);
} else {
LOG(("nsHttpChannel::InstallCacheListener async tee %p\n",
tee.get()));
rv = tee->InitAsync(mListener, gHttpHandler->mCacheWriteThread, out, nsnull);
LOG(("nsHttpChannel::InstallCacheListener async tee %p", tee.get()));
rv = tee->InitAsync(mListener, cacheIOTarget, out, nsnull);
}
if (NS_FAILED(rv)) return rv;
mListener = tee;
return NS_OK;
@ -4770,6 +4869,8 @@ nsHttpChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry,
nsCacheAccessMode access,
nsresult status)
{
nsresult rv;
LOG(("nsHttpChannel::OnCacheEntryAvailable [this=%p entry=%p "
"access=%x status=%x]\n", this, entry, access, status));
@ -4778,27 +4879,12 @@ nsHttpChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry,
if (!mIsPending)
return NS_OK;
// otherwise, we have to handle this event.
if (NS_SUCCEEDED(status)) {
mCacheEntry = entry;
mCacheAccess = access;
}
nsOnCacheEntryAvailableCallback callback = mOnCacheEntryAvailableCallback;
mOnCacheEntryAvailableCallback = nsnull;
nsresult rv;
if (mCanceled && NS_FAILED(mStatus)) {
LOG(("channel was canceled [this=%p status=%x]\n", this, mStatus));
rv = mStatus;
}
else if ((mLoadFlags & LOAD_ONLY_FROM_CACHE) && NS_FAILED(status))
// if this channel is only allowed to pull from the cache, then
// we must fail if we were unable to open a cache entry.
rv = NS_ERROR_DOCUMENT_NOT_CACHED;
else
// advance to the next state...
rv = Connect(PR_FALSE);
// a failure from Connect means that we have to abort the channel.
NS_ASSERTION(callback,
"nsHttpChannel::OnCacheEntryAvailable called without callback");
rv = ((*this).*callback)(entry, access, status, PR_FALSE);
if (NS_FAILED(rv)) {
CloseCacheEntry(PR_TRUE);
AsyncAbort(rv);
@ -5166,6 +5252,27 @@ nsHttpChannel::DetermineStoragePolicy()
return policy;
}
nsresult
nsHttpChannel::DetermineCacheAccess(nsCacheAccessMode *_retval)
{
PRBool offline = gIOService->IsOffline();
if (offline || (mLoadFlags & INHIBIT_CACHING)) {
// If we have been asked to bypass the cache and not write to the
// cache, then don't use the cache at all. Unless we're actually
// offline, which takes precedence over BYPASS_LOCAL_CACHE.
if (BYPASS_LOCAL_CACHE(mLoadFlags) && !offline)
return NS_ERROR_NOT_AVAILABLE;
*_retval = nsICache::ACCESS_READ;
}
else if (BYPASS_LOCAL_CACHE(mLoadFlags))
*_retval = nsICache::ACCESS_WRITE; // replace cache entry
else
*_retval = nsICache::ACCESS_READ_WRITE; // normal browsing
return NS_OK;
}
void
nsHttpChannel::AsyncOnExamineCachedResponse()
{

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

@ -206,7 +206,16 @@ private:
nsresult ResolveProxy();
// cache specific methods
nsresult OpenCacheEntry(PRBool offline, PRBool *delayed);
nsresult OpenCacheEntry();
nsresult OnOfflineCacheEntryAvailable(nsICacheEntryDescriptor *aEntry,
nsCacheAccessMode aAccess,
nsresult aResult,
PRBool aSync);
nsresult OpenNormalCacheEntry(PRBool aSync);
nsresult OnNormalCacheEntryAvailable(nsICacheEntryDescriptor *aEntry,
nsCacheAccessMode aAccess,
nsresult aResult,
PRBool aSync);
nsresult OpenOfflineCacheEntryForWriting();
nsresult GenerateCacheKey(PRUint32 postID, nsACString &key);
nsresult UpdateExpirationTime();
@ -224,6 +233,7 @@ private:
nsresult InstallOfflineCacheListener();
void MaybeInvalidateCacheEntryForSubsequentGet();
nsCacheStoragePolicy DetermineStoragePolicy();
nsresult DetermineCacheAccess(nsCacheAccessMode *_retval);
void AsyncOnExamineCachedResponse();
// Handle the bogus Content-Encoding Apache sometimes sends
@ -279,6 +289,11 @@ private:
PRUint32 mPostID;
PRUint32 mRequestTime;
typedef nsresult (nsHttpChannel:: *nsOnCacheEntryAvailableCallback)(
nsICacheEntryDescriptor *, nsCacheAccessMode, nsresult, PRBool);
nsOnCacheEntryAvailableCallback mOnCacheEntryAvailableCallback;
PRBool mAsyncCacheOpen;
nsCOMPtr<nsICacheEntryDescriptor> mOfflineCacheEntry;
nsCacheAccessMode mOfflineCacheAccess;
nsCString mOfflineCacheClientID;

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

@ -275,14 +275,6 @@ nsHttpHandler::Init()
rv = InitConnectionMgr();
if (NS_FAILED(rv)) return rv;
rv = NS_NewThread(getter_AddRefs(mCacheWriteThread));
if (NS_FAILED(rv)) {
mCacheWriteThread = nsnull;
LOG(("Failed creating cache-write thread - writes will be synchronous"));
} else {
LOG(("Created cache-write thread = %p", mCacheWriteThread.get()));
}
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1");
if (appInfo)
@ -302,7 +294,6 @@ nsHttpHandler::Init()
mObserverService->AddObserver(this, "profile-change-net-restore", PR_TRUE);
mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
mObserverService->AddObserver(this, "net:clear-active-logins", PR_TRUE);
mObserverService->AddObserver(this, "xpcom-shutdown-threads", PR_TRUE);
}
StartPruneDeadConnectionsTimer();
@ -1804,18 +1795,6 @@ nsHttpHandler::Observe(nsISupports *subject,
else if (strcmp(topic, "net:clear-active-logins") == 0) {
mAuthCache.ClearAll();
}
else if (strcmp(topic, "xpcom-shutdown-threads") == 0) {
// Shutdown the cache write thread. This must be done after shutting down
// the cache service, because the (memory) cache entries' storage streams
// get released on the thread on which they were first written to, which
// is this thread.
if (mCacheWriteThread) {
LOG((" shutting down cache-write thread...\n"));
mCacheWriteThread->Shutdown();
LOG((" cache-write thread shutdown complete\n"));
mCacheWriteThread = nsnull;
}
}
return NS_OK;
}

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

@ -210,8 +210,6 @@ public:
static nsresult GenerateHostPort(const nsCString& host, PRInt32 port,
nsCString& hostLine);
// The thread used to implement async cache-writes
nsCOMPtr<nsIThread> mCacheWriteThread;
private:
//