[Cache API] Support cache names persistency
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 22:50:22 +0000 (22:50 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 22:50:22 +0000 (22:50 +0000)
commitafb0815db793b3ce067c3228abea512f7b4a293f
tree220b07d49b7e68e37ca5fd2540fe56c026e12397
parent0507dd7fa5832ac011ca35f5db43f3256a2fd9ff
[Cache API] Support cache names persistency
https://bugs.webkit.org/show_bug.cgi?id=175995

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-30
Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/cache-storage/cache-persistency.https.html

Adding method to clear the memory representation of the cache storage.
Exposing it as internals so that layout tests can be used for testing persistency by combining clearing and private browsing mode.

Introducing ReadDisk and WriteDisk errors that are used by CacheStorage::Engine.

* Modules/cache/CacheStorageConnection.h:
(WebCore::CacheStorageConnection::clearMemoryRepresentation):
* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::errorToException):
* Modules/cache/DOMCache.h:
* testing/Internals.cpp:
(WebCore::Internals::clearCacheStorageMemoryRepresentation):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Adding disk read/write capacities to CacheStorage engine.
This is used to store per-origin cache names in a file.
Making Engine a thread safe refcounted object so that it does read/write in a background thread.

Introducing CacheStorage::Caches as the object managing the list of Cache objects for a given origin.
Caches will be responsible to do all the read/write operations for all of its caches.
It will be responsible for quota limitation as well.

Moving part of the logic from CacheStorage::Engine into CacheStorage::Caches.

CacheStorage::Engine is initialized asynchronously as it first creates a salt which is used
to obfuscate the names of the various files stored on disk.

In the same spirit, CacheStorage::Caches is initialized asynchronously as it needs to read from the disk the list of cache names.
Once read, the names will be stored in memory.
Added the possibility to clear this in-memory representation. This will be useful for testing.
This might also be useful to save memory when there is no more use of CacheStorage by web pages.

Introducing a new cacheStorageSubdirectoryName parameter for WebsiteDataStore so as to segment the different per session CacheStorageEngine
in direct sub folders of the main cacheStorageDirectory folder.

* CMakeLists.txt:
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::open):
(WebKit::CacheStorage::Engine::remove):
(WebKit::CacheStorage::Engine::retrieveCaches):
(WebKit::CacheStorage::Engine::retrieveRecords):
(WebKit::CacheStorage::Engine::initialize):
(WebKit::CacheStorage::Engine::readCachesFromDisk):
(WebKit::CacheStorage::Engine::cache):
(WebKit::CacheStorage::Engine::writeFile): Making use of default parameter to directly return to the main loop.
(WebKit::CacheStorage::Engine::readFile): Ditto.
(WebKit::CacheStorage::Engine::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngine.h:
(WebKit::CacheStorage::Engine::rootPath const):
(WebKit::CacheStorage::Engine::salt const):
(WebKit::CacheStorage::Engine::nextCacheIdentifier):
* NetworkProcess/cache/CacheStorageEngineCaches.cpp: Added.
(WebKit::CacheStorage::cachesRootPath):
(WebKit::CacheStorage::cachesListFilename):
(WebKit::CacheStorage::Caches::Caches):
(WebKit::CacheStorage::Caches::initialize):
(WebKit::CacheStorage::Caches::find):
(WebKit::CacheStorage::Caches::open):
(WebKit::CacheStorage::Caches::remove):
(WebKit::CacheStorage::encodeCacheNames):
(WebKit::CacheStorage::decodeCachesNames):
(WebKit::CacheStorage::Caches::readCachesFromDisk):
(WebKit::CacheStorage::Caches::writeCachesToDisk):
(WebKit::CacheStorage::Caches::clearMemoryRepresentation):
(WebKit::CacheStorage::Caches::cacheInfos const):
* NetworkProcess/cache/CacheStorageEngineCaches.h: Added.
(WebKit::CacheStorage::Caches::create):
(WebKit::CacheStorage::Caches::isInitialized const):
(WebKit::CacheStorage::Caches::detach):
* NetworkProcess/cache/CacheStorageEngineConnection.cpp:
(WebKit::CacheStorageEngineConnection::clearMemoryRepresentation):
* NetworkProcess/cache/CacheStorageEngineConnection.h:
* NetworkProcess/cache/CacheStorageEngineConnection.messages.in:
* NetworkProcess/cache/NetworkCacheData.cpp:
(WebKit::NetworkCache::makeSalt):
* NetworkProcess/cache/NetworkCacheData.h:
* UIProcess/WebsiteData/WebsiteDataStore.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Cache/WebCacheStorageConnection.cpp:
(WebKit::WebCacheStorageConnection::clearMemoryRepresentation):
* WebProcess/Cache/WebCacheStorageConnection.h:

LayoutTests:

Putting these tests in http/tests folder so that they run in a different origin and so a different Caches than other tests.
Testing private browsing caching and clearing the memory representation would probably affect other cache+prviate browsing tests that would run in parallel.

* http/tests/cache-storage/cache-persistency.https-expected.txt: Added.
* http/tests/cache-storage/cache-persistency.https.html: Added.
* http/tests/cache-storage/resources/cache-persistency-iframe.html: Added.
* platform/ios-wk1/TestExpectations: Skipping new test on WK1.
* platform/mac-wk1/TestExpectations: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache-storage/cache-persistency.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache-storage/cache-persistency.https.html [new file with mode: 0644]
LayoutTests/http/tests/cache-storage/resources/cache-persistency-iframe.html [new file with mode: 0644]
LayoutTests/platform/ios-wk1/TestExpectations
LayoutTests/platform/mac-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/cache/CacheStorageConnection.h
Source/WebCore/Modules/cache/DOMCache.cpp
Source/WebCore/Modules/cache/DOMCache.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.messages.in
Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheData.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.cpp
Source/WebKit/WebProcess/Cache/WebCacheStorageConnection.h