зеркало из https://github.com/mozilla/pjs.git
Bug 430061: Don't use necko's memory cache in imglib; r/sr=stuart,vlad,bz
? .fast-update ? _profile ? _tests ? obj-ff-debug ? staticlib ? README/.fast-update ? browser/app/profile/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}/install.rdf ? build/pgo/automation.py ? build/pgo/profileserver.py ? config/buildid ? config/system_wrappers ? content/base/test/TestNativeXMLHttpRequest ? content/base/test/TestPlainTextSerializer ? embedding/components/printingui/src/mac/printpde/build ? gfx/thebes/public/.gfxContext.h.swp ? gfx/thebes/test/gfxFontSelectionTest ? gfx/thebes/test/gfxSurfaceRefCountTest ? gfx/thebes/test/gfxTextRunPerfTest ? gfx/thebes/test/gfxWordCacheTest ? intl/uconv/tests/TestUConv ? intl/uconv/tests/nsconv ? intl/uconv/tests/plattest ? intl/unicharutil/tests/NormalizationTest ? js/src/host_jskwgen ? js/src/jsautokw.h ? layout/style/test/css_properties.js ? layout/style/test/host_ListCSSProperties ? layout/tools/reftest/autoconf.js ? modules/libpr0n/src/.imgContainer.cpp.swp ? modules/libpr0n/src/.imgLoader.cpp.swp ? modules/libpr0n/src/.imgLoader.h.swp ? modules/libpr0n/src/.imgRequestProxy.cpp.swp ? modules/libpr0n/src/check-all-at-removal-time ? modules/libpr0n/src/currpatch ? modules/libpr0n/src/update-every-time ? modules/plugin/samples/default/mac/build ? netwerk/cache/src/.nsMemoryCacheDevice.cpp.swp ? netwerk/dns/src/etld_data.inc ? netwerk/test/ReadNTLM ? netwerk/test/TestCookie ? netwerk/test/TestIncrementalDownload ? netwerk/test/TestOpen ? netwerk/test/TestServ ? netwerk/test/TestStreamLoader ? netwerk/test/TestUDPSocketProvider ? nsprpub/.fast-update ? nsprpub/unallmakefiles ? parser/htmlparser/robot/test/htmlrobot ? parser/htmlparser/tests/grabpage/grabpage ? parser/htmlparser/tests/html/TestParser ? rdf/tests/triplescat/triplescat ? storage/test/teststorage1 ? testing/mochitest/automation.py ? testing/mochitest/automation.pyc ? testing/mochitest/runtests.pl ? testing/mochitest/runtests.py ? testing/mochitest/ssltunnel/ssltunnel ? toolkit/components/url-classifier/tests/TestUrlClassifierUtils ? toolkit/crashreporter/client/crashreporter ? toolkit/crashreporter/google-breakpad/src/tools/mac/dump_syms/dump_syms ? toolkit/crashreporter/test/TestCrashReporterAPI ? toolkit/library/XUL ? toolkit/mozapps/update/src/nsUpdateService.js ? toolkit/xre/platform.ini ? tools/rb ? tools/trace-malloc ? widget/src/cocoa/libwidget.rsrc ? xpcom/io/.nsStringStream.cpp.swp ? xpcom/proxy/tests/proxy-create-threadsafety ? xpcom/sample/program/nsTestSample ? xpcom/tests/TestAutoPtr ? xpcom/tests/TestExpirationTracker ? xpcom/tests/TestHashtables ? xpcom/tests/TestINIParser ? xpcom/tests/TestPipe ? xpcom/tests/TestProxies ? xpcom/tests/TestRegistrationOrder ? xpcom/tests/TestStorageStream ? xpcom/tests/TestStringAPI ? xpcom/tests/TestStrings ? xpcom/tests/TestTArray ? xpcom/tests/TestTextFormatter ? xpcom/tests/TestThreadPool ? xpcom/tests/TestVersionComparator ? xpcom/tests/external/TestMinStringAPI ? xpfe/bootstrap/appleevents/mozillaSuite.rsrc Index: modules/libpr0n/build/nsImageModule.cpp =================================================================== RCS file: /cvsroot/mozilla/modules/libpr0n/build/nsImageModule.cpp,v retrieving revision 1.20
This commit is contained in:
Родитель
b965e578c9
Коммит
8660f7da95
|
@ -53,7 +53,6 @@
|
|||
#include "nsXPCOMCID.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "imgCache.h"
|
||||
#include "imgContainer.h"
|
||||
#include "imgLoader.h"
|
||||
#include "imgRequest.h"
|
||||
|
@ -99,7 +98,6 @@
|
|||
|
||||
// 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)
|
||||
|
@ -203,9 +201,9 @@ static NS_METHOD ImageUnregisterProc(nsIComponentManager *aCompMgr,
|
|||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "image cache",
|
||||
NS_IMGCACHE_CID,
|
||||
NS_IMGLOADER_CID,
|
||||
"@mozilla.org/image/cache;1",
|
||||
imgCacheConstructor, },
|
||||
imgLoaderConstructor, },
|
||||
{ "image container",
|
||||
NS_IMGCONTAINER_CID,
|
||||
"@mozilla.org/image/container;1",
|
||||
|
@ -315,14 +313,14 @@ static const nsModuleComponentInfo components[] =
|
|||
PR_STATIC_CALLBACK(nsresult)
|
||||
imglib_Initialize(nsIModule* aSelf)
|
||||
{
|
||||
imgCache::Init();
|
||||
imgLoader::InitCache();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
imglib_Shutdown(nsIModule* aSelf)
|
||||
{
|
||||
imgCache::Shutdown();
|
||||
imgLoader::Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsImageLib2Module, components,
|
||||
|
|
|
@ -61,7 +61,6 @@ REQUIRES = xpcom \
|
|||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
imgCache.cpp \
|
||||
imgContainer.cpp \
|
||||
imgLoader.cpp \
|
||||
imgRequest.cpp \
|
||||
|
|
|
@ -1,357 +0,0 @@
|
|||
/* -*- 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;
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/* -*- 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,7 +38,14 @@
|
|||
* ***** 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"
|
||||
|
@ -50,6 +57,117 @@ 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;
|
||||
NS_LOG_ADDREF(this, mRefCnt, "imgCacheEntry", sizeof(*this));
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt Release()
|
||||
{
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
NS_ASSERT_OWNINGTHREAD(imgCacheEntry);
|
||||
--mRefCnt;
|
||||
NS_LOG_RELEASE(this, mRefCnt, "imgCacheEntry");
|
||||
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, \
|
||||
|
@ -58,23 +176,124 @@ class nsILoadGroup;
|
|||
{0xa5, 0xb8, 0x95, 0x1f, 0x13, 0xc8, 0x46, 0xf7} \
|
||||
}
|
||||
|
||||
class imgLoader : public imgILoader, public nsIContentSniffer
|
||||
class imgCacheQueue
|
||||
{
|
||||
public:
|
||||
imgCacheQueue();
|
||||
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
|
||||
{
|
||||
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);
|
||||
|
||||
private:
|
||||
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);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -124,8 +343,10 @@ public:
|
|||
private:
|
||||
nsCOMPtr<nsIStreamListener> mDestListener;
|
||||
|
||||
imgRequest *mRequest;
|
||||
nsRefPtr<imgRequest> mRequest;
|
||||
nsCOMArray<imgIRequest> mProxies;
|
||||
|
||||
void *mContext;
|
||||
|
||||
static imgLoader sImgLoader;
|
||||
};
|
||||
|
|
|
@ -63,6 +63,8 @@
|
|||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#include "nsICacheVisitor.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "plstr.h" // PL_strcasestr(...)
|
||||
|
@ -92,7 +94,7 @@ imgRequest::~imgRequest()
|
|||
|
||||
nsresult imgRequest::Init(nsIURI *aURI,
|
||||
nsIRequest *aRequest,
|
||||
nsICacheEntryDescriptor *aCacheEntry,
|
||||
imgCacheEntry *aCacheEntry,
|
||||
void *aCacheId,
|
||||
void *aLoadId)
|
||||
{
|
||||
|
@ -336,7 +338,7 @@ void imgRequest::RemoveFromCache()
|
|||
LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");
|
||||
|
||||
if (mCacheEntry) {
|
||||
mCacheEntry->Doom();
|
||||
imgLoader::RemoveFromCache(mURI);
|
||||
mCacheEntry = nsnull;
|
||||
}
|
||||
}
|
||||
|
@ -523,13 +525,19 @@ NS_IMETHODIMP imgRequest::OnStopFrame(imgIRequest *request,
|
|||
mImageStatus |= imgIRequest::STATUS_FRAME_COMPLETE;
|
||||
|
||||
if (mCacheEntry) {
|
||||
PRUint32 cacheSize = 0;
|
||||
mCacheEntry->GetDataSize(&cacheSize);
|
||||
PRUint32 cacheSize = mCacheEntry->GetDataSize();
|
||||
|
||||
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);
|
||||
|
@ -647,7 +655,7 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
|
|||
entryDesc->GetExpirationTime(&expiration);
|
||||
|
||||
/* set the expiration time on our entry */
|
||||
mCacheEntry->SetExpirationTime(expiration);
|
||||
mCacheEntry->SetExpiryTime(expiration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -678,9 +686,7 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
|
|||
}
|
||||
}
|
||||
|
||||
if (bMustRevalidate) {
|
||||
mCacheEntry->SetMetaDataElement("MustValidateIfExpired", "true");
|
||||
}
|
||||
mCacheEntry->SetMustValidateIfExpired(bMustRevalidate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,9 +759,6 @@ 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,7 +46,6 @@
|
|||
#include "imgIDecoder.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsIContentSniffer.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIProperties.h"
|
||||
|
@ -63,6 +62,7 @@
|
|||
class imgCacheValidator;
|
||||
|
||||
class imgRequestProxy;
|
||||
class imgCacheEntry;
|
||||
|
||||
enum {
|
||||
onStartRequest = PR_BIT(0),
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
|
||||
nsresult Init(nsIURI *aURI,
|
||||
nsIRequest *aRequest,
|
||||
nsICacheEntryDescriptor *aCacheEntry,
|
||||
imgCacheEntry *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;
|
||||
|
@ -170,7 +170,7 @@ private:
|
|||
PRUint32 mState;
|
||||
nsCString mContentType;
|
||||
|
||||
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry; /* we hold on to this to this so long as we have observers */
|
||||
nsRefPtr<imgCacheEntry> 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
|
||||
|
|
|
@ -2622,3 +2622,10 @@ 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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче