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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.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 // 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 #include "modules/indexeddb/IDBRequestLoader.h"
6
7 #include "core/dom/DOMException.h"
8 #include "core/fileapi/FileReaderLoader.h"
9 #include "modules/indexeddb/IDBRequest.h"
10 #include "modules/indexeddb/IDBRequestQueueItem.h"
11 #include "modules/indexeddb/IDBValue.h"
12 #include "modules/indexeddb/IDBValueWrapping.h"
13 #include "public/platform/modules/indexeddb/WebIDBDatabaseException.h"
14
15 namespace blink {
16
17 IDBRequestLoader::IDBRequestLoader(IDBRequestQueueItem* queue_item,
18 Vector<RefPtr<IDBValue>>* result_values)
19 : queue_item_(queue_item), values_(result_values) {
20 DCHECK(IDBRequestLoader::NeedUnwrapping(*values_));
21 loader_ = FileReaderLoader::Create(FileReaderLoader::kReadByClient, this);
22 }
23
24 IDBRequestLoader::~IDBRequestLoader() {
25 // TODO(pwnall): Do we need to call loader_->Cancel() here?
26 }
27
28 bool IDBRequestLoader::NeedsUnwrapping(IDBValue* value) {
29 return IDBValueUnwrapper::IsWrapped(value);
30 }
31
32 bool IDBRequestLoader::NeedUnwrapping(const Vector<RefPtr<IDBValue>>& values) {
33 for (const auto& value : values) {
34 if (IDBValueUnwrapper::IsWrapped(value.Get()))
35 return true;
36 }
37 return false;
38 }
39
40 void IDBRequestLoader::Start() {
41 current_value_ = values_->begin();
42 StartNextValue();
43 }
44
45 void IDBRequestLoader::StartNextValue() {
46 IDBValueUnwrapper unwrapper;
47
48 while (true) {
49 if (current_value_ == values_->end()) {
50 ReportSuccess();
51 return;
52 }
53 if (unwrapper.Parse(current_value_->Get()))
54 break;
55 ++current_value_;
56 }
57
58 DCHECK(current_value_ != values_->end());
59
60 ExecutionContext* context = queue_item_->Request()->GetExecutionContext();
61 if (!context) {
62 ReportError();
63 return;
64 }
65
66 wrapped_data_.ReserveCapacity(unwrapper.WrapperBlobSize());
67 loader_->Start(context, unwrapper.WrapperBlobHandle());
68 }
69
70 void IDBRequestLoader::DidStartLoading() {}
71
72 void IDBRequestLoader::DidReceiveDataForClient(const char* data,
73 unsigned data_length) {
74 DCHECK_LE(wrapped_data_.size() + data_length, wrapped_data_.capacity())
75 << "The reader returned more data than we were prepared for";
jsbell 2017/05/15 23:37:38 nit: maybe log expected/actual ?
pwnall 2017/05/19 18:27:34 AFAIK the DCHECK_xx variants log their arguments.
jsbell 2017/05/22 21:54:19 That's fine.
76
77 wrapped_data_.Append(data, data_length);
78 }
79
80 void IDBRequestLoader::DidFinishLoading() {
81 *current_value_ = IDBValueUnwrapper::CreateUnwrapped(
82 current_value_->Get(), SharedBuffer::AdoptVector(wrapped_data_));
83 ++current_value_;
84
85 StartNextValue();
86 }
87
88 void IDBRequestLoader::DidFail(FileError::ErrorCode) {
89 ReportError();
90 }
91
92 void IDBRequestLoader::ReportSuccess() {
93 queue_item_->MarkReady();
94 }
95
96 void IDBRequestLoader::ReportError() {
97 queue_item_->MarkReady(
98 DOMException::Create(kDataError, "Failed to read large IndexedDB value"));
99 }
100
101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698