IDB: Implement cross-thread and IPC plumbing for 'get' support
[WebKit-https.git] / Source / WebKit2 / DatabaseProcess / IndexedDB / DatabaseProcessIDBConnection.h
1 /*
2  * Copyright (C) 2013 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 DatabaseProcessIDBConnection_h
27 #define DatabaseProcessIDBConnection_h
28
29 #include "MessageSender.h"
30
31 #if ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
32
33 #include "SecurityOriginData.h"
34 #include "UniqueIDBDatabaseIdentifier.h"
35 #include <wtf/text/WTFString.h>
36
37 namespace WebCore {
38 struct IDBKeyData;
39 struct IDBKeyRangeData;
40 }
41
42 namespace WebKit {
43
44 class DatabaseToWebProcessConnection;
45 class UniqueIDBDatabase;
46
47 class DatabaseProcessIDBConnection : public RefCounted<DatabaseProcessIDBConnection>, public IPC::MessageSender {
48 public:
49     static RefPtr<DatabaseProcessIDBConnection> create(DatabaseToWebProcessConnection& connection, uint64_t serverConnectionIdentifier)
50     {
51         return adoptRef(new DatabaseProcessIDBConnection(connection, serverConnectionIdentifier));
52     }
53
54     virtual ~DatabaseProcessIDBConnection();
55
56     // Message handlers.
57     void didReceiveDatabaseProcessIDBConnectionMessage(IPC::Connection*, IPC::MessageDecoder&);
58
59     void disconnectedFromWebProcess();
60
61 private:
62     DatabaseProcessIDBConnection(DatabaseToWebProcessConnection&, uint64_t idbConnectionIdentifier);
63
64     // IPC::MessageSender
65     virtual IPC::Connection* messageSenderConnection() override;
66     virtual uint64_t messageSenderDestinationID() override { return m_serverConnectionIdentifier; }
67
68     // Message handlers.
69     void establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
70     void getOrEstablishIDBDatabaseMetadata(uint64_t requestID);
71     void openTransaction(uint64_t requestID, int64_t transactionID, const Vector<int64_t>& objectStoreIDs, uint64_t transactionMode);
72     void beginTransaction(uint64_t requestID, int64_t transactionID);
73     void commitTransaction(uint64_t requestID, int64_t transactionID);
74     void resetTransaction(uint64_t requestID, int64_t transactionID);
75     void rollbackTransaction(uint64_t requestID, int64_t transactionID);
76     void changeDatabaseVersion(uint64_t requestID, int64_t transactionID, uint64_t newVersion);
77     void createObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata);
78     void deleteObjectStore(uint64_t requestID, int64_t transactionID, int64_t objectStoreID);
79     void putRecord(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBKeyData&, const IPC::DataReference& value, int64_t putMode, const Vector<int64_t>& indexIDs, const Vector<Vector<WebCore::IDBKeyData>>& indexKeys);
80     void getRecord(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&, int64_t cursorType);
81
82     Ref<DatabaseToWebProcessConnection> m_connection;
83     uint64_t m_serverConnectionIdentifier;
84
85     RefPtr<UniqueIDBDatabase> m_uniqueIDBDatabase;
86 };
87
88 } // namespace WebKit
89
90 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
91 #endif // DatabaseProcessIDBConnection_h