| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IDBValueWrapping_h | 5 #ifndef IDBValueWrapping_h |
| 6 #define IDBValueWrapping_h | 6 #define IDBValueWrapping_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/serialization/SerializedScriptValue.h" | 9 #include "bindings/core/v8/serialization/SerializedScriptValue.h" |
| 10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // This method must be called at most once, and must be called after | 104 // This method must be called at most once, and must be called after |
| 105 // WrapIfBiggerThan(). | 105 // WrapIfBiggerThan(). |
| 106 inline Vector<WebBlobInfo>& WrappedBlobInfo() { | 106 inline Vector<WebBlobInfo>& WrappedBlobInfo() { |
| 107 #if DCHECK_IS_ON() | 107 #if DCHECK_IS_ON() |
| 108 DCHECK(!had_exception_) | 108 DCHECK(!had_exception_) |
| 109 << "WrapBlobInfo() called on wrapper with serialization exception"; | 109 << "WrapBlobInfo() called on wrapper with serialization exception"; |
| 110 #endif // DCHECK_IS_ON() | 110 #endif // DCHECK_IS_ON() |
| 111 return blob_info_; | 111 return blob_info_; |
| 112 } | 112 } |
| 113 | 113 |
| 114 size_t DataLengthBeforeWrapInBytes() { return original_data_length_; } |
| 115 |
| 114 // Default threshold for WrapIfBiggerThan(). | 116 // Default threshold for WrapIfBiggerThan(). |
| 115 // | 117 // |
| 116 // This should be tuned to achieve a compromise between short-term IndexedDB | 118 // This should be tuned to achieve a compromise between short-term IndexedDB |
| 117 // throughput and long-term I/O load and memory usage. LevelDB, the underlying | 119 // throughput and long-term I/O load and memory usage. LevelDB, the underlying |
| 118 // storage for IndexedDB, was not designed with large values in mind. At the | 120 // storage for IndexedDB, was not designed with large values in mind. At the |
| 119 // very least, large values will slow down compaction, causing occasional I/O | 121 // very least, large values will slow down compaction, causing occasional I/O |
| 120 // spikes. | 122 // spikes. |
| 121 static constexpr unsigned kWrapThreshold = 64 * 1024; | 123 static constexpr unsigned kWrapThreshold = 64 * 1024; |
| 122 | 124 |
| 123 // MIME type used for Blobs that wrap IDBValues. | 125 // MIME type used for Blobs that wrap IDBValues. |
| 124 static constexpr const char* kWrapMimeType = | 126 static constexpr const char* kWrapMimeType = |
| 125 "application/vnd.blink-idb-value-wrapper"; | 127 "application/vnd.blink-idb-value-wrapper"; |
| 126 | 128 |
| 127 private: | 129 private: |
| 128 // Used to serialize the wrapped value. | 130 // Used to serialize the wrapped value. |
| 129 static void WriteVarint(unsigned value, Vector<char>& output); | 131 static void WriteVarint(unsigned value, Vector<char>& output); |
| 130 | 132 |
| 131 RefPtr<SerializedScriptValue> serialized_value_; | 133 RefPtr<SerializedScriptValue> serialized_value_; |
| 132 RefPtr<BlobDataHandle> wrapper_handle_; | 134 RefPtr<BlobDataHandle> wrapper_handle_; |
| 133 Vector<WebBlobInfo> blob_info_; | 135 Vector<WebBlobInfo> blob_info_; |
| 134 Vector<char> wire_bytes_; | 136 Vector<char> wire_bytes_; |
| 137 size_t original_data_length_ = 0; |
| 135 #if DCHECK_IS_ON() | 138 #if DCHECK_IS_ON() |
| 136 bool had_exception_ = false; | 139 bool had_exception_ = false; |
| 137 bool wrap_called_ = false; | 140 bool wrap_called_ = false; |
| 138 #endif // DCHECK_IS_ON() | 141 #endif // DCHECK_IS_ON() |
| 139 }; | 142 }; |
| 140 | 143 |
| 141 // State and logic for unwrapping large IndexedDB values from Blobs. | 144 // State and logic for unwrapping large IndexedDB values from Blobs. |
| 142 // | 145 // |
| 143 // See IDBValueWrapper for an explanation of the wrapping concept. | 146 // See IDBValueWrapper for an explanation of the wrapping concept. |
| 144 // | 147 // |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // The size of the Blob holding the data for the last unwrapped IDBValue. | 208 // The size of the Blob holding the data for the last unwrapped IDBValue. |
| 206 unsigned blob_size_; | 209 unsigned blob_size_; |
| 207 | 210 |
| 208 // Handle to the Blob holding the data for the last unwrapped IDBValue. | 211 // Handle to the Blob holding the data for the last unwrapped IDBValue. |
| 209 RefPtr<BlobDataHandle> blob_handle_; | 212 RefPtr<BlobDataHandle> blob_handle_; |
| 210 }; | 213 }; |
| 211 | 214 |
| 212 } // namespace blink | 215 } // namespace blink |
| 213 | 216 |
| 214 #endif // IDBValueWrapping_h | 217 #endif // IDBValueWrapping_h |
| OLD | NEW |