1 | /* |
2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef NetworkCacheEntry_h |
27 | #define NetworkCacheEntry_h |
28 | |
29 | #include "NetworkCacheStorage.h" |
30 | #include "ShareableResource.h" |
31 | #include <WebCore/ResourceRequest.h> |
32 | #include <WebCore/ResourceResponse.h> |
33 | #include <wtf/Noncopyable.h> |
34 | #include <wtf/Seconds.h> |
35 | #include <wtf/text/WTFString.h> |
36 | |
37 | namespace WebCore { |
38 | class SharedBuffer; |
39 | } |
40 | |
41 | namespace WebKit { |
42 | namespace NetworkCache { |
43 | |
44 | class Entry { |
45 | WTF_MAKE_FAST_ALLOCATED; |
46 | public: |
47 | Entry(const Key&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, const Vector<std::pair<String, String>>& ); |
48 | Entry(const Key&, const WebCore::ResourceResponse&, const WebCore::ResourceRequest& redirectRequest, const Vector<std::pair<String, String>>& ); |
49 | explicit Entry(const Storage::Record&); |
50 | Entry(const Entry&); |
51 | |
52 | Storage::Record encodeAsStorageRecord() const; |
53 | static std::unique_ptr<Entry> decodeStorageRecord(const Storage::Record&); |
54 | |
55 | const Key& key() const { return m_key; } |
56 | WallTime timeStamp() const { return m_timeStamp; } |
57 | const WebCore::ResourceResponse& response() const { return m_response; } |
58 | const Vector<std::pair<String, String>>& () const { return m_varyingRequestHeaders; } |
59 | |
60 | WebCore::SharedBuffer* buffer() const; |
61 | const Optional<WebCore::ResourceRequest>& redirectRequest() const { return m_redirectRequest; } |
62 | |
63 | #if ENABLE(SHAREABLE_RESOURCE) |
64 | ShareableResource::Handle& shareableResourceHandle() const; |
65 | #endif |
66 | |
67 | bool needsValidation() const; |
68 | void setNeedsValidation(bool); |
69 | |
70 | const Storage::Record& sourceStorageRecord() const { return m_sourceStorageRecord; } |
71 | |
72 | void asJSON(StringBuilder&, const Storage::RecordInfo&) const; |
73 | |
74 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
75 | bool hasReachedPrevalentResourceAgeCap() const; |
76 | void capMaxAge(const Seconds); |
77 | #endif |
78 | |
79 | private: |
80 | void initializeBufferFromStorageRecord() const; |
81 | #if ENABLE(SHAREABLE_RESOURCE) |
82 | void initializeShareableResourceHandleFromStorageRecord() const; |
83 | #endif |
84 | |
85 | Key m_key; |
86 | WallTime m_timeStamp; |
87 | WebCore::ResourceResponse m_response; |
88 | Vector<std::pair<String, String>> ; |
89 | |
90 | Optional<WebCore::ResourceRequest> m_redirectRequest; |
91 | mutable RefPtr<WebCore::SharedBuffer> m_buffer; |
92 | #if ENABLE(SHAREABLE_RESOURCE) |
93 | mutable ShareableResource::Handle m_shareableResourceHandle; |
94 | #endif |
95 | |
96 | Storage::Record m_sourceStorageRecord { }; |
97 | |
98 | Optional<Seconds> m_maxAgeCap; |
99 | }; |
100 | |
101 | } |
102 | } |
103 | |
104 | #endif |
105 | |