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 "IDBTransactionInfo.h" |
28 | |
29 | #if ENABLE(INDEXED_DATABASE) |
30 | |
31 | #include "IDBTransaction.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | IDBTransactionInfo::IDBTransactionInfo() |
36 | { |
37 | } |
38 | |
39 | IDBTransactionInfo::IDBTransactionInfo(const IDBResourceIdentifier& identifier) |
40 | : m_identifier(identifier) |
41 | { |
42 | } |
43 | |
44 | IDBTransactionInfo IDBTransactionInfo::clientTransaction(const IDBClient::IDBConnectionProxy& connectionProxy, const Vector<String>& objectStores, IDBTransactionMode mode) |
45 | { |
46 | IDBTransactionInfo result((IDBResourceIdentifier(connectionProxy))); |
47 | result.m_mode = mode; |
48 | result.m_objectStores = objectStores; |
49 | |
50 | return result; |
51 | } |
52 | |
53 | IDBTransactionInfo IDBTransactionInfo::versionChange(const IDBServer::IDBConnectionToClient& connection, const IDBDatabaseInfo& originalDatabaseInfo, uint64_t newVersion) |
54 | { |
55 | IDBTransactionInfo result((IDBResourceIdentifier(connection))); |
56 | result.m_mode = IDBTransactionMode::Versionchange; |
57 | result.m_newVersion = newVersion; |
58 | result.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(originalDatabaseInfo); |
59 | |
60 | return result; |
61 | } |
62 | |
63 | IDBTransactionInfo::IDBTransactionInfo(const IDBTransactionInfo& info) |
64 | : m_identifier(info.identifier()) |
65 | , m_mode(info.m_mode) |
66 | , m_newVersion(info.m_newVersion) |
67 | , m_objectStores(info.m_objectStores) |
68 | { |
69 | if (info.m_originalDatabaseInfo) |
70 | m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*info.m_originalDatabaseInfo); |
71 | } |
72 | |
73 | IDBTransactionInfo::IDBTransactionInfo(const IDBTransactionInfo& that, IsolatedCopyTag) |
74 | { |
75 | isolatedCopy(that, *this); |
76 | } |
77 | |
78 | IDBTransactionInfo IDBTransactionInfo::isolatedCopy() const |
79 | { |
80 | return { *this, IsolatedCopy }; |
81 | } |
82 | |
83 | void IDBTransactionInfo::isolatedCopy(const IDBTransactionInfo& source, IDBTransactionInfo& destination) |
84 | { |
85 | destination.m_identifier = source.m_identifier.isolatedCopy(); |
86 | destination.m_mode = source.m_mode; |
87 | destination.m_newVersion = source.m_newVersion; |
88 | |
89 | destination.m_objectStores.reserveCapacity(source.m_objectStores.size()); |
90 | for (auto& objectStore : source.m_objectStores) |
91 | destination.m_objectStores.uncheckedAppend(objectStore.isolatedCopy()); |
92 | |
93 | if (source.m_originalDatabaseInfo) |
94 | destination.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*source.m_originalDatabaseInfo, IDBDatabaseInfo::IsolatedCopy); |
95 | } |
96 | |
97 | #if !LOG_DISABLED |
98 | |
99 | String IDBTransactionInfo::loggingString() const |
100 | { |
101 | String modeString; |
102 | switch (m_mode) { |
103 | case IDBTransactionMode::Readonly: |
104 | modeString = "readonly"_s ; |
105 | break; |
106 | case IDBTransactionMode::Readwrite: |
107 | modeString = "readwrite"_s ; |
108 | break; |
109 | case IDBTransactionMode::Versionchange: |
110 | modeString = "versionchange"_s ; |
111 | break; |
112 | default: |
113 | ASSERT_NOT_REACHED(); |
114 | } |
115 | |
116 | return makeString("Transaction: " , m_identifier.loggingString(), " mode " , modeString, " newVersion " , m_newVersion); |
117 | } |
118 | |
119 | #endif |
120 | |
121 | } // namespace WebCore |
122 | |
123 | #endif // ENABLE(INDEXED_DATABASE) |
124 | |