Commit 990cb0f6 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

IndexedDB: Remove reference-counting from IDBValue.

This reduces the cognitive load of reasoning about IDBValue ownership,
which makes it easier to add complexity to the IndexedDB value wrapping
logic.

Bug: 719007
Change-Id: I3afe209a4d1d58440fce424bd263e4888ebde503
Reviewed-on: https://chromium-review.googlesource.com/828531Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524463}
parent cac6e998
......@@ -59,7 +59,7 @@ static v8::Local<v8::Value> DeserializeIDBValueData(v8::Isolate*,
static v8::Local<v8::Value> DeserializeIDBValueArray(
v8::Isolate*,
v8::Local<v8::Object> creation_context,
const Vector<scoped_refptr<IDBValue>>*);
const Vector<std::unique_ptr<IDBValue>>&);
v8::Local<v8::Value> ToV8(const IDBKeyPath& value,
v8::Local<v8::Object> creation_context,
......@@ -392,7 +392,7 @@ static v8::Local<v8::Value> DeserializeIDBValueData(v8::Isolate* isolate,
scoped_refptr<SerializedScriptValue> serialized_value =
value->CreateSerializedValue();
SerializedScriptValue::DeserializeOptions options;
options.blob_info = value->BlobInfo();
options.blob_info = &value->BlobInfo();
options.read_wasm_from_stream = true;
// deserialize() returns null when serialization fails. This is sub-optimal
......@@ -438,14 +438,14 @@ v8::Local<v8::Value> DeserializeIDBValue(v8::Isolate* isolate,
static v8::Local<v8::Value> DeserializeIDBValueArray(
v8::Isolate* isolate,
v8::Local<v8::Object> creation_context,
const Vector<scoped_refptr<IDBValue>>* values) {
const Vector<std::unique_ptr<IDBValue>>& values) {
DCHECK(isolate->InContext());
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Array> array = v8::Array::New(isolate, values->size());
for (size_t i = 0; i < values->size(); ++i) {
v8::Local<v8::Array> array = v8::Array::New(isolate, values.size());
for (size_t i = 0; i < values.size(); ++i) {
v8::Local<v8::Value> v8_value =
DeserializeIDBValue(isolate, creation_context, values->at(i).get());
DeserializeIDBValue(isolate, creation_context, values[i].get());
if (v8_value.IsEmpty())
v8_value = v8::Undefined(isolate);
if (!V8CallBoolean(array->CreateDataProperty(context, i, v8_value)))
......
......@@ -174,10 +174,10 @@ void SerializeV8Value(v8::Local<v8::Value> value,
// wire_data[kSSVHeaderV8VersionOffset]);
}
scoped_refptr<IDBValue> CreateIDBValue(v8::Isolate* isolate,
Vector<char>& wire_bytes,
double primary_key,
const WebString& key_path) {
std::unique_ptr<IDBValue> CreateIDBValue(v8::Isolate* isolate,
Vector<char>& wire_bytes,
double primary_key,
const WebString& key_path) {
WebData web_data(SharedBuffer::AdoptVector(wire_bytes));
Vector<WebBlobInfo> web_blob_info;
WebIDBKey web_idb_key = WebIDBKey::CreateNumber(primary_key);
......@@ -317,7 +317,7 @@ TEST(DeserializeIDBValueTest, CurrentVersions) {
Vector<char> object_bytes;
v8::Local<v8::Object> empty_object = v8::Object::New(isolate);
SerializeV8Value(empty_object, isolate, &object_bytes);
scoped_refptr<IDBValue> idb_value =
std::unique_ptr<IDBValue> idb_value =
CreateIDBValue(isolate, object_bytes, 42.0, "foo");
v8::Local<v8::Value> v8_value = DeserializeIDBValue(
......@@ -349,7 +349,7 @@ TEST(DeserializeIDBValueTest, FutureV8Version) {
// the serialized value uses a newer format version.
//
// http://crbug.com/703704 has a reproduction for this test's circumstances.
scoped_refptr<IDBValue> idb_value =
std::unique_ptr<IDBValue> idb_value =
CreateIDBValue(isolate, object_bytes, 42.0, "foo");
v8::Local<v8::Value> v8_value = DeserializeIDBValue(
......@@ -367,7 +367,7 @@ TEST(DeserializeIDBValueTest, InjectionIntoNonObject) {
Vector<char> object_bytes;
v8::Local<v8::Number> number = v8::Number::New(isolate, 42.0);
SerializeV8Value(number, isolate, &object_bytes);
scoped_refptr<IDBValue> idb_value =
std::unique_ptr<IDBValue> idb_value =
CreateIDBValue(isolate, object_bytes, 42.0, "foo");
v8::Local<v8::Value> v8_value = DeserializeIDBValue(
......@@ -387,7 +387,7 @@ TEST(DeserializeIDBValueTest, NestedInjectionIntoNonObject) {
Vector<char> object_bytes;
v8::Local<v8::Number> number = v8::Number::New(isolate, 42.0);
SerializeV8Value(number, isolate, &object_bytes);
scoped_refptr<IDBValue> idb_value =
std::unique_ptr<IDBValue> idb_value =
CreateIDBValue(isolate, object_bytes, 42.0, "foo.bar");
v8::Local<v8::Value> v8_value = DeserializeIDBValue(
......
......@@ -25,7 +25,8 @@
#include "modules/indexeddb/IDBAny.h"
#include "base/memory/scoped_refptr.h"
#include <memory>
#include "core/dom/DOMStringList.h"
#include "modules/indexeddb/IDBCursorWithValue.h"
#include "modules/indexeddb/IDBDatabase.h"
......@@ -96,9 +97,9 @@ IDBValue* IDBAny::Value() const {
return idb_value_.get();
}
const Vector<scoped_refptr<IDBValue>>* IDBAny::Values() const {
const Vector<std::unique_ptr<IDBValue>>& IDBAny::Values() const {
DCHECK_EQ(type_, kIDBValueArrayType);
return &idb_values_;
return idb_values_;
}
int64_t IDBAny::Integer() const {
......@@ -122,10 +123,10 @@ IDBAny::IDBAny(IDBIndex* value) : type_(kIDBIndexType), idb_index_(value) {}
IDBAny::IDBAny(IDBObjectStore* value)
: type_(kIDBObjectStoreType), idb_object_store_(value) {}
IDBAny::IDBAny(const Vector<scoped_refptr<IDBValue>>& values)
: type_(kIDBValueArrayType), idb_values_(values) {}
IDBAny::IDBAny(Vector<std::unique_ptr<IDBValue>> values)
: type_(kIDBValueArrayType), idb_values_(std::move(values)) {}
IDBAny::IDBAny(scoped_refptr<IDBValue> value)
IDBAny::IDBAny(std::unique_ptr<IDBValue> value)
: type_(kIDBValueType), idb_value_(std::move(value)) {}
IDBAny::IDBAny(IDBKey* key) : type_(kKeyType), idb_key_(key) {}
......
......@@ -26,7 +26,8 @@
#ifndef IDBAny_h
#define IDBAny_h
#include "base/memory/scoped_refptr.h"
#include <memory>
#include "core/dom/DOMStringList.h"
#include "modules/ModulesExport.h"
#include "modules/indexeddb/IDBKey.h"
......@@ -64,11 +65,11 @@ class MODULES_EXPORT IDBAny : public GarbageCollectedFinalized<IDBAny> {
return new IDBAny(dom_string_list);
}
static IDBAny* Create(int64_t value) { return new IDBAny(value); }
static IDBAny* Create(scoped_refptr<IDBValue> value) {
static IDBAny* Create(std::unique_ptr<IDBValue> value) {
return new IDBAny(std::move(value));
}
static IDBAny* Create(const Vector<scoped_refptr<IDBValue>>& values) {
return new IDBAny(values);
static IDBAny* Create(Vector<std::unique_ptr<IDBValue>> values) {
return new IDBAny(std::move(values));
}
~IDBAny();
void Trace(blink::Visitor*);
......@@ -98,7 +99,7 @@ class MODULES_EXPORT IDBAny : public GarbageCollectedFinalized<IDBAny> {
IDBIndex* IdbIndex() const;
IDBObjectStore* IdbObjectStore() const;
IDBValue* Value() const;
const Vector<scoped_refptr<IDBValue>>* Values() const;
const Vector<std::unique_ptr<IDBValue>>& Values() const;
int64_t Integer() const;
const IDBKey* Key() const;
......@@ -110,8 +111,8 @@ class MODULES_EXPORT IDBAny : public GarbageCollectedFinalized<IDBAny> {
explicit IDBAny(IDBIndex*);
explicit IDBAny(IDBObjectStore*);
explicit IDBAny(IDBKey*);
explicit IDBAny(const Vector<scoped_refptr<IDBValue>>&);
explicit IDBAny(scoped_refptr<IDBValue>);
explicit IDBAny(Vector<std::unique_ptr<IDBValue>>);
explicit IDBAny(std::unique_ptr<IDBValue>);
explicit IDBAny(int64_t);
const Type type_;
......@@ -123,8 +124,8 @@ class MODULES_EXPORT IDBAny : public GarbageCollectedFinalized<IDBAny> {
const Member<IDBIndex> idb_index_;
const Member<IDBObjectStore> idb_object_store_;
const Member<IDBKey> idb_key_;
const scoped_refptr<IDBValue> idb_value_;
const Vector<scoped_refptr<IDBValue>> idb_values_;
const std::unique_ptr<IDBValue> idb_value_;
const Vector<std::unique_ptr<IDBValue>> idb_values_;
const int64_t integer_ = 0;
};
......
......@@ -82,6 +82,7 @@ void IDBCursor::Trace(blink::Visitor* visitor) {
visitor->Trace(transaction_);
visitor->Trace(key_);
visitor->Trace(primary_key_);
visitor->Trace(value_);
ScriptWrappable::Trace(visitor);
}
......@@ -383,20 +384,20 @@ ScriptValue IDBCursor::primaryKey(ScriptState* script_state) {
ScriptValue IDBCursor::value(ScriptState* script_state) {
DCHECK(IsCursorWithValue());
IDBObjectStore* object_store = EffectiveObjectStore();
IDBAny* value;
if (!value_) {
value = IDBAny::CreateUndefined();
} else if (object_store->autoIncrement() &&
!object_store->IdbKeyPath().IsNull()) {
scoped_refptr<IDBValue> idb_value = IDBValue::Create(
value_.get(), primary_key_, object_store->IdbKeyPath());
if (value_) {
value = value_;
#if DCHECK_IS_ON()
AssertPrimaryKeyValidOrInjectable(script_state, idb_value.get());
if (value_has_injected_primary_key_) {
IDBObjectStore* object_store = EffectiveObjectStore();
DCHECK(object_store->autoIncrement() &&
!object_store->IdbKeyPath().IsNull());
AssertPrimaryKeyValidOrInjectable(script_state, value_->Value());
}
#endif // DCHECK_IS_ON()
value = IDBAny::Create(std::move(idb_value));
} else {
value = IDBAny::Create(value_);
value = IDBAny::CreateUndefined();
}
value_dirty_ = false;
......@@ -410,19 +411,40 @@ ScriptValue IDBCursor::source(ScriptState* script_state) const {
void IDBCursor::SetValueReady(IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue> value) {
std::unique_ptr<IDBValue> value) {
key_ = key;
key_dirty_ = true;
primary_key_ = primary_key;
primary_key_dirty_ = true;
if (IsCursorWithValue()) {
value_ = std::move(value);
value_dirty_ = true;
got_value_ = true;
if (!IsCursorWithValue())
return;
value_dirty_ = true;
#if DCHECK_IS_ON()
value_has_injected_primary_key_ = false;
#endif // DCHECK_IS_ON()
if (!value) {
value_ = nullptr;
return;
}
got_value_ = true;
IDBObjectStore* object_store = EffectiveObjectStore();
if (!object_store->autoIncrement() || object_store->IdbKeyPath().IsNull()) {
value_ = IDBAny::Create(std::move(value));
return;
}
#if DCHECK_IS_ON()
value_has_injected_primary_key_ = true;
#endif // DCHECK_IS_ON()
std::unique_ptr<IDBValue> value_with_injected_primary_key = IDBValue::Create(
std::move(value), primary_key_, object_store->IdbKeyPath());
value_ = IDBAny::Create(std::move(value_with_injected_primary_key));
}
IDBObjectStore* IDBCursor::EffectiveObjectStore() const {
......
......@@ -92,7 +92,7 @@ class IDBCursor : public ScriptWrappable {
void PostSuccessHandlerCallback();
bool IsDeleted() const;
void Close();
void SetValueReady(IDBKey*, IDBKey* primary_key, scoped_refptr<IDBValue>);
void SetValueReady(IDBKey*, IDBKey* primary_key, std::unique_ptr<IDBValue>);
IDBKey* IdbPrimaryKey() const { return primary_key_; }
virtual bool IsKeyCursor() const { return true; }
virtual bool IsCursorWithValue() const { return false; }
......@@ -118,7 +118,11 @@ class IDBCursor : public ScriptWrappable {
bool value_dirty_ = true;
Member<IDBKey> key_;
Member<IDBKey> primary_key_;
scoped_refptr<IDBValue> value_;
Member<IDBAny> value_;
#if DCHECK_IS_ON()
bool value_has_injected_primary_key_ = false;
#endif // DCHECK_IS_ON()
};
} // namespace blink
......
......@@ -28,11 +28,7 @@ ScriptValue IDBObservation::key(ScriptState* script_state) {
}
ScriptValue IDBObservation::value(ScriptState* script_state) {
if (!value_)
return ScriptValue::From(script_state,
v8::Undefined(script_state->GetIsolate()));
return ScriptValue::From(script_state, IDBAny::Create(value_));
return ScriptValue::From(script_state, value_);
}
WebIDBOperationType IDBObservation::StringToOperationType(const String& type) {
......@@ -77,11 +73,12 @@ IDBObservation* IDBObservation::Create(const WebIDBObservation& observation,
IDBObservation::IDBObservation(const WebIDBObservation& observation,
v8::Isolate* isolate)
: key_range_(observation.key_range),
value_(IDBValue::Create(observation.value, isolate)),
value_(IDBAny::Create(IDBValue::Create(observation.value, isolate))),
operation_type_(observation.type) {}
void IDBObservation::Trace(blink::Visitor* visitor) {
visitor->Trace(key_range_);
visitor->Trace(value_);
ScriptWrappable::Trace(visitor);
}
......
......@@ -5,7 +5,8 @@
#ifndef IDBObservation_h
#define IDBObservation_h
#include "base/memory/scoped_refptr.h"
#include <memory>
#include "bindings/core/v8/ScriptValue.h"
#include "platform/bindings/ScriptWrappable.h"
#include "platform/heap/Handle.h"
......@@ -13,8 +14,8 @@
namespace blink {
class IDBAny;
class IDBKeyRange;
class IDBValue;
class ScriptState;
struct WebIDBObservation;
......@@ -36,7 +37,7 @@ class IDBObservation final : public ScriptWrappable {
private:
IDBObservation(const WebIDBObservation&, v8::Isolate*);
Member<IDBKeyRange> key_range_;
scoped_refptr<IDBValue> value_;
Member<IDBAny> value_;
const WebIDBOperationType operation_type_;
};
......
......@@ -254,7 +254,7 @@ IDBCursor* IDBRequest::GetResultCursor() const {
void IDBRequest::SetResultCursor(IDBCursor* cursor,
IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue>&& value) {
std::unique_ptr<IDBValue> value) {
DCHECK_EQ(ready_state_, PENDING);
cursor_key_ = key;
cursor_primary_key_ = primary_key;
......@@ -263,18 +263,18 @@ void IDBRequest::SetResultCursor(IDBCursor* cursor,
EnqueueResultInternal(IDBAny::Create(cursor));
}
void IDBRequest::AckReceivedBlobs(const IDBValue* value) {
void IDBRequest::AckReceivedBlobs(const IDBValue& value) {
if (!transaction_ || !transaction_->BackendDB())
return;
Vector<String> uuids = value->GetUUIDs();
Vector<String> uuids = value.GetUUIDs();
if (!uuids.IsEmpty())
transaction_->BackendDB()->AckReceivedBlobs(uuids);
}
void IDBRequest::AckReceivedBlobs(
const Vector<scoped_refptr<IDBValue>>& values) {
const Vector<std::unique_ptr<IDBValue>>& values) {
for (size_t i = 0; i < values.size(); ++i)
AckReceivedBlobs(values[i].get());
AckReceivedBlobs(*values[i]);
}
bool IDBRequest::ShouldEnqueueEvent() const {
......@@ -344,10 +344,10 @@ void IDBRequest::HandleResponse() {
void IDBRequest::HandleResponse(std::unique_ptr<WebIDBCursor> backend,
IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue>&& value) {
std::unique_ptr<IDBValue> value) {
DCHECK(transit_blob_handles_.IsEmpty());
DCHECK(transaction_);
AckReceivedBlobs(value.get());
AckReceivedBlobs(*value);
bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.get());
if (!transaction_->HasQueuedResults() && !is_wrapped) {
return EnqueueResponse(std::move(backend), key, primary_key,
......@@ -359,10 +359,10 @@ void IDBRequest::HandleResponse(std::unique_ptr<WebIDBCursor> backend,
WrapPersistent(transaction_.Get()))));
}
void IDBRequest::HandleResponse(scoped_refptr<IDBValue>&& value) {
void IDBRequest::HandleResponse(std::unique_ptr<IDBValue> value) {
DCHECK(transit_blob_handles_.IsEmpty());
DCHECK(transaction_);
AckReceivedBlobs(value.get());
AckReceivedBlobs(*value);
bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.get());
if (!transaction_->HasQueuedResults() && !is_wrapped)
return EnqueueResponse(std::move(value));
......@@ -372,25 +372,25 @@ void IDBRequest::HandleResponse(scoped_refptr<IDBValue>&& value) {
WrapPersistent(transaction_.Get()))));
}
void IDBRequest::HandleResponse(const Vector<scoped_refptr<IDBValue>>& values) {
void IDBRequest::HandleResponse(Vector<std::unique_ptr<IDBValue>> values) {
DCHECK(transit_blob_handles_.IsEmpty());
DCHECK(transaction_);
AckReceivedBlobs(values);
bool is_wrapped = IDBValueUnwrapper::IsWrapped(values);
if (!transaction_->HasQueuedResults() && !is_wrapped)
return EnqueueResponse(values);
return EnqueueResponse(std::move(values));
transaction_->EnqueueResult(std::make_unique<IDBRequestQueueItem>(
this, values, is_wrapped,
this, std::move(values), is_wrapped,
WTF::Bind(&IDBTransaction::OnResultReady,
WrapPersistent(transaction_.Get()))));
}
void IDBRequest::HandleResponse(IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue>&& value) {
std::unique_ptr<IDBValue> value) {
DCHECK(transit_blob_handles_.IsEmpty());
DCHECK(transaction_);
AckReceivedBlobs(value.get());
AckReceivedBlobs(*value);
bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.get());
if (!transaction_->HasQueuedResults() && !is_wrapped)
return EnqueueResponse(key, primary_key, std::move(value));
......@@ -432,7 +432,7 @@ void IDBRequest::EnqueueResponse(const Vector<String>& string_list) {
void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend,
IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue>&& value) {
std::unique_ptr<IDBValue> value) {
IDB_TRACE1("IDBRequest::EnqueueResponse(IDBCursor)", "size",
value ? value->DataSize() : 0);
if (!ShouldEnqueueEvent()) {
......@@ -474,7 +474,7 @@ void IDBRequest::EnqueueResponse(IDBKey* idb_key) {
}
namespace {
size_t SizeOfValues(const Vector<scoped_refptr<IDBValue>>& values) {
size_t SizeOfValues(const Vector<std::unique_ptr<IDBValue>>& values) {
size_t size = 0;
for (const auto& value : values)
size += value->DataSize();
......@@ -482,8 +482,7 @@ size_t SizeOfValues(const Vector<scoped_refptr<IDBValue>>& values) {
}
} // namespace
void IDBRequest::EnqueueResponse(
const Vector<scoped_refptr<IDBValue>>& values) {
void IDBRequest::EnqueueResponse(Vector<std::unique_ptr<IDBValue>> values) {
IDB_TRACE1("IDBRequest::EnqueueResponse([IDBValue])", "size",
SizeOfValues(values));
if (!ShouldEnqueueEvent()) {
......@@ -491,7 +490,7 @@ void IDBRequest::EnqueueResponse(
return;
}
EnqueueResultInternal(IDBAny::Create(values));
EnqueueResultInternal(IDBAny::Create(std::move(values)));
metrics_.RecordAndReset();
}
......@@ -507,7 +506,7 @@ static IDBObjectStore* EffectiveObjectStore(IDBAny* source) {
}
#endif // DCHECK_IS_ON()
void IDBRequest::EnqueueResponse(scoped_refptr<IDBValue>&& value) {
void IDBRequest::EnqueueResponse(std::unique_ptr<IDBValue> value) {
IDB_TRACE1("IDBRequest::EnqueueResponse(IDBValue)", "size",
value ? value->DataSize() : 0);
if (!ShouldEnqueueEvent()) {
......@@ -518,7 +517,7 @@ void IDBRequest::EnqueueResponse(scoped_refptr<IDBValue>&& value) {
if (pending_cursor_) {
// Value should be null, signifying the end of the cursor's range.
DCHECK(value->IsNull());
DCHECK(!value->BlobInfo()->size());
DCHECK(!value->BlobInfo().size());
pending_cursor_->Close();
pending_cursor_.Clear();
}
......@@ -567,7 +566,7 @@ void IDBRequest::SetResult(IDBAny* result) {
void IDBRequest::EnqueueResponse(IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue>&& value) {
std::unique_ptr<IDBValue> value) {
IDB_TRACE("IDBRequest::EnqueueResponse(IDBKey, IDBKey primaryKey, IDBValue)");
if (!ShouldEnqueueEvent()) {
metrics_.RecordAndReset();
......
......@@ -242,10 +242,10 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData,
void HandleResponse(std::unique_ptr<WebIDBCursor>,
IDBKey*,
IDBKey* primary_key,
scoped_refptr<IDBValue>&&);
void HandleResponse(IDBKey*, IDBKey* primary_key, scoped_refptr<IDBValue>&&);
void HandleResponse(scoped_refptr<IDBValue>&&);
void HandleResponse(const Vector<scoped_refptr<IDBValue>>&);
std::unique_ptr<IDBValue>);
void HandleResponse(IDBKey*, IDBKey* primary_key, std::unique_ptr<IDBValue>);
void HandleResponse(std::unique_ptr<IDBValue>);
void HandleResponse(Vector<std::unique_ptr<IDBValue>>);
void HandleResponse(int64_t);
void HandleResponse();
......@@ -349,19 +349,19 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData,
void SetResultCursor(IDBCursor*,
IDBKey*,
IDBKey* primary_key,
scoped_refptr<IDBValue>&&);
void AckReceivedBlobs(const IDBValue*);
void AckReceivedBlobs(const Vector<scoped_refptr<IDBValue>>&);
std::unique_ptr<IDBValue>);
void AckReceivedBlobs(const IDBValue&);
void AckReceivedBlobs(const Vector<std::unique_ptr<IDBValue>>&);
void EnqueueResponse(DOMException*);
void EnqueueResponse(IDBKey*);
void EnqueueResponse(std::unique_ptr<WebIDBCursor>,
IDBKey*,
IDBKey* primary_key,
scoped_refptr<IDBValue>&&);
void EnqueueResponse(IDBKey*, IDBKey* primary_key, scoped_refptr<IDBValue>&&);
void EnqueueResponse(scoped_refptr<IDBValue>&&);
void EnqueueResponse(const Vector<scoped_refptr<IDBValue>>&);
std::unique_ptr<IDBValue>);
void EnqueueResponse(IDBKey*, IDBKey* primary_key, std::unique_ptr<IDBValue>);
void EnqueueResponse(std::unique_ptr<IDBValue>);
void EnqueueResponse(Vector<std::unique_ptr<IDBValue>>);
void EnqueueResponse();
void ClearPutOperationBlobs() { transit_blob_handles_.clear(); }
......@@ -383,7 +383,7 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData,
// dispatched.
Member<IDBKey> cursor_key_;
Member<IDBKey> cursor_primary_key_;
scoped_refptr<IDBValue> cursor_value_;
std::unique_ptr<IDBValue> cursor_value_;
Vector<scoped_refptr<BlobDataHandle>> transit_blob_handles_;
......
......@@ -16,9 +16,9 @@ namespace blink {
IDBRequestLoader::IDBRequestLoader(
IDBRequestQueueItem* queue_item,
Vector<scoped_refptr<IDBValue>>* result_values)
Vector<std::unique_ptr<IDBValue>>& result_values)
: queue_item_(queue_item), values_(result_values) {
DCHECK(IDBValueUnwrapper::IsWrapped(*values_));
DCHECK(IDBValueUnwrapper::IsWrapped(values_));
}
IDBRequestLoader::~IDBRequestLoader() {
......@@ -35,7 +35,7 @@ void IDBRequestLoader::Start() {
// Consider parallelizing. The main issue is that the Blob reads
// will have to be throttled somewhere, and the extra complexity
// only benefits applications that use getAll().
current_value_ = values_->begin();
current_value_ = values_.begin();
StartNextValue();
}
......@@ -56,7 +56,7 @@ void IDBRequestLoader::StartNextValue() {
IDBValueUnwrapper unwrapper;
while (true) {
if (current_value_ == values_->end()) {
if (current_value_ == values_.end()) {
ReportSuccess();
return;
}
......@@ -65,7 +65,7 @@ void IDBRequestLoader::StartNextValue() {
++current_value_;
}
DCHECK(current_value_ != values_->end());
DCHECK(current_value_ != values_.end());
ExecutionContext* context = queue_item_->Request()->GetExecutionContext();
if (!context) {
......@@ -104,7 +104,7 @@ void IDBRequestLoader::DidFinishLoading() {
#endif // DCHECK_IS_ON()
*current_value_ = IDBValueUnwrapper::Unwrap(
current_value_->get(), SharedBuffer::AdoptVector(wrapped_data_));
std::move(*current_value_), SharedBuffer::AdoptVector(wrapped_data_));
++current_value_;
StartNextValue();
......
......@@ -7,7 +7,6 @@
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "core/fileapi/FileReaderLoaderClient.h"
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Vector.h"
......@@ -37,7 +36,7 @@ class IDBRequestLoader : public FileReaderLoaderClient {
// result_values must be kept alive until the loader calls
// IDBRequestQueueItem::OnResultLoadComplete().
IDBRequestLoader(IDBRequestQueueItem*,
Vector<scoped_refptr<IDBValue>>* result_values);
Vector<std::unique_ptr<IDBValue>>& result_values);
~IDBRequestLoader() override;
......@@ -76,13 +75,13 @@ class IDBRequestLoader : public FileReaderLoaderClient {
//
// The Vector is owned by the IDBRequestLoader owner, which is currently a
// IDBRequestQueueItem.
Vector<scoped_refptr<IDBValue>>* const values_;
Vector<std::unique_ptr<IDBValue>>& values_;
// Buffer used to unwrap an IDBValue.
Vector<char> wrapped_data_;
// The value being currently unwrapped.
Vector<scoped_refptr<IDBValue>>::iterator current_value_;
Vector<std::unique_ptr<IDBValue>>::iterator current_value_;
#if DCHECK_IS_ON()
// True after Start() is called.
......
......@@ -73,7 +73,7 @@ IDBRequestQueueItem::IDBRequestQueueItem(
IDBRequestQueueItem::IDBRequestQueueItem(
IDBRequest* request,
scoped_refptr<IDBValue> value,
std::unique_ptr<IDBValue> value,
bool attach_loader,
base::OnceClosure on_result_load_complete)
: request_(request),
......@@ -85,16 +85,16 @@ IDBRequestQueueItem::IDBRequestQueueItem(
request_->queue_item_ = this;
values_.push_back(std::move(value));
if (attach_loader)
loader_ = std::make_unique<IDBRequestLoader>(this, &values_);
loader_ = std::make_unique<IDBRequestLoader>(this, values_);
}
IDBRequestQueueItem::IDBRequestQueueItem(
IDBRequest* request,
const Vector<scoped_refptr<IDBValue>>& values,
Vector<std::unique_ptr<IDBValue>> values,
bool attach_loader,
base::OnceClosure on_result_load_complete)
: request_(request),
values_(values),
values_(std::move(values)),
on_result_load_complete_(std::move(on_result_load_complete)),
response_type_(kValueArray),
ready_(!attach_loader) {
......@@ -102,14 +102,14 @@ IDBRequestQueueItem::IDBRequestQueueItem(
DCHECK_EQ(request->queue_item_, nullptr);
request_->queue_item_ = this;
if (attach_loader)
loader_ = std::make_unique<IDBRequestLoader>(this, &values_);
loader_ = std::make_unique<IDBRequestLoader>(this, values_);
}
IDBRequestQueueItem::IDBRequestQueueItem(
IDBRequest* request,
IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue> value,
std::unique_ptr<IDBValue> value,
bool attach_loader,
base::OnceClosure on_result_load_complete)
: request_(request),
......@@ -123,7 +123,7 @@ IDBRequestQueueItem::IDBRequestQueueItem(
request_->queue_item_ = this;
values_.push_back(std::move(value));
if (attach_loader)
loader_ = std::make_unique<IDBRequestLoader>(this, &values_);
loader_ = std::make_unique<IDBRequestLoader>(this, values_);
}
IDBRequestQueueItem::IDBRequestQueueItem(
......@@ -131,7 +131,7 @@ IDBRequestQueueItem::IDBRequestQueueItem(
std::unique_ptr<WebIDBCursor> cursor,
IDBKey* key,
IDBKey* primary_key,
scoped_refptr<IDBValue> value,
std::unique_ptr<IDBValue> value,
bool attach_loader,
base::OnceClosure on_result_load_complete)
: request_(request),
......@@ -146,7 +146,7 @@ IDBRequestQueueItem::IDBRequestQueueItem(
request_->queue_item_ = this;
values_.push_back(std::move(value));
if (attach_loader)
loader_ = std::make_unique<IDBRequestLoader>(this, &values_);
loader_ = std::make_unique<IDBRequestLoader>(this, values_);
}
IDBRequestQueueItem::~IDBRequestQueueItem() {
......@@ -264,7 +264,7 @@ void IDBRequestQueueItem::EnqueueResponse() {
break;
case kValueArray:
request_->EnqueueResponse(values_);
request_->EnqueueResponse(std::move(values_));
break;
case kVoid:
......
......@@ -7,7 +7,6 @@
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Vector.h"
......@@ -57,24 +56,24 @@ class IDBRequestQueueItem {
IDBKey*,
base::OnceClosure on_result_load_complete);
IDBRequestQueueItem(IDBRequest*,
scoped_refptr<IDBValue>,
std::unique_ptr<IDBValue>,
bool attach_loader,
base::OnceClosure on_load_complete);
IDBRequestQueueItem(IDBRequest*,
const Vector<scoped_refptr<IDBValue>>&,
Vector<std::unique_ptr<IDBValue>>,
bool attach_loader,
base::OnceClosure on_result_load_complete);
IDBRequestQueueItem(IDBRequest*,
IDBKey*,
IDBKey* primary_key,
scoped_refptr<IDBValue>,
std::unique_ptr<IDBValue>,
bool attach_loader,
base::OnceClosure on_result_load_complete);
IDBRequestQueueItem(IDBRequest*,
std::unique_ptr<WebIDBCursor>,
IDBKey*,
IDBKey* primary_key,
scoped_refptr<IDBValue>,
std::unique_ptr<IDBValue>,
bool attach_loader,
base::OnceClosure on_result_load_complete);
~IDBRequestQueueItem();
......@@ -143,7 +142,7 @@ class IDBRequestQueueItem {
Persistent<DOMException> error_;
// All the values that will be passed back to the IDBRequest.
Vector<scoped_refptr<IDBValue>> values_;
Vector<std::unique_ptr<IDBValue>> values_;
// The cursor argument to the IDBRequest callback.
std::unique_ptr<WebIDBCursor> cursor_;
......
......@@ -17,8 +17,8 @@
namespace blink {
scoped_refptr<IDBValue> CreateIDBValueForTesting(v8::Isolate* isolate,
bool create_wrapped_value) {
std::unique_ptr<IDBValue> CreateIDBValueForTesting(v8::Isolate* isolate,
bool create_wrapped_value) {
size_t element_count = create_wrapped_value ? 16 : 2;
v8::Local<v8::Array> v8_array = v8::Array::New(isolate, element_count);
for (size_t i = 0; i < element_count; ++i)
......@@ -38,11 +38,9 @@ scoped_refptr<IDBValue> CreateIDBValueForTesting(v8::Isolate* isolate,
IDBKey* key = IDBKey::CreateNumber(42.0);
IDBKeyPath key_path(String("primaryKey"));
scoped_refptr<IDBValue> idb_value = IDBValue::Create(
std::move(wrapped_marker_buffer),
std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>(
blob_data_handles),
std::make_unique<Vector<WebBlobInfo>>(blob_infos), key, key_path);
std::unique_ptr<IDBValue> idb_value = IDBValue::Create(
std::move(wrapped_marker_buffer), std::move(blob_data_handles),
std::move(blob_infos), key, key_path);
DCHECK_EQ(create_wrapped_value,
IDBValueUnwrapper::IsWrapped(idb_value.get()));
......
......@@ -13,8 +13,8 @@ namespace blink {
// The created value is an array of true. If create_wrapped_value is true, the
// IDBValue's byte array will be wrapped in a Blob, otherwise it will not be.
scoped_refptr<IDBValue> CreateIDBValueForTesting(v8::Isolate*,
bool create_wrapped_value);
std::unique_ptr<IDBValue> CreateIDBValueForTesting(v8::Isolate*,
bool create_wrapped_value);
} // namespace blink
......
......@@ -4,7 +4,9 @@
#include "modules/indexeddb/IDBValue.h"
#include "base/memory/scoped_refptr.h"
#include <memory>
#include <utility>
#include "bindings/core/v8/serialization/SerializedScriptValue.h"
#include "platform/blob/BlobData.h"
#include "platform/wtf/PtrUtil.h"
......@@ -32,41 +34,33 @@ IDBValue::IDBValue(scoped_refptr<SharedBuffer> data,
IDBKey* primary_key,
const IDBKeyPath& key_path)
: data_(std::move(data)),
blob_data_(std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>()),
blob_info_(
WTF::WrapUnique(new Vector<WebBlobInfo>(web_blob_info.size()))),
primary_key_(primary_key && primary_key->IsValid() ? primary_key
: nullptr),
key_path_(key_path) {
for (size_t i = 0; i < web_blob_info.size(); ++i) {
const WebBlobInfo& info = (*blob_info_)[i] = web_blob_info[i];
blob_data_->push_back(
blob_info_.ReserveInitialCapacity(web_blob_info.size());
blob_data_.ReserveInitialCapacity(web_blob_info.size());
for (const WebBlobInfo& info : web_blob_info) {
blob_info_.push_back(info);
blob_data_.push_back(
BlobDataHandle::Create(info.Uuid(), info.GetType(), info.size()));
}
}
IDBValue::IDBValue(const IDBValue* value,
IDBValue::IDBValue(std::unique_ptr<IDBValue> value,
IDBKey* primary_key,
const IDBKeyPath& key_path)
: data_(value->data_),
blob_data_(std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>()),
blob_info_(
WTF::WrapUnique(new Vector<WebBlobInfo>(value->blob_info_->size()))),
: data_(std::move(value->data_)),
blob_data_(std::move(value->blob_data_)),
blob_info_(std::move(value->blob_info_)),
primary_key_(primary_key),
key_path_(key_path) {
for (size_t i = 0; i < value->blob_info_->size(); ++i) {
const WebBlobInfo& info = (*blob_info_)[i] = value->blob_info_->at(i);
blob_data_->push_back(
BlobDataHandle::Create(info.Uuid(), info.GetType(), info.size()));
}
}
key_path_(key_path) {}
IDBValue::IDBValue(
scoped_refptr<SharedBuffer> unwrapped_data,
std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>> blob_data,
std::unique_ptr<Vector<WebBlobInfo>> blob_info,
const IDBKey* primary_key,
const IDBKeyPath& key_path)
IDBValue::IDBValue(scoped_refptr<SharedBuffer> unwrapped_data,
Vector<scoped_refptr<BlobDataHandle>> blob_data,
Vector<WebBlobInfo> blob_info,
const IDBKey* primary_key,
const IDBKeyPath& key_path)
: data_(std::move(unwrapped_data)),
blob_data_(std::move(blob_data)),
blob_info_(std::move(blob_info)),
......@@ -78,36 +72,36 @@ IDBValue::~IDBValue() {
isolate_->AdjustAmountOfExternalAllocatedMemory(-external_allocated_size_);
}
scoped_refptr<IDBValue> IDBValue::Create() {
return base::AdoptRef(new IDBValue());
std::unique_ptr<IDBValue> IDBValue::Create() {
return WTF::WrapUnique(new IDBValue());
}
scoped_refptr<IDBValue> IDBValue::Create(const WebIDBValue& value,
v8::Isolate* isolate) {
return base::AdoptRef(new IDBValue(value, isolate));
std::unique_ptr<IDBValue> IDBValue::Create(const WebIDBValue& value,
v8::Isolate* isolate) {
return WTF::WrapUnique(new IDBValue(value, isolate));
}
scoped_refptr<IDBValue> IDBValue::Create(const IDBValue* value,
IDBKey* primary_key,
const IDBKeyPath& key_path) {
return base::AdoptRef(new IDBValue(value, primary_key, key_path));
std::unique_ptr<IDBValue> IDBValue::Create(std::unique_ptr<IDBValue> value,
IDBKey* primary_key,
const IDBKeyPath& key_path) {
return WTF::WrapUnique(new IDBValue(std::move(value), primary_key, key_path));
}
scoped_refptr<IDBValue> IDBValue::Create(
std::unique_ptr<IDBValue> IDBValue::Create(
scoped_refptr<SharedBuffer> unwrapped_data,
std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>> blob_data,
std::unique_ptr<Vector<WebBlobInfo>> blob_info,
Vector<scoped_refptr<BlobDataHandle>> blob_data,
Vector<WebBlobInfo> blob_info,
const IDBKey* primary_key,
const IDBKeyPath& key_path) {
return base::AdoptRef(new IDBValue(std::move(unwrapped_data),
std::move(blob_data), std::move(blob_info),
primary_key, key_path));
return WTF::WrapUnique(
new IDBValue(std::move(unwrapped_data), std::move(blob_data),
std::move(blob_info), primary_key, key_path));
}
Vector<String> IDBValue::GetUUIDs() const {
Vector<String> uuids;
uuids.ReserveCapacity(blob_info_->size());
for (const auto& info : *blob_info_)
uuids.ReserveCapacity(blob_info_.size());
for (const WebBlobInfo& info : blob_info_)
uuids.push_back(info.Uuid());
return uuids;
}
......
......@@ -6,6 +6,8 @@
#define IDBValue_h
#include <memory>
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "modules/ModulesExport.h"
#include "modules/indexeddb/IDBKey.h"
......@@ -20,18 +22,21 @@ class SerializedScriptValue;
class WebBlobInfo;
struct WebIDBValue;
class MODULES_EXPORT IDBValue final : public RefCounted<IDBValue> {
class MODULES_EXPORT IDBValue final {
public:
static scoped_refptr<IDBValue> Create();
static scoped_refptr<IDBValue> Create(const WebIDBValue&, v8::Isolate*);
static scoped_refptr<IDBValue> Create(const IDBValue*,
IDBKey*,
const IDBKeyPath&);
static std::unique_ptr<IDBValue> Create();
static std::unique_ptr<IDBValue> Create(const WebIDBValue&, v8::Isolate*);
// Injects a primary key into a value coming from the backend.
static std::unique_ptr<IDBValue> Create(std::unique_ptr<IDBValue>,
IDBKey*,
const IDBKeyPath&);
// Used by IDBValueUnwrapper and its tests.
static scoped_refptr<IDBValue> Create(
static std::unique_ptr<IDBValue> Create(
scoped_refptr<SharedBuffer> unwrapped_data,
std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>>,
std::unique_ptr<Vector<WebBlobInfo>>,
Vector<scoped_refptr<BlobDataHandle>>,
Vector<WebBlobInfo>,
const IDBKey*,
const IDBKeyPath&);
......@@ -42,11 +47,18 @@ class MODULES_EXPORT IDBValue final : public RefCounted<IDBValue> {
bool IsNull() const;
Vector<String> GetUUIDs() const;
scoped_refptr<SerializedScriptValue> CreateSerializedValue() const;
Vector<WebBlobInfo>* BlobInfo() const { return blob_info_.get(); }
const Vector<WebBlobInfo>& BlobInfo() const { return blob_info_; }
const IDBKey* PrimaryKey() const { return primary_key_; }
const IDBKeyPath& KeyPath() const { return key_path_; }
Vector<scoped_refptr<BlobDataHandle>> TakeBlobData() {
return std::move(blob_data_);
}
Vector<WebBlobInfo> TakeBlobInfo() { return std::move(blob_info_); }
private:
DISALLOW_COPY_AND_ASSIGN(IDBValue);
friend class IDBValueUnwrapper;
IDBValue();
......@@ -55,25 +67,28 @@ class MODULES_EXPORT IDBValue final : public RefCounted<IDBValue> {
const WebVector<WebBlobInfo>&,
IDBKey*,
const IDBKeyPath&);
IDBValue(const IDBValue*, IDBKey*, const IDBKeyPath&);
IDBValue(std::unique_ptr<IDBValue>, IDBKey*, const IDBKeyPath&);
IDBValue(scoped_refptr<SharedBuffer> unwrapped_data,
std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>>,
std::unique_ptr<Vector<WebBlobInfo>>,
Vector<scoped_refptr<BlobDataHandle>>,
Vector<WebBlobInfo>,
const IDBKey*,
const IDBKeyPath&);
// Keep this private to prevent new refs because we manually bookkeep the
// memory to V8.
const scoped_refptr<SharedBuffer> data_;
const std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>> blob_data_;
const std::unique_ptr<Vector<WebBlobInfo>> blob_info_;
scoped_refptr<SharedBuffer> data_;
Vector<scoped_refptr<BlobDataHandle>> blob_data_;
Vector<WebBlobInfo> blob_info_;
const Persistent<const IDBKey> primary_key_;
const IDBKeyPath key_path_;
int64_t external_allocated_size_ = 0;
// Used to register memory externally allocated by the WebIDBValue, and to
// unregister that memory in the destructor. Unused in other construction
// paths.
v8::Isolate* isolate_ = nullptr;
int64_t external_allocated_size_ = 0;
};
} // namespace blink
......
......@@ -208,7 +208,7 @@ bool IDBValueUnwrapper::IsWrapped(IDBValue* value) {
}
bool IDBValueUnwrapper::IsWrapped(
const Vector<scoped_refptr<IDBValue>>& values) {
const Vector<std::unique_ptr<IDBValue>>& values) {
for (const auto& value : values) {
if (IsWrapped(value.get()))
return true;
......@@ -216,28 +216,20 @@ bool IDBValueUnwrapper::IsWrapped(
return false;
}
scoped_refptr<IDBValue> IDBValueUnwrapper::Unwrap(
IDBValue* wrapped_value,
std::unique_ptr<IDBValue> IDBValueUnwrapper::Unwrap(
std::unique_ptr<IDBValue> wrapped_value,
scoped_refptr<SharedBuffer>&& wrapper_blob_content) {
DCHECK(wrapped_value);
DCHECK(wrapped_value->data_);
DCHECK_GT(wrapped_value->blob_info_->size(), 0U);
DCHECK_EQ(wrapped_value->blob_info_->size(),
wrapped_value->blob_data_->size());
// Create an IDBValue with the same blob information, minus the last blob.
unsigned blob_count = wrapped_value->BlobInfo()->size() - 1;
std::unique_ptr<Vector<scoped_refptr<BlobDataHandle>>> blob_data =
std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>();
blob_data->ReserveCapacity(blob_count);
std::unique_ptr<Vector<WebBlobInfo>> blob_info =
std::make_unique<Vector<WebBlobInfo>>();
blob_info->ReserveCapacity(blob_count);
for (unsigned i = 0; i < blob_count; ++i) {
blob_data->push_back((*wrapped_value->blob_data_)[i]);
blob_info->push_back((*wrapped_value->blob_info_)[i]);
}
Vector<scoped_refptr<BlobDataHandle>> blob_data =
wrapped_value->TakeBlobData();
Vector<WebBlobInfo> blob_info = wrapped_value->TakeBlobInfo();
DCHECK_EQ(blob_data.size(), blob_info.size());
DCHECK_GT(blob_info.size(), 0U);
blob_data.pop_back();
blob_info.pop_back();
return IDBValue::Create(std::move(wrapper_blob_content), std::move(blob_data),
std::move(blob_info), wrapped_value->PrimaryKey(),
......@@ -260,11 +252,11 @@ bool IDBValueUnwrapper::Parse(IDBValue* value) {
if (!ReadVarInt(blob_offset))
return Reset();
size_t value_blob_count = value->blob_data_->size();
size_t value_blob_count = value->blob_data_.size();
if (!value_blob_count || blob_offset != value_blob_count - 1)
return Reset();
blob_handle_ = value->blob_data_->back();
blob_handle_ = value->blob_data_.back();
if (blob_handle_->size() != blob_size_)
return Reset();
......
......@@ -217,11 +217,11 @@ class MODULES_EXPORT IDBValueUnwrapper {
static bool IsWrapped(IDBValue*);
// True if at least one of the IDBValues' data was wrapped in a Blob.
static bool IsWrapped(const Vector<scoped_refptr<IDBValue>>&);
static bool IsWrapped(const Vector<std::unique_ptr<IDBValue>>&);
// Pieces together an unwrapped IDBValue from a wrapped value and Blob data.
static scoped_refptr<IDBValue> Unwrap(
IDBValue* wrapped_value,
static std::unique_ptr<IDBValue> Unwrap(
std::unique_ptr<IDBValue> wrapped_value,
scoped_refptr<SharedBuffer>&& wrapper_blob_content);
// Parses the wrapper Blob information from a wrapped IDBValue.
......
......@@ -485,11 +485,8 @@ TEST(IDBValueUnwrapperTest, IsWrapped) {
IDBKey* key = IDBKey::CreateNumber(42.0);
IDBKeyPath key_path(String("primaryKey"));
scoped_refptr<IDBValue> wrapped_value = IDBValue::Create(
wrapped_marker_buffer,
std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>(
blob_data_handles),
std::make_unique<Vector<WebBlobInfo>>(blob_infos), key, key_path);
std::unique_ptr<IDBValue> wrapped_value = IDBValue::Create(
wrapped_marker_buffer, blob_data_handles, blob_infos, key, key_path);
EXPECT_TRUE(IDBValueUnwrapper::IsWrapped(wrapped_value.get()));
Vector<char> wrapped_marker_bytes(wrapped_marker_buffer->size());
......@@ -501,11 +498,9 @@ TEST(IDBValueUnwrapperTest, IsWrapped) {
// return false.
ASSERT_LT(3U, wrapped_marker_bytes.size());
for (size_t i = 0; i < 3; ++i) {
scoped_refptr<IDBValue> mutant_value = IDBValue::Create(
SharedBuffer::Create(wrapped_marker_bytes.data(), i),
std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>(
blob_data_handles),
std::make_unique<Vector<WebBlobInfo>>(blob_infos), key, key_path);
std::unique_ptr<IDBValue> mutant_value =
IDBValue::Create(SharedBuffer::Create(wrapped_marker_bytes.data(), i),
blob_data_handles, blob_infos, key, key_path);
EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.get()));
}
......@@ -517,12 +512,10 @@ TEST(IDBValueUnwrapperTest, IsWrapped) {
for (int j = 0; j < 8; ++j) {
char mask = 1 << j;
wrapped_marker_bytes[i] ^= mask;
scoped_refptr<IDBValue> mutant_value = IDBValue::Create(
SharedBuffer::Create(wrapped_marker_bytes.data(),
wrapped_marker_bytes.size()),
std::make_unique<Vector<scoped_refptr<BlobDataHandle>>>(
blob_data_handles),
std::make_unique<Vector<WebBlobInfo>>(blob_infos), key, key_path);
std::unique_ptr<IDBValue> mutant_value =
IDBValue::Create(SharedBuffer::Create(wrapped_marker_bytes.data(),
wrapped_marker_bytes.size()),
blob_data_handles, blob_infos, key, key_path);
EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.get()));
wrapped_marker_bytes[i] ^= mask;
......
......@@ -147,10 +147,10 @@ void WebIDBCallbacksImpl::OnSuccess(const WebVector<WebIDBValue>& values) {
return;
probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success");
Vector<scoped_refptr<IDBValue>> idb_values(values.size());
Vector<std::unique_ptr<IDBValue>> idb_values(values.size());
for (size_t i = 0; i < values.size(); ++i)
idb_values[i] = IDBValue::Create(values[i], request_->GetIsolate());
request_->HandleResponse(idb_values);
request_->HandleResponse(std::move(idb_values));
}
void WebIDBCallbacksImpl::OnSuccess(long long value) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment