Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(828)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.h

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Fixed Windows compilation. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 IDBRequestQueueItem_h
6 #define IDBRequestQueueItem_h
7
8 #include "platform/heap/Handle.h"
9 #include "platform/wtf/Allocator.h"
10 #include "platform/wtf/PassRefPtr.h"
11 #include "platform/wtf/RefPtr.h"
12 #include "platform/wtf/Vector.h"
13
14 #include <memory>
15
16 namespace blink {
17
18 class DOMException;
19 class IDBKey;
20 class IDBRequest;
21 class IDBRequestLoader;
22 class IDBValue;
23 class WebIDBCursor;
24
25 // Queues up a transaction's IDBRequest results for orderly delivery.
26 //
27 // The IndexedDB specification requires that the events corresponding to IDB
28 // request results fire in the order in which the requests were issued. The
29 // browser-side backend processes requests in order, but the Blink side may need
30 // to perform post-processing on the results (e.g. large value unwrapping).
31 // When a result needs post-processing, this queue captures all results received
32 // during the post-processing steps. The events for these results may only fire
33 // after the post-processed result's event is fired.
34 class IDBRequestQueueItem {
35 USING_FAST_MALLOC(IDBRequestQueueItem);
36
37 public:
38 IDBRequestQueueItem(IDBRequest*,
39 DOMException*,
40 std::unique_ptr<WTF::Closure> on_result_load_complete);
41 IDBRequestQueueItem(IDBRequest*,
42 int64_t,
43 std::unique_ptr<WTF::Closure> on_result_load_complete);
44 IDBRequestQueueItem(IDBRequest*,
45 std::unique_ptr<WTF::Closure> on_result_load_complete);
46 IDBRequestQueueItem(IDBRequest*,
47 IDBKey*,
48 std::unique_ptr<WTF::Closure> on_result_load_complete);
49 IDBRequestQueueItem(IDBRequest*,
50 PassRefPtr<IDBValue>,
51 bool attach_loader,
52 std::unique_ptr<WTF::Closure> on_load_complete);
53 IDBRequestQueueItem(IDBRequest*,
54 const Vector<RefPtr<IDBValue>>&,
55 bool attach_loader,
56 std::unique_ptr<WTF::Closure> on_result_load_complete);
57 IDBRequestQueueItem(IDBRequest*,
58 IDBKey*,
59 IDBKey* primary_key,
60 PassRefPtr<IDBValue>,
61 bool attach_loader,
62 std::unique_ptr<WTF::Closure> on_result_load_complete);
63 IDBRequestQueueItem(IDBRequest*,
64 std::unique_ptr<WebIDBCursor>,
65 IDBKey*,
66 IDBKey* primary_key,
67 PassRefPtr<IDBValue>,
68 bool attach_loader,
69 std::unique_ptr<WTF::Closure> on_result_load_complete);
70 ~IDBRequestQueueItem();
71
72 // False if this result still requires post-processing.
73 inline bool IsReady() { return ready_; }
74
75 // The request whose queued result is tracked by this item.
76 inline IDBRequest* Request() { return request_; }
77
78 // Starts post-processing the IDBRequest's result.
79 //
80 // This method must be called after the IDBRequestQueueItem is enqueued into
81 // the appropriate queue, because it is possible for the loading operation to
82 // complete synchronously, in which case IDBTransaction::OnResultReady() will
83 // be called with the (presumably) enqueued IDBRequest before this method
84 // returns.
85 void StartLoading();
86
87 // Stops post-processing the IDBRequest's result.
88 //
89 // This method may be called without an associated StartLoading().
90 void CancelLoading();
91
92 // Calls the correct EnqueueResponse overload on the associated request.
93 //
94 // This should only be called by the request's IDBTransaction.
95 void EnqueueResponse();
96
97 // Called by the associated IDBRequestLoader when result processing is done.
98 void OnResultLoadComplete();
99
100 // Called by the associated IDBRequestLoader when result processing fails.
101 void OnResultLoadComplete(DOMException* error);
102
103 private:
104 // The IDBRequest callback that will be called for this result.
105 enum ResponseType {
106 kCanceled,
107 kCursorKeyPrimaryKeyValue,
108 kError,
109 kNumber,
110 kKey,
111 kKeyPrimaryKeyValue,
112 kValue,
113 kValueArray,
114 kVoid,
115 };
116
117 // The IDBRequest that will receive a callback for this result.
118 Persistent<IDBRequest> request_;
119
120 // The key argument to the IDBRequest callback.
121 //
122 // Only used if mode_ is kKeyPrimaryKeyValue.
123 Persistent<IDBKey> key_;
124
125 // The primary_key argument to the IDBRequest callback.
126 //
127 // Only used if mode_ is kKeyPrimaryKeyValue.
128 Persistent<IDBKey> primary_key_;
129
130 // The error argument to the IDBRequest callback.
131 //
132 // Only used if the mode_ is kError.
133 Persistent<DOMException> error_;
134
135 // All the values that will be passed back to the IDBRequest.
136 Vector<RefPtr<IDBValue>> values_;
137
138 // The cursor argument to the IDBRequest callback.
139 std::unique_ptr<WebIDBCursor> cursor_;
140
141 // Performs post-processing on this result.
142 //
143 // nullptr for results that do not require post-processing and for results
144 // whose post-processing has completed.
145 std::unique_ptr<IDBRequestLoader> loader_;
146
147 // Called when result post-processing has completed.
148 std::unique_ptr<WTF::Closure> on_result_load_complete_;
149
150 // The integer value argument to the IDBRequest callback.
151 int64_t int64_value_;
152
153 // Identifies the IDBRequest::EnqueueResponse() overload that will be called.
154 ResponseType response_type_;
155
156 // False if this result still requires post-processing.
157 bool ready_;
158
159 #if DCHECK_IS_ON()
160 // True if the appropriate EnqueueResponse() method was called in IDBRequest.
161 //
162 // If CancelLoading() is called, the ResponseType might be kCanceled. In this
163 // case, callback_fired_ can be set to true even though no EnqueueResponse()
164 // call occurs.
165 bool callback_fired_ = false;
166 #endif // DCHECK_IS_ON()
167 };
168
169 using IDBRequestQueue = Deque<std::unique_ptr<IDBRequestQueueItem>>;
170
171 } // namespace blink
172
173 #endif // IDBRequestQueueItem_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698