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 | #include "config.h" |
27 | #include "IDBRequestData.h" |
28 | |
29 | #if ENABLE(INDEXED_DATABASE) |
30 | |
31 | #include "IDBConnectionToServer.h" |
32 | #include "IDBDatabase.h" |
33 | #include "IDBOpenDBRequest.h" |
34 | |
35 | namespace WebCore { |
36 | |
37 | IDBRequestData::IDBRequestData() |
38 | { |
39 | } |
40 | |
41 | IDBRequestData::IDBRequestData(const IDBClient::IDBConnectionProxy& connectionProxy, const IDBOpenDBRequest& request) |
42 | : m_serverConnectionIdentifier(connectionProxy.serverConnectionIdentifier()) |
43 | , m_requestIdentifier(std::make_unique<IDBResourceIdentifier>(connectionProxy, request)) |
44 | , m_databaseIdentifier(request.databaseIdentifier()) |
45 | , m_requestedVersion(request.version()) |
46 | , m_requestType(request.requestType()) |
47 | { |
48 | } |
49 | |
50 | IDBRequestData::IDBRequestData(IDBClient::TransactionOperation& operation) |
51 | : m_serverConnectionIdentifier(operation.transaction().database().connectionProxy().serverConnectionIdentifier()) |
52 | , m_requestIdentifier(std::make_unique<IDBResourceIdentifier>(operation.identifier())) |
53 | , m_transactionIdentifier(std::make_unique<IDBResourceIdentifier>(operation.transactionIdentifier())) |
54 | , m_objectStoreIdentifier(operation.objectStoreIdentifier()) |
55 | , m_indexIdentifier(operation.indexIdentifier()) |
56 | { |
57 | if (m_indexIdentifier) |
58 | m_indexRecordType = operation.indexRecordType(); |
59 | |
60 | if (operation.cursorIdentifier()) |
61 | m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*operation.cursorIdentifier()); |
62 | } |
63 | |
64 | IDBRequestData::IDBRequestData(const IDBRequestData& other) |
65 | : m_serverConnectionIdentifier(other.m_serverConnectionIdentifier) |
66 | , m_objectStoreIdentifier(other.m_objectStoreIdentifier) |
67 | , m_indexIdentifier(other.m_indexIdentifier) |
68 | , m_indexRecordType(other.m_indexRecordType) |
69 | , m_databaseIdentifier(other.m_databaseIdentifier) |
70 | , m_requestedVersion(other.m_requestedVersion) |
71 | , m_requestType(other.m_requestType) |
72 | { |
73 | if (other.m_requestIdentifier) |
74 | m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_requestIdentifier); |
75 | if (other.m_transactionIdentifier) |
76 | m_transactionIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_transactionIdentifier); |
77 | if (other.m_cursorIdentifier) |
78 | m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*other.m_cursorIdentifier); |
79 | } |
80 | |
81 | IDBRequestData::IDBRequestData(const IDBRequestData& that, IsolatedCopyTag) |
82 | { |
83 | isolatedCopy(that, *this); |
84 | } |
85 | |
86 | |
87 | IDBRequestData IDBRequestData::isolatedCopy() const |
88 | { |
89 | return { *this, IsolatedCopy }; |
90 | } |
91 | |
92 | void IDBRequestData::isolatedCopy(const IDBRequestData& source, IDBRequestData& destination) |
93 | { |
94 | destination.m_serverConnectionIdentifier = source.m_serverConnectionIdentifier; |
95 | destination.m_objectStoreIdentifier = source.m_objectStoreIdentifier; |
96 | destination.m_indexIdentifier = source.m_indexIdentifier; |
97 | destination.m_indexRecordType = source.m_indexRecordType; |
98 | destination.m_requestedVersion = source.m_requestedVersion; |
99 | destination.m_requestType = source.m_requestType; |
100 | |
101 | destination.m_databaseIdentifier = source.m_databaseIdentifier.isolatedCopy(); |
102 | |
103 | if (source.m_requestIdentifier) |
104 | destination.m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_requestIdentifier); |
105 | if (source.m_transactionIdentifier) |
106 | destination.m_transactionIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_transactionIdentifier); |
107 | if (source.m_cursorIdentifier) |
108 | destination.m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_cursorIdentifier); |
109 | } |
110 | |
111 | uint64_t IDBRequestData::serverConnectionIdentifier() const |
112 | { |
113 | ASSERT(m_serverConnectionIdentifier); |
114 | return m_serverConnectionIdentifier; |
115 | } |
116 | |
117 | IDBResourceIdentifier IDBRequestData::requestIdentifier() const |
118 | { |
119 | ASSERT(m_requestIdentifier); |
120 | return *m_requestIdentifier; |
121 | } |
122 | |
123 | IDBResourceIdentifier IDBRequestData::transactionIdentifier() const |
124 | { |
125 | ASSERT(m_transactionIdentifier); |
126 | return *m_transactionIdentifier; |
127 | } |
128 | |
129 | IDBResourceIdentifier IDBRequestData::cursorIdentifier() const |
130 | { |
131 | ASSERT(m_cursorIdentifier); |
132 | return *m_cursorIdentifier; |
133 | } |
134 | |
135 | uint64_t IDBRequestData::objectStoreIdentifier() const |
136 | { |
137 | ASSERT(m_objectStoreIdentifier); |
138 | return m_objectStoreIdentifier; |
139 | } |
140 | |
141 | uint64_t IDBRequestData::indexIdentifier() const |
142 | { |
143 | ASSERT(m_objectStoreIdentifier || m_indexIdentifier); |
144 | return m_indexIdentifier; |
145 | } |
146 | |
147 | IndexedDB::IndexRecordType IDBRequestData::indexRecordType() const |
148 | { |
149 | ASSERT(m_indexIdentifier); |
150 | return m_indexRecordType; |
151 | } |
152 | |
153 | uint64_t IDBRequestData::requestedVersion() const |
154 | { |
155 | return m_requestedVersion; |
156 | } |
157 | |
158 | } // namespace WebCore |
159 | |
160 | #endif // ENABLE(INDEXED_DATABASE) |
161 | |