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 28 matching lines...) Expand all Loading... | |
39 #include "modules/EventModules.h" | 39 #include "modules/EventModules.h" |
40 #include "modules/ModulesExport.h" | 40 #include "modules/ModulesExport.h" |
41 #include "modules/indexeddb/IDBAny.h" | 41 #include "modules/indexeddb/IDBAny.h" |
42 #include "modules/indexeddb/IDBTransaction.h" | 42 #include "modules/indexeddb/IDBTransaction.h" |
43 #include "modules/indexeddb/IndexedDB.h" | 43 #include "modules/indexeddb/IndexedDB.h" |
44 #include "platform/bindings/ActiveScriptWrappable.h" | 44 #include "platform/bindings/ActiveScriptWrappable.h" |
45 #include "platform/bindings/ScriptState.h" | 45 #include "platform/bindings/ScriptState.h" |
46 #include "platform/blob/BlobData.h" | 46 #include "platform/blob/BlobData.h" |
47 #include "platform/heap/Handle.h" | 47 #include "platform/heap/Handle.h" |
48 #include "platform/wtf/HashMap.h" | 48 #include "platform/wtf/HashMap.h" |
49 #include "platform/wtf/RefPtr.h" | |
49 #include "public/platform/WebBlobInfo.h" | 50 #include "public/platform/WebBlobInfo.h" |
50 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | 51 #include "public/platform/modules/indexeddb/WebIDBCursor.h" |
51 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 52 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
52 | 53 |
53 namespace blink { | 54 namespace blink { |
54 | 55 |
55 class DOMException; | 56 class DOMException; |
56 class ExceptionState; | 57 class ExceptionState; |
57 class IDBCursor; | 58 class IDBCursor; |
58 struct IDBDatabaseMetadata; | 59 struct IDBDatabaseMetadata; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 std::unique_ptr<WebIDBCallbacks> CreateWebCallbacks(); | 92 std::unique_ptr<WebIDBCallbacks> CreateWebCallbacks(); |
92 void WebCallbacksDestroyed(); | 93 void WebCallbacksDestroyed(); |
93 | 94 |
94 DEFINE_ATTRIBUTE_EVENT_LISTENER(success); | 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(success); |
95 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
96 | 97 |
97 void SetCursorDetails(IndexedDB::CursorType, WebIDBCursorDirection); | 98 void SetCursorDetails(IndexedDB::CursorType, WebIDBCursorDirection); |
98 void SetPendingCursor(IDBCursor*); | 99 void SetPendingCursor(IDBCursor*); |
99 void Abort(); | 100 void Abort(); |
100 | 101 |
101 void EnqueueResponse(DOMException*); | 102 void HandleResponse(DOMException*); |
jsbell
2017/05/15 23:37:38
Please add a comment covering the general behavior
pwnall
2017/05/19 18:27:34
Done.
| |
102 void EnqueueResponse(std::unique_ptr<WebIDBCursor>, | 103 void HandleResponse(IDBKey*); |
103 IDBKey*, | 104 void HandleResponse(std::unique_ptr<WebIDBCursor>, |
104 IDBKey* primary_key, | 105 IDBKey*, |
105 PassRefPtr<IDBValue>); | 106 IDBKey* primary_key, |
106 void EnqueueResponse(IDBKey*); | 107 RefPtr<IDBValue>&&); |
107 void EnqueueResponse(PassRefPtr<IDBValue>); | 108 void HandleResponse(IDBKey*, IDBKey* primary_key, RefPtr<IDBValue>&&); |
108 void EnqueueResponse(const Vector<RefPtr<IDBValue>>&); | 109 void HandleResponse(RefPtr<IDBValue>&&); |
109 void EnqueueResponse(); | 110 void HandleResponse(const Vector<RefPtr<IDBValue>>&); |
110 void EnqueueResponse(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>); | 111 void HandleResponse(int64_t); |
jsbell
2017/05/15 23:37:38
Since it's non-obvious, add the parameter name her
pwnall
2017/05/19 18:27:34
Done.
I didn't add the parameter name before becau
| |
112 void HandleResponse(); | |
jsbell
2017/05/15 23:37:38
At one point we had documentation in the .h files
pwnall
2017/05/19 18:27:34
I agree!
Can I do that in a follow-up CL? Making
jsbell
2017/05/22 21:54:19
sgtm
| |
111 | 113 |
112 // Only used in webkitGetDatabaseNames(), which is deprecated and hopefully | 114 // Only used in webkitGetDatabaseNames(), which is deprecated and hopefully |
113 // going away soon. | 115 // going away soon. |
114 void EnqueueResponse(const Vector<String>&); | 116 void EnqueueResponse(const Vector<String>&); |
115 | 117 |
116 // Overridden by IDBOpenDBRequest. | |
117 virtual void EnqueueResponse(int64_t); | |
118 | |
119 // Only IDBOpenDBRequest instances should receive these: | 118 // Only IDBOpenDBRequest instances should receive these: |
120 virtual void EnqueueBlocked(int64_t old_version) { NOTREACHED(); } | 119 virtual void EnqueueBlocked(int64_t old_version) { NOTREACHED(); } |
121 virtual void EnqueueUpgradeNeeded(int64_t old_version, | 120 virtual void EnqueueUpgradeNeeded(int64_t old_version, |
122 std::unique_ptr<WebIDBDatabase>, | 121 std::unique_ptr<WebIDBDatabase>, |
123 const IDBDatabaseMetadata&, | 122 const IDBDatabaseMetadata&, |
124 WebIDBDataLoss, | 123 WebIDBDataLoss, |
125 String data_loss_message) { | 124 String data_loss_message) { |
126 NOTREACHED(); | 125 NOTREACHED(); |
127 } | 126 } |
128 virtual void EnqueueResponse(std::unique_ptr<WebIDBDatabase>, | 127 virtual void EnqueueResponse(std::unique_ptr<WebIDBDatabase>, |
(...skipping 12 matching lines...) Expand all Loading... | |
141 ExecutionContext* GetExecutionContext() const final; | 140 ExecutionContext* GetExecutionContext() const final; |
142 void UncaughtExceptionInEventHandler() final; | 141 void UncaughtExceptionInEventHandler() final; |
143 | 142 |
144 // Called by a version change transaction that has finished to set this | 143 // Called by a version change transaction that has finished to set this |
145 // request back from DONE (following "upgradeneeded") back to PENDING (for | 144 // request back from DONE (following "upgradeneeded") back to PENDING (for |
146 // the upcoming "success" or "error"). | 145 // the upcoming "success" or "error"). |
147 void TransactionDidFinishAndDispatch(); | 146 void TransactionDidFinishAndDispatch(); |
148 | 147 |
149 IDBCursor* GetResultCursor() const; | 148 IDBCursor* GetResultCursor() const; |
150 | 149 |
151 void StorePutOperationBlobs( | 150 // Used to hang onto Blobs until the browser process handles the request. |
152 HashMap<String, RefPtr<BlobDataHandle>> blob_handles) { | 151 // |
153 transit_blob_handles_ = std::move(blob_handles); | 152 // Blobs are ref-counted on the browser side, and BlobDataHandles manage |
153 // references from renderers. When a BlobDataHandle gets destroyed, the | |
154 // browser-side Blob gets derefenced, which might cause it to be destroyed as | |
155 // well. | |
156 // | |
157 // After script uses a Blob in a put() request, the Blink-side Blob object | |
158 // (which hangs onto the BlobDataHandle) may get garbage-collected. IDBRequest | |
159 // needs to hang onto the BlobDataHandle as well, to avoid having the | |
160 // browser-side Blob get destroyed before the IndexedDB request is processed. | |
161 inline Vector<RefPtr<BlobDataHandle>>* transit_blob_handles() { | |
162 return &transit_blob_handles_; | |
154 } | 163 } |
155 | 164 |
165 #if DCHECK_IS_ON() | |
166 inline bool TransactionHasQueuedResults() const { | |
jsbell
2017/05/15 23:37:38
Why did you decide to make this debug-only? Seems
pwnall
2017/05/19 18:27:34
This method does an extra check -- transaction_ !=
| |
167 return transaction_ && transaction_->HasQueuedResults(); | |
168 } | |
169 | |
170 inline IDBRequestQueueItem* QueueItem() const { return queue_item_; } | |
171 #endif // DCHECK_IS_ON() | |
172 | |
156 protected: | 173 protected: |
157 IDBRequest(ScriptState*, IDBAny* source, IDBTransaction*); | 174 IDBRequest(ScriptState*, IDBAny* source, IDBTransaction*); |
158 void EnqueueEvent(Event*); | 175 void EnqueueEvent(Event*); |
159 void DequeueEvent(Event*); | 176 void DequeueEvent(Event*); |
160 virtual bool ShouldEnqueueEvent() const; | 177 virtual bool ShouldEnqueueEvent() const; |
161 void EnqueueResultInternal(IDBAny*); | 178 void EnqueueResultInternal(IDBAny*); |
162 void SetResult(IDBAny*); | 179 void SetResult(IDBAny*); |
163 | 180 |
181 // Overridden by IDBOpenDBRequest. | |
182 virtual void EnqueueResponse(int64_t); | |
183 | |
164 // EventTarget | 184 // EventTarget |
165 DispatchEventResult DispatchEventInternal(Event*) override; | 185 DispatchEventResult DispatchEventInternal(Event*) override; |
166 | 186 |
187 // Can be nullptr for requests that are not associated with a transaction, | |
188 // i.e. delete requests and completed or unsuccessful open requests. | |
167 Member<IDBTransaction> transaction_; | 189 Member<IDBTransaction> transaction_; |
190 | |
168 ReadyState ready_state_ = PENDING; | 191 ReadyState ready_state_ = PENDING; |
169 bool request_aborted_ = false; // May be aborted by transaction then receive | 192 bool request_aborted_ = false; // May be aborted by transaction then receive |
170 // async onsuccess; ignore vs. assert. | 193 // async onsuccess; ignore vs. assert. |
171 // Maintain the isolate so that all externally allocated memory can be | 194 // Maintain the isolate so that all externally allocated memory can be |
172 // registered against it. | 195 // registered against it. |
173 v8::Isolate* isolate_; | 196 v8::Isolate* isolate_; |
174 | 197 |
175 private: | 198 private: |
199 // Calls into OnError() and OnSuccess(). | |
jsbell
2017/05/15 23:37:38
Comment is obsolete
pwnall
2017/05/19 18:27:34
Done.
Updated the method name. Thank you for catch
| |
200 friend class IDBRequestQueueItem; | |
201 | |
176 void SetResultCursor(IDBCursor*, | 202 void SetResultCursor(IDBCursor*, |
177 IDBKey*, | 203 IDBKey*, |
178 IDBKey* primary_key, | 204 IDBKey* primary_key, |
179 PassRefPtr<IDBValue>); | 205 RefPtr<IDBValue>&&); |
180 void AckReceivedBlobs(const IDBValue*); | 206 void AckReceivedBlobs(const IDBValue*); |
181 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&); | 207 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&); |
182 | 208 |
183 void ClearPutOperationBlobs() { transit_blob_handles_.clear(); } | 209 void EnqueueResponse(DOMException*); |
210 void EnqueueResponse(IDBKey*); | |
211 void EnqueueResponse(std::unique_ptr<WebIDBCursor>, | |
212 IDBKey*, | |
213 IDBKey* primary_key, | |
214 RefPtr<IDBValue>&&); | |
215 void EnqueueResponse(IDBKey*, IDBKey* primary_key, RefPtr<IDBValue>&&); | |
216 void EnqueueResponse(RefPtr<IDBValue>&&); | |
217 void EnqueueResponse(const Vector<RefPtr<IDBValue>>&); | |
218 void EnqueueResponse(); | |
184 | 219 |
185 Member<IDBAny> source_; | 220 Member<IDBAny> source_; |
186 Member<IDBAny> result_; | 221 Member<IDBAny> result_; |
187 Member<DOMException> error_; | 222 Member<DOMException> error_; |
188 | 223 |
189 bool has_pending_activity_ = true; | 224 bool has_pending_activity_ = true; |
190 HeapVector<Member<Event>> enqueued_events_; | 225 HeapVector<Member<Event>> enqueued_events_; |
191 | 226 |
192 // Only used if the result type will be a cursor. | 227 // Only used if the result type will be a cursor. |
193 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue; | 228 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue; |
194 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext; | 229 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext; |
195 // When a cursor is continued/advanced, |result_| is cleared and | 230 // When a cursor is continued/advanced, |result_| is cleared and |
196 // |pendingCursor_| holds it. | 231 // |pendingCursor_| holds it. |
197 Member<IDBCursor> pending_cursor_; | 232 Member<IDBCursor> pending_cursor_; |
198 // New state is not applied to the cursor object until the event is | 233 // New state is not applied to the cursor object until the event is |
199 // dispatched. | 234 // dispatched. |
200 Member<IDBKey> cursor_key_; | 235 Member<IDBKey> cursor_key_; |
201 Member<IDBKey> cursor_primary_key_; | 236 Member<IDBKey> cursor_primary_key_; |
202 RefPtr<IDBValue> cursor_value_; | 237 RefPtr<IDBValue> cursor_value_; |
203 | 238 |
204 HashMap<String, RefPtr<BlobDataHandle>> transit_blob_handles_; | 239 Vector<RefPtr<BlobDataHandle>> transit_blob_handles_; |
205 | 240 |
206 bool did_fire_upgrade_needed_event_ = false; | 241 bool did_fire_upgrade_needed_event_ = false; |
207 bool prevent_propagation_ = false; | 242 bool prevent_propagation_ = false; |
208 bool result_dirty_ = true; | 243 bool result_dirty_ = true; |
209 | 244 |
210 // Transactions should be aborted after event dispatch if an exception was | 245 // Transactions should be aborted after event dispatch if an exception was |
211 // not caught. This is cleared before dispatch, set by a call to | 246 // not caught. This is cleared before dispatch, set by a call to |
212 // UncaughtExceptionInEventHandler() during dispatch, and checked afterwards | 247 // UncaughtExceptionInEventHandler() during dispatch, and checked afterwards |
213 // to abort if necessary. | 248 // to abort if necessary. |
214 bool did_throw_in_event_handler_ = false; | 249 bool did_throw_in_event_handler_ = false; |
215 | 250 |
216 // Pointer back to the WebIDBCallbacks that holds a persistent reference to | 251 // Pointer back to the WebIDBCallbacks that holds a persistent reference to |
217 // this object. | 252 // this object. |
218 WebIDBCallbacks* web_callbacks_ = nullptr; | 253 WebIDBCallbacks* web_callbacks_ = nullptr; |
254 | |
255 #if DCHECK_IS_ON() | |
256 // Non-null while this request's is queued behind other requests that are | |
jsbell
2017/05/15 23:37:38
nit: grammar: 'request is'
pwnall
2017/05/19 18:27:34
Done.
| |
257 // still getting post-processed. | |
258 IDBRequestQueueItem* queue_item_ = nullptr; | |
259 #endif // DCHECK_IS_ON() | |
219 }; | 260 }; |
220 | 261 |
221 } // namespace blink | 262 } // namespace blink |
222 | 263 |
223 #endif // IDBRequest_h | 264 #endif // IDBRequest_h |
OLD | NEW |