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 21 matching lines...) Expand all Loading... |
32 #include "modules/indexeddb/IDBIndex.h" | 32 #include "modules/indexeddb/IDBIndex.h" |
33 #include "modules/indexeddb/IDBIndexParameters.h" | 33 #include "modules/indexeddb/IDBIndexParameters.h" |
34 #include "modules/indexeddb/IDBKey.h" | 34 #include "modules/indexeddb/IDBKey.h" |
35 #include "modules/indexeddb/IDBKeyRange.h" | 35 #include "modules/indexeddb/IDBKeyRange.h" |
36 #include "modules/indexeddb/IDBMetadata.h" | 36 #include "modules/indexeddb/IDBMetadata.h" |
37 #include "modules/indexeddb/IDBRequest.h" | 37 #include "modules/indexeddb/IDBRequest.h" |
38 #include "modules/indexeddb/IDBTransaction.h" | 38 #include "modules/indexeddb/IDBTransaction.h" |
39 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | 39 #include "public/platform/modules/indexeddb/WebIDBCursor.h" |
40 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | 40 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" |
41 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 41 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
42 #include "wtf/PassRefPtr.h" | |
43 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
44 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
45 | 44 |
46 namespace blink { | 45 namespace blink { |
47 | 46 |
48 class DOMStringList; | 47 class DOMStringList; |
49 class IDBAny; | 48 class IDBAny; |
50 class ExceptionState; | 49 class ExceptionState; |
51 | 50 |
52 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, p
ublic ScriptWrappable { | 51 class IDBObjectStore final : public GarbageCollectedFinalized<IDBObjectStore>, p
ublic ScriptWrappable { |
53 DEFINE_WRAPPERTYPEINFO(); | 52 DEFINE_WRAPPERTYPEINFO(); |
54 public: | 53 public: |
55 static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTra
nsaction* transaction) | 54 static IDBObjectStore* create(RefPtr<IDBObjectStoreMetadata> metadata, IDBTr
ansaction* transaction) |
56 { | 55 { |
57 return new IDBObjectStore(metadata, transaction); | 56 return new IDBObjectStore(std::move(metadata), transaction); |
58 } | 57 } |
59 ~IDBObjectStore() { } | 58 ~IDBObjectStore() { } |
60 DECLARE_TRACE(); | 59 DECLARE_TRACE(); |
61 | 60 |
| 61 const IDBObjectStoreMetadata& metadata() const { return *m_metadata; } |
| 62 |
62 // Implement the IDBObjectStore IDL | 63 // Implement the IDBObjectStore IDL |
63 int64_t id() const { return m_metadata.id; } | 64 int64_t id() const { return metadata().own.id; } |
64 const String& name() const { return m_metadata.name; } | 65 const String& name() const { return metadata().own.name; } |
65 void setName(const String& name, ExceptionState&); | 66 void setName(const String& name, ExceptionState&); |
66 ScriptValue keyPath(ScriptState*) const; | 67 ScriptValue keyPath(ScriptState*) const; |
67 DOMStringList* indexNames() const; | 68 DOMStringList* indexNames() const; |
68 IDBTransaction* transaction() const { return m_transaction.get(); } | 69 IDBTransaction* transaction() const { return m_transaction.get(); } |
69 bool autoIncrement() const { return m_metadata.autoIncrement; } | 70 bool autoIncrement() const { return metadata().own.autoIncrement; } |
70 | 71 |
71 IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String&
direction, ExceptionState&); | 72 IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String&
direction, ExceptionState&); |
72 IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const Stri
ng& direction, ExceptionState&); | 73 IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const Stri
ng& direction, ExceptionState&); |
73 IDBRequest* get(ScriptState*, const ScriptValue& key, ExceptionState&); | 74 IDBRequest* get(ScriptState*, const ScriptValue& key, ExceptionState&); |
74 IDBRequest* getKey(ScriptState*, const ScriptValue& key, ExceptionState&); | 75 IDBRequest* getKey(ScriptState*, const ScriptValue& key, ExceptionState&); |
75 IDBRequest* getAll(ScriptState*, const ScriptValue& range, unsigned long max
Count, ExceptionState&); | 76 IDBRequest* getAll(ScriptState*, const ScriptValue& range, unsigned long max
Count, ExceptionState&); |
76 IDBRequest* getAll(ScriptState*, const ScriptValue& range, ExceptionState&); | 77 IDBRequest* getAll(ScriptState*, const ScriptValue& range, ExceptionState&); |
77 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, unsigned long
maxCount, ExceptionState&); | 78 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, unsigned long
maxCount, ExceptionState&); |
78 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, ExceptionStat
e&); | 79 IDBRequest* getAllKeys(ScriptState*, const ScriptValue& range, ExceptionStat
e&); |
79 IDBRequest* add(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex
ceptionState&); | 80 IDBRequest* add(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex
ceptionState&); |
80 IDBRequest* put(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex
ceptionState&); | 81 IDBRequest* put(ScriptState*, const ScriptValue&, const ScriptValue& key, Ex
ceptionState&); |
81 IDBRequest* deleteFunction(ScriptState*, const ScriptValue& key, ExceptionSt
ate&); | 82 IDBRequest* deleteFunction(ScriptState*, const ScriptValue& key, ExceptionSt
ate&); |
82 IDBRequest* clear(ScriptState*, ExceptionState&); | 83 IDBRequest* clear(ScriptState*, ExceptionState&); |
83 | 84 |
84 IDBIndex* createIndex(ScriptState* scriptState, const String& name, const St
ringOrStringSequence& keyPath, const IDBIndexParameters& options, ExceptionState
& exceptionState) | 85 IDBIndex* createIndex(ScriptState* scriptState, const String& name, const St
ringOrStringSequence& keyPath, const IDBIndexParameters& options, ExceptionState
& exceptionState) |
85 { | 86 { |
86 return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exce
ptionState); | 87 return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exce
ptionState); |
87 } | 88 } |
88 IDBIndex* index(const String& name, ExceptionState&); | 89 IDBIndex* index(const String& name, ExceptionState&); |
89 void deleteIndex(const String& name, ExceptionState&); | 90 void deleteIndex(const String& name, ExceptionState&); |
90 | 91 |
91 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&); | 92 IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&); |
92 | 93 |
93 // Used by IDBCursor::update(): | 94 // Used by IDBCursor::update(): |
94 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal
ue&, IDBKey*, ExceptionState&); | 95 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal
ue&, IDBKey*, ExceptionState&); |
95 | 96 |
96 // Used internally and by InspectorIndexedDBAgent: | 97 // Used internally and by InspectorIndexedDBAgent: |
97 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We
bIDBTaskType = WebIDBTaskTypeNormal); | 98 IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, We
bIDBTaskType = WebIDBTaskTypeNormal); |
98 | 99 |
99 void markDeleted() { m_deleted = true; } | 100 void markDeleted(); |
100 bool isDeleted() const { return m_deleted; } | 101 bool isDeleted() const { return m_deleted; } |
101 void abort(); | |
102 void transactionFinished(); | 102 void transactionFinished(); |
103 | 103 |
104 const IDBObjectStoreMetadata& metadata() const { return m_metadata; } | 104 // Sets the object store's metadata to a previous version. |
105 void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = meta
data; } | 105 // |
106 | 106 // The reverting process includes reverting the metadata for the IDBIndex |
107 typedef HeapVector<Member<IDBKey>> IndexKeys; | 107 // instances that are still tracked by the store. It does not revert the |
| 108 // IDBIndex metadata for indexes that were deleted in this transaction. |
| 109 // |
| 110 // Used when a versionchange transaction is aborted. |
| 111 void revertMetadata(RefPtr<IDBObjectStoreMetadata> previousMetadata); |
| 112 // This relies on the changes made by revertMetadata(). |
| 113 void revertDeletedIndexMetadata(IDBIndex& deletedIndex); |
108 | 114 |
109 // Used by IDBIndex::setName: | 115 // Used by IDBIndex::setName: |
110 bool containsIndex(const String& name) const | 116 bool containsIndex(const String& name) const |
111 { | 117 { |
112 return findIndexId(name) != IDBIndexMetadata::InvalidId; | 118 return findIndexId(name) != IDBIndexMetadata::InvalidId; |
113 } | 119 } |
114 void indexRenamed(int64_t indexId, const String& newName); | 120 void renameIndex(int64_t indexId, const String& newName); |
115 | 121 |
116 WebIDBDatabase* backendDB() const; | 122 WebIDBDatabase* backendDB() const; |
117 | 123 |
118 private: | 124 private: |
119 IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*); | 125 IDBObjectStore(RefPtr<IDBObjectStoreMetadata>, IDBTransaction*); |
120 | 126 |
121 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c
onst IDBIndexParameters&, ExceptionState&); | 127 IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, c
onst IDBIndexParameters&, ExceptionState&); |
122 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal
ue&, const ScriptValue& key, ExceptionState&); | 128 IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptVal
ue&, const ScriptValue& key, ExceptionState&); |
123 | 129 |
124 int64_t findIndexId(const String& name) const; | 130 int64_t findIndexId(const String& name) const; |
125 | 131 |
126 IDBObjectStoreMetadata m_metadata; | 132 // The IDBObjectStoreMetadata is shared with the object store map in the |
| 133 // database's metadata. |
| 134 RefPtr<IDBObjectStoreMetadata> m_metadata; |
127 Member<IDBTransaction> m_transaction; | 135 Member<IDBTransaction> m_transaction; |
128 bool m_deleted = false; | 136 bool m_deleted = false; |
129 | 137 |
130 typedef HeapHashMap<String, Member<IDBIndex>> IDBIndexMap; | 138 // Caches the IDBIndex instances returned by the index() method. |
131 IDBIndexMap m_indexMap; | 139 // |
132 | 140 // The spec requires that an object store's index() returns the same |
133 // Used to mark indexes created in an aborted upgrade transaction as | 141 // IDBIndex instance for a specific index, so this cache is necessary |
134 // deleted. | 142 // for correctness. |
135 HeapHashSet<Member<IDBIndex>> m_createdIndexes; | 143 // |
| 144 // The cache may be in an inconsistent state after a transaction is aborted. |
| 145 // index() throws for inactive transactions, which makes the cache not |
| 146 // observable, so reverting the cache would be a waste of resources. |
| 147 using IndexMap = HeapHashMap<String, Member<IDBIndex>>; |
| 148 IndexMap m_indexMap; |
136 }; | 149 }; |
137 | 150 |
138 } // namespace blink | 151 } // namespace blink |
139 | 152 |
140 #endif // IDBObjectStore_h | 153 #endif // IDBObjectStore_h |
OLD | NEW |