2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef IDBIdentifier_h
27 #define IDBIdentifier_h
29 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
31 #include <wtf/HashTraits.h>
32 #include <wtf/StringHasher.h>
36 class DatabaseProcessIDBConnection;
41 : m_connection(nullptr)
46 IDBIdentifier(DatabaseProcessIDBConnection& connection, int64_t identifier)
47 : m_connection(&connection)
48 , m_identifier(identifier)
52 IDBIdentifier isolatedCopy() const
59 return !m_connection && !m_identifier;
64 uint64_t hashCodes[2] = { reinterpret_cast<uint64_t>(m_connection), static_cast<uint64_t>(m_identifier) };
65 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
68 bool operator==(const IDBIdentifier& other) const
70 return m_connection == other.m_connection && m_identifier == other.m_identifier;
73 IDBIdentifier(WTF::HashTableDeletedValueType)
74 : m_connection(nullptr)
79 bool isHashTableDeletedValue() const
81 return !m_connection && m_identifier == -1;
84 DatabaseProcessIDBConnection& connection() const
90 int64_t id() const { return m_identifier; }
93 // If any members are added that cannot be safely copied across threads, isolatedCopy() must be updated.
94 DatabaseProcessIDBConnection* m_connection;
98 struct IDBIdentifierHash {
99 static unsigned hash(const IDBIdentifier& a) { return a.hash(); }
100 static bool equal(const IDBIdentifier& a, const IDBIdentifier& b) { return a == b; }
101 static const bool safeToCompareToEmptyOrDeleted = false;
104 struct IDBIdentifierHashTraits : WTF::SimpleClassHashTraits<IDBIdentifier> {
105 static const bool hasIsEmptyValueFunction = true;
106 static bool isEmptyValue(const IDBIdentifier& info) { return info.isEmpty(); }
109 } // namespace WebKit
113 template<> struct HashTraits<WebKit::IDBIdentifier> : WebKit::IDBIdentifierHashTraits { };
114 template<> struct DefaultHash<WebKit::IDBIdentifier> {
115 typedef WebKit::IDBIdentifierHash Hash;
120 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
121 #endif // IDBIdentifier_h