| 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 | #pragma once |
| 27 | |
| 28 | #if ENABLE(INDEXED_DATABASE) |
| 29 | |
| 30 | #include "IDBConnectionToClientDelegate.h" |
| 31 | #include <wtf/HashSet.h> |
| 32 | #include <wtf/Ref.h> |
| 33 | #include <wtf/RefCounted.h> |
| 34 | #include <wtf/WeakPtr.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class IDBError; |
| 39 | class IDBResourceIdentifier; |
| 40 | class IDBResultData; |
| 41 | |
| 42 | namespace IDBServer { |
| 43 | |
| 44 | class UniqueIDBDatabaseConnection; |
| 45 | |
| 46 | class IDBConnectionToClient : public RefCounted<IDBConnectionToClient> { |
| 47 | public: |
| 48 | WEBCORE_EXPORT static Ref<IDBConnectionToClient> create(IDBConnectionToClientDelegate&); |
| 49 | |
| 50 | uint64_t identifier() const; |
| 51 | |
| 52 | void didDeleteDatabase(const IDBResultData&); |
| 53 | void didOpenDatabase(const IDBResultData&); |
| 54 | void didAbortTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
| 55 | void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
| 56 | void didCreateObjectStore(const IDBResultData&); |
| 57 | void didDeleteObjectStore(const IDBResultData&); |
| 58 | void didRenameObjectStore(const IDBResultData&); |
| 59 | void didClearObjectStore(const IDBResultData&); |
| 60 | void didCreateIndex(const IDBResultData&); |
| 61 | void didDeleteIndex(const IDBResultData&); |
| 62 | void didRenameIndex(const IDBResultData&); |
| 63 | void didPutOrAdd(const IDBResultData&); |
| 64 | void didGetRecord(const IDBResultData&); |
| 65 | void didGetAllRecords(const IDBResultData&); |
| 66 | void didGetCount(const IDBResultData&); |
| 67 | void didDeleteRecord(const IDBResultData&); |
| 68 | void didOpenCursor(const IDBResultData&); |
| 69 | void didIterateCursor(const IDBResultData&); |
| 70 | |
| 71 | void fireVersionChangeEvent(UniqueIDBDatabaseConnection&, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion); |
| 72 | void didStartTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&); |
| 73 | void didCloseFromServer(UniqueIDBDatabaseConnection&, const IDBError&); |
| 74 | |
| 75 | void notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion); |
| 76 | |
| 77 | void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames); |
| 78 | |
| 79 | void registerDatabaseConnection(UniqueIDBDatabaseConnection&); |
| 80 | void unregisterDatabaseConnection(UniqueIDBDatabaseConnection&); |
| 81 | void connectionToClientClosed(); |
| 82 | bool isClosed() { return m_isClosed; } |
| 83 | private: |
| 84 | IDBConnectionToClient(IDBConnectionToClientDelegate&); |
| 85 | |
| 86 | WeakPtr<IDBConnectionToClientDelegate> m_delegate; |
| 87 | HashSet<UniqueIDBDatabaseConnection*> m_databaseConnections; |
| 88 | bool m_isClosed { false }; |
| 89 | }; |
| 90 | |
| 91 | } // namespace IDBServer |
| 92 | } // namespace WebCore |
| 93 | |
| 94 | #endif // ENABLE(INDEXED_DATABASE) |
| 95 | |