Changeset 179347 in webkit


Ignore:
Timestamp:
Jan 29, 2015 10:38:51 AM (9 years ago)
Author:
Chris Dumez
Message:

Clean up / modernize PageCache class
https://bugs.webkit.org/show_bug.cgi?id=141009

Reviewed by Darin Adler.

Source/WebCore:

Clean up / modernize PageCache class:

  • Use more references instead of pointers
  • Use a ListHashSet<Ref<HistoryItem>> internally instead of a linked list of HistoryItem*. This avoids having the ref/unref HistoryItems manually and maintaining the list size separately. It also simplifies the code dealing with the container and makes looking up HistoryItems faster as a bonus. Similarly to the previous implementation, we are adding elements to one end and removing from the opposite end when pruning to drop old history items first. Note that even though the previous implementation was called LRUList, it did not move items to the front when accessed. The new implementation doesn't either.
    • Rename "capacity" to "maxSize" to avoid confusing with containers' capacity (which doesn't limit the size of the container).
    • Use unsigned instead of int for all values that are supposed to be positive.
    • Do not explicitely define the default constructor and let the compiler generate it for us (and use in-class initialization for members)
    • Fix indentation in the header.

Source/WebKit/mac:

Clean up / modernize PageCache class.

  • History/WebBackForwardList.mm:

(-[WebBackForwardList pageCacheSize]):

  • WebView/WebView.mm:

(-[WebView _loadBackForwardListFromOtherView:]):
(-[WebView goToBackForwardItem:]):
(+[WebView _setCacheModel:]):

Source/WebKit/win:

Clean up / modernize PageCache class.

  • WebView.cpp:

(WebView::setCacheModel):

Source/WebKit2:

Clean up / modernize PageCache class.

  • WebProcess/WebPage/WebBackForwardListProxy.cpp:

(WebKit::WebBackForwardListProxy::removeItem):
(WebKit::WebBackForwardListProxy::close):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::goForward):
(WebKit::WebPage::goBack):
(WebKit::WebPage::goToBackForwardItem):

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::releasePageCache):

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformSetCacheModel):

  • WebProcess/soup/WebProcessSoup.cpp:

(WebKit::WebProcess::platformSetCacheModel):

Location:
trunk/Source
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r179344 r179347  
     12015-01-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Clean up / modernize PageCache class
     4        https://bugs.webkit.org/show_bug.cgi?id=141009
     5
     6        Reviewed by Darin Adler.
     7
     8        Clean up / modernize PageCache class:
     9        - Use more references instead of pointers
     10        - Use a ListHashSet<Ref<HistoryItem>> internally instead of a linked
     11          list of HistoryItem*. This avoids having the ref/unref HistoryItems
     12          manually and maintaining the list size separately. It also simplifies
     13          the code dealing with the container and makes looking up HistoryItems
     14          faster as a bonus. Similarly to the previous implementation, we are
     15          adding elements to one end and removing from the opposite end when
     16          pruning to drop old history items first. Note that even though the
     17          previous implementation was called LRUList, it did not move items to
     18          the front when accessed. The new implementation doesn't either.
     19         - Rename "capacity" to "maxSize" to avoid confusing with containers'
     20           capacity (which doesn't limit the size of the container).
     21         - Use unsigned instead of int for all values that are supposed to be
     22           positive.
     23         - Do not explicitely define the default constructor and let the
     24           compiler generate it for us (and use in-class initialization for
     25           members)
     26         - Fix indentation in the header.
     27
    1282015-01-29  Julien Isorce  <j.isorce@samsung.com>
    229
  • trunk/Source/WebCore/WebCore.exp.in

    r179293 r179347  
    12401240__ZN7WebCore4Page36suspendActiveDOMObjectsAndAnimationsEv
    12411241__ZN7WebCore4Page37setInLowQualityImageInterpolationModeEb
    1242 __ZN7WebCore4Page8goToItemEPNS_11HistoryItemENS_13FrameLoadTypeE
     1242__ZN7WebCore4Page8goToItemERNS_11HistoryItemENS_13FrameLoadTypeE
    12431243__ZN7WebCore4Page8setMutedEb
    12441244__ZN7WebCore4Page9initGroupEv
     
    16071607__ZN7WebCore9LayerPoolC1Ev
    16081608__ZN7WebCore9LayerPoolD1Ev
    1609 __ZN7WebCore9PageCache11setCapacityEi
    1610 __ZN7WebCore9PageCache18pruneToCapacityNowEiNS_13PruningReasonE
     1609__ZN7WebCore9PageCache10setMaxSizeEj
     1610__ZN7WebCore9PageCache14pruneToSizeNowEjNS_13PruningReasonE
    16111611__ZN7WebCore9PageCache34markPagesForVisitedLinkStyleRecalcEv
    1612 __ZN7WebCore9PageCache6removeEPNS_11HistoryItemE
     1612__ZN7WebCore9PageCache6removeERNS_11HistoryItemE
    16131613__ZN7WebCore9PageCache6sharedEv
    16141614__ZN7WebCore9PageGroup9pageGroupERKN3WTF6StringE
  • trunk/Source/WebCore/history/BackForwardController.cpp

    r170134 r179347  
    7575        return;
    7676
    77     m_page.goToItem(item, FrameLoadType::IndexedBackForward);
     77    m_page.goToItem(*item, FrameLoadType::IndexedBackForward);
    7878}
    7979
     
    8484        return false;
    8585
    86     m_page.goToItem(item, FrameLoadType::Back);
     86    m_page.goToItem(*item, FrameLoadType::Back);
    8787    return true;
    8888}
     
    9494        return false;
    9595
    96     m_page.goToItem(item, FrameLoadType::Forward);
     96    m_page.goToItem(*item, FrameLoadType::Forward);
    9797    return true;
    9898}
  • trunk/Source/WebCore/history/BackForwardList.cpp

    r179247 r179347  
    6969            m_entries.removeLast();
    7070            m_entryHash.remove(item);
    71             PageCache::shared().remove(item.get());
     71            PageCache::shared().remove(*item);
    7272        }
    7373    }
     
    7979        m_entries.remove(0);
    8080        m_entryHash.remove(item);
    81         PageCache::shared().remove(item.get());
     81        PageCache::shared().remove(*item);
    8282        m_current--;
    8383    }
     
    176176        m_entries.removeLast();
    177177        m_entryHash.remove(item);
    178         PageCache::shared().remove(item.get());
     178        PageCache::shared().remove(*item);
    179179    }
    180180
     
    243243{
    244244    bool didRemoveAtLeastOneItem = false;
    245     unsigned length = m_entries.size();
    246     for (unsigned i = 0; i < length; ++i) {
    247         HistoryItem* item = m_entries[i].get();
     245    for (auto& item : m_entries) {
    248246        if (item->isInPageCache()) {
    249247            didRemoveAtLeastOneItem = true;
    250             PageCache::shared().remove(item);
     248            PageCache::shared().remove(*item);
    251249        }
    252250    }
     
    257255void BackForwardList::close()
    258256{
    259     int size = m_entries.size();
    260     for (int i = 0; i < size; ++i)
    261         PageCache::shared().remove(m_entries[i].get());
     257    for (auto& item : m_entries)
     258        PageCache::shared().remove(*item);
    262259    m_entries.clear();
    263260    m_entryHash.clear();
    264     m_page = 0;
     261    m_page = nullptr;
    265262    m_closed = true;
    266263}
  • trunk/Source/WebCore/history/HistoryItem.cpp

    r179247 r179347  
    287287void HistoryItem::setURL(const URL& url)
    288288{
    289     PageCache::shared().remove(this);
     289    PageCache::shared().remove(*this);
    290290    setURLString(url.string());
    291291    clearDocumentState();
  • trunk/Source/WebCore/history/PageCache.cpp

    r179263 r179347  
    11/*
    2  * Copyright (C) 2007, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007, 2014, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4444#include "FrameView.h"
    4545#include "HistoryController.h"
    46 #include "HistoryItem.h"
    4746#include "Logging.h"
    4847#include "MainFrame.h"
     
    111110}
    112111
    113 static unsigned logCanCacheFrameDecision(Frame& frame, DiagnosticLoggingClient& diagnosticLoggingClient, int indentLevel)
     112static unsigned logCanCacheFrameDecision(Frame& frame, DiagnosticLoggingClient& diagnosticLoggingClient, unsigned indentLevel)
    114113{
    115114    PCLOG("+---");
     
    235234        return;
    236235   
    237     int indentLevel = 0;   
     236    unsigned indentLevel = 0;
    238237    PCLOG("--------\n Determining if page can be cached:");
    239238   
     
    298297    return globalPageCache;
    299298}
    300 
    301 PageCache::PageCache()
    302     : m_capacity(0)
    303     , m_size(0)
    304     , m_head(0)
    305     , m_tail(0)
    306     , m_shouldClearBackingStores(false)
    307 {
    308 }
    309    
    310 bool PageCache::canCachePageContainingThisFrame(Frame* frame)
    311 {
    312     for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) {
    313         if (!canCachePageContainingThisFrame(child))
     299   
     300bool PageCache::canCachePageContainingThisFrame(Frame& frame)
     301{
     302    for (Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling()) {
     303        if (!canCachePageContainingThisFrame(*child))
    314304            return false;
    315305    }
    316306   
    317     FrameLoader& frameLoader = frame->loader();
     307    FrameLoader& frameLoader = frame.loader();
    318308    DocumentLoader* documentLoader = frameLoader.documentLoader();
    319     Document* document = frame->document();
     309    Document* document = frame.document();
    320310   
    321311    return documentLoader
     
    327317        // Do not cache error pages (these can be recognized as pages with substitute data or unreachable URLs).
    328318        && !(documentLoader->substituteData().isValid() && !documentLoader->substituteData().failingURL().isEmpty())
    329         && (!frameLoader.subframeLoader().containsPlugins() || frame->page()->settings().pageCacheSupportsPlugins())
    330         && !(frame->isMainFrame() && document->url().protocolIs("https") && documentLoader->response().cacheControlContainsNoStore())
     319        && (!frameLoader.subframeLoader().containsPlugins() || frame.page()->settings().pageCacheSupportsPlugins())
     320        && !(frame.isMainFrame() && document->url().protocolIs("https") && documentLoader->response().cacheControlContainsNoStore())
    331321        && !DatabaseManager::manager().hasOpenDatabases(document)
    332322        && frameLoader.history().currentItem()
     
    358348    FrameLoadType loadType = page->mainFrame().loader().loadType();
    359349   
    360     return m_capacity > 0
    361         && canCachePageContainingThisFrame(&page->mainFrame())
     350    return m_maxSize > 0
     351        && canCachePageContainingThisFrame(page->mainFrame())
    362352        && page->settings().usesPageCache()
    363353#if ENABLE(DEVICE_ORIENTATION) && !PLATFORM(IOS)
     
    374364}
    375365
    376 void PageCache::pruneToCapacityNow(int capacity, PruningReason pruningReason)
    377 {
    378     TemporaryChange<int>(m_capacity, std::max(capacity, 0));
     366void PageCache::pruneToSizeNow(unsigned size, PruningReason pruningReason)
     367{
     368    TemporaryChange<unsigned>(m_maxSize, size);
    379369    prune(pruningReason);
    380370}
    381371
    382 void PageCache::setCapacity(int capacity)
    383 {
    384     ASSERT(capacity >= 0);
    385     m_capacity = std::max(capacity, 0);
    386 
     372void PageCache::setMaxSize(unsigned maxSize)
     373{
     374    m_maxSize = maxSize;
    387375    prune(PruningReason::None);
    388376}
    389377
    390 int PageCache::frameCount() const
    391 {
    392     int frameCount = 0;
    393     for (HistoryItem* current = m_head; current; current = current->m_next) {
    394         ++frameCount;
    395         ASSERT(current->m_cachedPage);
    396         frameCount += current->m_cachedPage->cachedMainFrame()->descendantFrameCount();
     378unsigned PageCache::frameCount() const
     379{
     380    unsigned frameCount = m_items.size();
     381    for (auto& item : m_items) {
     382        ASSERT(item->m_cachedPage);
     383        frameCount += item->m_cachedPage->cachedMainFrame()->descendantFrameCount();
    397384    }
    398385   
     
    402389void PageCache::markPagesForVisitedLinkStyleRecalc()
    403390{
    404     for (HistoryItem* current = m_head; current; current = current->m_next) {
    405         ASSERT(current->m_cachedPage);
    406         current->m_cachedPage->markForVisitedLinkStyleRecalc();
    407     }
    408 }
    409 
    410 void PageCache::markPagesForFullStyleRecalc(Page* page)
    411 {
    412     for (HistoryItem* current = m_head; current; current = current->m_next) {
    413         CachedPage& cachedPage = *current->m_cachedPage;
    414         if (&page->mainFrame() == &cachedPage.cachedMainFrame()->view()->frame())
     391    for (auto& item : m_items) {
     392        ASSERT(item->m_cachedPage);
     393        item->m_cachedPage->markForVisitedLinkStyleRecalc();
     394    }
     395}
     396
     397void PageCache::markPagesForFullStyleRecalc(Page& page)
     398{
     399    for (auto& item : m_items) {
     400        CachedPage& cachedPage = *item->m_cachedPage;
     401        if (&page.mainFrame() == &cachedPage.cachedMainFrame()->view()->frame())
    415402            cachedPage.markForFullStyleRecalc();
    416403    }
    417404}
    418405
    419 void PageCache::markPagesForDeviceScaleChanged(Page* page)
    420 {
    421     for (HistoryItem* current = m_head; current; current = current->m_next) {
    422         CachedPage& cachedPage = *current->m_cachedPage;
    423         if (&page->mainFrame() == &cachedPage.cachedMainFrame()->view()->frame())
     406void PageCache::markPagesForDeviceScaleChanged(Page& page)
     407{
     408    for (auto& item : m_items) {
     409        CachedPage& cachedPage = *item->m_cachedPage;
     410        if (&page.mainFrame() == &cachedPage.cachedMainFrame()->view()->frame())
    424411            cachedPage.markForDeviceScaleChanged();
    425412    }
     
    429416void PageCache::markPagesForCaptionPreferencesChanged()
    430417{
    431     for (HistoryItem* current = m_head; current; current = current->m_next) {
    432         ASSERT(current->m_cachedPage);
    433         current->m_cachedPage->markForCaptionPreferencesChanged();
     418    for (auto& item : m_items) {
     419        ASSERT(item->m_cachedPage);
     420        item->m_cachedPage->markForCaptionPreferencesChanged();
    434421    }
    435422}
     
    443430    case PruningReason::ProcessSuspended:
    444431        return DiagnosticLoggingKeys::prunedDueToProcessSuspended();
    445     case PruningReason::ReachedCapacity:
    446         return DiagnosticLoggingKeys::prunedDueToCapacityReached();
     432    case PruningReason::ReachedMaxSize:
     433        return DiagnosticLoggingKeys::prunedDueToMaxSizeReached();
    447434    case PruningReason::None:
    448435        break;
     
    452439}
    453440
    454 void PageCache::add(PassRefPtr<HistoryItem> prpItem, Page& page)
    455 {
    456     ASSERT(prpItem);
     441void PageCache::add(HistoryItem& item, Page& page)
     442{
    457443    ASSERT(canCache(&page));
    458    
    459     HistoryItem* item = prpItem.leakRef(); // Balanced in remove().
    460444
    461445    // Remove stale cache entry if necessary.
    462     if (item->m_cachedPage)
    463         remove(item);
    464 
    465     item->m_cachedPage = std::make_unique<CachedPage>(page);
    466     item->m_pruningReason = PruningReason::None;
    467     addToLRUList(item);
    468     ++m_size;
    469    
    470     prune(PruningReason::ReachedCapacity);
    471 }
    472 
    473 std::unique_ptr<CachedPage> PageCache::take(HistoryItem* item, Page* page)
    474 {
    475     if (!item)
     446    remove(item);
     447
     448    item.m_cachedPage = std::make_unique<CachedPage>(page);
     449    item.m_pruningReason = PruningReason::None;
     450    m_items.add(&item);
     451   
     452    prune(PruningReason::ReachedMaxSize);
     453}
     454
     455std::unique_ptr<CachedPage> PageCache::take(HistoryItem& item, Page* page)
     456{
     457    if (!item.m_cachedPage) {
     458        if (item.m_pruningReason != PruningReason::None)
     459            logPageCacheFailureDiagnosticMessage(page, pruningReasonToDiagnosticLoggingKey(item.m_pruningReason));
    476460        return nullptr;
    477 
    478     std::unique_ptr<CachedPage> cachedPage = WTF::move(item->m_cachedPage);
    479 
    480     removeFromLRUList(item);
    481     --m_size;
    482 
    483     item->deref(); // Balanced in add().
    484 
    485     if (!cachedPage) {
    486         if (item->m_pruningReason != PruningReason::None)
    487             logPageCacheFailureDiagnosticMessage(page, pruningReasonToDiagnosticLoggingKey(item->m_pruningReason));
    488         return nullptr;
    489     }
     461    }
     462
     463    std::unique_ptr<CachedPage> cachedPage = WTF::move(item.m_cachedPage);
     464    m_items.remove(&item);
    490465
    491466    if (cachedPage->hasExpired()) {
    492         LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item->url().string().ascii().data());
     467        LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item.url().string().ascii().data());
    493468        logPageCacheFailureDiagnosticMessage(page, DiagnosticLoggingKeys::expiredKey());
    494469        return nullptr;
     
    498473}
    499474
    500 CachedPage* PageCache::get(HistoryItem* item, Page* page)
    501 {
    502     if (!item)
     475CachedPage* PageCache::get(HistoryItem& item, Page* page) const
     476{
     477    CachedPage* cachedPage = item.m_cachedPage.get();
     478    if (!cachedPage) {
     479        if (item.m_pruningReason != PruningReason::None)
     480            logPageCacheFailureDiagnosticMessage(page, pruningReasonToDiagnosticLoggingKey(item.m_pruningReason));
    503481        return nullptr;
    504 
    505     if (CachedPage* cachedPage = item->m_cachedPage.get()) {
    506         if (!cachedPage->hasExpired())
    507             return cachedPage;
    508        
    509         LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item->url().string().ascii().data());
     482    }
     483
     484    if (cachedPage->hasExpired()) {
     485        LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item.url().string().ascii().data());
    510486        logPageCacheFailureDiagnosticMessage(page, DiagnosticLoggingKeys::expiredKey());
    511487        PageCache::shared().remove(item);
    512     } else if (item->m_pruningReason != PruningReason::None)
    513         logPageCacheFailureDiagnosticMessage(page, pruningReasonToDiagnosticLoggingKey(item->m_pruningReason));
    514 
    515     return nullptr;
    516 }
    517 
    518 void PageCache::remove(HistoryItem* item)
     488        return nullptr;
     489    }
     490    return cachedPage;
     491}
     492
     493void PageCache::remove(HistoryItem& item)
    519494{
    520495    // Safely ignore attempts to remove items not in the cache.
    521     if (!item || !item->m_cachedPage)
     496    if (!item.m_cachedPage)
    522497        return;
    523498
    524     item->m_cachedPage = nullptr;
    525     removeFromLRUList(item);
    526     --m_size;
    527 
    528     item->deref(); // Balanced in add().
     499    item.m_cachedPage = nullptr;
     500    m_items.remove(&item);
    529501}
    530502
    531503void PageCache::prune(PruningReason pruningReason)
    532504{
    533     while (m_size > m_capacity) {
    534         ASSERT(m_tail && m_tail->m_cachedPage);
    535         m_tail->m_pruningReason = pruningReason;
    536         remove(m_tail);
    537     }
    538 }
    539 
    540 void PageCache::addToLRUList(HistoryItem* item)
    541 {
    542     item->m_next = m_head;
    543     item->m_prev = 0;
    544 
    545     if (m_head) {
    546         ASSERT(m_tail);
    547         m_head->m_prev = item;
    548     } else {
    549         ASSERT(!m_tail);
    550         m_tail = item;
    551     }
    552 
    553     m_head = item;
    554 }
    555 
    556 void PageCache::removeFromLRUList(HistoryItem* item)
    557 {
    558     if (!item->m_next) {
    559         ASSERT(item == m_tail);
    560         m_tail = item->m_prev;
    561     } else {
    562         ASSERT(item != m_tail);
    563         item->m_next->m_prev = item->m_prev;
    564     }
    565 
    566     if (!item->m_prev) {
    567         ASSERT(item == m_head);
    568         m_head = item->m_next;
    569     } else {
    570         ASSERT(item != m_head);
    571         item->m_prev->m_next = item->m_next;
     505    while (pageCount() > maxSize()) {
     506        auto& oldestItem = m_items.first();
     507        oldestItem->m_cachedPage = nullptr;
     508        oldestItem->m_pruningReason = pruningReason;
     509        m_items.removeFirst();
    572510    }
    573511}
  • trunk/Source/WebCore/history/PageCache.h

    r179263 r179347  
    11/*
    2  * Copyright (C) 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define PageCache_h
    2828
     29#include "HistoryItem.h"
    2930#include "Timer.h"
    3031#include <wtf/Forward.h>
    31 #include <wtf/HashSet.h>
     32#include <wtf/ListHashSet.h>
    3233#include <wtf/Noncopyable.h>
    3334
    3435namespace WebCore {
    3536
    36     class CachedPage;
    37     class Frame;
    38     class HistoryItem;
    39     class Page;
     37class CachedPage;
     38class Frame;
     39class Page;
    4040
    41     enum class PruningReason { None, ProcessSuspended, MemoryPressure, ReachedCapacity };
    42    
    43     class PageCache {
    44         WTF_MAKE_NONCOPYABLE(PageCache); WTF_MAKE_FAST_ALLOCATED;
    45     public:
    46         // Function to obtain the global page cache.
    47         WEBCORE_EXPORT static PageCache& shared();
    48        
    49         bool canCache(Page*) const;
     41enum class PruningReason { None, ProcessSuspended, MemoryPressure, ReachedMaxSize };
    5042
    51         WEBCORE_EXPORT void setCapacity(int); // number of pages to cache
    52         int capacity() { return m_capacity; }
    53        
    54         void add(PassRefPtr<HistoryItem>, Page&); // Prunes if capacity() is exceeded.
    55         WEBCORE_EXPORT void remove(HistoryItem*);
    56         CachedPage* get(HistoryItem*, Page*);
    57         std::unique_ptr<CachedPage> take(HistoryItem*, Page*);
     43class PageCache {
     44    WTF_MAKE_NONCOPYABLE(PageCache); WTF_MAKE_FAST_ALLOCATED;
     45public:
     46    // Function to obtain the global page cache.
     47    WEBCORE_EXPORT static PageCache& shared();
    5848
    59         int pageCount() const { return m_size; }
    60         WEBCORE_EXPORT int frameCount() const;
     49    bool canCache(Page*) const;
    6150
    62         WEBCORE_EXPORT void markPagesForVisitedLinkStyleRecalc();
     51    // Used when memory is low to prune some cached pages.
     52    WEBCORE_EXPORT void pruneToSizeNow(unsigned maxSize, PruningReason);
     53    WEBCORE_EXPORT void setMaxSize(unsigned); // number of pages to cache.
     54    unsigned maxSize() const { return m_maxSize; }
    6355
    64         // Will mark all cached pages associated with the given page as needing style recalc.
    65         void markPagesForFullStyleRecalc(Page*);
     56    void add(HistoryItem&, Page&); // Prunes if maxSize() is exceeded.
     57    WEBCORE_EXPORT void remove(HistoryItem&);
     58    CachedPage* get(HistoryItem&, Page*) const;
     59    std::unique_ptr<CachedPage> take(HistoryItem&, Page*);
    6660
    67         // Used when memory is low to prune some cached pages.
    68         WEBCORE_EXPORT void pruneToCapacityNow(int capacity, PruningReason);
     61    unsigned pageCount() const { return m_items.size(); }
     62    WEBCORE_EXPORT unsigned frameCount() const;
    6963
     64    WEBCORE_EXPORT void markPagesForVisitedLinkStyleRecalc();
     65    // Will mark all cached pages associated with the given page as needing style recalc.
     66    void markPagesForFullStyleRecalc(Page&);
     67    void markPagesForDeviceScaleChanged(Page&);
    7068#if ENABLE(VIDEO_TRACK)
    71         void markPagesForCaptionPreferencesChanged();
     69    void markPagesForCaptionPreferencesChanged();
    7270#endif
    7371
    74         bool shouldClearBackingStores() const { return m_shouldClearBackingStores; }
    75         void setShouldClearBackingStores(bool flag) { m_shouldClearBackingStores = flag; }
    76         void markPagesForDeviceScaleChanged(Page*);
     72    bool shouldClearBackingStores() const { return m_shouldClearBackingStores; }
     73    void setShouldClearBackingStores(bool flag) { m_shouldClearBackingStores = flag; }
    7774
    78     private:
    79         PageCache(); // Use shared() instead.
    80         ~PageCache(); // Not implemented to make sure nobody accidentally calls delete -- WebCore does not delete singletons.
    81        
    82         static bool canCachePageContainingThisFrame(Frame*);
     75private:
     76    PageCache() = default; // Use shared() instead.
     77    ~PageCache() = delete; // Make sure nobody accidentally calls delete -- WebCore does not delete singletons.
    8378
    84         void addToLRUList(HistoryItem*); // Adds to the head of the list.
    85         void removeFromLRUList(HistoryItem*);
     79    static bool canCachePageContainingThisFrame(Frame&);
    8680
    87         void prune(PruningReason);
     81    void prune(PruningReason);
    8882
    89         int m_capacity;
    90         int m_size;
     83    ListHashSet<RefPtr<HistoryItem>> m_items;
     84    unsigned m_maxSize {0};
     85    bool m_shouldClearBackingStores {false};
    9186
    92         // LRU List
    93         HistoryItem* m_head;
    94         HistoryItem* m_tail;
    95        
    96         bool m_shouldClearBackingStores;
    97 
    98         friend class WTF::NeverDestroyed<PageCache>;
    99     };
     87    friend class WTF::NeverDestroyed<PageCache>;
     88};
    10089
    10190} // namespace WebCore
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r179247 r179347  
    922922        if (childItem) {
    923923            childFrame->loader().m_requestedHistoryItem = childItem;
    924             childFrame->loader().loadDifferentDocumentItem(childItem, loadType(), MayAttemptCacheOnlyLoadForFormSubmissionItem);
     924            childFrame->loader().loadDifferentDocumentItem(*childItem, loadType(), MayAttemptCacheOnlyLoadForFormSubmissionItem);
    925925            return;
    926926        }
     
    17411741
    17421742    std::unique_ptr<CachedPage> cachedPage;
    1743     if (m_loadingFromCachedPage)
    1744         cachedPage = PageCache::shared().take(history().provisionalItem(), m_frame.page());
     1743    if (m_loadingFromCachedPage && history().provisionalItem())
     1744        cachedPage = PageCache::shared().take(*history().provisionalItem(), m_frame.page());
    17451745
    17461746    LOG(PageCache, "WebCoreLoading %s: About to commit provisional load from previous URL '%s' to new URL '%s'", m_frame.tree().uniqueName().string().utf8().data(),
     
    17591759            LOG(PageCache, "Pruning page cache to 0 due to memory pressure");
    17601760            // Don't cache any page if we are under memory pressure.
    1761             PageCache::shared().pruneToCapacityNow(0, PruningReason::MemoryPressure);
     1761            PageCache::shared().pruneToSizeNow(0, PruningReason::MemoryPressure);
    17621762        } else if (systemMemoryLevel() <= memoryLevelThresholdToPrunePageCache) {
    17631763            LOG(MemoryPressure, "Pruning page cache because system memory level is %d at: %s", systemMemoryLevel(), __PRETTY_FUNCTION__);
    17641764            LOG(PageCache, "Pruning page cache to %d due to low memory (level %d less or equal to %d threshold)", PageCache::shared().capacity() / 2, systemMemoryLevel(), memoryLevelThresholdToPrunePageCache);
    1765             PageCache::shared().pruneToCapacityNow(PageCache::shared().capacity() / 2, PruningReason::MemoryPressure);
     1765            PageCache::shared().pruneToSizeNow(PageCache::shared().maxSize() / 2, PruningReason::MemoryPressure);
    17661766        }
    17671767    }
     
    17721772    // Check to see if we need to cache the page we are navigating away from into the back/forward cache.
    17731773    // We are doing this here because we know for sure that a new page is about to be loaded.
    1774     HistoryItem* item = history().currentItem();
    1775     if (!m_frame.tree().parent() && PageCache::shared().canCache(m_frame.page()) && !item->isInPageCache())
     1774    HistoryItem& item = *history().currentItem();
     1775    if (!m_frame.tree().parent() && PageCache::shared().canCache(m_frame.page()) && !item.isInPageCache())
    17761776        PageCache::shared().add(item, *m_frame.page());
    17771777
     
    31283128
    31293129    if (!activeDocument->canNavigate(frame))
    3130         return 0;
     3130        return nullptr;
    31313131
    31323132    return frame;
    31333133}
    31343134
    3135 void FrameLoader::loadSameDocumentItem(HistoryItem* item)
    3136 {
    3137     ASSERT(item->documentSequenceNumber() == history().currentItem()->documentSequenceNumber());
     3135void FrameLoader::loadSameDocumentItem(HistoryItem& item)
     3136{
     3137    ASSERT(item.documentSequenceNumber() == history().currentItem()->documentSequenceNumber());
    31383138
    31393139    // Save user view state to the current history item here since we don't do a normal load.
     
    31433143        view->setWasScrolledByUser(false);
    31443144
    3145     history().setCurrentItem(item);
     3145    history().setCurrentItem(&item);
    31463146       
    31473147    // loadInSameDocument() actually changes the URL and notifies load delegates of a "fake" load
    3148     loadInSameDocument(item->url(), item->stateObject(), false);
     3148    loadInSameDocument(item.url(), item.stateObject(), false);
    31493149
    31503150    // Restore user view state from the current history item here since we don't do a normal load.
     
    31553155// which should be methods of HistoryController and some of which should be
    31563156// methods of FrameLoader.
    3157 void FrameLoader::loadDifferentDocumentItem(HistoryItem* item, FrameLoadType loadType, FormSubmissionCacheLoadPolicy cacheLoadPolicy)
     3157void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, FrameLoadType loadType, FormSubmissionCacheLoadPolicy cacheLoadPolicy)
    31583158{
    31593159    // Remember this item so we can traverse any child items as child frames load
    3160     history().setProvisionalItem(item);
     3160    history().setProvisionalItem(&item);
    31613161
    31623162    if (CachedPage* cachedPage = PageCache::shared().get(item, m_frame.page())) {
     
    31683168    }
    31693169
    3170     URL itemURL = item->url();
    3171     URL itemOriginalURL = item->originalURL();
     3170    URL itemURL = item.url();
     3171    URL itemOriginalURL = item.originalURL();
    31723172    URL currentURL;
    31733173    if (documentLoader())
    31743174        currentURL = documentLoader()->url();
    3175     RefPtr<FormData> formData = item->formData();
     3175    RefPtr<FormData> formData = item.formData();
    31763176
    31773177    ResourceRequest request(itemURL);
    31783178
    3179     if (!item->referrer().isNull())
    3180         request.setHTTPReferrer(item->referrer());
     3179    if (!item.referrer().isNull())
     3180        request.setHTTPReferrer(item.referrer());
    31813181   
    31823182    // If this was a repost that failed the page cache, we might try to repost the form.
     
    31873187        request.setHTTPMethod("POST");
    31883188        request.setHTTPBody(formData);
    3189         request.setHTTPContentType(item->formContentType());
    3190         RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString(item->referrer());
     3189        request.setHTTPContentType(item.formContentType());
     3190        RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString(item.referrer());
    31913191        addHTTPOriginIfNeeded(request, securityOrigin->toString());
    31923192
     
    32433243
    32443244// Loads content into this frame, as specified by history item
    3245 void FrameLoader::loadItem(HistoryItem* item, FrameLoadType loadType)
    3246 {
    3247     m_requestedHistoryItem = item;
     3245void FrameLoader::loadItem(HistoryItem& item, FrameLoadType loadType)
     3246{
     3247    m_requestedHistoryItem = &item;
    32483248    HistoryItem* currentItem = history().currentItem();
    3249     bool sameDocumentNavigation = currentItem && item->shouldDoSameDocumentNavigationTo(currentItem);
     3249    bool sameDocumentNavigation = currentItem && item.shouldDoSameDocumentNavigationTo(currentItem);
    32503250
    32513251    if (sameDocumentNavigation)
     
    32613261    // We only use cache-only loads to avoid resubmitting forms.
    32623262    ASSERT(isBackForwardLoadType(m_loadType));
     3263    ASSERT(history().provisionalItem());
    32633264    ASSERT(history().provisionalItem()->formData());
    32643265    ASSERT(history().provisionalItem() == m_requestedHistoryItem.get());
    32653266
    32663267    FrameLoadType loadType = m_loadType;
    3267     HistoryItem* item = history().provisionalItem();
     3268    HistoryItem& item = *history().provisionalItem();
    32683269
    32693270    stopAllLoaders(ShouldNotClearProvisionalItem);
  • trunk/Source/WebCore/loader/FrameLoader.h

    r177482 r179347  
    126126
    127127    void open(CachedFrameBase&);
    128     void loadItem(HistoryItem*, FrameLoadType);
     128    void loadItem(HistoryItem&, FrameLoadType);
    129129    HistoryItem* requestedHistoryItem() const { return m_requestedHistoryItem.get(); }
    130130
     
    300300    void checkTimerFired();
    301301   
    302     void loadSameDocumentItem(HistoryItem*);
    303     void loadDifferentDocumentItem(HistoryItem*, FrameLoadType, FormSubmissionCacheLoadPolicy);
     302    void loadSameDocumentItem(HistoryItem&);
     303    void loadDifferentDocumentItem(HistoryItem&, FrameLoadType, FormSubmissionCacheLoadPolicy);
    304304   
    305305    void loadProvisionalItemFromCachedPage();
  • trunk/Source/WebCore/loader/HistoryController.cpp

    r179247 r179347  
    235235void HistoryController::invalidateCurrentItemCachedPage()
    236236{
     237    if (!currentItem())
     238        return;
     239
    237240    // When we are pre-commit, the currentItem is where any page cache data resides.
    238     if (!PageCache::shared().get(currentItem(), m_frame.page()))
    239         return;
    240 
    241     std::unique_ptr<CachedPage> cachedPage = PageCache::shared().take(currentItem(), m_frame.page());
     241    std::unique_ptr<CachedPage> cachedPage = PageCache::shared().take(*currentItem(), m_frame.page());
     242    if (!cachedPage)
     243        return;
    242244
    243245    // FIXME: This is a grotesque hack to fix <rdar://problem/4059059> Crash in RenderFlow::detach
     
    266268// Main funnel for navigating to a previous location (back/forward, non-search snap-back)
    267269// This includes recursion to handle loading into framesets properly
    268 void HistoryController::goToItem(HistoryItem* targetItem, FrameLoadType type)
     270void HistoryController::goToItem(HistoryItem& targetItem, FrameLoadType type)
    269271{
    270272    ASSERT(!m_frame.tree().parent());
     
    277279    if (!page)
    278280        return;
    279     if (!m_frame.loader().client().shouldGoToHistoryItem(targetItem))
     281    if (!m_frame.loader().client().shouldGoToHistoryItem(&targetItem))
    280282        return;
    281283    if (m_defersLoading) {
    282         m_deferredItem = targetItem;
     284        m_deferredItem = &targetItem;
    283285        m_deferredFrameLoadType = type;
    284286        return;
     
    289291    // as opposed to happening for some/one of the page commits that might happen soon
    290292    RefPtr<HistoryItem> currentItem = page->backForward().currentItem();
    291     page->backForward().setCurrentItem(targetItem);
     293    page->backForward().setCurrentItem(&targetItem);
    292294    m_frame.loader().client().updateGlobalHistoryItemForPage();
    293295
     
    306308    m_defersLoading = defer;
    307309    if (!defer && m_deferredItem) {
    308         goToItem(m_deferredItem.get(), m_deferredFrameLoadType);
    309         m_deferredItem = 0;
     310        goToItem(*m_deferredItem, m_deferredFrameLoadType);
     311        m_deferredItem = nullptr;
    310312    }
    311313}
     
    335337
    336338    if (m_currentItem) {
    337         PageCache::shared().remove(m_currentItem.get());
     339        PageCache::shared().remove(*m_currentItem);
    338340   
    339341        if (m_frame.loader().loadType() == FrameLoadType::Reload || m_frame.loader().loadType() == FrameLoadType::ReloadFromOrigin)
     
    500502    // (a matching URL and frame tree snapshot), just restore the scroll position.
    501503    // Save form state (works from currentItem, since m_frameLoadComplete is true)
    502     if (m_currentItem && itemsAreClones(m_currentItem.get(), m_provisionalItem.get())) {
     504    if (m_currentItem && itemsAreClones(*m_currentItem, m_provisionalItem.get())) {
    503505        ASSERT(m_frameLoadComplete);
    504506        saveDocumentState();
     
    708710// a match, we set the provisional item and recurse.  Otherwise we will reload that
    709711// frame and all its kids in recursiveGoToItem.
    710 void HistoryController::recursiveSetProvisionalItem(HistoryItem* item, HistoryItem* fromItem)
    711 {
    712     ASSERT(item);
    713 
     712void HistoryController::recursiveSetProvisionalItem(HistoryItem& item, HistoryItem* fromItem)
     713{
    714714    if (!itemsAreClones(item, fromItem))
    715715        return;
    716716
    717717    // Set provisional item, which will be committed in recursiveUpdateForCommit.
    718     m_provisionalItem = item;
    719 
    720     for (const auto& childItem : item->children()) {
     718    m_provisionalItem = &item;
     719
     720    for (const auto& childItem : item.children()) {
    721721        const String& childFrameName = childItem->target();
    722722
     
    726726        ASSERT(childFrame);
    727727
    728         childFrame->loader().history().recursiveSetProvisionalItem(childItem.get(), fromChildItem);
     728        childFrame->loader().history().recursiveSetProvisionalItem(*childItem, fromChildItem);
    729729    }
    730730}
     
    732732// We now traverse the frame tree and item tree a second time, loading frames that
    733733// do have the content the item requests.
    734 void HistoryController::recursiveGoToItem(HistoryItem* item, HistoryItem* fromItem, FrameLoadType type)
    735 {
    736     ASSERT(item);
    737 
     734void HistoryController::recursiveGoToItem(HistoryItem& item, HistoryItem* fromItem, FrameLoadType type)
     735{
    738736    if (!itemsAreClones(item, fromItem)) {
    739737        m_frame.loader().loadItem(item, type);
     
    742740
    743741    // Just iterate over the rest, looking for frames to navigate.
    744     for (const auto& childItem : item->children()) {
     742    for (const auto& childItem : item.children()) {
    745743        const String& childFrameName = childItem->target();
    746744
     
    749747        Frame* childFrame = m_frame.tree().child(childFrameName);
    750748        ASSERT(childFrame);
    751         childFrame->loader().history().recursiveGoToItem(childItem.get(), fromChildItem, type);
    752     }
    753 }
    754 
    755 bool HistoryController::itemsAreClones(HistoryItem* item1, HistoryItem* item2) const
     749        childFrame->loader().history().recursiveGoToItem(*childItem, fromChildItem, type);
     750    }
     751}
     752
     753bool HistoryController::itemsAreClones(HistoryItem& item1, HistoryItem* item2) const
    756754{
    757755    // If the item we're going to is a clone of the item we're at, then we do
     
    762760    // new document and should not consider them clones.
    763761    // (See http://webkit.org/b/35532 for details.)
    764     return item1
    765         && item2
    766         && item1 != item2
    767         && item1->itemSequenceNumber() == item2->itemSequenceNumber()
    768         && currentFramesMatchItem(item1)
    769         && item2->hasSameFrames(item1);
     762    return item2
     763        && &item1 != item2
     764        && item1.itemSequenceNumber() == item2->itemSequenceNumber()
     765        && currentFramesMatchItem(&item1)
     766        && item2->hasSameFrames(&item1);
    770767}
    771768
  • trunk/Source/WebCore/loader/HistoryController.h

    r172862 r179347  
    9494    friend class Page;
    9595    bool shouldStopLoadingForHistoryItem(HistoryItem*) const;
    96     void goToItem(HistoryItem*, FrameLoadType);
     96    void goToItem(HistoryItem&, FrameLoadType);
    9797
    9898    void initializeItem(HistoryItem*);
     
    100100    PassRefPtr<HistoryItem> createItemTree(Frame& targetFrame, bool clipAtTarget);
    101101
    102     void recursiveSetProvisionalItem(HistoryItem*, HistoryItem*);
    103     void recursiveGoToItem(HistoryItem*, HistoryItem*, FrameLoadType);
     102    void recursiveSetProvisionalItem(HistoryItem&, HistoryItem*);
     103    void recursiveGoToItem(HistoryItem&, HistoryItem*, FrameLoadType);
    104104    bool isReplaceLoadTypeWithProvisionalItem(FrameLoadType);
    105105    bool isReloadTypeWithProvisionalItem(FrameLoadType);
    106106    void recursiveUpdateForCommit();
    107107    void recursiveUpdateForSameDocumentNavigation();
    108     bool itemsAreClones(HistoryItem*, HistoryItem*) const;
     108    bool itemsAreClones(HistoryItem&, HistoryItem*) const;
    109109    bool currentFramesMatchItem(HistoryItem*) const;
    110110    void updateBackForwardListClippedAtTarget(bool doClip);
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp

    r178949 r179347  
    389389}
    390390
    391 String DiagnosticLoggingKeys::prunedDueToCapacityReached()
     391String DiagnosticLoggingKeys::prunedDueToMaxSizeReached()
    392392{
    393393    return ASCIILiteral("pruned.capacityReached");
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.h

    r178949 r179347  
    7777    static String pluginLoadedKey();
    7878    static String pluginLoadingFailedKey();
    79     static String prunedDueToCapacityReached();
     79    static String prunedDueToMaxSizeReached();
    8080    static String prunedDueToMemoryPressureKey();
    8181    static String prunedDueToProcessSuspended();
  • trunk/Source/WebCore/page/Frame.cpp

    r179247 r179347  
    990990
    991991    if (isMainFrame())
    992         PageCache::shared().markPagesForFullStyleRecalc(page);
     992        PageCache::shared().markPagesForFullStyleRecalc(*page);
    993993}
    994994
  • trunk/Source/WebCore/page/Page.cpp

    r179247 r179347  
    431431}
    432432
    433 void Page::goToItem(HistoryItem* item, FrameLoadType type)
     433void Page::goToItem(HistoryItem& item, FrameLoadType type)
    434434{
    435435    // stopAllLoaders may end up running onload handlers, which could cause further history traversals that may lead to the passed in HistoryItem
    436436    // being deref()-ed. Make sure we can still use it with HistoryController::goToItem later.
    437     RefPtr<HistoryItem> protector(item);
    438 
    439     if (m_mainFrame->loader().history().shouldStopLoadingForHistoryItem(item))
     437    Ref<HistoryItem> protector(item);
     438
     439    if (m_mainFrame->loader().history().shouldStopLoadingForHistoryItem(&item))
    440440        m_mainFrame->loader().stopAllLoaders();
    441441
     
    840840
    841841    mainFrame().deviceOrPageScaleFactorChanged();
    842     PageCache::shared().markPagesForDeviceScaleChanged(this);
    843 
    844     PageCache::shared().markPagesForFullStyleRecalc(this);
     842    PageCache::shared().markPagesForDeviceScaleChanged(*this);
     843
     844    PageCache::shared().markPagesForFullStyleRecalc(*this);
    845845    GraphicsContext::updateDocumentMarkerResources();
    846846
     
    922922
    923923    setNeedsRecalcStyleInAllFrames();
    924     PageCache::shared().markPagesForFullStyleRecalc(this);
     924    PageCache::shared().markPagesForFullStyleRecalc(*this);
    925925}
    926926
     
    16621662
    16631663    invalidateStylesForAllLinks();
    1664     PageCache::shared().markPagesForFullStyleRecalc(this);
     1664    PageCache::shared().markPagesForFullStyleRecalc(*this);
    16651665}
    16661666
  • trunk/Source/WebCore/page/Page.h

    r178820 r179347  
    151151    void setOpenedByDOM();
    152152
    153     WEBCORE_EXPORT void goToItem(HistoryItem*, FrameLoadType);
     153    WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType);
    154154
    155155    WEBCORE_EXPORT void setGroupName(const String&);
  • trunk/Source/WebCore/page/Settings.cpp

    r179247 r179347  
    520520        return;
    521521
    522     if (!m_usesPageCache) {
    523         int first = -m_page->backForward().backCount();
    524         int last = m_page->backForward().forwardCount();
    525         for (int i = first; i <= last; i++)
    526             PageCache::shared().remove(m_page->backForward().itemAtIndex(i));
    527     }
     522    if (!m_usesPageCache)
     523        PageCache::shared().pruneToSizeNow(0, PruningReason::None);
    528524}
    529525
  • trunk/Source/WebCore/platform/MemoryPressureHandler.cpp

    r179293 r179347  
    103103        // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
    104104        PruningReason pruningReason = memoryPressureHandler().isUnderMemoryPressure() ? PruningReason::MemoryPressure : PruningReason::ProcessSuspended;
    105         PageCache::shared().pruneToCapacityNow(0, pruningReason);
     105        PageCache::shared().pruneToSizeNow(0, pruningReason);
    106106    }
    107107
  • trunk/Source/WebKit/mac/ChangeLog

    r179294 r179347  
     12015-01-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Clean up / modernize PageCache class
     4        https://bugs.webkit.org/show_bug.cgi?id=141009
     5
     6        Reviewed by Darin Adler.
     7
     8        Clean up / modernize PageCache class.
     9
     10        * History/WebBackForwardList.mm:
     11        (-[WebBackForwardList pageCacheSize]):
     12        * WebView/WebView.mm:
     13        (-[WebView _loadBackForwardListFromOtherView:]):
     14        (-[WebView goToBackForwardItem:]):
     15        (+[WebView _setCacheModel:]):
     16
    1172015-01-28  Beth Dakin  <bdakin@apple.com>
    218
  • trunk/Source/WebKit/mac/History/WebBackForwardList.mm

    r179247 r179347  
    356356- (NSUInteger)pageCacheSize
    357357{
    358     return [kit(core(self)->page()) usesPageCache] ? PageCache::shared().capacity() : 0;
     358    return [kit(core(self)->page()) usesPageCache] ? PageCache::shared().maxSize() : 0;
    359359}
    360360
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r179247 r179347  
    19981998        return; // empty back forward list, bail
    19991999   
    2000     HistoryItem* newItemToGoTo = 0;
     2000    HistoryItem* newItemToGoTo = nullptr;
    20012001
    20022002    int lastItemIndex = otherBackForwardClient->forwardListCount();
     
    20152015   
    20162016    ASSERT(newItemToGoTo);
    2017     _private->page->goToItem(newItemToGoTo, FrameLoadType::IndexedBackForward);
     2017    _private->page->goToItem(*newItemToGoTo, FrameLoadType::IndexedBackForward);
    20182018}
    20192019
     
    56485648        return NO;
    56495649
    5650     _private->page->goToItem(core(item), FrameLoadType::IndexedBackForward);
     5650    ASSERT(item);
     5651    _private->page->goToItem(*core(item), FrameLoadType::IndexedBackForward);
    56515652    return YES;
    56525653}
     
    77437744    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    77447745
    7745     unsigned pageCacheCapacity = 0;
     7746    unsigned pageCacheSize = 0;
    77467747
    77477748    NSUInteger nsurlCacheMemoryCapacity = 0;
     
    77547755    case WebCacheModelDocumentViewer: {
    77557756        // Page cache capacity (in pages)
    7756         pageCacheCapacity = 0;
     7757        pageCacheSize = 0;
    77577758
    77587759        // Object cache capacities (in bytes)
     
    77917792        // Page cache capacity (in pages)
    77927793        if (memSize >= 1024)
    7793             pageCacheCapacity = 3;
     7794            pageCacheSize = 3;
    77947795        else if (memSize >= 512)
    7795             pageCacheCapacity = 2;
     7796            pageCacheSize = 2;
    77967797        else if (memSize >= 256)
    7797             pageCacheCapacity = 1;
     7798            pageCacheSize = 1;
    77987799        else
    7799             pageCacheCapacity = 0;
     7800            pageCacheSize = 0;
    78007801
    78017802        // Object cache capacities (in bytes)
     
    78457846        // (Research indicates that value / page drops substantially after 3 pages.)
    78467847        if (memSize >= 2048)
    7847             pageCacheCapacity = 5;
     7848            pageCacheSize = 5;
    78487849        else if (memSize >= 1024)
    7849             pageCacheCapacity = 4;
     7850            pageCacheSize = 4;
    78507851        else if (memSize >= 512)
    7851             pageCacheCapacity = 3;
     7852            pageCacheSize = 3;
    78527853        else if (memSize >= 256)
    7853             pageCacheCapacity = 2;
     7854            pageCacheSize = 2;
    78547855        else
    7855             pageCacheCapacity = 1;
     7856            pageCacheSize = 1;
    78567857
    78577858#if PLATFORM(IOS)
     
    78597860        // FIXME (<rdar://problem/11779846>): Avoiding jettisoning should not have to require reducing the page cache capacity.
    78607861        // Reducing the capacity by 1 reduces overall back-forward performance.
    7861         if (pageCacheCapacity > 0)
    7862             pageCacheCapacity -= 1;
     7862        if (pageCacheSize > 0)
     7863            pageCacheSize -= 1;
    78637864#endif
    78647865
     
    79367937    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    79377938    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    7938     PageCache::shared().setCapacity(pageCacheCapacity);
     7939    PageCache::shared().setMaxSize(pageCacheSize);
    79397940#if PLATFORM(IOS)
    79407941    PageCache::shared().setShouldClearBackingStores(true);
  • trunk/Source/WebKit/win/ChangeLog

    r179278 r179347  
     12015-01-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Clean up / modernize PageCache class
     4        https://bugs.webkit.org/show_bug.cgi?id=141009
     5
     6        Reviewed by Darin Adler.
     7
     8        Clean up / modernize PageCache class.
     9
     10        * WebView.cpp:
     11        (WebView::setCacheModel):
     12
    1132015-01-28  peavo@outlook.com  <peavo@outlook.com>
    214
  • trunk/Source/WebKit/win/WebView.cpp

    r179247 r179347  
    531531    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    532532
    533     unsigned pageCacheCapacity = 0;
     533    unsigned pageCacheSize = 0;
    534534
    535535
     
    537537    case WebCacheModelDocumentViewer: {
    538538        // Page cache capacity (in pages)
    539         pageCacheCapacity = 0;
     539        pageCacheSize = 0;
    540540
    541541        // Object cache capacities (in bytes)
     
    564564        // Page cache capacity (in pages)
    565565        if (memSize >= 1024)
    566             pageCacheCapacity = 3;
     566            pageCacheSize = 3;
    567567        else if (memSize >= 512)
    568             pageCacheCapacity = 2;
     568            pageCacheSize = 2;
    569569        else if (memSize >= 256)
    570             pageCacheCapacity = 1;
     570            pageCacheSize = 1;
    571571        else
    572             pageCacheCapacity = 0;
     572            pageCacheSize = 0;
    573573
    574574        // Object cache capacities (in bytes)
     
    611611        // (Research indicates that value / page drops substantially after 3 pages.)
    612612        if (memSize >= 2048)
    613             pageCacheCapacity = 5;
     613            pageCacheSize = 5;
    614614        else if (memSize >= 1024)
    615             pageCacheCapacity = 4;
     615            pageCacheSize = 4;
    616616        else if (memSize >= 512)
    617             pageCacheCapacity = 3;
     617            pageCacheSize = 3;
    618618        else if (memSize >= 256)
    619             pageCacheCapacity = 2;
     619            pageCacheSize = 2;
    620620        else
    621             pageCacheCapacity = 1;
     621            pageCacheSize = 1;
    622622
    623623        // Object cache capacities (in bytes)
     
    676676    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    677677    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    678     PageCache::shared().setCapacity(pageCacheCapacity);
     678    PageCache::shared().setMaxSize(pageCacheSize);
    679679
    680680#if USE(CFNETWORK)
     
    31553155        return hr;
    31563156
    3157     m_page->goToItem(webHistoryItem->historyItem(), FrameLoadType::IndexedBackForward);
     3157    m_page->goToItem(*webHistoryItem->historyItem(), FrameLoadType::IndexedBackForward);
    31583158    *succeeded = TRUE;
    31593159
     
    55025502   
    55035503    ASSERT(newItemToGoTo);
    5504     m_page->goToItem(newItemToGoTo, FrameLoadType::IndexedBackForward);
     5504    m_page->goToItem(*newItemToGoTo, FrameLoadType::IndexedBackForward);
    55055505    return S_OK;
    55065506}
  • trunk/Source/WebKit2/ChangeLog

    r179346 r179347  
     12015-01-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Clean up / modernize PageCache class
     4        https://bugs.webkit.org/show_bug.cgi?id=141009
     5
     6        Reviewed by Darin Adler.
     7
     8        Clean up / modernize PageCache class.
     9
     10        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
     11        (WebKit::WebBackForwardListProxy::removeItem):
     12        (WebKit::WebBackForwardListProxy::close):
     13        * WebProcess/WebPage/WebPage.cpp:
     14        (WebKit::WebPage::goForward):
     15        (WebKit::WebPage::goBack):
     16        (WebKit::WebPage::goToBackForwardItem):
     17        * WebProcess/WebProcess.cpp:
     18        (WebKit::WebProcess::releasePageCache):
     19        * WebProcess/cocoa/WebProcessCocoa.mm:
     20        (WebKit::WebProcess::platformSetCacheModel):
     21        * WebProcess/soup/WebProcessSoup.cpp:
     22        (WebKit::WebProcess::platformSetCacheModel):
     23
    1242015-01-29  Csaba Osztrogonác  <ossy@webkit.org>
    225
  • trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp

    r179247 r179347  
    133133        return;
    134134       
    135     PageCache::shared().remove(item.get());
     135    PageCache::shared().remove(*item);
    136136    WebCore::Page::clearPreviousItemFromAllPages(item.get());
    137137    historyItemToIDMap().remove(item);
     
    217217void WebBackForwardListProxy::close()
    218218{
    219     HashSet<uint64_t>::iterator end = m_associatedItemIDs.end();
    220     for (HashSet<uint64_t>::iterator i = m_associatedItemIDs.begin(); i != end; ++i)
    221         WebCore::PageCache::shared().remove(itemForID(*i));
     219    for (auto& itemID : m_associatedItemIDs) {
     220        if (HistoryItem* item = itemForID(itemID))
     221            WebCore::PageCache::shared().remove(*item);
     222    }
    222223
    223224    m_associatedItemIDs.clear();
    224 
    225225    m_page = nullptr;
    226226}
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r179321 r179347  
    12111211        m_pendingNavigationID = navigationID;
    12121212
    1213     m_page->goToItem(item, FrameLoadType::Forward);
     1213    m_page->goToItem(*item, FrameLoadType::Forward);
    12141214}
    12151215
     
    12271227        m_pendingNavigationID = navigationID;
    12281228
    1229     m_page->goToItem(item, FrameLoadType::Back);
     1229    m_page->goToItem(*item, FrameLoadType::Back);
    12301230}
    12311231
     
    12431243        m_pendingNavigationID = navigationID;
    12441244
    1245     m_page->goToItem(item, FrameLoadType::IndexedBackForward);
     1245    m_page->goToItem(*item, FrameLoadType::IndexedBackForward);
    12461246}
    12471247
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r179247 r179347  
    11171117void WebProcess::releasePageCache()
    11181118{
    1119     PageCache::shared().pruneToCapacityNow(0, PruningReason::MemoryPressure);
     1119    PageCache::shared().pruneToSizeNow(0, PruningReason::MemoryPressure);
    11201120}
    11211121
  • trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm

    r179247 r179347  
    105105    unsigned cacheMaxDeadCapacity = 0;
    106106    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    107     unsigned pageCacheCapacity = 0;
     107    unsigned pageCacheSize = 0;
    108108    unsigned long urlCacheMemoryCapacity = 0;
    109109    unsigned long urlCacheDiskCapacity = 0;
     
    111111    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    112112        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    113         pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     113        pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    114114
    115115
    116116    memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    117117    memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    118     PageCache::shared().setCapacity(pageCacheCapacity);
     118    PageCache::shared().setMaxSize(pageCacheSize);
    119119
    120120    NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
  • trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

    r179247 r179347  
    8484    unsigned cacheMaxDeadCapacity = 0;
    8585    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    86     unsigned pageCacheCapacity = 0;
     86    unsigned pageCacheSize = 0;
    8787
    8888    unsigned long urlCacheMemoryCapacity = 0;
     
    100100    calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    101101                        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    102                         pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     102                        pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    103103
    104104    WebCore::memoryCache().setDisabled(cacheModel == CacheModelDocumentViewer);
    105105    WebCore::memoryCache().setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    106106    WebCore::memoryCache().setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    107     WebCore::PageCache::shared().setCapacity(pageCacheCapacity);
     107    WebCore::PageCache::shared().setMaxSize(pageCacheSize);
    108108
    109109#if PLATFORM(GTK)
Note: See TracChangeset for help on using the changeset viewer.