NetworkProcess Cache and Caches should be cleared when the last related WebProcess Cache or CacheStorage is destroyed
https://bugs.webkit.org/show_bug.cgi?id=176249
Patch by Youenn Fablet <youenn@apple.com> on 2017-09-06
Reviewed by Alex Christensen.
Source/WebCore:
Test: http/tests/cache-storage/cache-representation.https.html
Each Cache construction/destruction is notified to the CacheStorageConnection
so that the WebKit2 engine can handle memory management accordingly.
Adding an internal API to grab the representation of an engine at any time.
* Modules/cache/Cache.cpp:
(WebCore::Cache::Cache):
(WebCore::Cache::~Cache):
* Modules/cache/CacheStorageConnection.h:
(WebCore::CacheStorageConnection::reference):
(WebCore::CacheStorageConnection::dereference):
* Modules/cache/WorkerCacheStorageConnection.cpp:
(WebCore::WorkerCacheStorageConnection::reference):
(WebCore::WorkerCacheStorageConnection::dereference):
* Modules/cache/WorkerCacheStorageConnection.h:
* testing/Internals.cpp:
(WebCore::Internals::cacheStorageEngineRepresentation):
* testing/Internals.h:
* testing/Internals.idl:
Source/WebKit:
CacheStorageEngineConnection will store the number of Caches references for its related WebProcess.
For a new reference, CacheStorageEngineConnection will notify its engine to lock the related Cache.
When the last reference is gone, CacheStorageEngineConnection will ask the engine to release the lock.
CacheStorageEngine will keep locks as a counter for each Cache object.
When the counter goes to zero, the engine asks the Cache to dispose itself.
Disposal is done by its parent Caches as only Caches knows whether the Cache is persistent or has been removed.
The Caches will remove the Cache from memory.
For removed caches, all information will be lost.
For caches that are not removed, they will keep their identifiers but all in-memory record information will be discarded.
If there is a need to reopen the Cache, it will need to read its information from the filesystem.
If the Caches has no longer any active Cache object, it will ask the engine to release itself.
WebProcess crashing is handled correctly as the CacheStorageEngineConnection will release its locks at destruction
time of the connection to the web process.
Adding the possiblity to grab an engine representation for test purposes.
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::readCachesFromDisk):
(WebKit::CacheStorage::Engine::removeCaches):
(WebKit::CacheStorage::Engine::lock):
(WebKit::CacheStorage::Engine::unlock):
* NetworkProcess/cache/CacheStorageEngine.h:
* NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::Cache::Cache):
(WebKit::CacheStorage::Cache::dispose):
(WebKit::CacheStorage::Cache::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngineCache.h:
(WebKit::CacheStorage::Cache::isActive const):
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::Caches):
(WebKit::CacheStorage::Caches::open):
(WebKit::CacheStorage::Caches::dispose):
(WebKit::CacheStorage::Caches::readCachesFromDisk):
(WebKit::CacheStorage::Caches::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngineCaches.h:
(WebKit::CacheStorage::Caches::create):
* NetworkProcess/cache/CacheStorageEngineConnection.cpp:
(WebKit::CacheStorageEngineConnection::~CacheStorageEngineConnection):
(WebKit::CacheStorageEngineConnection::reference):
(WebKit::CacheStorageEngineConnection::dereference):
* NetworkProcess/cache/CacheStorageEngineConnection.h:
* NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
* WebProcess/Cache/WebCacheStorageConnection.cpp:
(WebKit::WebCacheStorageConnection::reference):
(WebKit::WebCacheStorageConnection::dereference):
* WebProcess/Cache/WebCacheStorageConnection.h:
LayoutTests:
* http/tests/cache-storage/cache-representation.https-expected.txt: Added.
* http/tests/cache-storage/cache-representation.https.html: Added.
* http/tests/cache-storage/resources/cache-persistency-iframe.html:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221710
268f45cc-cd09-0410-ab3c-
d52691b4dbfc