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

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: WIP: Getting IDBRequestTest.EventsAfterStopping to pass. 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), mode_(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), int64_value_(value), mode_(kInt64Value), ready_(true) {
29 #if DCHECK_IS_ON()
30 DCHECK_EQ(request->queue_item_, nullptr);
31 request_->queue_item_ = this;
32 #endif // DCHECK_IS_ON()
33 }
34
35 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request)
36 : request_(request), mode_(kNoArguments), ready_(true) {
37 #if DCHECK_IS_ON()
38 DCHECK_EQ(request->queue_item_, nullptr);
39 request_->queue_item_ = this;
40 #endif // DCHECK_IS_ON()
41 }
42
43 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request, IDBKey* key)
44 : request_(request), key_(key), mode_(kKey), ready_(true) {
45 #if DCHECK_IS_ON()
46 DCHECK_EQ(request->queue_item_, nullptr);
47 request_->queue_item_ = this;
48 #endif // DCHECK_IS_ON()
49 }
50
51 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
52 PassRefPtr<IDBValue> value,
53 bool attach_loader)
54 : request_(request), mode_(kValue), ready_(!attach_loader) {
55 #if DCHECK_IS_ON()
56 DCHECK_EQ(request->queue_item_, nullptr);
57 request_->queue_item_ = this;
58 #endif // DCHECK_IS_ON()
59 values_.push_back(std::move(value));
60 if (attach_loader)
jsbell 2017/05/15 23:37:38 Should we DCHECK_EQ(attach_loader, NeedsUnwrapping
pwnall 2017/05/19 18:27:34 The loader DCHECKs that the values given to it nee
61 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
62 }
63
64 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
65 const Vector<RefPtr<IDBValue>>& values,
66 bool attach_loader)
67 : request_(request),
68 values_(values),
69 mode_(kValueArray),
70 ready_(attach_loader) {
71 #if DCHECK_IS_ON()
72 DCHECK_EQ(request->queue_item_, nullptr);
73 request_->queue_item_ = this;
74 #endif // DCHECK_IS_ON()
75 if (attach_loader)
jsbell 2017/05/15 23:37:38 Should we DCHECK_EQ(attach_loader, NeedUnwrapping(
pwnall 2017/05/19 18:27:34 Same as above :)
76 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
77 }
78
79 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
80 IDBKey* key,
81 IDBKey* primary_key,
82 PassRefPtr<IDBValue> value,
83 bool attach_loader)
84 : request_(request),
85 key_(key),
86 primary_key_(primary_key),
87 mode_(kKeyPrimaryKeyValue),
88 ready_(!attach_loader) {
89 #if DCHECK_IS_ON()
90 DCHECK_EQ(request->queue_item_, nullptr);
91 request_->queue_item_ = this;
92 #endif // DCHECK_IS_ON()
93 values_.push_back(std::move(value));
94 if (attach_loader)
95 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
96 }
97
98 IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
99 std::unique_ptr<WebIDBCursor> backend,
100 IDBKey* key,
101 IDBKey* primary_key,
102 PassRefPtr<IDBValue> value,
103 bool attach_loader)
104 : request_(request),
105 key_(key),
106 primary_key_(primary_key),
107 backend_(std::move(backend)),
108 mode_(kBackendKeyPrimaryKeyValue),
109 ready_(!attach_loader) {
110 #if DCHECK_IS_ON()
111 DCHECK_EQ(request->queue_item_, nullptr);
112 request_->queue_item_ = this;
113 #endif // DCHECK_IS_ON()
114 values_.push_back(std::move(value));
115 if (attach_loader)
116 loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
117 }
118
119 IDBRequestQueueItem::~IDBRequestQueueItem() {
120 #if DCHECK_IS_ON()
121 DCHECK(ready_);
122 DCHECK(callback_fired_);
123 #endif // DCHECK_IS_ON()
124 }
125
126 void IDBRequestQueueItem::MarkReady() {
dmurph 2017/05/15 19:32:23 Can we rename this NotifyTransactionResultReady? O
pwnall 2017/05/15 23:15:00 I didn't like this name either, and I left it ther
pwnall 2017/05/19 18:27:34 How about OnResultLoadComplete()?
127 DCHECK(!ready_);
128 ready_ = true;
129
130 request_->transaction()->OnResultReady();
131 }
132
133 void IDBRequestQueueItem::MarkReady(DOMException* error) {
134 DCHECK(!ready_);
135 DCHECK(mode_ != kError);
136
137 mode_ = kError;
138 error_ = error;
139
140 // This is not necessary, but releases non-trivial amounts of memory early.
141 values_.clear();
142
143 MarkReady();
144 }
145
146 void IDBRequestQueueItem::StartLoading() {
147 if (loader_) {
148 DCHECK(!ready_);
149 loader_->Start();
150 }
151 }
152
153 void IDBRequestQueueItem::FireCallback() {
154 #if DCHECK_IS_ON()
155 DCHECK(ready_);
156 DCHECK(!callback_fired_);
157 callback_fired_ = true;
158
159 DCHECK_EQ(request_->queue_item_, this);
160 request_->queue_item_ = nullptr;
161 #endif // DCHECK_IS_ON()
162
163 switch (mode_) {
164 case kError:
165 DCHECK(error_);
166 request_->EnqueueResponse(error_);
167 break;
168
169 case kBackendKeyPrimaryKeyValue:
170 DCHECK_EQ(values_.size(), 1U);
171 request_->EnqueueResponse(std::move(backend_), key_, primary_key_,
172 std::move(values_.front()));
173 break;
174
175 case kInt64Value:
176 DCHECK_EQ(values_.size(), 0U);
177 request_->EnqueueResponse(int64_value_);
178 break;
179
180 case kKeyPrimaryKeyValue:
181 DCHECK_EQ(values_.size(), 1U);
182 request_->EnqueueResponse(key_, primary_key_, std::move(values_.front()));
183 break;
184
185 case kKey:
186 DCHECK_EQ(values_.size(), 0U);
187 request_->EnqueueResponse(key_);
188 break;
189
190 case kNoArguments:
191 DCHECK_EQ(values_.size(), 0U);
192 request_->EnqueueResponse();
193 break;
194
195 case kValue:
196 DCHECK_EQ(values_.size(), 1U);
197 request_->EnqueueResponse(std::move(values_.front()));
198 break;
199
200 case kValueArray:
201 request_->EnqueueResponse(values_);
202 break;
203 }
204 }
205
206 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698