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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Created 3 years, 8 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 #ifndef IDBRequestLoader_h
6 #define IDBRequestLoader_h
7
8 #include "core/fileapi/FileReaderLoaderClient.h"
9 #include "platform/heap/Handle.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 IDBKey;
20 class IDBRequest;
21 class IDBValue;
22 class WebIDBCursor;
23
24 // Loads IndexedDB values that have been wrapped in Blobs by IDBValueWrapper.
25 class IDBRequestLoader : public GarbageCollectedFinalized<IDBRequestLoader>,
26 public FileReaderLoaderClient {
27 public:
28 // Creates a reader that will unwrap IDBValues received by a IDBRequest.
29 IDBRequestLoader(IDBRequest*);
30
31 ~IDBRequestLoader() override;
32
33 static bool NeedsUnwrapping(IDBValue*);
34 static bool NeedUnwrapping(const Vector<RefPtr<IDBValue>>&);
35
36 // Start unwrapping values.
37 //
38 // Exactly one of these methods should be called for a reader.
39 void Start(PassRefPtr<IDBValue>);
40 void Start(const Vector<RefPtr<IDBValue>>&);
41 void Start(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>);
42 void Start(std::unique_ptr<WebIDBCursor> backend,
43 IDBKey*,
44 IDBKey* primary_key,
45 PassRefPtr<IDBValue>);
46
47 // FileReaderLoaderClient implementaton.
48 void DidStartLoading() override;
49 void DidReceiveDataForClient(const char* data, unsigned data_length) override;
50 void DidFinishLoading() override;
51 void DidFail(FileError::ErrorCode) override;
52
53 DEFINE_INLINE_TRACE() {
54 visitor->Trace(request_);
55 visitor->Trace(key_);
56 visitor->Trace(primary_key_);
57 }
58
59 private:
60 // The IDBRequest callback that will be called by this reader.
61 enum Mode {
62 kUninitialized = 0,
63 kValue,
64 kValueArray,
65 kKeyPrimaryKeyValue,
66 kBackendKeyPrimaryKeyValue,
67 };
68
69 // Starts unwrapping the next wrapped IDBValue.
70 //
71 // If no more wrapped IDBValues are found, this calls the IDBRequest
72 // callbacks.
73 void StartNextValue();
74
75 void ReportSuccess();
76 void ReportError();
77
78 // The IDBRequest callback that will be called by this reader.
79 Mode mode_;
80
81 std::unique_ptr<FileReaderLoader> loader_;
82
83 // The IDBRequest whose IDBValues are unwrapped by this reader.
84 Member<IDBRequest> request_;
85
86 // All the values that will be passed back to the IDBRequest.
87 Vector<RefPtr<IDBValue>> values_;
88
89 // The key argument to the IDBRequest callback.
90 //
91 // Only used if mode_ is kKeyPrimaryKeyValue.
92 Member<IDBKey> key_;
93
94 // The primary_key argument to the IDBRequest callback.
95 //
96 // Only used if mode_ is kKeyPrimaryKeyValue.
97 Member<IDBKey> primary_key_;
98
99 // The backend argument to the IDBRequest callback.
100 std::unique_ptr<WebIDBCursor> backend_;
101
102 // Indexes of the IDBValues in values_ that have been wrapped in Blobs.
103 Vector<unsigned> wrapped_value_indexes_;
104
105 // Buffer used to unwrap an IDBValue.
106 Vector<char> wrapped_data_;
107
108 // The value being currently unwrapped.
109 Vector<RefPtr<IDBValue>>::iterator current_value_;
110 };
111
112 } // namespace blink
113
114 #endif // IDBRequestLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698