summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc')
-rw-r--r--chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc93
1 files changed, 53 insertions, 40 deletions
diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc
index c308cf7cab9..e65a8840ba8 100644
--- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc
+++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc
@@ -11,17 +11,10 @@
#include "base/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/strong_associated_binding.h"
-#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h"
-#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h"
#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h"
#include "third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h"
+#include "third_party/blink/renderer/platform/wtf/functional.h"
-using blink::WebBlobInfo;
-using blink::WebData;
-using blink::WebIDBCallbacks;
-using blink::WebIDBKey;
-using blink::WebIDBKeyView;
-using blink::WebIDBValue;
using blink::mojom::blink::IDBCallbacksAssociatedPtrInfo;
using blink::mojom::blink::IDBCursorAssociatedPtrInfo;
@@ -29,14 +22,16 @@ namespace blink {
WebIDBCursorImpl::WebIDBCursorImpl(
mojom::blink::IDBCursorAssociatedPtrInfo cursor_info,
- int64_t transaction_id)
+ int64_t transaction_id,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: transaction_id_(transaction_id),
- cursor_(std::move(cursor_info)),
continue_count_(0),
used_prefetches_(0),
pending_onsuccess_callbacks_(0),
prefetch_amount_(kMinPrefetchAmount),
+ task_runner_(task_runner),
weak_factory_(this) {
+ cursor_.Bind(std::move(cursor_info), std::move(task_runner));
IndexedDBDispatcher::RegisterCursor(this);
}
@@ -56,21 +51,42 @@ void WebIDBCursorImpl::Advance(uint32_t count, WebIDBCallbacks* callbacks_ptr) {
}
ResetPrefetchCache();
- // Reset all cursor prefetch caches except for this cursor.
- IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this);
+ callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_);
+ cursor_->Advance(count,
+ WTF::Bind(&WebIDBCursorImpl::AdvanceCallback,
+ WTF::Unretained(this), std::move(callbacks)));
+}
+
+void WebIDBCursorImpl::AdvanceCallback(
+ std::unique_ptr<WebIDBCallbacks> callbacks,
+ mojom::blink::IDBErrorPtr error,
+ mojom::blink::IDBCursorValuePtr cursor_value) {
+ if (error) {
+ callbacks->Error(error->error_code, error->error_message);
+ callbacks.reset();
+ return;
+ }
- auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
- std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr());
- cursor_->Advance(count, GetCallbacksProxy(std::move(callbacks_impl)));
+ if (!cursor_value) {
+ callbacks->SuccessValue(nullptr);
+ callbacks.reset();
+ return;
+ }
+
+ callbacks->SuccessCursorContinue(std::move(cursor_value->key),
+ std::move(cursor_value->primary_key),
+ std::move(cursor_value->value));
+ callbacks.reset();
}
-void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key,
- WebIDBKeyView primary_key,
+void WebIDBCursorImpl::CursorContinue(const IDBKey* key,
+ const IDBKey* primary_key,
WebIDBCallbacks* callbacks_ptr) {
+ DCHECK(key && primary_key);
std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
- if (key.KeyType() == kWebIDBKeyTypeNull &&
- primary_key.KeyType() == kWebIDBKeyTypeNull) {
+ if (key->GetType() == mojom::IDBKeyType::Null &&
+ primary_key->GetType() == mojom::IDBKeyType::Null) {
// No key(s), so this would qualify for a prefetch.
++continue_count_;
@@ -84,10 +100,9 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key,
// Request pre-fetch.
++pending_onsuccess_callbacks_;
- auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
- std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr());
+ callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_);
cursor_->Prefetch(prefetch_amount_,
- GetCallbacksProxy(std::move(callbacks_impl)));
+ GetCallbacksProxy(std::move(callbacks)));
// Increase prefetch_amount_ exponentially.
prefetch_amount_ *= 2;
@@ -101,14 +116,9 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key,
ResetPrefetchCache();
}
- // Reset all cursor prefetch caches except for this cursor.
- IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this);
-
- auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
- std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr());
- cursor_->CursorContinue(WebIDBKeyBuilder::Build(key),
- WebIDBKeyBuilder::Build(primary_key),
- GetCallbacksProxy(std::move(callbacks_impl)));
+ callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_);
+ cursor_->CursorContinue(IDBKey::Clone(key), IDBKey::Clone(primary_key),
+ GetCallbacksProxy(std::move(callbacks)));
}
void WebIDBCursorImpl::PostSuccessHandlerCallback() {
@@ -124,9 +134,10 @@ void WebIDBCursorImpl::PostSuccessHandlerCallback() {
ResetPrefetchCache();
}
-void WebIDBCursorImpl::SetPrefetchData(Vector<WebIDBKey> keys,
- Vector<WebIDBKey> primary_keys,
- Vector<WebIDBValue> values) {
+void WebIDBCursorImpl::SetPrefetchData(
+ Vector<std::unique_ptr<IDBKey>> keys,
+ Vector<std::unique_ptr<IDBKey>> primary_keys,
+ Vector<std::unique_ptr<IDBValue>> values) {
// Keys and values are stored in reverse order so that a cache'd continue can
// pop a value off of the back and prevent new memory allocations.
prefetch_keys_.AppendRange(std::make_move_iterator(keys.rbegin()),
@@ -165,9 +176,10 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) {
// Keys and values are stored in reverse order so that a cache'd continue can
// pop a value off of the back and prevent new memory allocations.
- WebIDBKey key = std::move(prefetch_keys_.back());
- WebIDBKey primary_key = std::move(prefetch_primary_keys_.back());
- WebIDBValue value = std::move(prefetch_values_.back());
+ std::unique_ptr<IDBKey> key = std::move(prefetch_keys_.back());
+ std::unique_ptr<IDBKey> primary_key =
+ std::move(prefetch_primary_keys_.back());
+ std::unique_ptr<IDBValue> value = std::move(prefetch_values_.back());
prefetch_keys_.pop_back();
prefetch_primary_keys_.pop_back();
@@ -184,8 +196,8 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) {
ResetPrefetchCache();
}
- callbacks->OnSuccess(std::move(key), std::move(primary_key),
- std::move(value));
+ callbacks->SuccessCursorContinue(std::move(key), std::move(primary_key),
+ std::move(value));
}
void WebIDBCursorImpl::ResetPrefetchCache() {
@@ -209,10 +221,11 @@ void WebIDBCursorImpl::ResetPrefetchCache() {
}
IDBCallbacksAssociatedPtrInfo WebIDBCursorImpl::GetCallbacksProxy(
- std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
+ std::unique_ptr<WebIDBCallbacks> callbacks) {
IDBCallbacksAssociatedPtrInfo ptr_info;
auto request = mojo::MakeRequest(&ptr_info);
- mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
+ mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request),
+ task_runner_);
return ptr_info;
}