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