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

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBValueWrapper.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/IDBValueWrapper.h
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBValueWrapper.h b/third_party/WebKit/Source/modules/indexeddb/IDBValueWrapper.h
new file mode 100644
index 0000000000000000000000000000000000000000..bff125278e63b9cb766f6c2c97ca5302d1224d88
--- /dev/null
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBValueWrapper.h
@@ -0,0 +1,99 @@
+// 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 IDBValueWrapper_h
+#define IDBValueWrapper_h
+
+#include "bindings/core/v8/ExceptionState.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"
+#include "v8/include/v8.h"
+
+namespace blink {
+
+class Blob;
+class BlobDataHandle;
+class ExceptionState;
+class ScriptState;
+class ScriptValue;
+class SerializedScriptValue;
+class SharedBuffer;
+
+// Logic for wrapping large IndexedDB values in Blobs.
+class IDBValueWrapper {
+ public:
+ // Wrapper for an IndexedDB value.
+ //
+ // The serialization process can throw an exception. The caller is responsible
+ // for checking exception_state.
+ IDBValueWrapper(v8::Isolate*,
+ v8::Local<v8::Value>,
+ bool write_wasm_to_stream,
+ ExceptionState&);
+
+ // Creates a clone of the serialized value.
+ //
+ // This method is necessary because the IndexedDB specification demands that a
+ // value's key and index keys are extracted from a structured clone of the
+ // value.
+ //
+ // This method cannot be called after WrapIfBiggerThan().
+ void Clone(ScriptState*, ScriptValue* clone);
+
+ // Wraps the serialized value into a Blob if it exceeds the given size.
+ //
+ // In production, the threshold is currently always kWrapThreshold.
+ //
+ // This method must be called before ExtractWireBytes() and cannot be called
+ // after ExtractWireBytes().
+ bool WrapIfBiggerThan(unsigned max_bytes);
+
+ void ExtractBlobDataHandles(
+ Vector<RefPtr<BlobDataHandle>>* blob_data_handles);
+
+ PassRefPtr<SharedBuffer> ExtractWireBytes();
+
+ inline Vector<WebBlobInfo>& WrappedBlobInfo() {
+#if DCHECK_IS_ON()
+ DCHECK(!had_exception_)
+ << "WrapBlobInfo() called on wrapper with serialization exception";
+#endif // DCHECK_IS_ON()
+ return blob_info_;
+ }
+
+ // Default threshold for WrapIfBiggerThan().
+ //
+ // This should be tuned to achieve a compromise between short-term IndexedDB
+ // throughput and long-term I/O load and memory usage. LevelDB, the underlying
+ // storage for IndexedDB, was not designed with large values in mind. At the
+ // very least, large values will slow down compaction, causing occasional I/O
+ // spikes.
+ static constexpr unsigned kWrapThreshold = 64 * 1024;
+
+ // MIME type used for Blobs that wrap IDBValues.
+ static constexpr const char* kWrapMimeType =
+ "application/x-blink-idb-value-wrapper";
+
+ private:
+ // Used to serialize the wrapped value.
+ static void WriteVarint(unsigned value, Vector<char>& output);
+ static void WriteAsciiString(const String& value, Vector<char>& output);
+
+ RefPtr<SerializedScriptValue> serialized_value_;
+ RefPtr<BlobDataHandle> wrapper_handle_;
+ Vector<WebBlobInfo> blob_info_;
+ Vector<BlobDataHandle> blob_handles_;
+ Vector<char> wire_bytes_;
+#if DCHECK_IS_ON()
+ bool had_exception_ = false;
+ bool wrap_called_ = false;
+#endif // DCHECK_IS_ON()
+};
+
+} // namespace blink
+
+#endif // IDBValueWrapper_h

Powered by Google App Engine
This is Rietveld 408576698