Backed out changeset e63a23edb90c due to Rlk regression (bug 430061).

This commit is contained in:
Dave Camp 2008-08-19 14:42:03 -07:00
Родитель d533375dd9
Коммит fc1687cad1
10 изменённых файлов: 925 добавлений и 1237 удалений

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

@ -53,6 +53,7 @@
#include "nsXPCOMCID.h"
#include "nsServiceManagerUtils.h"
#include "imgCache.h"
#include "imgContainer.h"
#include "imgLoader.h"
#include "imgRequest.h"
@ -98,6 +99,7 @@
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(imgCache)
NS_GENERIC_FACTORY_CONSTRUCTOR(imgContainer)
NS_GENERIC_FACTORY_CONSTRUCTOR(imgLoader)
NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy)
@ -201,9 +203,9 @@ static NS_METHOD ImageUnregisterProc(nsIComponentManager *aCompMgr,
static const nsModuleComponentInfo components[] =
{
{ "image cache",
NS_IMGLOADER_CID,
NS_IMGCACHE_CID,
"@mozilla.org/image/cache;1",
imgLoaderConstructor, },
imgCacheConstructor, },
{ "image container",
NS_IMGCONTAINER_CID,
"@mozilla.org/image/container;1",
@ -313,14 +315,14 @@ static const nsModuleComponentInfo components[] =
PR_STATIC_CALLBACK(nsresult)
imglib_Initialize(nsIModule* aSelf)
{
imgLoader::InitCache();
imgCache::Init();
return NS_OK;
}
PR_STATIC_CALLBACK(void)
imglib_Shutdown(nsIModule* aSelf)
{
imgLoader::Shutdown();
imgCache::Shutdown();
}
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsImageLib2Module, components,

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

@ -61,6 +61,7 @@ REQUIRES = xpcom \
$(NULL)
CPPSRCS = \
imgCache.cpp \
imgContainer.cpp \
imgLoader.cpp \
imgRequest.cpp \

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

@ -0,0 +1,357 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "imgCache.h"
#include "ImageLogging.h"
#include "imgRequest.h"
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIMemory.h"
#include "nsIObserverService.h"
#include "nsICache.h"
#include "nsICacheService.h"
#include "nsICacheSession.h"
#include "nsICacheEntryDescriptor.h"
#include "nsIFile.h"
#include "nsIFileURL.h"
NS_IMPL_ISUPPORTS3(imgCache, imgICache, nsIObserver, nsISupportsWeakReference)
imgCache::imgCache()
{
/* member initializers and constructor code */
}
imgCache::~imgCache()
{
/* destructor code */
}
nsresult imgCache::Init()
{
nsresult rv;
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv))
return rv;
imgCache* cache = new imgCache();
if(!cache) return NS_ERROR_OUT_OF_MEMORY;
os->AddObserver(cache, "memory-pressure", PR_FALSE);
os->AddObserver(cache, "chrome-flush-skin-caches", PR_FALSE);
os->AddObserver(cache, "chrome-flush-caches", PR_FALSE);
return NS_OK;
}
/* void clearCache (in boolean chrome); */
NS_IMETHODIMP imgCache::ClearCache(PRBool chrome)
{
if (chrome)
return imgCache::ClearChromeImageCache();
else
return imgCache::ClearImageCache();
}
/* void removeEntry(in nsIURI uri); */
NS_IMETHODIMP imgCache::RemoveEntry(nsIURI *uri)
{
if (imgCache::Remove(uri))
return NS_OK;
return NS_ERROR_NOT_AVAILABLE;
}
/* imgIRequest findEntry(in nsIURI uri); */
NS_IMETHODIMP imgCache::FindEntryProperties(nsIURI *uri, nsIProperties **_retval)
{
PRBool expired;
// This is an owning reference that must be released.
imgRequest *request = nsnull;
nsCOMPtr<nsICacheEntryDescriptor> entry;
// addrefs request
imgCache::Get(uri, &expired, &request, getter_AddRefs(entry));
*_retval = nsnull;
if (request) {
*_retval = request->Properties();
NS_ADDREF(*_retval);
}
NS_IF_RELEASE(request);
return NS_OK;
}
static nsCOMPtr<nsICacheSession> gSession = nsnull;
static nsCOMPtr<nsICacheSession> gChromeSession = nsnull;
void GetCacheSession(nsIURI *aURI, nsICacheSession **_retval)
{
NS_ASSERTION(aURI, "Null URI!");
PRBool isChrome = PR_FALSE;
aURI->SchemeIs("chrome", &isChrome);
if (gSession && !isChrome) {
*_retval = gSession;
NS_ADDREF(*_retval);
return;
}
if (gChromeSession && isChrome) {
*_retval = gChromeSession;
NS_ADDREF(*_retval);
return;
}
nsCOMPtr<nsICacheService> cacheService(do_GetService("@mozilla.org/network/cache-service;1"));
if (!cacheService) {
NS_WARNING("Unable to get the cache service");
return;
}
nsCOMPtr<nsICacheSession> newSession;
cacheService->CreateSession(isChrome ? "image-chrome" : "image",
nsICache::STORE_IN_MEMORY,
nsICache::NOT_STREAM_BASED,
getter_AddRefs(newSession));
if (!newSession) {
NS_WARNING("Unable to create a cache session");
return;
}
if (isChrome)
gChromeSession = newSession;
else {
gSession = newSession;
gSession->SetDoomEntriesIfExpired(PR_FALSE);
}
*_retval = newSession;
NS_ADDREF(*_retval);
}
void imgCache::Shutdown()
{
gSession = nsnull;
gChromeSession = nsnull;
}
nsresult imgCache::ClearChromeImageCache()
{
if (!gChromeSession)
return NS_OK;
return gChromeSession->EvictEntries();
}
nsresult imgCache::ClearImageCache()
{
if (!gSession)
return NS_OK;
return gSession->EvictEntries();
}
PRBool imgCache::Put(nsIURI *aKey, imgRequest *request, nsICacheEntryDescriptor **aEntry)
{
LOG_STATIC_FUNC(gImgLog, "imgCache::Put");
nsresult rv;
nsCOMPtr<nsICacheSession> ses;
GetCacheSession(aKey, getter_AddRefs(ses));
if (!ses) return PR_FALSE;
nsCAutoString spec;
aKey->GetAsciiSpec(spec);
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;
nsCOMPtr<nsISupports> sup = reinterpret_cast<nsISupports*>(request);
entry->SetCacheElement(sup);
entry->MarkValid();
// If file, force revalidation on expiration
PRBool isFile;
aKey->SchemeIs("file", &isFile);
if (isFile)
entry->SetMetaDataElement("MustValidateIfExpired", "true");
*aEntry = entry;
NS_ADDREF(*aEntry);
return PR_TRUE;
}
static PRUint32
SecondsFromPRTime(PRTime prTime)
{
PRInt64 microSecondsPerSecond, intermediateResult;
PRUint32 seconds;
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
LL_DIV(intermediateResult, prTime, microSecondsPerSecond);
LL_L2UI(seconds, intermediateResult);
return seconds;
}
PRBool imgCache::Get(nsIURI *aKey, PRBool *aHasExpired, imgRequest **aRequest, nsICacheEntryDescriptor **aEntry)
{
LOG_STATIC_FUNC(gImgLog, "imgCache::Get");
nsresult rv;
nsCOMPtr<nsICacheSession> ses;
GetCacheSession(aKey, getter_AddRefs(ses));
if (!ses) return PR_FALSE;
nsCAutoString spec;
aKey->GetAsciiSpec(spec);
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;
if (aHasExpired) {
PRUint32 expirationTime;
rv = entry->GetExpirationTime(&expirationTime);
if (NS_FAILED(rv) || (expirationTime <= SecondsFromPRTime(PR_Now()))) {
*aHasExpired = PR_TRUE;
} else {
*aHasExpired = PR_FALSE;
}
// Special treatment for file URLs - entry has expired if file has changed
nsCOMPtr<nsIFileURL> fileUrl(do_QueryInterface(aKey));
if (fileUrl) {
PRUint32 lastModTime;
entry->GetLastModified(&lastModTime);
nsCOMPtr<nsIFile> theFile;
rv = fileUrl->GetFile(getter_AddRefs(theFile));
if (NS_SUCCEEDED(rv)) {
PRInt64 fileLastMod;
rv = theFile->GetLastModifiedTime(&fileLastMod);
if (NS_SUCCEEDED(rv)) {
// nsIFile uses millisec, NSPR usec
PRInt64 one_thousand = LL_INIT(0, 1000);
LL_MUL(fileLastMod, fileLastMod, one_thousand);
*aHasExpired = SecondsFromPRTime((PRTime)fileLastMod) > lastModTime;
}
}
}
}
nsCOMPtr<nsISupports> sup;
entry->GetCacheElement(getter_AddRefs(sup));
*aRequest = reinterpret_cast<imgRequest*>(sup.get());
NS_IF_ADDREF(*aRequest);
*aEntry = entry;
NS_ADDREF(*aEntry);
return PR_TRUE;
}
PRBool imgCache::Remove(nsIURI *aKey)
{
LOG_STATIC_FUNC(gImgLog, "imgCache::Remove");
if (!aKey) return PR_FALSE;
nsresult rv;
nsCOMPtr<nsICacheSession> ses;
GetCacheSession(aKey, getter_AddRefs(ses));
if (!ses) return PR_FALSE;
nsCAutoString spec;
aKey->GetAsciiSpec(spec);
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = ses->OpenCacheEntry(spec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));
if (NS_FAILED(rv) || !entry)
return PR_FALSE;
entry->Doom();
return PR_TRUE;
}
NS_IMETHODIMP
imgCache::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
{
if (strcmp(aTopic, "memory-pressure") == 0) {
ClearCache(PR_FALSE);
ClearCache(PR_TRUE);
} else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
strcmp(aTopic, "chrome-flush-caches") == 0) {
ClearCache(PR_TRUE);
}
return NS_OK;
}

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

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "imgICache.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "prtypes.h"
class imgRequest;
class nsIURI;
class nsICacheEntryDescriptor;
#define NS_IMGCACHE_CID \
{ /* fb4fd28a-1dd1-11b2-8391-e14242c59a41 */ \
0xfb4fd28a, \
0x1dd1, \
0x11b2, \
{0x83, 0x91, 0xe1, 0x42, 0x42, 0xc5, 0x9a, 0x41} \
}
class imgCache : public imgICache,
public nsIObserver,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGICACHE
NS_DECL_NSIOBSERVER
imgCache();
virtual ~imgCache();
static nsresult Init();
static void Shutdown(); // for use by the factory
/* additional members */
static PRBool Put(nsIURI *aKey, imgRequest *request, nsICacheEntryDescriptor **aEntry);
static PRBool Get(nsIURI *aKey, PRBool *aHasExpired, imgRequest **aRequest, nsICacheEntryDescriptor **aEntry);
static PRBool Remove(nsIURI *aKey);
static nsresult ClearChromeImageCache();
static nsresult ClearImageCache();
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -38,14 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "imgILoader.h"
#include "imgICache.h"
#include "nsWeakReference.h"
#include "nsIContentSniffer.h"
#include "nsRefPtrHashtable.h"
#include "nsExpirationTracker.h"
#include "nsAutoPtr.h"
#include "prtypes.h"
#include "imgRequest.h"
#ifdef LOADER_THREADSAFE
#include "prlock.h"
@ -57,115 +50,6 @@ class imgIRequest;
class imgIDecoderObserver;
class nsILoadGroup;
class imgCacheEntry
{
public:
imgCacheEntry(imgRequest *request, PRBool mustValidateIfExpired = PR_FALSE);
nsrefcnt AddRef()
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
NS_ASSERT_OWNINGTHREAD(imgCacheEntry);
++mRefCnt;
return mRefCnt;
}
nsrefcnt Release()
{
NS_PRECONDITION(0 != mRefCnt, "dup release");
NS_ASSERT_OWNINGTHREAD(imgCacheEntry);
--mRefCnt;
if (mRefCnt == 0) {
mRefCnt = 1; /* stabilize */
delete this;
return 0;
}
return mRefCnt;
}
PRUint32 GetDataSize() const
{
return mDataSize;
}
void SetDataSize(PRUint32 aDataSize)
{
PRInt32 oldsize = mDataSize;
mDataSize = aDataSize;
TouchWithSize(mDataSize - oldsize);
}
PRInt32 GetTouchedTime() const
{
return mTouchedTime;
}
void SetTouchedTime(PRInt32 time)
{
mTouchedTime = time;
Touch(/* updateTime = */ PR_FALSE);
}
PRInt32 GetExpiryTime() const
{
return mExpiryTime;
}
void SetExpiryTime(PRInt32 aExpiryTime)
{
mExpiryTime = aExpiryTime;
Touch();
}
PRBool GetMustValidateIfExpired() const
{
return mMustValidateIfExpired;
}
void SetMustValidateIfExpired(PRBool aValidate)
{
mMustValidateIfExpired = aValidate;
Touch();
}
already_AddRefed<imgRequest> GetRequest() const
{
imgRequest *req = mRequest;
NS_ADDREF(req);
return req;
}
PRBool Evicted() const
{
return mEvicted;
}
nsExpirationState *GetExpirationState()
{
return &mExpirationState;
}
private: // methods
friend class imgLoader;
friend class imgCacheQueue;
void Touch(PRBool updateTime = PR_TRUE);
void TouchWithSize(PRInt32 diff);
void SetEvicted(PRBool evict)
{
mEvicted = evict;
}
private: // data
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
nsRefPtr<imgRequest> mRequest;
PRUint32 mDataSize;
PRInt32 mTouchedTime;
PRInt32 mExpiryTime;
nsExpirationState mExpirationState;
PRBool mMustValidateIfExpired;
PRBool mEvicted;
};
#include <vector>
#define NS_IMGLOADER_CID \
{ /* 9f6a0d2e-1dd1-11b2-a5b8-951f13c846f7 */ \
0x9f6a0d2e, \
@ -174,125 +58,23 @@ private: // data
{0xa5, 0xb8, 0x95, 0x1f, 0x13, 0xc8, 0x46, 0xf7} \
}
class imgCacheQueue
{
public:
imgCacheQueue();
void EvictAll();
void Remove(imgCacheEntry *);
void Push(imgCacheEntry *);
void MarkDirty();
PRBool IsDirty();
already_AddRefed<imgCacheEntry> Pop();
void Refresh();
PRUint32 GetSize() const;
void UpdateSize(PRInt32 diff);
PRUint32 GetNumElements() const;
typedef std::vector<nsRefPtr<imgCacheEntry> > queueContainer;
typedef queueContainer::iterator iterator;
typedef queueContainer::const_iterator const_iterator;
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
private:
queueContainer mQueue;
PRBool mDirty;
PRUint32 mSize;
};
class imgLoader : public imgILoader,
public nsIContentSniffer,
public imgICache,
public nsSupportsWeakReference
class imgLoader : public imgILoader, public nsIContentSniffer
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGILOADER
NS_DECL_NSICONTENTSNIFFER
NS_DECL_IMGICACHE
imgLoader();
virtual ~imgLoader();
static nsresult GetMimeTypeFromContent(const char* aContents, PRUint32 aLength, nsACString& aContentType);
static void Shutdown(); // for use by the factory
static nsresult ClearChromeImageCache();
static nsresult ClearImageCache();
static nsresult InitCache();
static PRBool RemoveFromCache(nsIURI *aKey);
static PRBool RemoveFromCache(imgCacheEntry *entry);
static PRBool PutIntoCache(nsIURI *key, imgCacheEntry *entry);
// Returns true if |one| is less than |two|
// This mixes units in the worst way, but provides reasonable results.
inline static bool CompareCacheEntries(const nsRefPtr<imgCacheEntry> &one,
const nsRefPtr<imgCacheEntry> &two)
{
if (!one)
return false;
if (!two)
return true;
const PRFloat64 sizeweight = 1.0 - sCacheTimeWeight;
PRInt32 diffsize = PRInt32(two->GetDataSize()) - PRInt32(one->GetDataSize());
PRInt32 difftime = one->GetTouchedTime() - two->GetTouchedTime();
return difftime * sCacheTimeWeight + diffsize * sizeweight < 0;
}
static void VerifyCacheSizes();
private: // methods
PRBool ValidateEntry(imgCacheEntry *aEntry, nsIURI *aKey,
nsIURI *aInitialDocumentURI, nsIURI *aReferrerURI,
nsILoadGroup *aLoadGroup,
imgIDecoderObserver *aObserver, nsISupports *aCX,
nsLoadFlags aLoadFlags, PRBool aCanMakeNewChannel,
imgIRequest *aExistingRequest,
imgIRequest **aProxyRequest);
PRBool ValidateRequestWithNewChannel(imgRequest *request, nsIURI *aURI,
nsIURI *aInitialDocumentURI,
nsIURI *aReferrerURI,
nsILoadGroup *aLoadGroup,
imgIDecoderObserver *aObserver,
nsISupports *aCX, nsLoadFlags aLoadFlags,
imgIRequest *aExistingRequest,
imgIRequest **aProxyRequest);
private:
nsresult CreateNewProxyForRequest(imgRequest *aRequest, nsILoadGroup *aLoadGroup,
imgIDecoderObserver *aObserver,
nsLoadFlags aLoadFlags, imgIRequest *aRequestProxy,
imgIRequest **_retval);
typedef nsRefPtrHashtable<nsCStringHashKey, imgCacheEntry> imgCacheTable;
static nsresult EvictEntries(imgCacheTable &aCacheToClear, imgCacheQueue &aQueueToClear);
static imgCacheTable &GetCache(nsIURI *aURI);
static imgCacheQueue &GetCacheQueue(nsIURI *aURI);
static void CacheEntriesChanged(nsIURI *aURI, PRInt32 sizediff = 0);
static void CheckCacheLimits(imgCacheTable &cache, imgCacheQueue &queue);
private: // data
friend class imgCacheEntry;
static imgCacheTable sCache;
static imgCacheQueue sCacheQueue;
static imgCacheTable sChromeCache;
static imgCacheQueue sChromeCacheQueue;
static PRFloat64 sCacheTimeWeight;
static PRUint32 sCacheMaxSize;
};
@ -346,6 +128,4 @@ private:
nsCOMArray<imgIRequest> mProxies;
void *mContext;
static imgLoader sImgLoader;
};

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

@ -63,8 +63,6 @@
#include "nsISupportsPrimitives.h"
#include "nsIScriptSecurityManager.h"
#include "nsICacheVisitor.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "plstr.h" // PL_strcasestr(...)
@ -94,7 +92,7 @@ imgRequest::~imgRequest()
nsresult imgRequest::Init(nsIURI *aURI,
nsIRequest *aRequest,
imgCacheEntry *aCacheEntry,
nsICacheEntryDescriptor *aCacheEntry,
void *aCacheId,
void *aLoadId)
{
@ -328,7 +326,7 @@ void imgRequest::RemoveFromCache()
LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");
if (mCacheEntry) {
imgLoader::RemoveFromCache(mURI);
mCacheEntry->Doom();
mCacheEntry = nsnull;
}
}
@ -515,19 +513,13 @@ NS_IMETHODIMP imgRequest::OnStopFrame(imgIRequest *request,
mImageStatus |= imgIRequest::STATUS_FRAME_COMPLETE;
if (mCacheEntry) {
PRUint32 cacheSize = mCacheEntry->GetDataSize();
PRUint32 cacheSize = 0;
mCacheEntry->GetDataSize(&cacheSize);
PRUint32 imageSize = 0;
frame->GetImageDataLength(&imageSize);
mCacheEntry->SetDataSize(cacheSize + imageSize);
#ifdef DEBUG_joe
nsCAutoString url;
mURI->GetSpec(url);
printf("CACHEPUT: %d %s %d\n", time(NULL), url.get(), cacheSize + imageSize);
#endif
}
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mObservers);
@ -641,7 +633,7 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
entryDesc->GetExpirationTime(&expiration);
/* set the expiration time on our entry */
mCacheEntry->SetExpiryTime(expiration);
mCacheEntry->SetExpirationTime(expiration);
}
}
}
@ -672,7 +664,9 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
}
}
mCacheEntry->SetMustValidateIfExpired(bMustRevalidate);
if (bMustRevalidate) {
mCacheEntry->SetMetaDataElement("MustValidateIfExpired", "true");
}
}
}
@ -745,6 +739,9 @@ NS_IMETHODIMP imgRequest::OnStopRequest(nsIRequest *aRequest, nsISupports *ctxt,
return NS_OK;
}
/* prototype for this defined below */
static NS_METHOD sniff_mimetype_callback(nsIInputStream* in, void* closure, const char* fromRawSegment,
PRUint32 toOffset, PRUint32 count, PRUint32 *writeCount);

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

@ -46,6 +46,7 @@
#include "imgIDecoder.h"
#include "imgIDecoderObserver.h"
#include "nsICacheEntryDescriptor.h"
#include "nsIContentSniffer.h"
#include "nsIRequest.h"
#include "nsIProperties.h"
@ -62,7 +63,6 @@
class imgCacheValidator;
class imgRequestProxy;
class imgCacheEntry;
enum {
onStartRequest = PR_BIT(0),
@ -86,7 +86,7 @@ public:
nsresult Init(nsIURI *aURI,
nsIRequest *aRequest,
imgCacheEntry *aCacheEntry,
nsICacheEntryDescriptor *aCacheEntry,
void *aCacheId,
void *aLoadId);
@ -109,10 +109,10 @@ public:
nsresult GetNetworkStatus();
private:
friend class imgCacheEntry;
friend class imgRequestProxy;
friend class imgLoader;
friend class imgCacheValidator;
friend class imgCache;
inline void SetLoadId(void *aLoadId) {
mLoadId = aLoadId;
@ -168,7 +168,7 @@ private:
PRUint32 mState;
nsCString mContentType;
nsRefPtr<imgCacheEntry> mCacheEntry; /* we hold on to this to this so long as we have observers */
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry; /* we hold on to this to this so long as we have observers */
void *mCacheId;

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

@ -49,7 +49,7 @@ MODULE = test_libpr0n
XPCSHELL_TESTS = unit
#ifdef MOZ_MOCHITEST
DIRS += mochitest
#DIRS += mochitest
#endif
include $(topsrcdir)/config/rules.mk

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

@ -2618,10 +2618,3 @@ pref("browser.zoom.full", false);
pref("zoom.minPercent", 30);
pref("zoom.maxPercent", 300);
pref("toolkit.zoomManager.zoomValues", ".3,.5,.67,.8,.9,1,1.1,1.2,1.33,1.5,1.7,2,2.4,3");
// Image cache prefs
// The maximum size, in bytes, of the decoded images we cache
pref("image.cache.size", 5242880);
// A weight, from 0-1000, to place on time when comparing to size.
// Size is given a weight of 1000 - timeweight.
pref("image.cache.timeweight", 500);