Chromium Code Reviews| Index: third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h |
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h b/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1c7a62175ddd57d3a4edf456cec5d22d83fd116c |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef IDBRequestLoader_h |
| +#define IDBRequestLoader_h |
| + |
| +#include "core/fileapi/FileReaderLoaderClient.h" |
| +#include "platform/wtf/Allocator.h" |
| +#include "platform/wtf/PassRefPtr.h" |
| +#include "platform/wtf/RefPtr.h" |
| +#include "platform/wtf/Vector.h" |
| + |
| +#include <memory> |
| + |
| +namespace blink { |
| + |
| +class FileReaderLoader; |
| +class IDBRequestQueueItem; |
| +class IDBRequest; |
| +class IDBValue; |
| + |
| +// Loads IndexedDB values that have been wrapped in Blobs by IDBValueWrapper. |
| +// |
| +// An IDBRequestLoader unwraps the result of a single IDBRequest. While most |
| +// IndexedDB requests result in a single value, getAll() in IDBObjectStore and |
| +// IDBIndex results in an array of values. In the interest of simplicity, |
| +// IDBRequestLoader only knows how to unwrap an array of values, even though |
| +// most of the time the array will consist of a single element. This design |
| +// assumes that the overhead of creating and destroying a Vector is much smaller |
| +// than the IPC overhead required to load the Blob data into the renderer. |
| +class IDBRequestLoader : public FileReaderLoaderClient { |
| + USING_FAST_MALLOC(IDBRequestLoader); |
| + |
| + public: |
| + // Creates a loader that will unwrap IDBValues received by a IDBRequest. |
| + // |
| + // result_values must be kept alive until the loader calls |
| + // IDBRequestQueueItem::MarkReady(). |
|
jsbell
2017/05/22 21:54:19
nit: MarkReady was renamed
pwnall
2017/05/25 13:27:11
Done.
|
| + IDBRequestLoader(IDBRequestQueueItem*, |
| + Vector<RefPtr<IDBValue>>* result_values); |
| + |
| + ~IDBRequestLoader() override; |
| + |
| + // Start unwrapping values. |
| + // |
| + // When the unwrapping completes, the loader will call MarkReady() on the |
|
jsbell
2017/05/22 21:54:19
nit: MarkReady was renamed
pwnall
2017/05/25 13:27:11
Done.
|
| + // request queue item. |
| + void Start(); |
| + // Halt the process of unwrapping values, if possible. |
| + void Cancel(); |
| + |
| + // FileReaderLoaderClient implementaton. |
| + void DidStartLoading() override; |
| + void DidReceiveDataForClient(const char* data, unsigned data_length) override; |
| + void DidFinishLoading() override; |
| + void DidFail(FileError::ErrorCode) override; |
| + |
| + private: |
| + // Starts unwrapping the next wrapped IDBValue. |
| + // |
| + // If no more wrapped IDBValues are found, this calls the IDBRequest |
|
jsbell
2017/05/22 21:54:19
nit: only calls the IDBRequest callbacks indirectl
pwnall
2017/05/25 13:27:11
Done.
|
| + // callbacks. |
| + void StartNextValue(); |
| + |
| + void ReportSuccess(); |
| + void ReportError(); |
| + |
| + std::unique_ptr<FileReaderLoader> loader_; |
| + |
| + // Transaction result queue item for the IDBRequest. |
| + // |
| + // The IDBRequestQueueItem owns this loader. |
| + IDBRequestQueueItem* queue_item_; |
| + |
| + // All the values that will be passed back to the IDBRequest. |
| + // |
| + // The Vector is owned by the IDBRequestLoader owner, which is currently a |
| + // IDBRequestQueueItem. |
| + Vector<RefPtr<IDBValue>>* const values_; |
| + |
| + // Buffer used to unwrap an IDBValue. |
| + Vector<char> wrapped_data_; |
| + |
| + // The value being currently unwrapped. |
| + Vector<RefPtr<IDBValue>>::iterator current_value_; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // IDBRequestLoader_h |