NetworkProcess Cache and Caches should be cleared when the last related WebProcess...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Sep 2017 00:03:13 +0000 (00:03 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Sep 2017 00:03:13 +0000 (00:03 +0000)
commit83e66f644d92a8b2ce47e91126a8390663b7c72a
treefd4086539ca95bd0b45f6dc8367f8302c23f2c5d
parentbd65ac57cecb6d375b1f11eb718276d0becf7623
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
26 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache-storage/cache-origins.https.html
LayoutTests/http/tests/cache-storage/cache-representation.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache-storage/cache-representation.https.html [new file with mode: 0644]
LayoutTests/http/tests/cache-storage/resources/cache-persistency-iframe.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/CacheStorageConnection.h
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp
Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.messages.in