⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 295189 in webkit


Ignore:
Timestamp:
Jun 2, 2022, 11:45:44 PM (4 years ago)
Author:
Alan Coon
Message:

Cherry-pick cb6ddf5edf6c. rdar://problem/92853663

Create a stopped CacheStorageConnection for workers in case of detached documents
​https://bugs.webkit.org/show_bug.cgi?id=240224
<rdar://problem/92853663>

Reviewed by Chris Dumez.

A worker might not always have a main thread connection as its document may be detached.
In that case, we now create a StoppedCacheStorageConnection that will always return Error::Stopped to any callback.

Covered by existing tests.

  • Modules/cache/WorkerCacheStorageConnection.cpp: (WebCore::StoppedCacheStorageConnection::create): (WebCore::createMainThreadConnection): (WebCore::WorkerCacheStorageConnection::WorkerCacheStorageConnection): (WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection): (WebCore::WorkerCacheStorageConnection::create): Deleted.
  • Modules/cache/WorkerCacheStorageConnection.h:

Canonical link: ​https://commits.webkit.org/250442@main
git-svn-id: ​https://svn.webkit.org/repository/webkit/trunk@294006 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-613-branch/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613-branch/Source/WebCore/ChangeLog

    r295187 r295189  
     12022-05-10  Youenn Fablet  <youenn@apple.com>
     2
     3        Create a stopped CacheStorageConnection for workers in case of detached documents
     4        https://bugs.webkit.org/show_bug.cgi?id=240224
     5        <rdar://problem/92853663>
     6
     7        Reviewed by Chris Dumez.
     8
     9        A worker might not always have a main thread connection as its document may be detached.
     10        In that case, we now create a StoppedCacheStorageConnection that will always return Error::Stopped to any callback.
     11
     12        Covered by existing tests.
     13
     14        * Modules/cache/WorkerCacheStorageConnection.cpp:
     15        (WebCore::StoppedCacheStorageConnection::create):
     16        (WebCore::createMainThreadConnection):
     17        (WebCore::WorkerCacheStorageConnection::WorkerCacheStorageConnection):
     18        (WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
     19        (WebCore::WorkerCacheStorageConnection::create): Deleted.
     20        * Modules/cache/WorkerCacheStorageConnection.h:
     21
    1222022-05-13  Brent Fulgham  <bfulgham@apple.com>
    223
  • branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp

    r282860 r295189  
    3232#include "ClientOrigin.h"
    3333#include "Document.h"
     34#include "Logging.h"
    3435#include "Page.h"
    3536#include "WorkerGlobalScope.h"
    … …  
    114115}
    115116
    116 Ref<WorkerCacheStorageConnection> WorkerCacheStorageConnection::create(WorkerGlobalScope& scope)
    117 {
    118     auto connection = adoptRef(*new WorkerCacheStorageConnection(scope));
    119     callOnMainThreadAndWait([workerThread = Ref { scope.thread() }, connection = connection.ptr()]() mutable {
    120         connection->m_mainThreadConnection = workerThread->workerLoaderProxy().createCacheStorageConnection();
    121     });
    122     ASSERT(connection->m_mainThreadConnection);
    123     return connection;
     117class StoppedCacheStorageConnection final : public CacheStorageConnection {
     118public:
     119    static Ref<CacheStorageConnection> create() { return adoptRef(*new StoppedCacheStorageConnection); }
     120
     121private:
     122    void open(const ClientOrigin&, const String&, DOMCacheEngine::CacheIdentifierCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     123    void remove(uint64_t, DOMCacheEngine::CacheIdentifierCallback&& callback)  final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     124    void retrieveCaches(const ClientOrigin&, uint64_t, DOMCacheEngine::CacheInfosCallback&& callback)  final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     125    void retrieveRecords(uint64_t, RetrieveRecordsOptions&&, DOMCacheEngine::RecordsCallback&& callback)  final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     126    void batchDeleteOperation(uint64_t, const ResourceRequest&, CacheQueryOptions&&, DOMCacheEngine::RecordIdentifiersCallback&& callback)  final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     127    void batchPutOperation(uint64_t, Vector<DOMCacheEngine::Record>&&, DOMCacheEngine::RecordIdentifiersCallback&& callback)  final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
     128    void reference(uint64_t)  final { }
     129    void dereference(uint64_t)  final { }
     130};
     131
     132static Ref<CacheStorageConnection> createMainThreadConnection(WorkerGlobalScope& scope)
     133{
     134    RefPtr<CacheStorageConnection> mainThreadConnection;
     135    callOnMainThreadAndWait([workerThread = Ref { scope.thread() }, &mainThreadConnection]() mutable {
     136        mainThreadConnection = workerThread->workerLoaderProxy().createCacheStorageConnection();
     137        if (!mainThreadConnection) {
     138            RELEASE_LOG_INFO(ServiceWorker, "Creating stopped WorkerCacheStorageConnection");
     139            mainThreadConnection = StoppedCacheStorageConnection::create();
     140        }
     141    });
     142    return mainThreadConnection.releaseNonNull();
    124143}
    125144
    126145WorkerCacheStorageConnection::WorkerCacheStorageConnection(WorkerGlobalScope& scope)
    127146    : m_scope(scope)
     147    , m_mainThreadConnection(createMainThreadConnection(scope))
    128148{
    129149}
    … …  
    131151WorkerCacheStorageConnection::~WorkerCacheStorageConnection()
    132152{
    133     if (m_mainThreadConnection)
    134         callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
     153    callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
    135154}
    136155
  • branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h

    r283069 r295189  
    3838class WorkerCacheStorageConnection final : public CacheStorageConnection {
    3939public:
    40     static Ref<WorkerCacheStorageConnection> create(WorkerGlobalScope&);
     40    static Ref<WorkerCacheStorageConnection> create(WorkerGlobalScope& scope) { return adoptRef(*new WorkerCacheStorageConnection(scope)); }
    4141    ~WorkerCacheStorageConnection();
    4242
    … …  
    7373    WorkerGlobalScope& m_scope;
    7474
    75     RefPtr<CacheStorageConnection> m_mainThreadConnection;
     75    Ref<CacheStorageConnection> m_mainThreadConnection;
    7676
    7777    HashMap<uint64_t, DOMCacheEngine::CacheIdentifierCallback> m_openAndRemoveCachePendingRequests;
Note: See TracChangeset for help on using the changeset viewer.