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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/indexeddb/IDBValueUnwrapper.h
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBValueUnwrapper.h b/third_party/WebKit/Source/modules/indexeddb/IDBValueUnwrapper.h
new file mode 100644
index 0000000000000000000000000000000000000000..707fbe492012a0b1e39d4e82a8090803a823f02d
--- /dev/null
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBValueUnwrapper.h
@@ -0,0 +1,91 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IDBValueUnwrapper_h
+#define IDBValueUnwrapper_h
+
+#include "platform/SharedBuffer.h"
+#include "platform/wtf/PassRefPtr.h"
+#include "platform/wtf/RefPtr.h"
+#include "platform/wtf/Vector.h"
+#include "public/platform/WebBlobInfo.h"
+
+namespace WTF {
+class String;
+}
+
+namespace blink {
+
+class BlobDataHandle;
+class IDBValue;
+class SharedBuffer;
+
+// Logic for unwrapping large IndexedDB values from Blobs.
+class IDBValueUnwrapper {
+ public:
+ // Wrapper for an IndexedDB value.
+ //
+ // The serialization process can throw an exception. The caller is responsible
+ // for checking exception_state.
+ IDBValueUnwrapper();
+
+ // Checks whether a IDBValue's data was wrapped in a Blob.
+ static bool IsWrapped(IDBValue*);
+
+ // Pieces together an unwrapped IDBValue from a wrapped value and Blob data.
+ static PassRefPtr<IDBValue> CreateUnwrapped(
+ IDBValue* wrapped_value,
+ PassRefPtr<SharedBuffer> wrapper_blob_content);
+
+ // Parses the wrapper Blob information from a wrapped IDBValue.
+ //
+ // Returns true for success, and false for failure. Failure can mean that the
+ // given value was not a wrapped IDBValue, or that the value bytes were
+ // corrupted.
+ bool Parse(IDBValue*);
+
+ // Returns the size of the Blob obtained by the last Unwrap() call.
+ //
+ // Should only be called after a successful result from Unwrap().
+ inline unsigned WrapperBlobSize() const {
+ DCHECK(end_);
+ return blob_size_;
+ }
+
+ // Returns a handle to the Blob obtained by the last Unwrap() call.
+ //
+ // Should only be called exactly once after a successful result from Unwrap().
+ PassRefPtr<BlobDataHandle> WrapperBlobHandle();
+
+ private:
+ // Used to deserialize the wrapped value.
+ bool ReadVarint(unsigned& value);
+ bool ReadAsciiString(String& value);
+
+ // Resets
+ inline bool Reset() {
+#if DCHECK_IS_ON()
+ blob_handle_.Clear();
+ current_ = nullptr;
+ end_ = nullptr;
+#endif // DCHECK_IS_ON()
+ return false;
+ }
+
+ // Deserialization cursor in the SharedBuffer of the IDBValue being unwrapped.
+ const uint8_t* current_;
+
+ // Smallest invalid position_ value.
+ const uint8_t* end_;
+
+ // The size of the Blob holding the data for the last unwrapped IDBValue.
+ unsigned blob_size_;
+
+ // Handle to the Blob holding the data for the last unwrapped IDBValue.
+ RefPtr<BlobDataHandle> blob_handle_;
+};
+
+} // namespace blink
+
+#endif // IDBValueWrapper_h

Powered by Google App Engine
This is Rietveld 408576698