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

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

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Rebased. Created 3 years, 7 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
2 // Copyright 2017 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "modules/indexeddb/IDBRequestQueueItem.h"
7
8 #include "core/dom/DOMException.h"
9 #include "modules/indexeddb/IDBKey.h"
10 #include "modules/indexeddb/IDBRequest.h"
11 #include "modules/indexeddb/IDBRequestLoader.h"
12 #include "modules/indexeddb/IDBValue.h"
13 #include "platform/wtf/PtrUtil.h"
14 #include "public/platform/modules/indexeddb/WebIDBCursor.h"
15
16 namespace blink {
17
18 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
19 DOMException* error)
20 : request_(request), error_(error), response_type_(kError), ready_(true) {
21 #if DCHECK_IS_ON()
22 DCHECK_EQ(request->queue_item_, nullptr);
23 request_->queue_item_ = this;
24 #endif // DCHECK_IS_ON()
25 }
26
27 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request, int64_t value)
28 : request_(request),
29 int64_value_(value),
30 response_type_(kNumber),
31 ready_(true) {
32 #if DCHECK_IS_ON()
33 DCHECK_EQ(request->queue_item_, nullptr);
34 request_->queue_item_ = this;
35 #endif // DCHECK_IS_ON()
36 }
37
38 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request)
39 : request_(request), response_type_(kVoid), ready_(true) {
40 #if DCHECK_IS_ON()
41 DCHECK_EQ(request->queue_item_, nullptr);
42 request_->queue_item_ = this;
43 #endif // DCHECK_IS_ON()
44 }
45
46 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request, IDBKey* key)
47 : request_(request), key_(key), response_type_(kKey), ready_(true) {
48 #if DCHECK_IS_ON()
49 DCHECK_EQ(request->queue_item_, nullptr);
50 request_->queue_item_ = this;
51 #endif // DCHECK_IS_ON()
52 }
53
54 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
55 PassRefPtr<IDBValue> value,
56 bool attach_loader)
57 : request_(request), response_type_(kValue), ready_(!attach_loader) {
58 #if DCHECK_IS_ON()
59 DCHECK_EQ(request->queue_item_, nullptr);
60 request_->queue_item_ = this;
61 #endif // DCHECK_IS_ON()
62 values_.push_back(std::move(value));
63 if (attach_loader)
64 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
65 }
66
67 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
68 const Vector<RefPtr<IDBValue>>& values,
69 bool attach_loader)
70 : request_(request),
71 values_(values),
72 response_type_(kValueArray),
73 ready_(!attach_loader) {
74 #if DCHECK_IS_ON()
75 DCHECK_EQ(request->queue_item_, nullptr);
76 request_->queue_item_ = this;
77 #endif // DCHECK_IS_ON()
78 if (attach_loader)
79 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
80 }
81
82 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
83 IDBKey* key,
84 IDBKey* primary_key,
85 PassRefPtr<IDBValue> value,
86 bool attach_loader)
87 : request_(request),
88 key_(key),
89 primary_key_(primary_key),
90 response_type_(kKeyPrimaryKeyValue),
91 ready_(!attach_loader) {
92 #if DCHECK_IS_ON()
93 DCHECK_EQ(request->queue_item_, nullptr);
94 request_->queue_item_ = this;
95 #endif // DCHECK_IS_ON()
96 values_.push_back(std::move(value));
97 if (attach_loader)
98 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
99 }
100
101 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
102 std::unique_ptr<WebIDBCursor> cursor,
103 IDBKey* key,
104 IDBKey* primary_key,
105 PassRefPtr<IDBValue> value,
106 bool attach_loader)
107 : request_(request),
108 key_(key),
109 primary_key_(primary_key),
110 cursor_(std::move(cursor)),
111 response_type_(kCursorKeyPrimaryKeyValue),
112 ready_(!attach_loader) {
113 #if DCHECK_IS_ON()
114 DCHECK_EQ(request->queue_item_, nullptr);
115 request_->queue_item_ = this;
116 #endif // DCHECK_IS_ON()
117 values_.push_back(std::move(value));
118 if (attach_loader)
119 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
120 }
121
122 IDBRequestQueueItem::~IDBRequestQueueItem() {
123 #if DCHECK_IS_ON()
124 DCHECK(ready_);
125 DCHECK(callback_fired_);
126 #endif // DCHECK_IS_ON()
127 }
128
129 void IDBRequestQueueItem::OnResultLoadComplete() {
130 DCHECK(!ready_);
131 ready_ = true;
132
133 request_->transaction()->OnResultReady();
dmurph 2017/05/23 18:16:39 This would be calling a callback - so we don't dep
pwnall 2017/05/25 13:27:11 I don't think there's general callback support in
134 }
135
136 void IDBRequestQueueItem::OnResultLoadComplete(DOMException* error) {
137 DCHECK(!ready_);
138 DCHECK(response_type_ != kError);
139
140 response_type_ = kError;
141 error_ = error;
142
143 // This is not necessary, but releases non-trivial amounts of memory early.
144 values_.clear();
145
146 OnResultLoadComplete();
147 }
148
149 void IDBRequestQueueItem::StartLoading() {
150 if (loader_) {
151 DCHECK(!ready_);
152 loader_->Start();
153 }
154 }
155
156 void IDBRequestQueueItem::CancelLoading() {
157 if (loader_ && !ready_) {
158 loader_->Cancel();
159 loader_ = nullptr;
160 }
161 }
162
163 void IDBRequestQueueItem::EnqueueResponse() {
164 #if DCHECK_IS_ON()
165 DCHECK(ready_);
166 DCHECK(!callback_fired_);
167 callback_fired_ = true;
168
169 DCHECK_EQ(request_->queue_item_, this);
170 request_->queue_item_ = nullptr;
171 #endif // DCHECK_IS_ON()
172
173 switch (response_type_) {
174 case kCursorKeyPrimaryKeyValue:
175 DCHECK_EQ(values_.size(), 1U);
176 request_->EnqueueResponse(std::move(cursor_), key_, primary_key_,
177 std::move(values_.front()));
178 break;
179
180 case kError:
181 DCHECK(error_);
182 request_->EnqueueResponse(error_);
183 break;
184
185 case kKeyPrimaryKeyValue:
186 DCHECK_EQ(values_.size(), 1U);
187 request_->EnqueueResponse(key_, primary_key_, std::move(values_.front()));
188 break;
189
190 case kKey:
191 DCHECK_EQ(values_.size(), 0U);
192 request_->EnqueueResponse(key_);
193 break;
194
195 case kNumber:
196 DCHECK_EQ(values_.size(), 0U);
197 request_->EnqueueResponse(int64_value_);
198 break;
199
200 case kValue:
201 DCHECK_EQ(values_.size(), 1U);
202 request_->EnqueueResponse(std::move(values_.front()));
203 break;
204
205 case kValueArray:
206 request_->EnqueueResponse(values_);
207 break;
208
209 case kVoid:
210 DCHECK_EQ(values_.size(), 0U);
211 request_->EnqueueResponse();
212 break;
213 }
214 }
215
216 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698