Change more of the IPC code to take connections by reference
[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 "DatabaseProcessIDBConnectionMessages.h"
34 #include "SecurityOriginData.h"
35 #include "UniqueIDBDatabaseIdentifier.h"
36 #include <wtf/text/WTFString.h>
37
38 namespace WebCore {
39 struct IDBKeyData;
40 struct IDBKeyRangeData;
41 }
42
43 namespace WebKit {
44
45 class DatabaseToWebProcessConnection;
46 class UniqueIDBDatabase;
47
48 class DatabaseProcessIDBConnection : public RefCounted<DatabaseProcessIDBConnection>, public IPC::MessageSender {
49 public:
50     static RefPtr<DatabaseProcessIDBConnection> create(DatabaseToWebProcessConnection& connection, uint64_t serverConnectionIdentifier)
51     {
52         return adoptRef(new DatabaseProcessIDBConnection(connection, serverConnectionIdentifier));
53     }
54
55     virtual ~DatabaseProcessIDBConnection();
56
57     // Message handlers.
58     void didReceiveDatabaseProcessIDBConnectionMessage(IPC::Connection&, IPC::MessageDecoder&);
59     void didReceiveSyncDatabaseProcessIDBConnectionMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
60
61     void disconnectedFromWebProcess();
62
63 private:
64     DatabaseProcessIDBConnection(DatabaseToWebProcessConnection&, uint64_t idbConnectionIdentifier);
65
66     // IPC::MessageSender
67     virtual IPC::Connection* messageSenderConnection() override;
68     virtual uint64_t messageSenderDestinationID() override { return m_serverConnectionIdentifier; }
69
70     // Message handlers.
71     void establishConnection(const String& databaseName, const SecurityOriginData& openingOrigin, const SecurityOriginData& mainFrameOrigin);
72     void getOrEstablishIDBDatabaseMetadata(uint64_t requestID);
73     void deleteDatabase(uint64_t requestID, const String& databaseName);
74     void openTransaction(uint64_t requestID, int64_t transactionID, const Vector<int64_t>& objectStoreIDs, uint64_t transactionMode);
75     void beginTransaction(uint64_t requestID, int64_t transactionID);
76     void commitTransaction(uint64_t requestID, int64_t transactionID);
77     void resetTransaction(uint64_t requestID, int64_t transactionID);
78     void rollbackTransaction(uint64_t requestID, int64_t transactionID);
79     void resetTransactionSync(int64_t transactionID, PassRefPtr<Messages::DatabaseProcessIDBConnection::ResetTransactionSync::DelayedReply>);
80     void rollbackTransactionSync(int64_t transactionID, PassRefPtr<Messages::DatabaseProcessIDBConnection::RollbackTransactionSync::DelayedReply>);
81     void changeDatabaseVersion(uint64_t requestID, int64_t transactionID, uint64_t newVersion);
82     void createObjectStore(uint64_t requestID, int64_t transactionID, WebCore::IDBObjectStoreMetadata);
83     void deleteObjectStore(uint64_t requestID, int64_t transactionID, int64_t objectStoreID);
84     void clearObjectStore(uint64_t requestID, int64_t transactionID, int64_t objectStoreID);
85     void createIndex(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBIndexMetadata&);
86     void deleteIndex(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID);
87     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);
88     void getRecord(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&, int64_t cursorType);
89
90     void openCursor(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, int64_t cursorDirection, int64_t cursorType, int64_t taskType, const WebCore::IDBKeyRangeData&);
91     void cursorAdvance(uint64_t requestID, int64_t cursorID, uint64_t count);
92     void cursorIterate(uint64_t requestID, int64_t cursorID, const WebCore::IDBKeyData&);
93
94     void count(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&);
95     void deleteRange(uint64_t requestID, int64_t transactionID, int64_t objectStoreID, const WebCore::IDBKeyRangeData& keyRange);
96
97     void close();
98
99     Ref<DatabaseToWebProcessConnection> m_connection;
100     uint64_t m_serverConnectionIdentifier;
101
102     RefPtr<UniqueIDBDatabase> m_uniqueIDBDatabase;
103 };
104
105 } // namespace WebKit
106
107 #endif // ENABLE(INDEXED_DATABASE) && ENABLE(DATABASE_PROCESS)
108 #endif // DatabaseProcessIDBConnection_h