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 IDBValueUnwrapper_h | |
| 6 #define IDBValueUnwrapper_h | |
| 7 | |
| 8 #include "platform/SharedBuffer.h" | |
| 9 #include "platform/wtf/PassRefPtr.h" | |
|
jsbell
2017/05/08 22:08:01
We prefer std::move() of RefPtr now. (Trade off be
pwnall
2017/05/11 23:54:25
Mostly done.
I also removed the PassRefPtr instan
| |
| 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. | |
|
jsbell
2017/05/08 22:08:01
More details?
pwnall
2017/05/11 23:54:25
Done.
I added more details to the top of the class
| |
| 28 // | |
| 29 // The serialization process can throw an exception. The caller is responsible | |
|
jsbell
2017/05/08 22:08:01
Comment doesn't apply to unwrapper
pwnall
2017/05/11 23:54:25
Done.
Thanks for catching!
| |
| 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 | |
|
jsbell
2017/05/08 22:08:01
nit: missing "Un"
pwnall
2017/05/11 23:54:25
Done.
| |
| OLD | NEW |