Bug 175995 - [Cache API] Support cache names persistency
Summary: [Cache API] Support cache names persistency
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-08-25 14:10 PDT by youenn fablet
Modified: 2017-08-31 14:21 PDT (History)
11 users (show)

See Also:


Attachments
Patch (56.33 KB, patch)
2017-08-25 15:43 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (56.91 KB, patch)
2017-08-25 15:58 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (56.97 KB, patch)
2017-08-25 16:28 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (58.30 KB, patch)
2017-08-25 17:03 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (58.06 KB, patch)
2017-08-28 13:36 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (69.10 KB, patch)
2017-08-28 17:05 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (70.53 KB, patch)
2017-08-28 17:38 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (55.02 KB, patch)
2017-08-29 16:36 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (54.88 KB, patch)
2017-08-30 14:54 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2017-08-25 14:10:19 PDT
Add support for cache names persistency
Comment 1 youenn fablet 2017-08-25 15:43:57 PDT
Created attachment 319106 [details]
Patch
Comment 2 Build Bot 2017-08-25 15:46:28 PDT
Attachment 319106 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 3 in 22 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 youenn fablet 2017-08-25 15:58:40 PDT
Created attachment 319107 [details]
Patch
Comment 4 Build Bot 2017-08-25 15:59:41 PDT
Attachment 319107 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 3 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 youenn fablet 2017-08-25 16:28:50 PDT
Created attachment 319114 [details]
Patch
Comment 6 Build Bot 2017-08-25 16:31:20 PDT
Attachment 319114 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:123:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 4 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 youenn fablet 2017-08-25 17:03:52 PDT
Created attachment 319119 [details]
Patch
Comment 8 Build Bot 2017-08-25 17:06:32 PDT
Attachment 319119 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:123:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 4 in 25 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Alex Christensen 2017-08-28 12:15:01 PDT
Comment on attachment 319119 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319119&action=review

> Source/WebCore/Modules/cache/CacheStorageConnection.h:49
> +    // Used only for testing purposes.
> +    virtual void setPersistency(const String& /* origin */, bool /* isPersistent */, DOMCache::CompletionCallback&& callback) { callback(DOMCache::Error::NotImplemented); }

Maybe we should call this setPersistencyForTesting, and I think we should do something similar to setPrivateBrowsingEnabled instead and use SessionID to determine whether a cache should touch the disk or not.
Comment 10 youenn fablet 2017-08-28 13:36:47 PDT
Created attachment 319201 [details]
Patch
Comment 11 Build Bot 2017-08-28 13:39:00 PDT
Attachment 319201 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:122:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 4 in 27 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 youenn fablet 2017-08-28 13:41:22 PDT
(In reply to Alex Christensen from comment #9)
> Comment on attachment 319119 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=319119&action=review
> 
> > Source/WebCore/Modules/cache/CacheStorageConnection.h:49
> > +    // Used only for testing purposes.
> > +    virtual void setPersistency(const String& /* origin */, bool /* isPersistent */, DOMCache::CompletionCallback&& callback) { callback(DOMCache::Error::NotImplemented); }
> 
> Maybe we should call this setPersistencyForTesting, and I think we should do
> something similar to setPrivateBrowsingEnabled instead and use SessionID to
> determine whether a cache should touch the disk or not.

I was not sure whether we wanted to implement cache API in private browsing with in-memory-only caches. Let's do it then.
This will probably end up having a much smaller quota for private browsing than for regular sessions.

I removed setPersistencyForTesting and used setPrivateBrowsingEnabled in the test.
Comment 13 Sam Weinig 2017-08-28 14:13:05 PDT
Comment on attachment 319201 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319201&action=review

> Source/WebCore/Modules/cache/DOMCache.cpp:44
> +        return Exception { TypeError, ASCIILiteral("Failed reading data from disk") };

I'm not sure 'disk' is the best name here, as many machines don't have hard-disks anymore. I like 'FileSystem' as a modifier, but I am sure we could come up with others.
Comment 14 Alex Christensen 2017-08-28 14:54:34 PDT
Comment on attachment 319201 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319201&action=review

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:47
> +    String sessionSubdirectory = ASCIILiteral("session") + String::number(sessionID.sessionID());
> +    return WebCore::pathByAppendingComponent(NetworkProcess::singleton().cacheStorageDirectory(), sessionSubdirectory);

This should be a String from the WebsiteDataStore.
Comment 15 youenn fablet 2017-08-28 17:05:40 PDT
Created attachment 319219 [details]
Patch
Comment 16 Build Bot 2017-08-28 17:07:31 PDT
Attachment 319219 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:117:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 4 in 38 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 17 youenn fablet 2017-08-28 17:08:57 PDT
(In reply to Sam Weinig from comment #13)
> Comment on attachment 319201 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=319201&action=review
> 
> > Source/WebCore/Modules/cache/DOMCache.cpp:44
> > +        return Exception { TypeError, ASCIILiteral("Failed reading data from disk") };
> 
> I'm not sure 'disk' is the best name here, as many machines don't have
> hard-disks anymore. I like 'FileSystem' as a modifier, but I am sure we
> could come up with others.

Changed to "file system".

(In reply to Alex Christensen from comment #14)
> Comment on attachment 319201 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=319201&action=review
> 
> > Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:47
> > +    String sessionSubdirectory = ASCIILiteral("session") + String::number(sessionID.sessionID());
> > +    return WebCore::pathByAppendingComponent(NetworkProcess::singleton().cacheStorageDirectory(), sessionSubdirectory);
> 
> This should be a String from the WebsiteDataStore.

I added a new parameter to WebsiteDataStoreParameters to pass the sub folder name.
This enforces one main folder for cache storage and one subfolder for each cache storage engine.
Comment 18 youenn fablet 2017-08-28 17:38:06 PDT
Created attachment 319221 [details]
Patch
Comment 19 Build Bot 2017-08-28 17:41:12 PDT
Attachment 319221 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:125:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:118:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 4 in 39 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 20 youenn fablet 2017-08-29 16:36:51 PDT
Created attachment 319303 [details]
Patch
Comment 21 Build Bot 2017-08-29 16:38:55 PDT
Attachment 319303 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:105:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:129:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:111:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 5 in 28 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 22 Alex Christensen 2017-08-30 13:41:54 PDT
Comment on attachment 319303 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319303&action=review

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:246
> +    if (!shouldPersist()) {
> +        m_salt = makeSalt();

I don't think we should need  a salt of it's not persistent.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:361
> +            callback(std::nullopt);

Let's put an ASSERT(RunLoop::isMain()); here.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:384
> +            callback(data, error);

Same here.  It might be worth having a bunch of such assertions.

> Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:163
> +    Vector<String> names;
> +    names.reserveInitialCapacity(count);

We should use the VectorCoders and put the reserveInitialCapacity optimization in them.
Comment 23 youenn fablet 2017-08-30 14:54:09 PDT
Created attachment 319409 [details]
Patch for landing
Comment 24 Build Bot 2017-08-30 14:56:51 PDT
Attachment 319409 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:95:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:101:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:105:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:128:  More than one command on the same line  [whitespace/newline] [4]
ERROR: Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:111:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 5 in 28 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 25 youenn fablet 2017-08-30 15:22:16 PDT
(In reply to Alex Christensen from comment #22)
> Comment on attachment 319303 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=319303&action=review
> 
> > Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:246
> > +    if (!shouldPersist()) {
> > +        m_salt = makeSalt();
> 
> I don't think we should need  a salt of it's not persistent.

Will do as a follow-up

> > Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:361
> > +            callback(std::nullopt);
> 
> Let's put an ASSERT(RunLoop::isMain()); here.

OK

> 
> > Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp:384
> > +            callback(data, error);
> 
> Same here.  It might be worth having a bunch of such assertions.

OK

> 
> > Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp:163
> > +    Vector<String> names;
> > +    names.reserveInitialCapacity(count);
> 
> We should use the VectorCoders and put the reserveInitialCapacity
> optimization in them.

I sticked with the current decoder since the encoder side is not using the Vector encoder either as it would need to create a vector of string for that.
Comment 26 WebKit Commit Bot 2017-08-30 15:50:26 PDT
Comment on attachment 319409 [details]
Patch for landing

Clearing flags on attachment: 319409

Committed r221403: <http://trac.webkit.org/changeset/221403>
Comment 27 WebKit Commit Bot 2017-08-30 15:50:28 PDT
All reviewed patches have been landed.  Closing bug.
Comment 28 Radar WebKit Bug Importer 2017-08-30 15:51:41 PDT
<rdar://problem/34174534>
Comment 29 Ryan Haddad 2017-08-31 09:04:30 PDT
The LayoutTest added with this change (http/tests/cache-storage/cache-persistency.https.html) is failing an assertion on El Capitan:

ASSERTION FAILED: position != notFound
/Volumes/Data/slave/elcapitan-debug/build/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp(130) : void WebKit::CacheStorage::Caches::remove(uint64_t, CompletionCallback &&)

https://build.webkit.org/results/Apple%20El%20Capitan%20Debug%20WK2%20(Tests)/r221417%20(2811)/results.html
Comment 30 youenn fablet 2017-08-31 09:31:42 PDT
(In reply to Ryan Haddad from comment #29)
> The LayoutTest added with this change
> (http/tests/cache-storage/cache-persistency.https.html) is failing an
> assertion on El Capitan:
> 
> ASSERTION FAILED: position != notFound
> /Volumes/Data/slave/elcapitan-debug/build/Source/WebKit/NetworkProcess/cache/
> CacheStorageEngineCaches.cpp(130) : void
> WebKit::CacheStorage::Caches::remove(uint64_t, CompletionCallback &&)
> 
> https://build.webkit.org/results/
> Apple%20El%20Capitan%20Debug%20WK2%20(Tests)/r221417%20(2811)/results.html

Will have a look at it.
Thanks!