Cache API and IDB space usages should be initialized on first quota check
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 22:52:18 +0000 (22:52 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 22:52:18 +0000 (22:52 +0000)
commit8028f0635903ec815f637f346121cb4b882400fc
tree3d0d438a0d77799e338582c9f4b50f5e9ef06f64
parentc78a54272b0da9fe245f2aaeb90e8ae68c2e8f8e
Cache API and IDB space usages should be initialized on first quota check
https://bugs.webkit.org/show_bug.cgi?id=195707

Reviewed by Chris Dumez.

Source/WebCore:

Add a way to require IDBServer to create a quota user for a given origin.
Make sure that removing a user might kick-in processing of pending requests.
In the case of processing pending requests, we should not decide on the first task
except if it is triggered by a request space response.
Update processPendingRequests accordingly.

Tests: http/tests/IndexedDB/storage-limit-1.https.html
       http/tests/IndexedDB/storage-limit-2.https.html

* Modules/indexeddb/server/IDBServer.h:
(WebCore::IDBServer::IDBServer::initializeQuotaUser):
* storage/StorageQuotaManager.cpp:
(WebCore::StorageQuotaManager::removeUser):
(WebCore::StorageQuotaManager::askForMoreSpace):
(WebCore::StorageQuotaManager::processPendingRequests):
* storage/StorageQuotaManager.h:

Source/WebKit:

When the quota manager is created, make sure it delays quota check decisions until IDB and Cache API quota users are initialized.
For IDB, the creation is synchronous but it may not be synchronous for Cache API.
For that purpose, add a temporary quota user that will stay uninitialized until these two quota users are added.
Once added, the temporary quota user is removed.
The addition of the real users is made asynchronously as this is triggered by the creation of one of the two quota users.

In the case of a Cache API caches being cleared, make sure to reset the size to zero and to redo the quota user initialization dance.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::QuotaUserInitializer::initialize):
(WebKit::QuotaUserInitializer::~QuotaUserInitializer):
(WebKit::QuotaUserInitializer::QuotaUserInitializer):
(WebKit::NetworkProcess::storageQuotaManager):
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::initializeQuotaUser):
* NetworkProcess/cache/CacheStorageEngine.h:
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::clear):

LayoutTests:

* TestExpectations:
Marking http/tests/cache-storage/cache-clearing-origin.https.html as
flaky on iOS as it is already marked flaky in MacOS.
* platform/mac-wk2/TestExpectations:
* http/tests/IndexedDB/storage-limit-1.https-expected.txt: Added.
* http/tests/IndexedDB/storage-limit-1.https.html: Added.
* http/tests/IndexedDB/storage-limit-2.https-expected.txt: Added.
* http/tests/IndexedDB/storage-limit-2.https.html: Added.
* http/tests/IndexedDB/storage-limit.https.html:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243339 268f45cc-cd09-0410-ab3c-d52691b4dbfc
22 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/IndexedDB/storage-limit-1.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/IndexedDB/storage-limit-1.https.html [moved from LayoutTests/http/tests/IndexedDB/resources/storage-limit.js with 61% similarity]
LayoutTests/http/tests/IndexedDB/storage-limit-2.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/IndexedDB/storage-limit-2.https.html [new file with mode: 0644]
LayoutTests/http/tests/IndexedDB/storage-limit.https.html
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/Modules/indexeddb/server/IDBServer.h
Source/WebCore/storage/StorageQuotaManager.cpp
Source/WebCore/storage/StorageQuotaManager.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h