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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBValueUnwrapper.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 IDBValueUnwrapper_h
6 #define IDBValueUnwrapper_h
7
8 #include "platform/SharedBuffer.h"
9 #include "platform/wtf/PassRefPtr.h"
10 #include "platform/wtf/RefPtr.h"
11 #include "platform/wtf/Vector.h"
12 #include "public/platform/WebBlobInfo.h"
13
14 namespace WTF {
15 class String;
16 }
17
18 namespace blink {
19
20 class BlobDataHandle;
21 class IDBValue;
22 class SharedBuffer;
23
24 // Logic for unwrapping large IndexedDB values from Blobs.
25 class IDBValueUnwrapper {
26 public:
27 // Wrapper for an IndexedDB value.
28 //
29 // The serialization process can throw an exception. The caller is responsible
30 // for checking exception_state.
31 IDBValueUnwrapper();
32
33 // Checks whether a IDBValue's data was wrapped in a Blob.
34 static bool IsWrapped(IDBValue*);
35
36 // Pieces together an unwrapped IDBValue from a wrapped value and Blob data.
37 static PassRefPtr<IDBValue> CreateUnwrapped(
38 IDBValue* wrapped_value,
39 PassRefPtr<SharedBuffer> unwrapped_data);
40
41 // Parses the wrapper Blob information from a wrapped IDBValue.
42 //
43 // Returns true for success, and false for failure. Failure can mean that the
44 // given value was not a wrapped IDBValue, or that the value bytes were
45 // corrupted.
46 bool Parse(IDBValue*);
47
48 // Returns the size of the Blob obtained by the last Unwrap() call.
49 //
50 // Should only be called after a successful result from Unwrap().
51 inline unsigned WrapperBlobSize() const {
52 DCHECK(data_);
53 return blob_size_;
54 }
55
56 // Returns a handle to the Blob obtained by the last Unwrap() call.
57 //
58 // Should only be called exactly once after a successful result from Unwrap().
59 PassRefPtr<BlobDataHandle> WrapperBlobHandle();
60
61 private:
62 // Used to deserialize the wrapped value.
63 bool ReadVarint(unsigned& value);
64 bool ReadAsciiString(String& value);
65
66 // The data of the SharedBuffer in the IDBValue being unwrapped.
67 const uint8_t* data_;
68
69 // Current deserialization position in data_.
70 unsigned position_;
71
72 // Smallest invalid position_ value.
73 unsigned end_;
74
75 // The size of the Blob holding the data for the last unwrapped IDBValue.
76 unsigned blob_size_;
77
78 // Handle to the Blob holding the data for the last unwrapped IDBValue.
79 RefPtr<BlobDataHandle> blob_handle_;
80 };
81
82 } // namespace blink
83
84 #endif // IDBValueWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698