⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243276 in webkit


Ignore:
Timestamp:
Mar 20, 2019, 9:38:29 PM (7 years ago)
Author:
youenn@apple.com
Message:

Compute quota after network process restart based on default quota and space used
https://bugs.webkit.org/show_bug.cgi?id=195804

Reviewed by Chris Dumez.

Source/WebCore:

At creation of quota manager, a default quota will be assigned.
This value is the same for all origins.
Some origins may have been granted a bigger quota by the user.
In that case, the space used might be greater for these origins.
Update at initialization time the quota according the space used as follows:

  • If space used is below default quota, stick with default quota.
  • If space used is above, set quota to space used rounded by one tenth of the default quota.

The rounding ensures that quota requests will not happen too quickly after a page is loaded.

Test: http/wpt/cache-storage/cache-quota-after-restart.any.html

  • Modules/cache/CacheStorageConnection.h:

(WebCore::CacheStorageConnection::setQuotaBasedOnSpaceUsage):

  • storage/StorageQuotaManager.cpp:

(WebCore::StorageQuotaManager::setQuotaBasedOnSpaceUsage):
(WebCore::StorageQuotaManager::addUser):

  • storage/StorageQuotaManager.h:
  • testing/Internals.cpp:

(WebCore::Internals::updateQuotaBasedOnSpaceUsage):

  • testing/Internals.h:
  • testing/Internals.idl:

Source/WebKit:

Make sure that Cache Storage quota user waits to declare as initialized to its manager
until all data is loaded so that it can report a valid space used from the start.

Add test API to reset the quota to its default value and compute it according current space use.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::updateQuotaBasedOnSpaceUsageForTesting):

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkProcess.messages.in:
  • NetworkProcess/cache/CacheStorageEngineCaches.cpp:

(WebKit::CacheStorage::Caches::create):
(WebKit::CacheStorage::Caches::Caches):
(WebKit::CacheStorage::Caches::whenInitialized):

  • NetworkProcess/cache/CacheStorageEngineCaches.h:
  • NetworkProcess/cache/CacheStorageEngineConnection.cpp:

(WebKit::CacheStorageEngineConnection::dereference):

  • WebProcess/Cache/WebCacheStorageConnection.cpp:

(WebKit::WebCacheStorageConnection::setQuotaBasedOnSpaceUsage):

  • WebProcess/Cache/WebCacheStorageConnection.h:

LayoutTests:

  • http/wpt/cache-storage/cache-quota-after-restart.any-expected.txt: Added.
  • http/wpt/cache-storage/cache-quota-after-restart.any.html: Added.
  • http/wpt/cache-storage/cache-quota-after-restart.any.js: Added.

(promise_test.async):

Location:
trunk
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243270 r243276  
     12019-03-20  Youenn Fablet  <youenn@apple.com>
     2
     3        Compute quota after network process restart based on default quota and space used
     4        https://bugs.webkit.org/show_bug.cgi?id=195804
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/wpt/cache-storage/cache-quota-after-restart.any-expected.txt: Added.
     9        * http/wpt/cache-storage/cache-quota-after-restart.any.html: Added.
     10        * http/wpt/cache-storage/cache-quota-after-restart.any.js: Added.
     11        (promise_test.async):
     12
    1132019-03-20  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r243275 r243276  
     12019-03-20  Youenn Fablet  <youenn@apple.com>
     2
     3        Compute quota after network process restart based on default quota and space used
     4        https://bugs.webkit.org/show_bug.cgi?id=195804
     5
     6        Reviewed by Chris Dumez.
     7
     8        At creation of quota manager, a default quota will be assigned.
     9        This value is the same for all origins.
     10        Some origins may have been granted a bigger quota by the user.
     11        In that case, the space used might be greater for these origins.
     12        Update at initialization time the quota according the space used as follows:
     13        - If space used is below default quota, stick with default quota.
     14        - If space used is above, set quota to space used rounded by one tenth of the default quota.
     15        The rounding ensures that quota requests will not happen too quickly after a page is loaded.
     16
     17        Test: http/wpt/cache-storage/cache-quota-after-restart.any.html
     18
     19        * Modules/cache/CacheStorageConnection.h:
     20        (WebCore::CacheStorageConnection::setQuotaBasedOnSpaceUsage):
     21        * storage/StorageQuotaManager.cpp:
     22        (WebCore::StorageQuotaManager::setQuotaBasedOnSpaceUsage):
     23        (WebCore::StorageQuotaManager::addUser):
     24        * storage/StorageQuotaManager.h:
     25        * testing/Internals.cpp:
     26        (WebCore::Internals::updateQuotaBasedOnSpaceUsage):
     27        * testing/Internals.h:
     28        * testing/Internals.idl:
     29
    1302019-03-20  Simon Fraser  <simon.fraser@apple.com>
    231
  • trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h

    r226481 r243276  
    5656    virtual void clearMemoryRepresentation(const ClientOrigin&, DOMCacheEngine::CompletionCallback&& callback) { callback(DOMCacheEngine::Error::NotImplemented); }
    5757    virtual void engineRepresentation(WTF::Function<void(const String&)>&& callback) { callback(String { }); }
     58    virtual void updateQuotaBasedOnSpaceUsage(const ClientOrigin&) { }
    5859
    5960protected:
  • trunk/Source/WebCore/storage/StorageQuotaManager.cpp

    r243270 r243276  
    4545}
    4646
     47void StorageQuotaManager::updateQuotaBasedOnSpaceUsage()
     48{
     49    if (!m_quota)
     50        return;
     51
     52    auto defaultQuotaStep = m_quota / 10;
     53    m_quota = std::max(m_quota, defaultQuotaStep * ((spaceUsage() / defaultQuotaStep) + 1));
     54}
     55
    4756void StorageQuotaManager::addUser(StorageQuotaUser& user)
    4857{
     
    5362        if (!weakThis)
    5463            return;
    55         m_pendingInitializationUsers.remove(&user);
    56         m_users.add(&user);
     64
     65        if (m_pendingInitializationUsers.remove(&user))
     66            m_users.add(&user);
     67
     68        if (!m_pendingInitializationUsers.isEmpty())
     69            return;
     70
     71        updateQuotaBasedOnSpaceUsage();
    5772        processPendingRequests({ });
    5873    });
  • trunk/Source/WebCore/storage/StorageQuotaManager.h

    r243270 r243276  
    6363    void resetQuota(uint64_t newQuota) { m_quota = newQuota; }
    6464
     65    WEBCORE_EXPORT void updateQuotaBasedOnSpaceUsage();
     66
    6567private:
    6668    uint64_t spaceUsage() const;
  • trunk/Source/WebCore/testing/Internals.cpp

    r243163 r243276  
    47584758}
    47594759
     4760void Internals::updateQuotaBasedOnSpaceUsage()
     4761{
     4762    auto* document = contextDocument();
     4763    if (!document)
     4764        return;
     4765
     4766    if (!m_cacheStorageConnection) {
     4767        if (auto* page = contextDocument()->page())
     4768            m_cacheStorageConnection = page->cacheStorageProvider().createCacheStorageConnection(page->sessionID());
     4769        if (!m_cacheStorageConnection)
     4770            return;
     4771    }
     4772
     4773    m_cacheStorageConnection->updateQuotaBasedOnSpaceUsage(ClientOrigin { document->topOrigin().data(), document->securityOrigin().data() });
     4774}
     4775
    47604776void Internals::setConsoleMessageListener(RefPtr<StringCallback>&& listener)
    47614777{
  • trunk/Source/WebCore/testing/Internals.h

    r242920 r243276  
    707707    uint64_t responseSizeWithPadding(FetchResponse&) const;
    708708
     709    void updateQuotaBasedOnSpaceUsage();
     710
    709711    void setConsoleMessageListener(RefPtr<StringCallback>&&);
    710712
  • trunk/Source/WebCore/testing/Internals.idl

    r242920 r243276  
    690690    unsigned long long responseSizeWithPadding(FetchResponse response);
    691691
     692    void updateQuotaBasedOnSpaceUsage();
     693
    692694    void setConsoleMessageListener(StringCallback callback);
    693695
  • trunk/Source/WebKit/ChangeLog

    r243275 r243276  
     12019-03-20  Youenn Fablet  <youenn@apple.com>
     2
     3        Compute quota after network process restart based on default quota and space used
     4        https://bugs.webkit.org/show_bug.cgi?id=195804
     5
     6        Reviewed by Chris Dumez.
     7
     8        Make sure that Cache Storage quota user waits to declare as initialized to its manager
     9        until all data is loaded so that it can report a valid space used from the start.
     10
     11        Add test API to reset the quota to its default value and compute it according current space use.
     12
     13        * NetworkProcess/NetworkProcess.cpp:
     14        (WebKit::NetworkProcess::updateQuotaBasedOnSpaceUsageForTesting):
     15        * NetworkProcess/NetworkProcess.h:
     16        * NetworkProcess/NetworkProcess.messages.in:
     17        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
     18        (WebKit::CacheStorage::Caches::create):
     19        (WebKit::CacheStorage::Caches::Caches):
     20        (WebKit::CacheStorage::Caches::whenInitialized):
     21        * NetworkProcess/cache/CacheStorageEngineCaches.h:
     22        * NetworkProcess/cache/CacheStorageEngineConnection.cpp:
     23        (WebKit::CacheStorageEngineConnection::dereference):
     24        * WebProcess/Cache/WebCacheStorageConnection.cpp:
     25        (WebKit::WebCacheStorageConnection::setQuotaBasedOnSpaceUsage):
     26        * WebProcess/Cache/WebCacheStorageConnection.h:
     27
    1282019-03-20  Simon Fraser  <simon.fraser@apple.com>
    229
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r243247 r243276  
    22292229#endif // ENABLE(INDEXED_DATABASE)
    22302230
     2231void NetworkProcess::updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID sessionID, const ClientOrigin& origin)
     2232{
     2233    auto& manager = storageQuotaManager(sessionID, origin);
     2234    manager.resetQuota(m_storageQuotaManagers.find(sessionID)->value.defaultQuota);
     2235    manager.updateQuotaBasedOnSpaceUsage();
     2236}
     2237
    22312238#if ENABLE(SANDBOX_EXTENSIONS)
    22322239void NetworkProcess::getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&& completionHandler)
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r243247 r243276  
    282282    void setIDBPerOriginQuota(uint64_t);
    283283#endif
     284    void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
    284285
    285286#if ENABLE(SANDBOX_EXTENSIONS)
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r243181 r243276  
    165165    SetIDBPerOriginQuota(uint64_t quota)
    166166#endif
     167    UpdateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID sessionID, struct WebCore::ClientOrigin origin)
    167168
    168169    StoreAdClickAttribution(PAL::SessionID sessionID, WebCore::AdClickAttribution adClickAttribution)
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp

    r243110 r243276  
    5252}
    5353
     54Ref<Caches> Caches::create(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, WebCore::StorageQuotaManager& quotaManager)
     55{
     56    auto caches = adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quotaManager });
     57    quotaManager.addUser(caches.get());
     58    return caches;
     59}
     60
    5461Caches::Caches(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, WebCore::StorageQuotaManager& quotaManager)
    5562    : m_engine(&engine)
     
    5865    , m_quotaManager(makeWeakPtr(quotaManager))
    5966{
    60     quotaManager.addUser(*this);
    6167}
    6268
     
    6773    if (m_quotaManager)
    6874        m_quotaManager->removeUser(*this);
     75}
     76
     77void Caches::whenInitialized(CompletionHandler<void()>&& callback)
     78{
     79    initialize([callback = WTFMove(callback)](auto&& error) mutable {
     80        if (error)
     81            RELEASE_LOG_ERROR(CacheStorage, "Caches::initialize failed, reported space used will be zero");
     82        callback();
     83    });
    6984}
    7085
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h

    r242599 r243276  
    4545class Caches final : public RefCounted<Caches>, private WebCore::StorageQuotaUser {
    4646public:
    47     static Ref<Caches> create(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, WebCore::StorageQuotaManager& quotaManager) { return adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quotaManager }); }
     47    static Ref<Caches> create(Engine&, WebCore::ClientOrigin&&, String&& rootPath, WebCore::StorageQuotaManager&);
    4848    ~Caches();
    4949
     
    9292    void writeCachesToDisk(WebCore::DOMCacheEngine::CompletionCallback&&);
    9393
     94    void whenInitialized(CompletionHandler<void()>&&) final;
     95
    9496    void storeOrigin(WebCore::DOMCacheEngine::CompletionCallback&&);
    9597    static Optional<WebCore::ClientOrigin> readOrigin(const NetworkCache::Data&);
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp

    r243110 r243276  
    139139
    140140    auto referenceResult = references.find(cacheIdentifier);
    141     ASSERT(referenceResult != references.end());
    142141    if (referenceResult == references.end())
    143142        return;
  • trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp

    r239427 r243276  
    3131#include "NetworkConnectionToWebProcessMessages.h"
    3232#include "NetworkProcessConnection.h"
     33#include "NetworkProcessMessages.h"
    3334#include "WebCacheStorageProvider.h"
    3435#include "WebCoreArgumentCoders.h"
     
    152153}
    153154
     155void WebCacheStorageConnection::updateQuotaBasedOnSpaceUsage(const ClientOrigin& origin)
     156{
     157    connection().send(Messages::NetworkProcess::UpdateQuotaBasedOnSpaceUsageForTesting(m_sessionID, origin), 0);
    154158}
     159
     160}
  • trunk/Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h

    r239427 r243276  
    6666    void clearMemoryRepresentation(const WebCore::ClientOrigin&, WebCore::DOMCacheEngine::CompletionCallback&&) final;
    6767    void engineRepresentation(WTF::Function<void(const String&)>&&) final;
     68    void updateQuotaBasedOnSpaceUsage(const WebCore::ClientOrigin&) final;
    6869
    6970    void openCompleted(uint64_t requestIdentifier, const WebCore::DOMCacheEngine::CacheIdentifierOrError&);
Note: See TracChangeset for help on using the changeset viewer.