Diff
Modified: trunk/Source/WebCore/ChangeLog (242598 => 242599)
--- trunk/Source/WebCore/ChangeLog 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebCore/ChangeLog 2019-03-07 17:40:40 UTC (rev 242599)
@@ -1,3 +1,37 @@
+2019-03-07 Youenn Fablet <[email protected]>
+
+ Introduce a quota manager for Cache API/Service Worker/IDB storage
+ https://bugs.webkit.org/show_bug.cgi?id=195283
+
+ Reviewed by Chris Dumez.
+
+ Introduce a generic quota manager and quota users to be used in Network Process.
+ Quota manager/users are scoped by client origin.
+ Quota manager is used to check for quota by an entity wanting to execute a storage task of a given taskSize.
+ Quota manager will check the current space used by all its quota users.
+ If the size + taskSize is above quota, it will call a function to try extend the quota.
+ In the meantime, the task (and all tasks that may be added) are queued.
+
+ Once the new quota is received, the quota manager will either allow or disallow the first task in the queue.
+ The quota manager will try to execute as many tasks as possible with the provided quota.
+ If some tasks are remaining and quota limit is hit, the quota manager will compute the space needed for all remaining requests
+ and do another quota extension request.
+
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/ClientOrigin.h:
+ * storage/StorageQuotaManager.cpp: Added.
+ (WebCore::StorageQuotaManager::~StorageQuotaManager):
+ (WebCore::StorageQuotaManager::spaceUsage const):
+ (WebCore::StorageQuotaManager::requestSpace):
+ (WebCore::StorageQuotaManager::askForMoreSpace):
+ (WebCore::StorageQuotaManager::processPendingRequests):
+ * storage/StorageQuotaManager.h: Added.
+ (WebCore::StorageQuotaManager::StorageQuotaManager):
+ (WebCore::StorageQuotaManager::addUser):
+ (WebCore::StorageQuotaManager::removeUser):
+ * storage/StorageQuotaUser.h: Added.
+
2019-03-07 John Wilander <[email protected]>
Resource Load Statistics: Make it possible to purge only script-accessible cookies
Modified: trunk/Source/WebCore/Sources.txt (242598 => 242599)
--- trunk/Source/WebCore/Sources.txt 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebCore/Sources.txt 2019-03-07 17:40:40 UTC (rev 242599)
@@ -2231,6 +2231,7 @@
replay/UserInputBridge.cpp
+storage/StorageQuotaManager.cpp
storage/Storage.cpp
storage/StorageEvent.cpp
storage/StorageEventDispatcher.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (242598 => 242599)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-03-07 17:40:40 UTC (rev 242599)
@@ -1168,6 +1168,8 @@
41D129D51F3D0F6900D15E47 /* CacheStorageProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129D41F3D0F6600D15E47 /* CacheStorageProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
41D129DB1F3D143800D15E47 /* FetchHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F54F831C50C4F600338488 /* FetchHeaders.h */; settings = {ATTRIBUTES = (Private, ); }; };
41D28D0D2139E05800F4206F /* LibWebRTCStatsCollector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D28D0B2139E01D00F4206F /* LibWebRTCStatsCollector.cpp */; };
+ 41DE7C7C222DA14300532B65 /* StorageQuotaManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DE7C7B222DA13E00532B65 /* StorageQuotaManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 41DE7C7D222DA14800532B65 /* StorageQuotaUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DE7C78222DA13C00532B65 /* StorageQuotaUser.h */; settings = {ATTRIBUTES = (Private, ); }; };
41DEFCB61E56C1BD000D9E5F /* JSDOMMapLike.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */; };
41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 41E1B1CB0FF5986900576B3B /* AbstractWorker.h */; };
41F062140F5F192600A07EAC /* InspectorDatabaseResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F062120F5F192600A07EAC /* InspectorDatabaseResource.h */; };
@@ -7511,6 +7513,9 @@
41D28D0B2139E01D00F4206F /* LibWebRTCStatsCollector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCStatsCollector.cpp; path = libwebrtc/LibWebRTCStatsCollector.cpp; sourceTree = "<group>"; };
41D28D0C2139E01E00F4206F /* LibWebRTCStatsCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCStatsCollector.h; path = libwebrtc/LibWebRTCStatsCollector.h; sourceTree = "<group>"; };
41D51BB21E4E2E8100131A5B /* LibWebRTCAudioFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioFormat.h; path = libwebrtc/LibWebRTCAudioFormat.h; sourceTree = "<group>"; };
+ 41DE7C78222DA13C00532B65 /* StorageQuotaUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageQuotaUser.h; sourceTree = "<group>"; };
+ 41DE7C7A222DA13D00532B65 /* StorageQuotaManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageQuotaManager.cpp; sourceTree = "<group>"; };
+ 41DE7C7B222DA13E00532B65 /* StorageQuotaManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageQuotaManager.h; sourceTree = "<group>"; };
41DEFCB21E56C1B9000D9E5F /* JSDOMBindingInternals.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = JSDOMBindingInternals.js; sourceTree = "<group>"; };
41DEFCB31E56C1B9000D9E5F /* JSDOMMapLike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMMapLike.cpp; sourceTree = "<group>"; };
41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMMapLike.h; sourceTree = "<group>"; };
@@ -16862,6 +16867,9 @@
C50D0E810FF4272900AC2644 /* StorageNamespace.h */,
1A3763691A2E68BB009A7EE2 /* StorageNamespaceProvider.cpp */,
1A37636A1A2E68BB009A7EE2 /* StorageNamespaceProvider.h */,
+ 41DE7C7A222DA13D00532B65 /* StorageQuotaManager.cpp */,
+ 41DE7C7B222DA13E00532B65 /* StorageQuotaManager.h */,
+ 41DE7C78222DA13C00532B65 /* StorageQuotaUser.h */,
5166D3CC1E8ED41100AD62E3 /* StorageType.h */,
);
indentWidth = 4;
@@ -31689,6 +31697,8 @@
51E0BB380DA5ACB600A9E417 /* StorageMap.h in Headers */,
C50D0E830FF4272900AC2644 /* StorageNamespace.h in Headers */,
1A37636C1A2E68BB009A7EE2 /* StorageNamespaceProvider.h in Headers */,
+ 41DE7C7C222DA14300532B65 /* StorageQuotaManager.h in Headers */,
+ 41DE7C7D222DA14800532B65 /* StorageQuotaUser.h in Headers */,
5C9EF2F321F06190003BDC56 /* StorageSessionProvider.h in Headers */,
5166D3CD1E8ED48F00AD62E3 /* StorageType.h in Headers */,
4682D2001F79783000C863DB /* StoredCredentialsPolicy.h in Headers */,
Modified: trunk/Source/WebCore/page/ClientOrigin.h (242598 => 242599)
--- trunk/Source/WebCore/page/ClientOrigin.h 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebCore/page/ClientOrigin.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -26,6 +26,7 @@
#pragma once
#include "SecurityOriginData.h"
+#include <wtf/HashTraits.h>
#include <wtf/URL.h>
namespace WebCore {
Added: trunk/Source/WebCore/storage/StorageQuotaManager.cpp (0 => 242599)
--- trunk/Source/WebCore/storage/StorageQuotaManager.cpp (rev 0)
+++ trunk/Source/WebCore/storage/StorageQuotaManager.cpp 2019-03-07 17:40:40 UTC (rev 242599)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StorageQuotaManager.h"
+
+#include "StorageQuotaUser.h"
+
+namespace WebCore {
+
+StorageQuotaManager::~StorageQuotaManager()
+{
+ while (!m_pendingRequests.isEmpty())
+ m_pendingRequests.takeFirst().callback(Decision::Deny);
+}
+
+uint64_t StorageQuotaManager::spaceUsage() const
+{
+ uint64_t usage = 0;
+ for (auto& user : m_users)
+ usage += user->spaceUsed();
+ return usage;
+}
+
+void StorageQuotaManager::requestSpace(uint64_t spaceIncrease, RequestCallback&& callback)
+{
+ if (!m_pendingRequests.isEmpty()) {
+ m_pendingRequests.append({ spaceIncrease, WTFMove(callback) });
+ return;
+ }
+
+ auto spaceUsage = this->spaceUsage();
+ if (spaceUsage + spaceIncrease > m_quota) {
+ m_pendingRequests.append({ spaceIncrease, WTFMove(callback) });
+ askForMoreSpace(spaceUsage, spaceIncrease);
+ return;
+ }
+ callback(Decision::Grant);
+}
+
+void StorageQuotaManager::askForMoreSpace(uint64_t spaceUsage, uint64_t spaceIncrease)
+{
+ ASSERT(spaceUsage + spaceIncrease > m_quota);
+ m_spaceIncreaseRequester(m_quota, spaceUsage, spaceIncrease, [this, weakThis = makeWeakPtr(*this)](Optional<uint64_t> newQuota) {
+ if (!weakThis)
+ return;
+ processPendingRequests(newQuota);
+ });
+}
+
+void StorageQuotaManager::processPendingRequests(Optional<uint64_t> newQuota)
+{
+ if (m_pendingRequests.isEmpty())
+ return;
+
+ if (newQuota)
+ m_quota = *newQuota;
+
+ auto request = m_pendingRequests.takeFirst();
+ auto decision = m_quota >= (spaceUsage() + request.spaceIncrease) ? Decision::Grant : Decision::Deny;
+ request.callback(decision);
+
+ while (!m_pendingRequests.isEmpty()) {
+ auto& request = m_pendingRequests.first();
+
+ auto spaceUsage = this->spaceUsage();
+ if (m_quota < spaceUsage + request.spaceIncrease) {
+ uint64_t spaceIncrease = 0;
+ for (auto& request : m_pendingRequests)
+ spaceIncrease += request.spaceIncrease;
+ askForMoreSpace(spaceUsage, spaceIncrease);
+ return;
+ }
+
+ m_pendingRequests.takeFirst().callback(Decision::Grant);
+ }
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/storage/StorageQuotaManager.h (0 => 242599)
--- trunk/Source/WebCore/storage/StorageQuotaManager.h (rev 0)
+++ trunk/Source/WebCore/storage/StorageQuotaManager.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ClientOrigin.h"
+#include <wtf/CompletionHandler.h>
+#include <wtf/Deque.h>
+#include <wtf/HashSet.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class StorageQuotaUser;
+
+class StorageQuotaManager : public CanMakeWeakPtr<StorageQuotaManager> {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ using SpaceIncreaseRequester = WTF::Function<void(uint64_t quota, uint64_t currentSpace, uint64_t spaceIncrease, CompletionHandler<void(Optional<uint64_t>)>&&)>;
+ StorageQuotaManager(uint64_t quota, SpaceIncreaseRequester&& spaceIncreaseRequester)
+ : m_quota(quota)
+ , m_spaceIncreaseRequester(WTFMove(spaceIncreaseRequester))
+ {
+ }
+ WEBCORE_EXPORT ~StorageQuotaManager();
+
+ void addUser(StorageQuotaUser& user)
+ {
+ ASSERT(!m_users.contains(&user));
+ m_users.add(&user);
+ }
+
+ void removeUser(StorageQuotaUser& user)
+ {
+ ASSERT(m_users.contains(&user));
+ m_users.remove(&user);
+ }
+
+ enum class Decision { Deny, Grant };
+ using RequestCallback = CompletionHandler<void(Decision)>;
+ WEBCORE_EXPORT void requestSpace(uint64_t, RequestCallback&&);
+
+private:
+ uint64_t spaceUsage() const;
+ void askForMoreSpace(uint64_t spaceUsage, uint64_t spaceIncrease);
+ void processPendingRequests(Optional<uint64_t>);
+
+ uint64_t m_quota { 0 };
+ SpaceIncreaseRequester m_spaceIncreaseRequester;
+ HashSet<const StorageQuotaUser*> m_users;
+
+ struct PendingRequest {
+ uint64_t spaceIncrease;
+ RequestCallback callback;
+ };
+ Deque<PendingRequest> m_pendingRequests;
+};
+
+} // namespace WebCore
Added: trunk/Source/WebCore/storage/StorageQuotaUser.h (0 => 242599)
--- trunk/Source/WebCore/storage/StorageQuotaUser.h (rev 0)
+++ trunk/Source/WebCore/storage/StorageQuotaUser.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+class StorageQuotaUser {
+public:
+ virtual ~StorageQuotaUser() = default;
+
+ virtual uint64_t spaceUsed() const = 0;
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebKit/ChangeLog (242598 => 242599)
--- trunk/Source/WebKit/ChangeLog 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/ChangeLog 2019-03-07 17:40:40 UTC (rev 242599)
@@ -1,3 +1,39 @@
+2019-03-07 Youenn Fablet <[email protected]>
+
+ Introduce a quota manager for Cache API/Service Worker/IDB storage
+ https://bugs.webkit.org/show_bug.cgi?id=195283
+
+ Reviewed by Chris Dumez.
+
+ Remove quota handling from Cache API storage and use StorageQuotaManager/StorageQuotaUser.
+ CacheStorage::Caches becomes a quota user and has a StorageQuotaManager to check for space for any cache API write task.
+ NetworkProcess is responsible to manage the quota managers.
+ Quota managers will go through network process to ask UIProcess for quota extension.
+
+ Remove pending callback handling from CacheStorage since they are queued in QuotaManager now.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::~NetworkProcess):
+ (WebKit::NetworkProcess::destroySession):
+ (WebKit::NetworkProcess::cacheStorageRootPath):
+ (WebKit::NetworkProcess::setCacheStorageParameters):
+ (WebKit::NetworkProcess::storageQuotaManager):
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/cache/CacheStorageEngine.cpp:
+ (WebKit::CacheStorage::Engine::from):
+ (WebKit::CacheStorage::Engine::Engine):
+ (WebKit::CacheStorage::Engine::readCachesFromDisk):
+ * NetworkProcess/cache/CacheStorageEngine.h:
+ * NetworkProcess/cache/CacheStorageEngineCache.cpp:
+ (WebKit::CacheStorage::Cache::put):
+ * NetworkProcess/cache/CacheStorageEngineCache.h:
+ * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+ (WebKit::CacheStorage::Caches::Caches):
+ (WebKit::CacheStorage::Caches::~Caches):
+ (WebKit::CacheStorage::Caches::requestSpace):
+ (WebKit::CacheStorage::Caches::writeRecord):
+ * NetworkProcess/cache/CacheStorageEngineCaches.h:
+
2019-03-07 John Wilander <[email protected]>
Resource Load Statistics: Make it possible to purge only script-accessible cookies
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2019-03-07 17:40:40 UTC (rev 242599)
@@ -76,6 +76,7 @@
#include <WebCore/RuntimeEnabledFeatures.h>
#include <WebCore/SchemeRegistry.h>
#include <WebCore/SecurityOriginData.h>
+#include <WebCore/StorageQuotaManager.h>
#include <wtf/Algorithms.h>
#include <wtf/CallbackAggregator.h>
#include <wtf/OptionSet.h>
@@ -168,7 +169,7 @@
{
for (auto& callbacks : m_cacheStorageParametersCallbacks.values()) {
for (auto& callback : callbacks)
- callback(String { }, 0);
+ callback(String { });
}
}
@@ -568,6 +569,8 @@
m_swServers.remove(sessionID);
m_swDatabasePaths.remove(sessionID);
#endif
+
+ m_storageQuotaManagers.remove(sessionID);
}
#if ENABLE(RESOURCE_LOAD_STATISTICS)
@@ -1927,16 +1930,20 @@
WebCore::prefetchDNS(hostname);
}
-void NetworkProcess::cacheStorageParameters(PAL::SessionID sessionID, CacheStorageParametersCallback&& callback)
+void NetworkProcess::cacheStorageRootPath(PAL::SessionID sessionID, CacheStorageRootPathCallback&& callback)
{
m_cacheStorageParametersCallbacks.ensure(sessionID, [&] {
parentProcessConnection()->send(Messages::NetworkProcessProxy::RetrieveCacheStorageParameters { sessionID }, 0);
- return Vector<CacheStorageParametersCallback> { };
+ return Vector<CacheStorageRootPathCallback> { };
}).iterator->value.append(WTFMove(callback));
}
void NetworkProcess::setCacheStorageParameters(PAL::SessionID sessionID, uint64_t quota, String&& cacheStorageDirectory, SandboxExtension::Handle&& handle)
{
+ m_storageQuotaManagers.ensure(sessionID, [] {
+ return StorageQuotaManagers { };
+ }).iterator->value.defaultQuota = quota;
+
auto iterator = m_cacheStorageParametersCallbacks.find(sessionID);
if (iterator == m_cacheStorageParametersCallbacks.end())
return;
@@ -1945,7 +1952,7 @@
auto callbacks = WTFMove(iterator->value);
m_cacheStorageParametersCallbacks.remove(iterator);
for (auto& callback : callbacks)
- callback(String { cacheStorageDirectory }, quota);
+ callback(String { cacheStorageDirectory });
}
void NetworkProcess::preconnectTo(const URL& url, WebCore::StoredCredentialsPolicy storedCredentialsPolicy)
@@ -2270,6 +2277,18 @@
parentProcessConnection()->sendWithAsyncReply(Messages::NetworkProcessProxy::RequestStorageSpace { sessionID, origin, quota, currentSize, spaceRequired }, WTFMove(callback), 0);
}
+StorageQuotaManager& NetworkProcess::storageQuotaManager(PAL::SessionID sessionID, const ClientOrigin& origin)
+{
+ auto& storageQuotaManagers = m_storageQuotaManagers.ensure(sessionID, [] {
+ return StorageQuotaManagers { };
+ }).iterator->value;
+ return *storageQuotaManagers.managersPerOrigin.ensure(origin, [this, &storageQuotaManagers, sessionID, &origin] {
+ return std::make_unique<StorageQuotaManager>(storageQuotaManagers.defaultQuota, [this, sessionID, origin](uint64_t quota, uint64_t currentSpace, uint64_t spaceIncrease, auto callback) {
+ this->requestStorageSpace(sessionID, origin, quota, currentSpace, spaceIncrease, WTFMove(callback));
+ });
+ }).iterator->value;
+}
+
#if !PLATFORM(COCOA)
void NetworkProcess::initializeProcess(const AuxiliaryProcessInitializationParameters&)
{
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -33,6 +33,7 @@
#include "NetworkHTTPSUpgradeChecker.h"
#include "SandboxExtension.h"
#include <WebCore/AdClickAttribution.h>
+#include <WebCore/ClientOrigin.h>
#include <WebCore/DiagnosticLoggingClient.h>
#include <WebCore/FetchIdentifier.h>
#include <WebCore/IDBKeyData.h>
@@ -69,6 +70,7 @@
class CertificateInfo;
class CurlProxySettings;
class DownloadID;
+class StorageQuotaManager;
class NetworkStorageSession;
class ResourceError;
class SWServer;
@@ -258,8 +260,8 @@
void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
#endif
- using CacheStorageParametersCallback = CompletionHandler<void(const String&, uint64_t quota)>;
- void cacheStorageParameters(PAL::SessionID, CacheStorageParametersCallback&&);
+ using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
+ void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
void preconnectTo(const URL&, WebCore::StoredCredentialsPolicy);
@@ -323,6 +325,8 @@
void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
+ WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
+
private:
void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
@@ -467,7 +471,8 @@
NetworkProcessSupplementMap m_supplements;
HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
- HashMap<PAL::SessionID, Vector<CacheStorageParametersCallback>> m_cacheStorageParametersCallbacks;
+ HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
+
HashMap<PAL::SessionID, Ref<NetworkSession>> m_networkSessions;
HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
@@ -516,6 +521,12 @@
#if PLATFORM(COCOA)
NetworkHTTPSUpgradeChecker m_networkHTTPSUpgradeChecker;
#endif
+
+ struct StorageQuotaManagers {
+ uint64_t defaultQuota { 0 };
+ HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> managersPerOrigin;
+ };
+ HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2019-03-07 17:40:40 UTC (rev 242599)
@@ -80,9 +80,9 @@
return;
}
- networkProcess.cacheStorageParameters(sessionID, [networkProcess = makeRef(networkProcess), sessionID, callback = WTFMove(callback)] (auto&& rootPath, auto quota) mutable {
+ networkProcess.cacheStorageRootPath(sessionID, [networkProcess = makeRef(networkProcess), sessionID, callback = WTFMove(callback)] (auto&& rootPath) mutable {
callback(networkProcess->ensureCacheEngine(sessionID, [&] {
- return adoptRef(*new Engine { sessionID, networkProcess.get(), String { rootPath }, quota });
+ return adoptRef(*new Engine { sessionID, networkProcess.get(), WTFMove(rootPath) });
}));
});
}
@@ -185,11 +185,10 @@
});
}
-Engine::Engine(PAL::SessionID sessionID, NetworkProcess& process, String&& rootPath, uint64_t quota)
+Engine::Engine(PAL::SessionID sessionID, NetworkProcess& process, String&& rootPath)
: m_sessionID(sessionID)
, m_networkProcess(makeWeakPtr(process))
, m_rootPath(WTFMove(rootPath))
- , m_quota(quota)
{
if (!m_rootPath.isNull())
m_ioQueue = WorkQueue::create("com.apple.WebKit.CacheStorageEngine.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background);
@@ -317,7 +316,7 @@
auto& caches = m_caches.ensure(origin, [&origin, this] {
auto path = cachesRootPath(origin);
- return Caches::create(*this, WebCore::ClientOrigin { origin }, WTFMove(path), m_quota);
+ return Caches::create(*this, WebCore::ClientOrigin { origin }, WTFMove(path), m_networkProcess->storageQuotaManager(m_sessionID, origin));
}).iterator->value;
if (caches->isInitialized()) {
@@ -650,15 +649,6 @@
return builder.toString();
}
-void Engine::requestSpace(const WebCore::ClientOrigin& origin, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, RequestSpaceCallback&& callback)
-{
- if (!m_networkProcess) {
- callback({ });
- return;
- }
- m_networkProcess->requestStorageSpace(m_sessionID, origin, quota, currentSize, spaceRequired, WTFMove(callback));
-}
-
} // namespace CacheStorage
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -90,11 +90,8 @@
const NetworkCache::Salt& salt() const { return m_salt.value(); }
uint64_t nextCacheIdentifier() { return ++m_nextCacheIdentifier; }
- using RequestSpaceCallback = CompletionHandler<void(Optional<uint64_t>)>;
- void requestSpace(const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, RequestSpaceCallback&&);
-
private:
- Engine(PAL::SessionID, NetworkProcess&, String&& rootPath, uint64_t quota);
+ Engine(PAL::SessionID, NetworkProcess&, String&& rootPath);
void open(const WebCore::ClientOrigin&, const String& cacheName, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
void remove(uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
@@ -137,7 +134,6 @@
HashMap<WebCore::ClientOrigin, RefPtr<Caches>> m_caches;
uint64_t m_nextCacheIdentifier { 0 };
String m_rootPath;
- uint64_t m_quota { 0 };
RefPtr<WorkQueue> m_ioQueue;
Optional<NetworkCache::Salt> m_salt;
HashMap<CacheIdentifier, LockCount> m_cacheLocks;
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp 2019-03-07 17:40:40 UTC (rev 242599)
@@ -400,15 +400,10 @@
}
}
-void Cache::put(Vector<Record>&& records, RecordIdentifiersCallback&& callback, CanRequestMoreSpace canRequestMoreSpace)
+void Cache::put(Vector<Record>&& records, RecordIdentifiersCallback&& callback)
{
ASSERT(m_state == State::Open);
- if (m_caches.isRequestingSpace()) {
- m_pendingPutRequests.append({ WTFMove(records), WTFMove(callback) });
- return;
- }
-
WebCore::CacheQueryOptions options;
uint64_t spaceRequired = 0;
@@ -423,16 +418,6 @@
spaceRequired -= sameURLRecords->at(position).size;
}
- if (m_caches.hasEnoughSpace(spaceRequired)) {
- storeRecords(WTFMove(records), WTFMove(callback));
- return;
- }
-
- if (canRequestMoreSpace == CanRequestMoreSpace::No) {
- callback(makeUnexpected(DOMCacheEngine::Error::QuotaExceeded));
- return;
- }
-
m_caches.requestSpace(spaceRequired, [caches = makeRef(m_caches), identifier = m_identifier, records = WTFMove(records), callback = WTFMove(callback)](Optional<DOMCacheEngine::Error>&& error) mutable {
if (error) {
callback(makeUnexpected(error.value()));
@@ -443,18 +428,10 @@
callback(makeUnexpected(DOMCacheEngine::Error::Internal));
return;
}
-
- cache->put(WTFMove(records), WTFMove(callback), CanRequestMoreSpace::No);
+ cache->storeRecords(WTFMove(records), WTFMove(callback));
});
}
-void Cache::retryPuttingPendingRecords()
-{
- auto pendingPutRequests = WTFMove(m_pendingPutRequests);
- for (auto& request : pendingPutRequests)
- put(WTFMove(request.records), WTFMove(request.callback));
-}
-
void Cache::remove(WebCore::ResourceRequest&& request, WebCore::CacheQueryOptions&& options, RecordIdentifiersCallback&& callback)
{
ASSERT(m_state == State::Open);
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -69,8 +69,7 @@
void retrieveRecords(const URL&, WebCore::DOMCacheEngine::RecordsCallback&&);
WebCore::DOMCacheEngine::CacheInfo info() const { return { m_identifier, m_name }; }
- enum class CanRequestMoreSpace { No, Yes };
- void put(Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&, CanRequestMoreSpace = CanRequestMoreSpace::Yes);
+ void put(Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
void remove(WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
Vector<NetworkCache::Key> keys() const;
@@ -78,8 +77,6 @@
void dispose();
void clearMemoryRepresentation();
- void retryPuttingPendingRecords();
-
static Optional<WebCore::DOMCacheEngine::Record> decode(const NetworkCache::Storage::Record&);
static NetworkCache::Storage::Record encode(const RecordInformation&, const WebCore::DOMCacheEngine::Record&);
@@ -123,12 +120,6 @@
HashMap<String, Vector<RecordInformation>> m_records;
uint64_t m_nextRecordIdentifier { 0 };
Vector<WebCore::DOMCacheEngine::CompletionCallback> m_pendingOpeningCallbacks;
-
- struct PendingPutRequest {
- Vector<WebCore::DOMCacheEngine::Record> records;
- WebCore::DOMCacheEngine::RecordIdentifiersCallback callback;
- };
- Vector<PendingPutRequest> m_pendingPutRequests;
};
} // namespace CacheStorage
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp 2019-03-07 17:40:40 UTC (rev 242599)
@@ -30,6 +30,7 @@
#include "NetworkCacheCoders.h"
#include "NetworkCacheIOChannel.h"
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/StorageQuotaManager.h>
#include <wtf/RunLoop.h>
#include <wtf/UUID.h>
#include <wtf/text/StringBuilder.h>
@@ -50,9 +51,21 @@
return FileSystem::pathByAppendingComponent(cachesRootPath, "origin"_s);
}
+Caches::Caches(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, StorageQuotaManager& quotaManager)
+ : m_engine(&engine)
+ , m_origin(WTFMove(origin))
+ , m_rootPath(WTFMove(rootPath))
+ , m_quotaManager(makeWeakPtr(quotaManager))
+{
+ quotaManager.addUser(*this);
+}
+
Caches::~Caches()
{
ASSERT(m_pendingWritingCachesToDiskCallbacks.isEmpty());
+
+ if (m_quotaManager)
+ m_quotaManager->removeUser(*this);
}
void Caches::retrieveOriginFromDirectory(const String& folderPath, WorkQueue& queue, WTF::CompletionHandler<void(Optional<WebCore::ClientOrigin>&&)>&& completionHandler)
@@ -78,14 +91,6 @@
});
}
-Caches::Caches(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, uint64_t quota)
- : m_engine(&engine)
- , m_origin(WTFMove(origin))
- , m_rootPath(WTFMove(rootPath))
- , m_quota(quota)
-{
-}
-
void Caches::storeOrigin(CompletionCallback&& completionHandler)
{
WTF::Persistence::Encoder encoder;
@@ -488,37 +493,22 @@
void Caches::requestSpace(uint64_t spaceRequired, WebCore::DOMCacheEngine::CompletionCallback&& callback)
{
- ASSERT(!m_isRequestingSpace);
-
- ASSERT(m_quota < m_size + spaceRequired);
-
- if (!m_engine) {
+ if (!m_quotaManager) {
callback(Error::QuotaExceeded);
return;
}
- m_isRequestingSpace = true;
- m_engine->requestSpace(m_origin, m_quota, m_size, spaceRequired, [this, protectedThis = makeRef(*this), callback = WTFMove(callback)] (Optional<uint64_t> newQuota) {
- m_isRequestingSpace = false;
- if (!newQuota) {
+ m_quotaManager->requestSpace(spaceRequired, [callback = WTFMove(callback)](auto decision) {
+ switch (decision) {
+ case StorageQuotaManager::Decision::Deny:
callback(Error::QuotaExceeded);
- notifyCachesOfRequestSpaceEnd();
return;
- }
- m_quota = *newQuota;
- callback({ });
- notifyCachesOfRequestSpaceEnd();
+ case StorageQuotaManager::Decision::Grant:
+ callback({ });
+ };
});
}
-void Caches::notifyCachesOfRequestSpaceEnd()
-{
- for (auto& cache : m_caches)
- cache.retryPuttingPendingRecords();
- for (auto& cache : m_removedCaches)
- cache.retryPuttingPendingRecords();
-}
-
void Caches::writeRecord(const Cache& cache, const RecordInformation& recordInformation, Record&& record, uint64_t previousRecordSize, CompletionCallback&& callback)
{
ASSERT(m_isInitialized);
@@ -527,8 +517,6 @@
m_size += recordInformation.size;
m_size -= previousRecordSize;
- ASSERT(m_size <= m_quota);
-
if (!shouldPersist()) {
m_volatileStorage.set(recordInformation.key, WTFMove(record));
callback(WTF::nullopt);
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h (242598 => 242599)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h 2019-03-07 17:22:27 UTC (rev 242598)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h 2019-03-07 17:40:40 UTC (rev 242599)
@@ -28,9 +28,14 @@
#include "CacheStorageEngineCache.h"
#include "NetworkCacheStorage.h"
#include <WebCore/ClientOrigin.h>
+#include <WebCore/StorageQuotaUser.h>
#include <wtf/CompletionHandler.h>
#include <wtf/Deque.h>
+namespace WebCore {
+class StorageQuotaManager;
+}
+
namespace WebKit {
namespace CacheStorage {
@@ -37,9 +42,9 @@
class Engine;
-class Caches : public RefCounted<Caches> {
+class Caches final : public RefCounted<Caches>, private WebCore::StorageQuotaUser {
public:
- static Ref<Caches> create(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, uint64_t quota) { return adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quota }); }
+ static Ref<Caches> create(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, WebCore::StorageQuotaManager& quotaManager) { return adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quotaManager }); }
~Caches();
static void retrieveOriginFromDirectory(const String& folderPath, WorkQueue&, WTF::CompletionHandler<void(Optional<WebCore::ClientOrigin>&&)>&&);
@@ -60,8 +65,6 @@
void readRecordsList(Cache&, NetworkCache::Storage::TraverseHandler&&);
void readRecord(const NetworkCache::Key&, WTF::Function<void(Expected<WebCore::DOMCacheEngine::Record, WebCore::DOMCacheEngine::Error>&&)>&&);
- bool hasEnoughSpace(uint64_t spaceRequired) const { return m_quota >= m_size + spaceRequired; }
- bool isRequestingSpace() const { return m_isRequestingSpace; }
void requestSpace(uint64_t spaceRequired, WebCore::DOMCacheEngine::CompletionCallback&&);
void writeRecord(const Cache&, const RecordInformation&, WebCore::DOMCacheEngine::Record&&, uint64_t previousRecordSize, WebCore::DOMCacheEngine::CompletionCallback&&);
@@ -79,8 +82,11 @@
uint64_t storageSize() const;
private:
- Caches(Engine&, WebCore::ClientOrigin&&, String&& rootPath, uint64_t quota);
+ Caches(Engine&, WebCore::ClientOrigin&&, String&& rootPath, WebCore::StorageQuotaManager&);
+ // StorageQuotaUser API.
+ uint64_t spaceUsed() const final { return m_size; }
+
void initializeSize();
void readCachesFromDisk(WTF::Function<void(Expected<Vector<Cache>, WebCore::DOMCacheEngine::Error>&&)>&&);
void writeCachesToDisk(WebCore::DOMCacheEngine::CompletionCallback&&);
@@ -94,17 +100,13 @@
void makeDirty() { ++m_updateCounter; }
bool isDirty(uint64_t updateCounter) const;
- void notifyCachesOfRequestSpaceEnd();
-
bool hasActiveCache() const;
bool m_isInitialized { false };
- bool m_isRequestingSpace { false };
Engine* m_engine { nullptr };
uint64_t m_updateCounter { 0 };
WebCore::ClientOrigin m_origin;
String m_rootPath;
- uint64_t m_quota { 0 };
uint64_t m_size { 0 };
Vector<Cache> m_caches;
Vector<Cache> m_removedCaches;
@@ -114,6 +116,7 @@
Vector<WebCore::DOMCacheEngine::CompletionCallback> m_pendingInitializationCallbacks;
bool m_isWritingCachesToDisk { false };
Deque<CompletionHandler<void(Optional<WebCore::DOMCacheEngine::Error>)>> m_pendingWritingCachesToDiskCallbacks;
+ WeakPtr<WebCore::StorageQuotaManager> m_quotaManager;
};
} // namespace CacheStorage