Access MemoryCache singleton using MemoryCache::singleton()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Feb 2015 20:50:16 +0000 (20:50 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Feb 2015 20:50:16 +0000 (20:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141104

Reviewed by Andreas Kling.

Access MemoryCache singleton using MemoryCache::singleton() static
member function, instead of a free function, as per the recent
coding style discussion on WebKit-dev.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@179489 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/MemoryCache.cpp
Source/WebCore/loader/cache/MemoryCache.h
Source/WebCore/loader/cocoa/DiskCacheMonitorCocoa.mm
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebCore/testing/Internals.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebCache.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCache.cpp
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
Source/WebKit2/WebProcess/ResourceCache/WebResourceCacheManager.cpp
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm
Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

index ff94600..7247c18 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-02  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryCache singleton using MemoryCache::singleton()
+        https://bugs.webkit.org/show_bug.cgi?id=141104
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryCache singleton using MemoryCache::singleton() static
+        member function, instead of a free function, as per the recent
+        coding style discussion on WebKit-dev.
+
 2015-02-02  Zalan Bujtas  <zalan@apple.com>
 
         Ambiguous naming: Do not call replacedContentRect()'s return value paint rect.
index e4a421b..15bb47e 100644 (file)
@@ -198,6 +198,7 @@ __ZN7WebCore11MemoryCache18resourceForRequestERKNS_15ResourceRequestENS_9Session
 __ZN7WebCore11MemoryCache19getOriginsWithCacheERN3WTF7HashSetINS1_6RefPtrINS_14SecurityOriginEEENS_18SecurityOriginHashENS1_10HashTraitsIS5_EEEE
 __ZN7WebCore11MemoryCache20removeImageFromCacheERKNS_3URLERKN3WTF6StringE
 __ZN7WebCore11MemoryCache25removeResourcesWithOriginERNS_14SecurityOriginE
+__ZN7WebCore11MemoryCache9singletonEv
 __ZN7WebCore11PageOverlay15setNeedsDisplayERKNS_7IntRectE
 __ZN7WebCore11PageOverlay15setNeedsDisplayEv
 __ZN7WebCore11PageOverlay20stopFadeOutAnimationEv
@@ -211,7 +212,6 @@ __ZN7WebCore11getFileSizeERKN3WTF6StringERx
 __ZN7WebCore11getURLBytesEPK7__CFURLRN3WTF6VectorIcLm512ENS3_15CrashOnOverflowEEE
 __ZN7WebCore11getURLBytesEPK7__CFURLRN3WTF7CStringE
 __ZN7WebCore11iBeamCursorEv
-__ZN7WebCore11memoryCacheEv
 __ZN7WebCore11startOfLineERKNS_15VisiblePositionE
 __ZN7WebCore11startOfWordERKNS_15VisiblePositionENS_9EWordSideE
 __ZN7WebCore11writeToFileEiPKci
index f91f7ee..91c7380 100644 (file)
@@ -261,7 +261,7 @@ CachedResource* InspectorPageAgent::cachedResource(Frame* frame, const URL& url)
 #if ENABLE(CACHE_PARTITIONING)
         request.setDomainForCachePartition(frame->document()->topOrigin()->domainForCachePartition());
 #endif
-        cachedResource = memoryCache().resourceForRequest(request, frame->page()->sessionID());
+        cachedResource = MemoryCache::singleton().resourceForRequest(request, frame->page()->sessionID());
     }
 
     return cachedResource;
index 120ffe8..4922f31 100644 (file)
@@ -708,9 +708,9 @@ void InspectorResourceAgent::replayXHR(ErrorString&, const String& requestId)
     request.setDomainForCachePartition(m_pageAgent->mainFrame()->document()->topOrigin()->domainForCachePartition());
 #endif
 
-    CachedResource* cachedResource = memoryCache().resourceForRequest(request, m_pageAgent->page()->sessionID());
-    if (cachedResource)
-        memoryCache().remove(*cachedResource);
+    auto& memoryCache = MemoryCache::singleton();
+    if (CachedResource* cachedResource = memoryCache.resourceForRequest(request, m_pageAgent->page()->sessionID()))
+        memoryCache.remove(*cachedResource);
 
     xhr->open(xhrReplayData->method(), xhrReplayData->url(), xhrReplayData->async(), IGNORE_EXCEPTION);
     for (const auto& header : xhrReplayData->headers())
@@ -742,7 +742,7 @@ void InspectorResourceAgent::setCacheDisabled(ErrorString&, bool cacheDisabled)
 {
     m_cacheDisabled = cacheDisabled;
     if (cacheDisabled)
-        memoryCache().evictResources();
+        MemoryCache::singleton().evictResources();
 }
 
 void InspectorResourceAgent::loadResource(ErrorString& errorString, const String& frameId, const String& urlString, Ref<LoadResourceCallback>&& callback)
@@ -788,7 +788,7 @@ void InspectorResourceAgent::loadResource(ErrorString& errorString, const String
 void InspectorResourceAgent::mainFrameNavigated(DocumentLoader& loader)
 {
     if (m_cacheDisabled)
-        memoryCache().evictResources();
+        MemoryCache::singleton().evictResources();
 
     m_resourcesData->clear(m_pageAgent->loaderId(&loader));
 }
index c1671bf..63d5e3a 100644 (file)
@@ -106,7 +106,7 @@ static bool areAllLoadersPageCacheAcceptable(const ResourceLoaderMap& loaders)
         if (!loader->frameLoader())
             return false;
 
-        CachedResource* cachedResource = memoryCache().resourceForURL(handle->firstRequest().url(), loader->frameLoader()->frame().page()->sessionID());
+        CachedResource* cachedResource = MemoryCache::singleton().resourceForURL(handle->firstRequest().url(), loader->frameLoader()->frame().page()->sessionID());
         if (!cachedResource)
             return false;
 
@@ -448,7 +448,7 @@ void DocumentLoader::finishedLoading(double finishTime)
     // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
     if (m_frame) {
         if (m_mainResource && m_frame->document()->hasManifest())
-            memoryCache().remove(*m_mainResource);
+            MemoryCache::singleton().remove(*m_mainResource);
     }
     m_applicationCacheHost->finishedLoadingMainResource();
 }
@@ -599,7 +599,7 @@ void DocumentLoader::responseReceived(CachedResource* resource, const ResourceRe
     // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served
     // from the application cache, ensure we don't save the result for future use.
     if (willLoadFallback)
-        memoryCache().remove(*m_mainResource);
+        MemoryCache::singleton().remove(*m_mainResource);
 
     if (willLoadFallback)
         return;
index ff1ecc4..d005fd5 100644 (file)
@@ -3390,7 +3390,7 @@ void FrameLoader::tellClientAboutPastMemoryCacheLoads()
 
     size_t size = pastLoads.size();
     for (size_t i = 0; i < size; ++i) {
-        CachedResource* resource = memoryCache().resourceForRequest(pastLoads[i], m_frame.page()->sessionID());
+        CachedResource* resource = MemoryCache::singleton().resourceForRequest(pastLoads[i], m_frame.page()->sessionID());
 
         // FIXME: These loads, loaded from cache, but now gone from the cache by the time
         // Page::setMemoryCacheClientCallsEnabled(true) is called, will not be seen by the client.
index b322fd1..731cd5d 100644 (file)
@@ -159,7 +159,7 @@ void SubresourceLoader::willSendRequest(ResourceRequest& newRequest, const Resou
         // Doing so would have us reusing the resource from the first request if the second request's revalidation succeeds.
         if (newRequest.isConditional() && m_resource->resourceToRevalidate() && newRequest.url() != m_resource->resourceToRevalidate()->response().url()) {
             newRequest.makeUnconditional();
-            memoryCache().revalidationFailed(*m_resource);
+            MemoryCache::singleton().revalidationFailed(*m_resource);
             if (m_frame)
                 m_frame->mainFrame().diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::cachedResourceRevalidationKey(), emptyString(), DiagnosticLoggingResultFail);
         }
@@ -207,7 +207,7 @@ void SubresourceLoader::didReceiveResponse(const ResourceResponse& response)
             // 304 Not modified / Use local copy
             // Existing resource is ok, just use it updating the expiration time.
             m_resource->setResponse(response);
-            memoryCache().revalidationSucceeded(*m_resource, response);
+            MemoryCache::singleton().revalidationSucceeded(*m_resource, response);
             if (m_frame)
                 m_frame->mainFrame().diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::cachedResourceRevalidationKey(), emptyString(), DiagnosticLoggingResultPass);
             if (!reachedTerminalState())
@@ -215,7 +215,7 @@ void SubresourceLoader::didReceiveResponse(const ResourceResponse& response)
             return;
         }
         // Did not get 304 response, continue as a regular resource load.
-        memoryCache().revalidationFailed(*m_resource);
+        MemoryCache::singleton().revalidationFailed(*m_resource);
         if (m_frame)
             m_frame->mainFrame().diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::cachedResourceRevalidationKey(), emptyString(), DiagnosticLoggingResultFail);
     }
@@ -385,10 +385,10 @@ void SubresourceLoader::didFail(const ResourceError& error)
     CachedResourceHandle<CachedResource> protectResource(m_resource);
     m_state = Finishing;
     if (m_resource->resourceToRevalidate())
-        memoryCache().revalidationFailed(*m_resource);
+        MemoryCache::singleton().revalidationFailed(*m_resource);
     m_resource->setResourceError(error);
     if (!m_resource->isPreloaded())
-        memoryCache().remove(*m_resource);
+        MemoryCache::singleton().remove(*m_resource);
     m_resource->error(CachedResource::LoadError);
     cleanupForError(error);
     notifyDone();
@@ -417,10 +417,11 @@ void SubresourceLoader::willCancel(const ResourceError& error)
 #else
     m_state = Finishing;
 #endif
+    auto& memoryCache = MemoryCache::singleton();
     if (m_resource->resourceToRevalidate())
-        memoryCache().revalidationFailed(*m_resource);
+        memoryCache.revalidationFailed(*m_resource);
     m_resource->setResourceError(error);
-    memoryCache().remove(*m_resource);
+    memoryCache.remove(*m_resource);
 }
 
 void SubresourceLoader::didCancel(const ResourceError&)
index aecf562..17ff0be 100644 (file)
@@ -547,7 +547,7 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
 #if ENABLE(CACHE_PARTITIONING)
                 request.setDomainForCachePartition(frame->document()->topOrigin()->domainForCachePartition());
 #endif
-                CachedResource* cachedResource = memoryCache().resourceForRequest(request, frame->page()->sessionID());
+                CachedResource* cachedResource = MemoryCache::singleton().resourceForRequest(request, frame->page()->sessionID());
                 if (cachedResource) {
                     if (RefPtr<ArchiveResource> resource = ArchiveResource::create(cachedResource->resourceBuffer(), subresourceURL, cachedResource->response())) {
                         subresources.append(WTF::move(resource));
index a7c3770..bb8583b 100644 (file)
@@ -381,7 +381,7 @@ void CachedImage::addIncrementalDataBuffer(SharedBuffer& data)
         // Image decoding failed. Either we need more image data or the image data is malformed.
         error(errorOccurred() ? status() : DecodeError);
         if (inCache())
-            memoryCache().remove(*this);
+            MemoryCache::singleton().remove(*this);
         return;
     }
 
@@ -422,7 +422,7 @@ void CachedImage::finishLoading(SharedBuffer* data)
         // Image decoding failed; the image data is malformed.
         error(errorOccurred() ? status() : DecodeError);
         if (inCache())
-            memoryCache().remove(*this);
+            MemoryCache::singleton().remove(*this);
         return;
     }
 
index bfef85b..971d864 100644 (file)
@@ -106,7 +106,7 @@ static std::chrono::milliseconds deadDecodedDataDeletionIntervalForResourceType(
     if (type == CachedResource::Script)
         return std::chrono::milliseconds { 0 };
 
-    return memoryCache().deadDecodedDataDeletionInterval();
+    return MemoryCache::singleton().deadDecodedDataDeletionInterval();
 }
 
 DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("CachedResource"));
@@ -162,7 +162,7 @@ CachedResource::~CachedResource()
     ASSERT(canDelete());
     ASSERT(!inCache());
     ASSERT(!m_deleted);
-    ASSERT(url().isNull() || memoryCache().resourceForRequest(resourceRequest(), sessionID()) != this);
+    ASSERT(url().isNull() || MemoryCache::singleton().resourceForRequest(resourceRequest(), sessionID()) != this);
 
 #ifndef NDEBUG
     m_deleted = true;
@@ -178,7 +178,7 @@ void CachedResource::failBeforeStarting()
     // FIXME: What if resources in other frames were waiting for this revalidation?
     LOG(ResourceLoading, "Cannot start loading '%s'", url().string().latin1().data());
     if (m_resourceToRevalidate) 
-        memoryCache().revalidationFailed(*this);
+        MemoryCache::singleton().revalidationFailed(*this);
     error(CachedResource::LoadError);
 }
 
@@ -415,7 +415,7 @@ bool CachedResource::addClientToSet(CachedResourceClient* client)
             m_preloadResult = PreloadReferenced;
     }
     if (!hasClients() && inCache())
-        memoryCache().addToLiveResourcesSize(*this);
+        MemoryCache::singleton().addToLiveResourcesSize(*this);
 
     if ((m_type == RawResource || m_type == MainResource) && !m_response.isNull() && !m_proxyResource) {
         // Certain resources (especially XHRs and main resources) do crazy things if an asynchronous load returns
@@ -446,9 +446,10 @@ void CachedResource::removeClient(CachedResourceClient* client)
 
     bool deleted = deleteIfPossible();
     if (!deleted && !hasClients()) {
+        auto& memoryCache = MemoryCache::singleton();
         if (inCache()) {
-            memoryCache().removeFromLiveResourcesSize(*this);
-            memoryCache().removeFromLiveDecodedResourcesList(*this);
+            memoryCache.removeFromLiveResourcesSize(*this);
+            memoryCache.removeFromLiveDecodedResourcesList(*this);
         }
         if (!m_switchingClientsToRevalidatedResource)
             allClientsRemoved();
@@ -458,9 +459,9 @@ void CachedResource::removeClient(CachedResourceClient* client)
             // "no-store: ... MUST make a best-effort attempt to remove the information from volatile storage as promptly as possible"
             // "... History buffers MAY store such responses as part of their normal operation."
             // We allow non-secure content to be reused in history, but we do not allow secure content to be reused.
-            memoryCache().remove(*this);
+            memoryCache.remove(*this);
         }
-        memoryCache().prune();
+        memoryCache.prune();
     }
     // This object may be dead here.
 }
@@ -469,7 +470,7 @@ void CachedResource::destroyDecodedDataIfNeeded()
 {
     if (!m_decodedSize)
         return;
-    if (!memoryCache().deadDecodedDataDeletionInterval().count())
+    if (!MemoryCache::singleton().deadDecodedDataDeletionInterval().count())
         return;
     m_decodedDataDeletionTimer.restart();
 }
@@ -499,13 +500,14 @@ void CachedResource::setDecodedSize(unsigned size)
     // The object must be moved to a different queue, since its size has been changed.
     // Remove before updating m_decodedSize, so we find the resource in the correct LRU list.
     if (inCache())
-        memoryCache().removeFromLRUList(*this);
+        MemoryCache::singleton().removeFromLRUList(*this);
     
     m_decodedSize = size;
    
-    if (inCache()) { 
+    if (inCache()) {
+        auto& memoryCache = MemoryCache::singleton();
         // Now insert into the new LRU list.
-        memoryCache().insertInLRUList(*this);
+        memoryCache.insertInLRUList(*this);
         
         // Insert into or remove from the live decoded list if necessary.
         // When inserting into the LiveDecodedResourcesList it is possible
@@ -514,14 +516,14 @@ void CachedResource::setDecodedSize(unsigned size)
         // violation of the invariant that the list is to be kept sorted
         // by access time. The weakening of the invariant does not pose
         // a problem. For more details please see: https://bugs.webkit.org/show_bug.cgi?id=30209
-        bool inLiveDecodedResourcesList = memoryCache().inLiveDecodedResourcesList(*this);
+        bool inLiveDecodedResourcesList = memoryCache.inLiveDecodedResourcesList(*this);
         if (m_decodedSize && !inLiveDecodedResourcesList && hasClients())
-            memoryCache().insertInLiveDecodedResourcesList(*this);
+            memoryCache.insertInLiveDecodedResourcesList(*this);
         else if (!m_decodedSize && inLiveDecodedResourcesList)
-            memoryCache().removeFromLiveDecodedResourcesList(*this);
+            memoryCache.removeFromLiveDecodedResourcesList(*this);
 
         // Update the cache's size totals.
-        memoryCache().adjustSize(hasClients(), delta);
+        memoryCache.adjustSize(hasClients(), delta);
     }
 }
 
@@ -535,13 +537,14 @@ void CachedResource::setEncodedSize(unsigned size)
     // The object must be moved to a different queue, since its size has been changed.
     // Remove before updating m_encodedSize, so we find the resource in the correct LRU list.
     if (inCache())
-        memoryCache().removeFromLRUList(*this);
+        MemoryCache::singleton().removeFromLRUList(*this);
 
     m_encodedSize = size;
 
-    if (inCache()) { 
-        memoryCache().insertInLRUList(*this);
-        memoryCache().adjustSize(hasClients(), delta);
+    if (inCache()) {
+        auto& memoryCache = MemoryCache::singleton();
+        memoryCache.insertInLRUList(*this);
+        memoryCache.adjustSize(hasClients(), delta);
     }
 }
 
@@ -550,11 +553,12 @@ void CachedResource::didAccessDecodedData(double timeStamp)
     m_lastDecodedAccessTime = timeStamp;
     
     if (inCache()) {
-        if (memoryCache().inLiveDecodedResourcesList(*this)) {
-            memoryCache().removeFromLiveDecodedResourcesList(*this);
-            memoryCache().insertInLiveDecodedResourcesList(*this);
+        auto& memoryCache = MemoryCache::singleton();
+        if (memoryCache.inLiveDecodedResourcesList(*this)) {
+            memoryCache.removeFromLiveDecodedResourcesList(*this);
+            memoryCache.insertInLiveDecodedResourcesList(*this);
         }
-        memoryCache().prune();
+        memoryCache.prune();
     }
 }
     
index 3dca1ae..10659fd 100644 (file)
@@ -215,17 +215,18 @@ CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestUserCSSSt
     request.mutableResourceRequest().setDomainForCachePartition(document()->topOrigin()->domainForCachePartition());
 #endif
 
-    if (CachedResource* existing = memoryCache().resourceForRequest(request.resourceRequest(), sessionID())) {
+    auto& memoryCache = MemoryCache::singleton();
+    if (CachedResource* existing = memoryCache.resourceForRequest(request.resourceRequest(), sessionID())) {
         if (is<CachedCSSStyleSheet>(*existing))
             return downcast<CachedCSSStyleSheet>(existing);
-        memoryCache().remove(*existing);
+        memoryCache.remove(*existing);
     }
     if (url.string() != request.resourceRequest().url())
         request.mutableResourceRequest().setURL(url);
 
     CachedResourceHandle<CachedCSSStyleSheet> userSheet = new CachedCSSStyleSheet(request.resourceRequest(), request.charset(), sessionID());
 
-    memoryCache().add(*userSheet);
+    memoryCache.add(*userSheet);
     // FIXME: loadResource calls setOwningCachedResourceLoader() if the resource couldn't be added to cache. Does this function need to call it, too?
 
     userSheet->load(*this, ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo));
@@ -467,7 +468,8 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         return nullptr;
 #endif
 
-    if (memoryCache().disabled()) {
+    auto& memoryCache = MemoryCache::singleton();
+    if (memoryCache.disabled()) {
         DocumentResourceMap::iterator it = m_documentResources.find(url.string());
         if (it != m_documentResources.end()) {
             it->value->setOwningCachedResourceLoader(0);
@@ -482,14 +484,14 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         request.mutableResourceRequest().setDomainForCachePartition(document()->topOrigin()->domainForCachePartition());
 #endif
 
-    resource = memoryCache().resourceForRequest(request.resourceRequest(), sessionID());
+    resource = memoryCache.resourceForRequest(request.resourceRequest(), sessionID());
 
     logMemoryCacheResourceRequest(frame(), resource ? DiagnosticLoggingKeys::inMemoryCacheKey() : DiagnosticLoggingKeys::notInMemoryCacheKey());
 
     const RevalidationPolicy policy = determineRevalidationPolicy(type, request.mutableResourceRequest(), request.forPreload(), resource.get(), request.defer());
     switch (policy) {
     case Reload:
-        memoryCache().remove(*resource);
+        memoryCache.remove(*resource);
         FALLTHROUGH;
     case Load:
         if (resource)
@@ -505,7 +507,7 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         if (!shouldContinueAfterNotifyingLoadedFromMemoryCache(request, resource.get()))
             return nullptr;
         logMemoryCacheResourceRequest(frame(), DiagnosticLoggingKeys::inMemoryCacheKey(), DiagnosticLoggingKeys::usedKey());
-        memoryCache().resourceAccessed(*resource);
+        memoryCache.resourceAccessed(*resource);
         break;
     }
 
@@ -521,7 +523,7 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         // We don't support immediate loads, but we do support immediate failure.
         if (resource->errorOccurred()) {
             if (resource->inCache())
-                memoryCache().remove(*resource);
+                memoryCache.remove(*resource);
             return nullptr;
         }
     }
@@ -543,20 +545,19 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::revalidateResource(co
 {
     ASSERT(resource);
     ASSERT(resource->inCache());
-    ASSERT(!memoryCache().disabled());
+    auto& memoryCache = MemoryCache::singleton();
+    ASSERT(!memoryCache.disabled());
     ASSERT(resource->canUseCacheValidator());
     ASSERT(!resource->resourceToRevalidate());
     ASSERT(resource->sessionID() == sessionID());
 
-    // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below.
-    String url = resource->url();
     CachedResourceHandle<CachedResource> newResource = createResource(resource->type(), resource->resourceRequest(), resource->encoding(), resource->sessionID());
     
     LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource.get(), resource);
     newResource->setResourceToRevalidate(resource);
     
-    memoryCache().remove(*resource);
-    memoryCache().add(*newResource);
+    memoryCache.remove(*resource);
+    memoryCache.add(*newResource);
 #if ENABLE(RESOURCE_TIMING)
     storeResourceTimingInitiatorInformation(resource, request);
 #else
@@ -567,13 +568,14 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::revalidateResource(co
 
 CachedResourceHandle<CachedResource> CachedResourceLoader::loadResource(CachedResource::Type type, CachedResourceRequest& request)
 {
-    ASSERT(!memoryCache().resourceForRequest(request.resourceRequest(), sessionID()));
+    auto& memoryCache = MemoryCache::singleton();
+    ASSERT(!memoryCache.resourceForRequest(request.resourceRequest(), sessionID()));
 
     LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.resourceRequest().url().stringCenterEllipsizedToLength().latin1().data());
 
     CachedResourceHandle<CachedResource> resource = createResource(type, request.mutableResourceRequest(), request.charset(), sessionID());
 
-    if (!memoryCache().add(*resource))
+    if (!memoryCache.add(*resource))
         resource->setOwningCachedResourceLoader(this);
 #if ENABLE(RESOURCE_TIMING)
     storeResourceTimingInitiatorInformation(resource, request);
@@ -803,7 +805,7 @@ void CachedResourceLoader::addCachedResource(CachedResource& resource)
 {
     m_documentResources.set(resource.url(), &resource);
 
-    if (!memoryCache().add(resource))
+    if (!MemoryCache::singleton().add(resource))
         resource.setOwningCachedResourceLoader(this);
 }
 
@@ -989,7 +991,7 @@ void CachedResourceLoader::clearPreloads()
         resource->decreasePreloadCount();
         bool deleted = resource->deleteIfPossible();
         if (!deleted && resource->preloadResult() == CachedResource::PreloadNotReferenced)
-            memoryCache().remove(*resource);
+            MemoryCache::singleton().remove(*resource);
     }
     m_preloads = nullptr;
 }
@@ -1033,7 +1035,7 @@ void CachedResourceLoader::printPreloadStats()
         }
         
         if (res->errorOccurred())
-            memoryCache().remove(res);
+            MemoryCache::singleton().remove(res);
         
         res->decreasePreloadCount();
     }
index 02f8a0f..c494db1 100644 (file)
@@ -53,12 +53,10 @@ static const double cMinDelayBeforeLiveDecodedPrune = 1; // Seconds.
 static const float cTargetPrunePercentage = .95f; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
 static const auto defaultDecodedDataDeletionInterval = std::chrono::seconds { 0 };
 
-MemoryCache& memoryCache()
+MemoryCache& MemoryCache::singleton()
 {
     ASSERT(WTF::isMainThread());
-
     static NeverDestroyed<MemoryCache> memoryCache;
-
     return memoryCache;
 }
 
@@ -639,9 +637,10 @@ void MemoryCache::removeRequestFromSessionCaches(ScriptExecutionContext& context
         return;
     }
 
-    for (auto& resources : memoryCache().m_sessionResources) {
-        if (CachedResource* resource = memoryCache().resourceForRequestImpl(request, *resources.value))
-            memoryCache().remove(*resource);
+    auto& memoryCache = MemoryCache::singleton();
+    for (auto& resources : memoryCache.m_sessionResources) {
+        if (CachedResource* resource = memoryCache.resourceForRequestImpl(request, *resources.value))
+            memoryCache.remove(*resource);
     }
 }
 
index fcdf6f4..7a08c46 100644 (file)
@@ -61,9 +61,9 @@ class SecurityOrigin;
 
 class MemoryCache {
     WTF_MAKE_NONCOPYABLE(MemoryCache); WTF_MAKE_FAST_ALLOCATED;
-public:
     friend NeverDestroyed<MemoryCache>;
 
+public:
     struct TypeStatistic {
         int count;
         int size;
@@ -89,6 +89,8 @@ public:
         TypeStatistic fonts;
     };
 
+    WEBCORE_EXPORT static MemoryCache& singleton();
+
     WEBCORE_EXPORT CachedResource* resourceForURL(const URL&, SessionID = SessionID::defaultSessionID());
     WEBCORE_EXPORT CachedResource* resourceForRequest(const ResourceRequest&, SessionID);
 
@@ -214,9 +216,6 @@ private:
     SessionCachedResourceMap m_sessionResources;
 };
 
-// Function to obtain the global cache.
-WEBCORE_EXPORT MemoryCache& memoryCache();
-
 }
 
 #endif
index b5ab707..ca1b5fe 100644 (file)
@@ -112,7 +112,7 @@ DiskCacheMonitor::DiskCacheMonitor(const ResourceRequest& request, SessionID ses
 
 void DiskCacheMonitor::resourceBecameFileBacked(SharedBuffer& fileBackedBuffer)
 {
-    CachedResource* resource = memoryCache().resourceForRequest(m_resourceRequest, m_sessionID);
+    CachedResource* resource = MemoryCache::singleton().resourceForRequest(m_resourceRequest, m_sessionID);
     if (!resource)
         return;
 
index 1ea720d..e802f91 100644 (file)
@@ -3761,7 +3761,7 @@ void FrameView::willPaintContents(GraphicsContext* context, const IntRect& dirty
 
         // To avoid unnecessary image decoding, we don't prune recently-decoded live resources here since
         // we might need some live bitmaps on painting.
-        memoryCache().prune();
+        MemoryCache::singleton().prune();
     }
 
     if (paintingState.isTopLevelPainter)
@@ -3801,7 +3801,7 @@ void FrameView::didPaintContents(GraphicsContext* context, const IntRect& dirtyR
     // Painting can lead to decoding of large amounts of bitmaps
     // If we are low on memory, wipe them out after the paint.
     if (paintingState.isTopLevelPainter && memoryPressureHandler().isUnderMemoryPressure())
-        memoryCache().pruneLiveResources(true);
+        MemoryCache::singleton().pruneLiveResources(true);
 
     // Regions may have changed as a result of the visibility/z-index of element changing.
 #if ENABLE(DASHBOARD_SUPPORT)
index e524696..034141d 100644 (file)
@@ -107,7 +107,7 @@ void MemoryPressureHandler::releaseCriticalMemory()
 
     {
         ReliefLogger log("Prune MemoryCache");
-        memoryCache().evictResources();
+        MemoryCache::singleton().evictResources();
     }
 
     {
index 87de756..3e3235b 100644 (file)
@@ -380,7 +380,7 @@ bool Internals::isLoadingFromMemoryCache(const String& url)
 {
     if (!contextDocument() || !contextDocument()->page())
         return false;
-    CachedResource* resource = memoryCache().resourceForURL(contextDocument()->completeURL(url), contextDocument()->page()->sessionID());
+    CachedResource* resource = MemoryCache::singleton().resourceForURL(contextDocument()->completeURL(url), contextDocument()->page()->sessionID());
     return resource && resource->status() == CachedResource::Cached;
 }
 
@@ -406,7 +406,7 @@ String Internals::xhrResponseSource(XMLHttpRequest* xhr)
 
 void Internals::clearMemoryCache()
 {
-    memoryCache().evictResources();
+    MemoryCache::singleton().evictResources();
 }
 
 Node* Internals::treeScopeRootNode(Node* node, ExceptionCode& ec)
index 528a717..9e3ae4b 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-02  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryCache singleton using MemoryCache::singleton()
+        https://bugs.webkit.org/show_bug.cgi?id=141104
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryCache singleton using MemoryCache::singleton() static
+        member function, instead of a free function, as per the recent
+        coding style discussion on WebKit-dev.
+
 2015-02-01  Chris Dumez  <cdumez@apple.com>
 
         Use more references in HistoryItem
index 4431a90..b4148ac 100644 (file)
@@ -65,7 +65,7 @@
 
 + (NSArray *)statistics
 {
-    WebCore::MemoryCache::Statistics s = WebCore::memoryCache().getStatistics();
+    WebCore::MemoryCache::Statistics s = WebCore::MemoryCache::singleton().getStatistics();
 
     return [NSArray arrayWithObjects:
         [NSDictionary dictionaryWithObjectsAndKeys:
         [WebView _setCacheModel:WebCacheModelDocumentViewer];
         [WebView _setCacheModel:cacheModel];
 
-        WebCore::memoryCache().pruneLiveResources(true);
+        WebCore::MemoryCache::singleton().pruneLiveResources(true);
     });
 }
 
 + (void)sizeOfDeadResources:(int *)resources
 {
-    WebCore::MemoryCache::Statistics stats = WebCore::memoryCache().getStatistics();
+    WebCore::MemoryCache::Statistics stats = WebCore::MemoryCache::singleton().getStatistics();
     if (resources) {
         *resources = (stats.images.size - stats.images.liveSize)
                      + (stats.cssStyleSheets.size - stats.cssStyleSheets.liveSize)
     if (frame)
         topOrigin = core(frame)->document()->topOrigin();
 #endif
-    return WebCore::memoryCache().addImageToCache(image, url, topOrigin ? topOrigin->domainForCachePartition() : emptyString());
+    return WebCore::MemoryCache::singleton().addImageToCache(image, url, topOrigin ? topOrigin->domainForCachePartition() : emptyString());
 }
 
 + (void)removeImageFromCacheForURL:(NSURL *)url
     if (frame)
         topOrigin = core(frame)->document()->topOrigin();
 #endif
-    WebCore::memoryCache().removeImageFromCache(url, topOrigin ? topOrigin->domainForCachePartition() : emptyString());
+    WebCore::MemoryCache::singleton().removeImageFromCache(url, topOrigin ? topOrigin->domainForCachePartition() : emptyString());
 }
 
 + (CGImageRef)imageForURL:(NSURL *)url
     if (!url)
         return nullptr;
     
-    WebCore::CachedResource* cachedResource = WebCore::memoryCache().resourceForURL(url);
+    WebCore::CachedResource* cachedResource = WebCore::MemoryCache::singleton().resourceForURL(url);
     if (!is<WebCore::CachedImage>(cachedResource))
         return nullptr;
     WebCore::CachedImage& cachedImage = downcast<WebCore::CachedImage>(*cachedResource);
     if (!pthread_main_np())
         return [[self _webkit_invokeOnMainThread] setDisabled:disabled];
 
-    WebCore::memoryCache().setDisabled(disabled);
+    WebCore::MemoryCache::singleton().setDisabled(disabled);
 }
 
 + (BOOL)isDisabled
 {
-    return WebCore::memoryCache().disabled();
+    return WebCore::MemoryCache::singleton().disabled();
 }
 
 @end
index 483ca0e..c2bdade 100644 (file)
@@ -7913,8 +7913,9 @@ static inline uint64_t roundUpToPowerOf2(uint64_t num)
     // Don't shrink a big disk cache, since that would cause churn.
     nsurlCacheDiskCapacity = std::max(nsurlCacheDiskCapacity, [nsurlCache diskCapacity]);
 
-    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+    auto& memoryCache = MemoryCache::singleton();
+    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
 
     auto& pageCache = PageCache::singleton();
     pageCache.setMaxSize(pageCacheSize);
index ce59fec..84a088a 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-02  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryCache singleton using MemoryCache::singleton()
+        https://bugs.webkit.org/show_bug.cgi?id=141104
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryCache singleton using MemoryCache::singleton() static
+        member function, instead of a free function, as per the recent
+        coding style discussion on WebKit-dev.
+
 2015-01-30  Chris Dumez  <cdumez@apple.com>
 
         Rename shared() static member functions to singleton() for singleton classes.
index da2726b..4ae500c 100644 (file)
@@ -99,7 +99,7 @@ HRESULT WebCache::statistics(int* count, IPropertyBag** s)
     if (!s)
         return S_OK;
 
-    WebCore::MemoryCache::Statistics stat = WebCore::memoryCache().getStatistics();
+    WebCore::MemoryCache::Statistics stat = WebCore::MemoryCache::singleton().getStatistics();
 
     static CFStringRef imagesKey = CFSTR("images");
     static CFStringRef stylesheetsKey = CFSTR("style sheets");
@@ -206,10 +206,11 @@ HRESULT WebCache::statistics(int* count, IPropertyBag** s)
 
 HRESULT STDMETHODCALLTYPE WebCache::empty( void)
 {
-    if (WebCore::memoryCache().disabled())
+    auto& memoryCache = WebCore::MemoryCache::singleton();
+    if (memoryCache.disabled())
         return S_OK;
-    WebCore::memoryCache().setDisabled(true);
-    WebCore::memoryCache().setDisabled(false);
+    memoryCache.setDisabled(true);
+    memoryCache.setDisabled(false);
 
     // Empty the application cache.
     WebCore::cacheStorage().empty();
@@ -223,7 +224,7 @@ HRESULT STDMETHODCALLTYPE WebCache::empty( void)
 HRESULT STDMETHODCALLTYPE WebCache::setDisabled( 
     /* [in] */ BOOL disabled)
 {
-    WebCore::memoryCache().setDisabled(!!disabled);
+    WebCore::MemoryCache::singleton().setDisabled(!!disabled);
     return S_OK;
 }
 
@@ -232,7 +233,7 @@ HRESULT STDMETHODCALLTYPE WebCache::disabled(
 {
     if (!disabled)
         return E_POINTER;
-    *disabled = WebCore::memoryCache().disabled();
+    *disabled = WebCore::MemoryCache::singleton().disabled();
     return S_OK;
 }
 
index 7ae02c0..fb084e3 100644 (file)
@@ -673,8 +673,9 @@ void WebView::setCacheModel(WebCacheModel cacheModel)
         ASSERT_NOT_REACHED();
     }
 
-    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+    auto& memoryCache = MemoryCache::singleton();
+    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
     PageCache::singleton().setMaxSize(pageCacheSize);
 
 #if USE(CFNETWORK)
index f3f2319..55668ab 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-02  Chris Dumez  <cdumez@apple.com>
+
+        Access MemoryCache singleton using MemoryCache::singleton()
+        https://bugs.webkit.org/show_bug.cgi?id=141104
+
+        Reviewed by Andreas Kling.
+
+        Access MemoryCache singleton using MemoryCache::singleton() static
+        member function, instead of a free function, as per the recent
+        coding style discussion on WebKit-dev.
+
 2015-02-02  Jeremy Jones  <jeremyj@apple.com>
 
         Prevent crash when accessing WebAVPlayerController.delegate.
index 8370cc4..43f5dec 100644 (file)
@@ -83,7 +83,7 @@ void NetworkProcessConnection::didReceiveInvalidMessage(IPC::Connection&, IPC::S
 #if ENABLE(SHAREABLE_RESOURCE)
 void NetworkProcessConnection::didCacheResource(const ResourceRequest& request, const ShareableResource::Handle& handle, SessionID sessionID)
 {
-    CachedResource* resource = memoryCache().resourceForRequest(request, sessionID);
+    CachedResource* resource = MemoryCache::singleton().resourceForRequest(request, sessionID);
     if (!resource)
         return;
     
index db82cea..35492f8 100644 (file)
@@ -57,7 +57,7 @@ void WebResourceCacheManager::getCacheOrigins(uint64_t callbackID) const
 #else
     MemoryCache::SecurityOriginSet origins;
 #endif
-    memoryCache().getOriginsWithCache(origins);
+    MemoryCache::singleton().getOriginsWithCache(origins);
 
 #if USE(CFURLCACHE)
 #if ENABLE(CACHE_PARTITIONING)
@@ -114,7 +114,7 @@ void WebResourceCacheManager::clearCacheForOrigin(const SecurityOriginData& orig
     if (!origin)
         return;
 
-    memoryCache().removeResourcesWithOrigin(*origin);
+    MemoryCache::singleton().removeResourcesWithOrigin(*origin);
 
 #if USE(CFURLCACHE)
     if (resourceCachesToClear != InMemoryResourceCachesOnly) { 
index f5a973d..05edf6a 100644 (file)
@@ -575,7 +575,7 @@ void WebProcess::terminate()
 #ifndef NDEBUG
     gcController().garbageCollectNow();
     fontCache().invalidate();
-    memoryCache().setDisabled(true);
+    MemoryCache::singleton().setDisabled(true);
 #endif
 
     m_webConnection->invalidate();
@@ -633,7 +633,7 @@ void WebProcess::didClose(IPC::Connection&)
 
     gcController().garbageCollectSoon();
     fontCache().invalidate();
-    memoryCache().setDisabled(true);
+    MemoryCache::singleton().setDisabled(true);
 #endif    
 
     // The UI process closed this connection, shut down.
@@ -705,7 +705,7 @@ void WebProcess::clearResourceCaches(ResourceCachesToClear resourceCachesToClear
     setCacheModel(CacheModelDocumentViewer);
     setCacheModel(cacheModel);
 
-    memoryCache().evictResources();
+    MemoryCache::singleton().evictResources();
 
     // Empty the cross-origin preflight cache.
     CrossOriginPreflightResultCache::singleton().empty();
@@ -861,7 +861,7 @@ static void getWebCoreMemoryCacheStatistics(Vector<HashMap<String, uint64_t>>& r
     String xslString(ASCIILiteral("XSL"));
     String javaScriptString(ASCIILiteral("JavaScript"));
     
-    MemoryCache::Statistics memoryCacheStatistics = memoryCache().getStatistics();
+    MemoryCache::Statistics memoryCacheStatistics = MemoryCache::singleton().getStatistics();
     
     HashMap<String, uint64_t> counts;
     counts.set(imagesString, memoryCacheStatistics.images.count);
@@ -1319,8 +1319,9 @@ RefPtr<API::Object> WebProcess::transformObjectsToHandles(API::Object* object)
 
 void WebProcess::setMemoryCacheDisabled(bool disabled)
 {
-    if (memoryCache().disabled() != disabled)
-        memoryCache().setDisabled(disabled);
+    auto& memoryCache = MemoryCache::singleton();
+    if (memoryCache.disabled() != disabled)
+        memoryCache.setDisabled(disabled);
 }
 
 #if ENABLE(SERVICE_CONTROLS)
index 0d8a3cf..2d6ba14 100644 (file)
@@ -112,9 +112,9 @@ void WebProcess::platformSetCacheModel(CacheModel cacheModel)
         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
         pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
 
-
-    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+    auto& memoryCache = MemoryCache::singleton();
+    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
     PageCache::singleton().setMaxSize(pageCacheSize);
 
     NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
index 9a28708..2f09d6c 100644 (file)
@@ -101,9 +101,10 @@ void WebProcess::platformSetCacheModel(CacheModel cacheModel)
                         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
                         pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
 
-    WebCore::memoryCache().setDisabled(cacheModel == CacheModelDocumentViewer);
-    WebCore::memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
-    WebCore::memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+    auto& memoryCache = WebCore::MemoryCache::singleton();
+    memoryCache.setDisabled(cacheModel == CacheModelDocumentViewer);
+    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
     WebCore::PageCache::singleton().setMaxSize(pageCacheSize);
 
 #if PLATFORM(GTK)