Chromium Code Reviews| 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 #ifndef IDBRequestLoader_h | |
| 6 #define IDBRequestLoader_h | |
| 7 | |
| 8 #include "core/fileapi/FileReaderLoaderClient.h" | |
| 9 #include "platform/wtf/Allocator.h" | |
| 10 #include "platform/wtf/PassRefPtr.h" | |
| 11 #include "platform/wtf/RefPtr.h" | |
| 12 #include "platform/wtf/Vector.h" | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 class FileReaderLoader; | |
| 19 class IDBRequestQueueItem; | |
| 20 class IDBRequest; | |
| 21 class IDBValue; | |
| 22 | |
| 23 // Loads IndexedDB values that have been wrapped in Blobs by IDBValueWrapper. | |
| 24 // | |
| 25 // An IDBRequestLoader unwraps the result of a single IDBRequest. While most | |
| 26 // IndexedDB requests result in a single value, getAll() in IDBObjectStore and | |
| 27 // IDBIndex results in an array of values. In the interest of simplicity, | |
| 28 // IDBRequestLoader only knows how to unwrap an array of values, even though | |
| 29 // most of the time the array will consist of a single element. This design | |
| 30 // assumes that the overhead of creating and destroying a Vector is much smaller | |
| 31 // than the IPC overhead required to load the Blob data into the renderer. | |
| 32 class IDBRequestLoader : public FileReaderLoaderClient { | |
| 33 USING_FAST_MALLOC(IDBRequestLoader); | |
| 34 | |
| 35 public: | |
| 36 // Creates a loader that will unwrap IDBValues received by a IDBRequest. | |
| 37 // | |
| 38 // result_values must be kept alive until the loader calls | |
| 39 // IDBRequestQueueItem::MarkReady(). | |
|
jsbell
2017/05/22 21:54:19
nit: MarkReady was renamed
pwnall
2017/05/25 13:27:11
Done.
| |
| 40 IDBRequestLoader(IDBRequestQueueItem*, | |
| 41 Vector<RefPtr<IDBValue>>* result_values); | |
| 42 | |
| 43 ~IDBRequestLoader() override; | |
| 44 | |
| 45 // Start unwrapping values. | |
| 46 // | |
| 47 // 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.
| |
| 48 // request queue item. | |
| 49 void Start(); | |
| 50 // Halt the process of unwrapping values, if possible. | |
| 51 void Cancel(); | |
| 52 | |
| 53 // FileReaderLoaderClient implementaton. | |
| 54 void DidStartLoading() override; | |
| 55 void DidReceiveDataForClient(const char* data, unsigned data_length) override; | |
| 56 void DidFinishLoading() override; | |
| 57 void DidFail(FileError::ErrorCode) override; | |
| 58 | |
| 59 private: | |
| 60 // Starts unwrapping the next wrapped IDBValue. | |
| 61 // | |
| 62 // 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.
| |
| 63 // callbacks. | |
| 64 void StartNextValue(); | |
| 65 | |
| 66 void ReportSuccess(); | |
| 67 void ReportError(); | |
| 68 | |
| 69 std::unique_ptr<FileReaderLoader> loader_; | |
| 70 | |
| 71 // Transaction result queue item for the IDBRequest. | |
| 72 // | |
| 73 // The IDBRequestQueueItem owns this loader. | |
| 74 IDBRequestQueueItem* queue_item_; | |
| 75 | |
| 76 // All the values that will be passed back to the IDBRequest. | |
| 77 // | |
| 78 // The Vector is owned by the IDBRequestLoader owner, which is currently a | |
| 79 // IDBRequestQueueItem. | |
| 80 Vector<RefPtr<IDBValue>>* const values_; | |
| 81 | |
| 82 // Buffer used to unwrap an IDBValue. | |
| 83 Vector<char> wrapped_data_; | |
| 84 | |
| 85 // The value being currently unwrapped. | |
| 86 Vector<RefPtr<IDBValue>>::iterator current_value_; | |
| 87 }; | |
| 88 | |
| 89 } // namespace blink | |
| 90 | |
| 91 #endif // IDBRequestLoader_h | |
| OLD | NEW |