| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | 45 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" |
| 46 #include "wtf/PassRefPtr.h" | 46 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/RefPtr.h" | 47 #include "wtf/RefPtr.h" |
| 48 #include <memory> | 48 #include <memory> |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 class DOMException; | 52 class DOMException; |
| 53 class ExceptionState; | 53 class ExceptionState; |
| 54 class ExecutionContext; | 54 class ExecutionContext; |
| 55 class IDBObserver; |
| 56 struct WebIDBObservation; |
| 55 | 57 |
| 56 class MODULES_EXPORT IDBDatabase final : public EventTargetWithInlineData, | 58 class MODULES_EXPORT IDBDatabase final : public EventTargetWithInlineData, |
| 57 public ActiveScriptWrappable, | 59 public ActiveScriptWrappable, |
| 58 public ActiveDOMObject { | 60 public ActiveDOMObject { |
| 59 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); | 61 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); |
| 60 DEFINE_WRAPPERTYPEINFO(); | 62 DEFINE_WRAPPERTYPEINFO(); |
| 61 | 63 |
| 62 public: | 64 public: |
| 63 static IDBDatabase* create(ExecutionContext*, | 65 static IDBDatabase* create(ExecutionContext*, |
| 64 std::unique_ptr<WebIDBDatabase>, | 66 std::unique_ptr<WebIDBDatabase>, |
| 65 IDBDatabaseCallbacks*); | 67 IDBDatabaseCallbacks*); |
| 66 ~IDBDatabase() override; | 68 ~IDBDatabase() override; |
| 67 DECLARE_VIRTUAL_TRACE(); | 69 DECLARE_VIRTUAL_TRACE(); |
| 68 | 70 |
| 69 // Overwrites the database metadata, including object store and index | 71 // Overwrites the database metadata, including object store and index |
| 70 // metadata. Used to pass metadata to the database when it is opened. | 72 // metadata. Used to pass metadata to the database when it is opened. |
| 71 void setMetadata(const IDBDatabaseMetadata&); | 73 void setMetadata(const IDBDatabaseMetadata&); |
| 72 // Overwrites the database's own metadata, but does not change object store | 74 // Overwrites the database's own metadata, but does not change object store |
| 73 // and index metadata. Used to revert the database's metadata when a | 75 // and index metadata. Used to revert the database's metadata when a |
| 74 // versionchage transaction is aborted. | 76 // versionchage transaction is aborted. |
| 75 void setDatabaseMetadata(const IDBDatabaseMetadata&); | 77 void setDatabaseMetadata(const IDBDatabaseMetadata&); |
| 76 void transactionCreated(IDBTransaction*); | 78 void transactionCreated(IDBTransaction*); |
| 77 void transactionFinished(const IDBTransaction*); | 79 void transactionFinished(const IDBTransaction*); |
| 78 const String& getObjectStoreName(int64_t objectStoreId) const; | 80 const String& getObjectStoreName(int64_t objectStoreId) const; |
| 81 int32_t addObserver( |
| 82 IDBObserver*, |
| 83 int64_t transactionId, |
| 84 bool includeTransaction, |
| 85 bool noRecords, |
| 86 bool values, |
| 87 const std::bitset<WebIDBOperationTypeCount>& operationTypes); |
| 88 void removeObservers(const Vector<int32_t>& observerIds); |
| 79 | 89 |
| 80 // Implement the IDL | 90 // Implement the IDL |
| 81 const String& name() const { return m_metadata.name; } | 91 const String& name() const { return m_metadata.name; } |
| 82 unsigned long long version() const { return m_metadata.version; } | 92 unsigned long long version() const { return m_metadata.version; } |
| 83 DOMStringList* objectStoreNames() const; | 93 DOMStringList* objectStoreNames() const; |
| 84 | 94 |
| 85 IDBObjectStore* createObjectStore(const String& name, | 95 IDBObjectStore* createObjectStore(const String& name, |
| 86 const IDBObjectStoreParameters& options, | 96 const IDBObjectStoreParameters& options, |
| 87 ExceptionState& exceptionState) { | 97 ExceptionState& exceptionState) { |
| 88 return createObjectStore(name, IDBKeyPath(options.keyPath()), | 98 return createObjectStore(name, IDBKeyPath(options.keyPath()), |
| 89 options.autoIncrement(), exceptionState); | 99 options.autoIncrement(), exceptionState); |
| 90 } | 100 } |
| 91 IDBTransaction* transaction( | 101 IDBTransaction* transaction( |
| 92 ScriptState*, | 102 ScriptState*, |
| 93 const StringOrStringSequenceOrDOMStringList& storeNames, | 103 const StringOrStringSequenceOrDOMStringList& storeNames, |
| 94 const String& mode, | 104 const String& mode, |
| 95 ExceptionState&); | 105 ExceptionState&); |
| 96 void deleteObjectStore(const String& name, ExceptionState&); | 106 void deleteObjectStore(const String& name, ExceptionState&); |
| 97 void close(); | 107 void close(); |
| 98 | 108 |
| 99 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 109 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
| 100 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 110 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
| 101 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 111 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 102 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); | 112 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); |
| 103 | 113 |
| 104 // IDBDatabaseCallbacks | 114 // IDBDatabaseCallbacks |
| 105 void onVersionChange(int64_t oldVersion, int64_t newVersion); | 115 void onVersionChange(int64_t oldVersion, int64_t newVersion); |
| 106 void onAbort(int64_t, DOMException*); | 116 void onAbort(int64_t, DOMException*); |
| 107 void onComplete(int64_t); | 117 void onComplete(int64_t); |
| 118 void onChanges(const std::unordered_map<int32_t, std::vector<int32_t>>& |
| 119 observation_index_map, |
| 120 const WebVector<WebIDBObservation>& observations); |
| 108 | 121 |
| 109 // ScriptWrappable | 122 // ScriptWrappable |
| 110 bool hasPendingActivity() const final; | 123 bool hasPendingActivity() const final; |
| 111 | 124 |
| 112 // ActiveDOMObject | 125 // ActiveDOMObject |
| 113 void contextDestroyed() override; | 126 void contextDestroyed() override; |
| 114 | 127 |
| 115 // EventTarget | 128 // EventTarget |
| 116 const AtomicString& interfaceName() const override; | 129 const AtomicString& interfaceName() const override; |
| 117 ExecutionContext* getExecutionContext() const override; | 130 ExecutionContext* getExecutionContext() const override; |
| 118 | 131 |
| 119 bool isClosePending() const { return m_closePending; } | 132 bool isClosePending() const { return m_closePending; } |
| 120 void forceClose(); | 133 void forceClose(); |
| 121 const IDBDatabaseMetadata& metadata() const { return m_metadata; } | 134 const IDBDatabaseMetadata& metadata() const { return m_metadata; } |
| 122 void enqueueEvent(Event*); | 135 void enqueueEvent(Event*); |
| 123 | 136 |
| 124 int64_t findObjectStoreId(const String& name) const; | 137 int64_t findObjectStoreId(const String& name) const; |
| 125 bool containsObjectStore(const String& name) const { | 138 bool containsObjectStore(const String& name) const { |
| 126 return findObjectStoreId(name) != IDBObjectStoreMetadata::InvalidId; | 139 return findObjectStoreId(name) != IDBObjectStoreMetadata::InvalidId; |
| 127 } | 140 } |
| 128 void renameObjectStore(int64_t storeId, const String& newName); | 141 void renameObjectStore(int64_t storeId, const String& newName); |
| 129 void revertObjectStoreCreation(int64_t objectStoreId); | 142 void revertObjectStoreCreation(int64_t objectStoreId); |
| 130 void revertObjectStoreMetadata(RefPtr<IDBObjectStoreMetadata> oldMetadata); | 143 void revertObjectStoreMetadata(RefPtr<IDBObjectStoreMetadata> oldMetadata); |
| 131 | 144 |
| 132 // Will return nullptr if this database is stopped. | 145 // Will return nullptr if this database is stopped. |
| 133 WebIDBDatabase* backend() const { return m_backend.get(); } | 146 WebIDBDatabase* backend() const { return m_backend.get(); } |
| 134 | 147 |
| 135 static int64_t nextTransactionId(); | 148 static int64_t nextTransactionId(); |
| 149 static int32_t nextObserverId(); |
| 136 | 150 |
| 137 static const char indexDeletedErrorMessage[]; | 151 static const char indexDeletedErrorMessage[]; |
| 138 static const char indexNameTakenErrorMessage[]; | 152 static const char indexNameTakenErrorMessage[]; |
| 139 static const char isKeyCursorErrorMessage[]; | 153 static const char isKeyCursorErrorMessage[]; |
| 140 static const char noKeyOrKeyRangeErrorMessage[]; | 154 static const char noKeyOrKeyRangeErrorMessage[]; |
| 141 static const char noSuchIndexErrorMessage[]; | 155 static const char noSuchIndexErrorMessage[]; |
| 142 static const char noSuchObjectStoreErrorMessage[]; | 156 static const char noSuchObjectStoreErrorMessage[]; |
| 143 static const char noValueErrorMessage[]; | 157 static const char noValueErrorMessage[]; |
| 144 static const char notValidKeyErrorMessage[]; | 158 static const char notValidKeyErrorMessage[]; |
| 145 static const char notVersionChangeTransactionErrorMessage[]; | 159 static const char notVersionChangeTransactionErrorMessage[]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 166 IDBObjectStore* createObjectStore(const String& name, | 180 IDBObjectStore* createObjectStore(const String& name, |
| 167 const IDBKeyPath&, | 181 const IDBKeyPath&, |
| 168 bool autoIncrement, | 182 bool autoIncrement, |
| 169 ExceptionState&); | 183 ExceptionState&); |
| 170 void closeConnection(); | 184 void closeConnection(); |
| 171 | 185 |
| 172 IDBDatabaseMetadata m_metadata; | 186 IDBDatabaseMetadata m_metadata; |
| 173 std::unique_ptr<WebIDBDatabase> m_backend; | 187 std::unique_ptr<WebIDBDatabase> m_backend; |
| 174 Member<IDBTransaction> m_versionChangeTransaction; | 188 Member<IDBTransaction> m_versionChangeTransaction; |
| 175 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; | 189 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; |
| 190 HeapHashMap<int32_t, Member<IDBObserver>> m_observers; |
| 176 | 191 |
| 177 bool m_closePending = false; | 192 bool m_closePending = false; |
| 178 | 193 |
| 179 // Keep track of the versionchange events waiting to be fired on this | 194 // Keep track of the versionchange events waiting to be fired on this |
| 180 // database so that we can cancel them if the database closes. | 195 // database so that we can cancel them if the database closes. |
| 181 HeapVector<Member<Event>> m_enqueuedEvents; | 196 HeapVector<Member<Event>> m_enqueuedEvents; |
| 182 | 197 |
| 183 Member<IDBDatabaseCallbacks> m_databaseCallbacks; | 198 Member<IDBDatabaseCallbacks> m_databaseCallbacks; |
| 184 }; | 199 }; |
| 185 | 200 |
| 186 } // namespace blink | 201 } // namespace blink |
| 187 | 202 |
| 188 #endif // IDBDatabase_h | 203 #endif // IDBDatabase_h |
| OLD | NEW |