Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IDBRequestQueue_h | |
| 6 #define IDBRequestQueue_h | |
| 7 | |
| 8 #include "platform/heap/Handle.h" | |
| 9 #include "platform/wtf/PassRefPtr.h" | |
| 10 #include "platform/wtf/RefPtr.h" | |
| 11 #include "platform/wtf/Vector.h" | |
| 12 | |
| 13 #include <memory> | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 class DOMException; | |
| 18 class IDBKey; | |
| 19 class IDBRequest; | |
| 20 class IDBRequestLoader; | |
| 21 class IDBValue; | |
| 22 class WebIDBCursor; | |
| 23 | |
| 24 // Queues up a transaction's IDBRequest results for orderly delivery. | |
| 25 // | |
| 26 // The IndexedDB specification requires that the events corresponding to IDB | |
| 27 // request results fire in the order in which the requests were issued. The | |
| 28 // browser-side backend processes requests in order, but the Blink side may need | |
| 29 // to perform post-processing on the results (e.g., large value unwrapping). | |
|
jsbell
2017/05/05 00:29:37
nit: no ,
pwnall
2017/05/11 23:54:24
Done.
| |
| 30 // When a result needs post-processing, this queue captures all results received | |
| 31 // during the post-processing steps. The events for these results may only fire | |
| 32 // after the post-processed result's event is fired. | |
| 33 class IDBRequestQueueItem | |
|
jsbell
2017/05/05 00:29:37
Filename should be IDBRequestQueueItem ?
pwnall
2017/05/11 23:54:24
Done.
| |
| 34 : public GarbageCollectedFinalized<IDBRequestQueueItem> { | |
|
jsbell
2017/05/05 00:29:37
Why GC'd? I would imagine this would be owned by t
pwnall
2017/05/11 23:54:24
Done.
I was being lazy and avoiding learning about
| |
| 35 public: | |
| 36 IDBRequestQueueItem(IDBRequest*, DOMException*); | |
| 37 IDBRequestQueueItem(IDBRequest*, IDBKey*); | |
| 38 IDBRequestQueueItem(IDBRequest*, PassRefPtr<IDBValue>); | |
| 39 IDBRequestQueueItem(IDBRequest*, const Vector<RefPtr<IDBValue>>&); | |
| 40 IDBRequestQueueItem(IDBRequest*, | |
| 41 IDBKey*, | |
| 42 IDBKey* primary_key, | |
| 43 PassRefPtr<IDBValue>); | |
| 44 IDBRequestQueueItem(IDBRequest*, | |
| 45 std::unique_ptr<WebIDBCursor> backend, | |
| 46 IDBKey*, | |
| 47 IDBKey* primary_key, | |
| 48 PassRefPtr<IDBValue>); | |
| 49 | |
| 50 // False if this result still requires post-processing. | |
| 51 inline bool IsReady() { return ready_; } | |
| 52 | |
| 53 // The request whose queued result is tracked by this item. | |
| 54 inline IDBRequest* Request() { return request_; } | |
| 55 | |
| 56 // Creates a IDBRequestLoader to post-process the IDBRequest's result. | |
| 57 void AttachLoader(); | |
| 58 | |
| 59 // Starts post-processing the IDBRequest's result. | |
| 60 // | |
| 61 // This method must be called after the IDBRequestQueueItem is enqueued into | |
| 62 // the appropriate queue, because it is possible for the loading operation to | |
| 63 // complete synchronously, in which case IDBtransaction::OnResultReady() will | |
|
jsbell
2017/05/05 00:29:37
nit: IDBTransaction
pwnall
2017/05/11 23:54:24
Done.
| |
| 64 // be called with the (presumably) enqueued IDBRequest before this method | |
| 65 // returns. | |
| 66 void StartLoading(); | |
| 67 | |
| 68 // Calls the correct overload of OnSuccess/OnError on the associated request. | |
| 69 // | |
| 70 // This should only be called by the request's IDBTransaction. | |
| 71 void FireCallback(); | |
| 72 | |
| 73 // Marks the result as having being post-processed. | |
| 74 // | |
| 75 // This method should only be called by the associated IDBRequestLoader. | |
| 76 void MarkReady(); | |
| 77 // Called when an error occurs during result post-processing. | |
| 78 // | |
| 79 // This method should only be called by the associated IDBRequestLoader. | |
| 80 void MarkReady(DOMException* error); | |
| 81 | |
| 82 DECLARE_TRACE(); | |
| 83 | |
| 84 private: | |
| 85 // The IDBRequest callback that will be called for this result. | |
| 86 enum Mode { | |
| 87 kError, | |
| 88 kBackendKeyPrimaryKeyValue, | |
| 89 kKey, | |
| 90 kKeyPrimaryKeyValue, | |
| 91 kValue, | |
| 92 kValueArray, | |
| 93 }; | |
| 94 | |
| 95 // Performs post-processing on this result. | |
| 96 // | |
| 97 // nullptr for results that do not require post-processing and for results | |
| 98 // whose post-processing has completed. | |
| 99 Member<IDBRequestLoader> loader_; | |
| 100 | |
| 101 // The IDBRequest that will receive a callback for this result. | |
| 102 Member<IDBRequest> request_; | |
| 103 | |
| 104 // The key argument to the IDBRequest callback. | |
| 105 // | |
| 106 // Only used if mode_ is kKeyPrimaryKeyValue. | |
| 107 Member<IDBKey> key_; | |
| 108 | |
| 109 // The primary_key argument to the IDBRequest callback. | |
| 110 // | |
| 111 // Only used if mode_ is kKeyPrimaryKeyValue. | |
| 112 Member<IDBKey> primary_key_; | |
| 113 | |
| 114 // The error argument to the IDBRequest callback. | |
| 115 // | |
| 116 // Only used if the mode_ is kError. | |
| 117 Member<DOMException> error_; | |
| 118 | |
| 119 // All the values that will be passed back to the IDBRequest. | |
| 120 Vector<RefPtr<IDBValue>> values_; | |
| 121 | |
| 122 // The backend argument to the IDBRequest callback. | |
| 123 std::unique_ptr<WebIDBCursor> backend_; | |
| 124 | |
| 125 // The IDBRequest callback that will be called for this result. | |
| 126 Mode mode_; | |
| 127 | |
| 128 // False if this result still requires post-processing. | |
| 129 bool ready_ = true; | |
| 130 | |
| 131 #if DCHECK_IS_ON() | |
| 132 bool callback_fired_; | |
| 133 #endif // DCHECK_IS_ON() | |
| 134 }; | |
| 135 | |
| 136 using IDBRequestQueue = HeapDeque<Member<IDBRequestQueueItem>>; | |
| 137 | |
| 138 } // namespace blink | |
| 139 | |
| 140 #endif // IDBRequestQueue_h | |
| OLD | NEW |