1 | |
2 | /* |
3 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
24 | * THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "DOMCacheEngine.h" |
30 | #include <wtf/HashMap.h> |
31 | #include <wtf/ThreadSafeRefCounted.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | struct ClientOrigin; |
36 | class FetchResponse; |
37 | |
38 | class CacheStorageConnection : public ThreadSafeRefCounted<CacheStorageConnection> { |
39 | public: |
40 | virtual ~CacheStorageConnection() = default; |
41 | |
42 | virtual void open(const ClientOrigin&, const String& cacheName, DOMCacheEngine::CacheIdentifierCallback&&) = 0; |
43 | virtual void remove(uint64_t cacheIdentifier, DOMCacheEngine::CacheIdentifierCallback&&) = 0; |
44 | virtual void retrieveCaches(const ClientOrigin&, uint64_t updateCounter, DOMCacheEngine::CacheInfosCallback&&) = 0; |
45 | |
46 | virtual void retrieveRecords(uint64_t cacheIdentifier, const URL&, DOMCacheEngine::RecordsCallback&&) = 0; |
47 | virtual void batchDeleteOperation(uint64_t cacheIdentifier, const ResourceRequest&, CacheQueryOptions&&, DOMCacheEngine::RecordIdentifiersCallback&&) = 0; |
48 | virtual void batchPutOperation(uint64_t cacheIdentifier, Vector<DOMCacheEngine::Record>&&, DOMCacheEngine::RecordIdentifiersCallback&&) = 0; |
49 | |
50 | virtual void reference(uint64_t /* cacheIdentifier */) = 0; |
51 | virtual void dereference(uint64_t /* cacheIdentifier */) = 0; |
52 | |
53 | uint64_t computeRecordBodySize(const FetchResponse&, const DOMCacheEngine::ResponseBody&); |
54 | |
55 | // Used only for testing purposes. |
56 | virtual void clearMemoryRepresentation(const ClientOrigin&, DOMCacheEngine::CompletionCallback&& callback) { callback(DOMCacheEngine::Error::NotImplemented); } |
57 | virtual void engineRepresentation(CompletionHandler<void(const String&)>&& callback) { callback(String { }); } |
58 | virtual void updateQuotaBasedOnSpaceUsage(const ClientOrigin&) { } |
59 | |
60 | protected: |
61 | HashMap<uint64_t, uint64_t> m_opaqueResponseToSizeWithPaddingMap; |
62 | }; |
63 | } // namespace WebCore |
64 | |