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

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: Fixed compilation errors on Windows and no-DCHECKs. Created 3 years, 7 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> wrapper_blob_content);
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(end_);
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 // Resets
67 inline bool Reset() {
68 #if DCHECK_IS_ON()
69 blob_handle_.Clear();
70 current_ = nullptr;
71 end_ = nullptr;
72 #endif // DCHECK_IS_ON()
73 return false;
74 }
75
76 // Deserialization cursor in the SharedBuffer of the IDBValue being unwrapped.
77 const uint8_t* current_;
78
79 // Smallest invalid position_ value.
80 const uint8_t* end_;
81
82 // The size of the Blob holding the data for the last unwrapped IDBValue.
83 unsigned blob_size_;
84
85 // Handle to the Blob holding the data for the last unwrapped IDBValue.
86 RefPtr<BlobDataHandle> blob_handle_;
87 };
88
89 } // namespace blink
90
91 #endif // IDBValueWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698