| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #define IDBDatabase_h | 27 #define IDBDatabase_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/ActiveScriptWrappable.h" | 29 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 30 #include "bindings/core/v8/ScriptState.h" | 30 #include "bindings/core/v8/ScriptState.h" |
| 31 #include "bindings/modules/v8/StringOrStringSequenceOrDOMStringList.h" | 31 #include "bindings/modules/v8/StringOrStringSequenceOrDOMStringList.h" |
| 32 #include "core/dom/ActiveDOMObject.h" | 32 #include "core/dom/ActiveDOMObject.h" |
| 33 #include "core/dom/DOMStringList.h" | 33 #include "core/dom/DOMStringList.h" |
| 34 #include "modules/EventModules.h" | 34 #include "modules/EventModules.h" |
| 35 #include "modules/EventTargetModules.h" | 35 #include "modules/EventTargetModules.h" |
| 36 #include "modules/ModulesExport.h" | 36 #include "modules/ModulesExport.h" |
| 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | |
| 38 #include "modules/indexeddb/IDBHistograms.h" | 37 #include "modules/indexeddb/IDBHistograms.h" |
| 39 #include "modules/indexeddb/IDBMetadata.h" | 38 #include "modules/indexeddb/IDBMetadata.h" |
| 40 #include "modules/indexeddb/IDBObjectStore.h" | 39 #include "modules/indexeddb/IDBObjectStore.h" |
| 41 #include "modules/indexeddb/IDBObjectStoreParameters.h" | 40 #include "modules/indexeddb/IDBObjectStoreParameters.h" |
| 42 #include "modules/indexeddb/IDBTransaction.h" | 41 #include "modules/indexeddb/IDBTransaction.h" |
| 43 #include "modules/indexeddb/IndexedDB.h" | 42 #include "modules/indexeddb/IndexedDB.h" |
| 43 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 44 #include "platform/heap/Handle.h" | 44 #include "platform/heap/Handle.h" |
| 45 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | 45 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" |
| 46 #include "public/platform/modules/indexeddb/indexed_db.mojom-blink.h" |
| 46 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
| 48 #include <memory> | 49 #include <memory> |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 52 class DOMException; | 53 class DOMException; |
| 53 class ExceptionState; | 54 class ExceptionState; |
| 54 class ExecutionContext; | 55 class ExecutionContext; |
| 55 | 56 |
| 56 class MODULES_EXPORT IDBDatabase final | 57 class MODULES_EXPORT IDBDatabase final |
| 57 : public EventTargetWithInlineData | 58 : public EventTargetWithInlineData |
| 58 , public ActiveScriptWrappable | 59 , public ActiveScriptWrappable |
| 59 , public ActiveDOMObject { | 60 , public ActiveDOMObject |
| 61 , public indexed_db::mojom::blink::DatabaseClient { |
| 60 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); | 62 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); |
| 61 DEFINE_WRAPPERTYPEINFO(); | 63 DEFINE_WRAPPERTYPEINFO(); |
| 64 USING_PRE_FINALIZER(IDBDatabase, dispose); |
| 65 |
| 62 public: | 66 public: |
| 63 static IDBDatabase* create(ExecutionContext*, std::unique_ptr<WebIDBDatabase
>, IDBDatabaseCallbacks*); | 67 static IDBDatabase* create(ExecutionContext*, std::unique_ptr<WebIDBDatabase
>, indexed_db::mojom::blink::DatabaseClientAssociatedRequest); |
| 64 ~IDBDatabase() override; | 68 ~IDBDatabase() override; |
| 65 DECLARE_VIRTUAL_TRACE(); | 69 DECLARE_VIRTUAL_TRACE(); |
| 66 | 70 |
| 71 void dispose(); |
| 72 |
| 67 void setMetadata(const IDBDatabaseMetadata& metadata) { m_metadata = metadat
a; } | 73 void setMetadata(const IDBDatabaseMetadata& metadata) { m_metadata = metadat
a; } |
| 68 void indexCreated(int64_t objectStoreId, const IDBIndexMetadata&); | 74 void indexCreated(int64_t objectStoreId, const IDBIndexMetadata&); |
| 69 void indexDeleted(int64_t objectStoreId, int64_t indexId); | 75 void indexDeleted(int64_t objectStoreId, int64_t indexId); |
| 70 void transactionCreated(IDBTransaction*); | 76 void transactionCreated(IDBTransaction*); |
| 71 void transactionFinished(const IDBTransaction*); | 77 void transactionFinished(const IDBTransaction*); |
| 72 const String& getObjectStoreName(int64_t objectStoreId) const; | 78 const String& getObjectStoreName(int64_t objectStoreId) const; |
| 73 | 79 |
| 74 // Implement the IDL | 80 // Implement the IDL |
| 75 const String& name() const { return m_metadata.name; } | 81 const String& name() const { return m_metadata.name; } |
| 76 unsigned long long version() const { return m_metadata.version; } | 82 unsigned long long version() const { return m_metadata.version; } |
| 77 DOMStringList* objectStoreNames() const; | 83 DOMStringList* objectStoreNames() const; |
| 78 | 84 |
| 79 IDBObjectStore* createObjectStore(const String& name, const IDBObjectStorePa
rameters& options, ExceptionState& exceptionState) { return createObjectStore(na
me, IDBKeyPath(options.keyPath()), options.autoIncrement(), exceptionState); } | 85 IDBObjectStore* createObjectStore(const String& name, const IDBObjectStorePa
rameters& options, ExceptionState& exceptionState) { return createObjectStore(na
me, IDBKeyPath(options.keyPath()), options.autoIncrement(), exceptionState); } |
| 80 IDBTransaction* transaction(ScriptState*, const StringOrStringSequenceOrDOMS
tringList&, const String& mode, ExceptionState&); | 86 IDBTransaction* transaction(ScriptState*, const StringOrStringSequenceOrDOMS
tringList&, const String& mode, ExceptionState&); |
| 81 void deleteObjectStore(const String& name, ExceptionState&); | 87 void deleteObjectStore(const String& name, ExceptionState&); |
| 82 void close(); | 88 void close(); |
| 83 | 89 |
| 84 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 90 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
| 85 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 91 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
| 86 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 92 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 87 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); | 93 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); |
| 88 | 94 |
| 89 // IDBDatabaseCallbacks | 95 // indexed_db::mojom::blink::DatabaseClient |
| 90 void onVersionChange(int64_t oldVersion, int64_t newVersion); | 96 void OnTransactionAborted(int64_t transactionId, indexed_db::mojom::blink::E
rrorInfoPtr) override; |
| 91 void onAbort(int64_t, DOMException*); | 97 void OnTransactionCompleted(int64_t transactionId) override; |
| 92 void onComplete(int64_t); | 98 void OnForcedClosed() override; |
| 99 void OnVersionChange(int64_t oldVersion, int64_t newVersion) override; |
| 93 | 100 |
| 94 // ScriptWrappable | 101 // ScriptWrappable |
| 95 bool hasPendingActivity() const final; | 102 bool hasPendingActivity() const final; |
| 96 | 103 |
| 97 // ActiveDOMObject | 104 // ActiveDOMObject |
| 98 void stop() override; | 105 void stop() override; |
| 99 | 106 |
| 100 // EventTarget | 107 // EventTarget |
| 101 const AtomicString& interfaceName() const override; | 108 const AtomicString& interfaceName() const override; |
| 102 ExecutionContext* getExecutionContext() const override; | 109 ExecutionContext* getExecutionContext() const override; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 133 static const char transactionReadOnlyErrorMessage[]; | 140 static const char transactionReadOnlyErrorMessage[]; |
| 134 static const char databaseClosedErrorMessage[]; | 141 static const char databaseClosedErrorMessage[]; |
| 135 | 142 |
| 136 static void recordApiCallsHistogram(IndexedDatabaseMethods); | 143 static void recordApiCallsHistogram(IndexedDatabaseMethods); |
| 137 | 144 |
| 138 protected: | 145 protected: |
| 139 // EventTarget | 146 // EventTarget |
| 140 DispatchEventResult dispatchEventInternal(Event*) override; | 147 DispatchEventResult dispatchEventInternal(Event*) override; |
| 141 | 148 |
| 142 private: | 149 private: |
| 143 IDBDatabase(ExecutionContext*, std::unique_ptr<WebIDBDatabase>, IDBDatabaseC
allbacks*); | 150 IDBDatabase(ExecutionContext*, std::unique_ptr<WebIDBDatabase>, indexed_db::
mojom::blink::DatabaseClientAssociatedRequest); |
| 144 | 151 |
| 145 IDBObjectStore* createObjectStore(const String& name, const IDBKeyPath&, boo
l autoIncrement, ExceptionState&); | 152 IDBObjectStore* createObjectStore(const String& name, const IDBKeyPath&, boo
l autoIncrement, ExceptionState&); |
| 146 void closeConnection(); | 153 void closeConnection(); |
| 147 | 154 |
| 148 IDBDatabaseMetadata m_metadata; | 155 IDBDatabaseMetadata m_metadata; |
| 149 std::unique_ptr<WebIDBDatabase> m_backend; | 156 std::unique_ptr<WebIDBDatabase> m_backend; |
| 150 Member<IDBTransaction> m_versionChangeTransaction; | 157 Member<IDBTransaction> m_versionChangeTransaction; |
| 151 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; | 158 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; |
| 152 | 159 |
| 153 bool m_closePending = false; | 160 bool m_closePending = false; |
| 154 bool m_contextStopped = false; | 161 bool m_contextStopped = false; |
| 155 | 162 |
| 156 // Keep track of the versionchange events waiting to be fired on this | 163 // Keep track of the versionchange events waiting to be fired on this |
| 157 // database so that we can cancel them if the database closes. | 164 // database so that we can cancel them if the database closes. |
| 158 HeapVector<Member<Event>> m_enqueuedEvents; | 165 HeapVector<Member<Event>> m_enqueuedEvents; |
| 159 | 166 |
| 160 Member<IDBDatabaseCallbacks> m_databaseCallbacks; | 167 mojo::AssociatedBinding<indexed_db::mojom::blink::DatabaseClient> m_clientBi
nding; |
| 161 }; | 168 }; |
| 162 | 169 |
| 163 } // namespace blink | 170 } // namespace blink |
| 164 | 171 |
| 165 #endif // IDBDatabase_h | 172 #endif // IDBDatabase_h |
| OLD | NEW |