Commit 799eac6f authored by Chase Phillips's avatar Chase Phillips Committed by Commit Bot

Remove WebIDB{Database,Cursor}Impl IOThreadHelper class

This is the next step in removing IO thread hopping from the
renderer-side non-Blink IDB code.

Bug: 717812
Change-Id: I4f0bfc8d98ad7bd9d041954f74215f75271702f9
Reviewed-on: https://chromium-review.googlesource.com/1155794Reviewed-by: default avatarChris Mumford <cmumford@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Chase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580282}
parent 6c90e03d
...@@ -26,50 +26,21 @@ using indexed_db::mojom::CursorAssociatedPtrInfo; ...@@ -26,50 +26,21 @@ using indexed_db::mojom::CursorAssociatedPtrInfo;
namespace content { namespace content {
class WebIDBCursorImpl::IOThreadHelper {
public:
explicit IOThreadHelper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~IOThreadHelper();
void Bind(CursorAssociatedPtrInfo cursor_info);
void Advance(uint32_t count,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
void Continue(const IndexedDBKey& key,
const IndexedDBKey& primary_key,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
void Prefetch(int32_t count,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches);
private:
CallbacksAssociatedPtrInfo GetCallbacksProxy(
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
indexed_db::mojom::CursorAssociatedPtr cursor_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
};
WebIDBCursorImpl::WebIDBCursorImpl( WebIDBCursorImpl::WebIDBCursorImpl(
indexed_db::mojom::CursorAssociatedPtrInfo cursor_info, indexed_db::mojom::CursorAssociatedPtrInfo cursor_info,
int64_t transaction_id, int64_t transaction_id,
scoped_refptr<base::SingleThreadTaskRunner> io_runner, scoped_refptr<base::SingleThreadTaskRunner> io_runner,
scoped_refptr<base::SingleThreadTaskRunner> callback_runner) scoped_refptr<base::SingleThreadTaskRunner> callback_runner)
: transaction_id_(transaction_id), : transaction_id_(transaction_id),
helper_(new IOThreadHelper(io_runner)),
io_runner_(std::move(io_runner)), io_runner_(std::move(io_runner)),
callback_runner_(std::move(callback_runner)), callback_runner_(std::move(callback_runner)),
cursor_(std::move(cursor_info)),
continue_count_(0), continue_count_(0),
used_prefetches_(0), used_prefetches_(0),
pending_onsuccess_callbacks_(0), pending_onsuccess_callbacks_(0),
prefetch_amount_(kMinPrefetchAmount), prefetch_amount_(kMinPrefetchAmount),
weak_factory_(this) { weak_factory_(this) {
IndexedDBDispatcher::ThreadSpecificInstance()->RegisterCursor(this); IndexedDBDispatcher::ThreadSpecificInstance()->RegisterCursor(this);
io_runner_->PostTask(FROM_HERE, base::BindOnce(&IOThreadHelper::Bind,
base::Unretained(helper_),
std::move(cursor_info)));
} }
WebIDBCursorImpl::~WebIDBCursorImpl() { WebIDBCursorImpl::~WebIDBCursorImpl() {
...@@ -78,7 +49,6 @@ WebIDBCursorImpl::~WebIDBCursorImpl() { ...@@ -78,7 +49,6 @@ WebIDBCursorImpl::~WebIDBCursorImpl() {
// this object. But, if that ever changed, then we'd need to invalidate // this object. But, if that ever changed, then we'd need to invalidate
// any such pointers. // any such pointers.
IndexedDBDispatcher::ThreadSpecificInstance()->UnregisterCursor(this); IndexedDBDispatcher::ThreadSpecificInstance()->UnregisterCursor(this);
io_runner_->DeleteSoon(FROM_HERE, helper_);
} }
void WebIDBCursorImpl::Advance(unsigned long count, void WebIDBCursorImpl::Advance(unsigned long count,
...@@ -97,10 +67,7 @@ void WebIDBCursorImpl::Advance(unsigned long count, ...@@ -97,10 +67,7 @@ void WebIDBCursorImpl::Advance(unsigned long count,
auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(), std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(),
io_runner_, callback_runner_); io_runner_, callback_runner_);
io_runner_->PostTask( cursor_->Advance(count, GetCallbacksProxy(std::move(callbacks_impl)));
FROM_HERE,
base::BindOnce(&IOThreadHelper::Advance, base::Unretained(helper_), count,
std::move(callbacks_impl)));
} }
void WebIDBCursorImpl::Continue(WebIDBKeyView key, void WebIDBCursorImpl::Continue(WebIDBKeyView key,
...@@ -126,10 +93,8 @@ void WebIDBCursorImpl::Continue(WebIDBKeyView key, ...@@ -126,10 +93,8 @@ void WebIDBCursorImpl::Continue(WebIDBKeyView key,
auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(), std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(),
io_runner_, callback_runner_); io_runner_, callback_runner_);
io_runner_->PostTask( cursor_->Prefetch(prefetch_amount_,
FROM_HERE, GetCallbacksProxy(std::move(callbacks_impl)));
base::BindOnce(&IOThreadHelper::Prefetch, base::Unretained(helper_),
prefetch_amount_, std::move(callbacks_impl)));
// Increase prefetch_amount_ exponentially. // Increase prefetch_amount_ exponentially.
prefetch_amount_ *= 2; prefetch_amount_ *= 2;
...@@ -150,12 +115,9 @@ void WebIDBCursorImpl::Continue(WebIDBKeyView key, ...@@ -150,12 +115,9 @@ void WebIDBCursorImpl::Continue(WebIDBKeyView key,
auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>(
std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(), std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr(),
io_runner_, callback_runner_); io_runner_, callback_runner_);
io_runner_->PostTask( cursor_->Continue(IndexedDBKeyBuilder::Build(key),
FROM_HERE, IndexedDBKeyBuilder::Build(primary_key),
base::BindOnce(&IOThreadHelper::Continue, base::Unretained(helper_), GetCallbacksProxy(std::move(callbacks_impl)));
IndexedDBKeyBuilder::Build(key),
IndexedDBKeyBuilder::Build(primary_key),
std::move(callbacks_impl)));
} }
void WebIDBCursorImpl::PostSuccessHandlerCallback() { void WebIDBCursorImpl::PostSuccessHandlerCallback() {
...@@ -239,10 +201,7 @@ void WebIDBCursorImpl::ResetPrefetchCache() { ...@@ -239,10 +201,7 @@ void WebIDBCursorImpl::ResetPrefetchCache() {
} }
// Reset the back-end cursor. // Reset the back-end cursor.
io_runner_->PostTask( cursor_->PrefetchReset(used_prefetches_, prefetch_keys_.size());
FROM_HERE,
base::BindOnce(&IOThreadHelper::PrefetchReset, base::Unretained(helper_),
used_prefetches_, prefetch_keys_.size()));
// Reset the prefetch cache. // Reset the prefetch cache.
prefetch_keys_.clear(); prefetch_keys_.clear();
...@@ -252,43 +211,7 @@ void WebIDBCursorImpl::ResetPrefetchCache() { ...@@ -252,43 +211,7 @@ void WebIDBCursorImpl::ResetPrefetchCache() {
pending_onsuccess_callbacks_ = 0; pending_onsuccess_callbacks_ = 0;
} }
WebIDBCursorImpl::IOThreadHelper::IOThreadHelper( CallbacksAssociatedPtrInfo WebIDBCursorImpl::GetCallbacksProxy(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: task_runner_(std::move(task_runner)) {}
WebIDBCursorImpl::IOThreadHelper::~IOThreadHelper() {}
void WebIDBCursorImpl::IOThreadHelper::Bind(
CursorAssociatedPtrInfo cursor_info) {
cursor_.Bind(std::move(cursor_info), task_runner_);
}
void WebIDBCursorImpl::IOThreadHelper::Advance(
uint32_t count,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
cursor_->Advance(count, GetCallbacksProxy(std::move(callbacks)));
}
void WebIDBCursorImpl::IOThreadHelper::Continue(
const IndexedDBKey& key,
const IndexedDBKey& primary_key,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
cursor_->Continue(key, primary_key, GetCallbacksProxy(std::move(callbacks)));
}
void WebIDBCursorImpl::IOThreadHelper::Prefetch(
int32_t count,
std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
cursor_->Prefetch(count, GetCallbacksProxy(std::move(callbacks)));
}
void WebIDBCursorImpl::IOThreadHelper::PrefetchReset(
int32_t used_prefetches,
int32_t unused_prefetches) {
cursor_->PrefetchReset(used_prefetches, unused_prefetches);
}
CallbacksAssociatedPtrInfo WebIDBCursorImpl::IOThreadHelper::GetCallbacksProxy(
std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
CallbacksAssociatedPtrInfo ptr_info; CallbacksAssociatedPtrInfo ptr_info;
auto request = mojo::MakeRequest(&ptr_info); auto request = mojo::MakeRequest(&ptr_info);
......
...@@ -27,6 +27,8 @@ class SingleThreadTaskRunner; ...@@ -27,6 +27,8 @@ class SingleThreadTaskRunner;
namespace content { namespace content {
class IndexedDBCallbacksImpl;
class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor {
public: public:
WebIDBCursorImpl(indexed_db::mojom::CursorAssociatedPtrInfo cursor, WebIDBCursorImpl(indexed_db::mojom::CursorAssociatedPtrInfo cursor,
...@@ -54,14 +56,15 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { ...@@ -54,14 +56,15 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor {
int64_t transaction_id() const { return transaction_id_; } int64_t transaction_id() const { return transaction_id_; }
private: private:
indexed_db::mojom::CallbacksAssociatedPtrInfo GetCallbacksProxy(
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset);
FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId);
FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, AdvancePrefetchTest); FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, AdvancePrefetchTest);
FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset); FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset);
FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest); FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest);
class IOThreadHelper;
enum { kInvalidCursorId = -1 }; enum { kInvalidCursorId = -1 };
enum { kPrefetchContinueThreshold = 2 }; enum { kPrefetchContinueThreshold = 2 };
enum { kMinPrefetchAmount = 5 }; enum { kMinPrefetchAmount = 5 };
...@@ -69,9 +72,9 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { ...@@ -69,9 +72,9 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor {
int64_t transaction_id_; int64_t transaction_id_;
IOThreadHelper* helper_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; scoped_refptr<base::SingleThreadTaskRunner> callback_runner_;
indexed_db::mojom::CursorAssociatedPtr cursor_;
// Prefetch cache. // Prefetch cache.
base::circular_deque<IndexedDBKey> prefetch_keys_; base::circular_deque<IndexedDBKey> prefetch_keys_;
......
...@@ -26,6 +26,8 @@ class WebString; ...@@ -26,6 +26,8 @@ class WebString;
namespace content { namespace content {
class IndexedDBCallbacksImpl;
class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase {
public: public:
WebIDBDatabaseImpl( WebIDBDatabaseImpl(
...@@ -134,21 +136,22 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { ...@@ -134,21 +136,22 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase {
void Commit(long long transaction_id) override; void Commit(long long transaction_id) override;
private: private:
indexed_db::mojom::CallbacksAssociatedPtrInfo GetCallbacksProxy(
std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, ValueSizeTest); FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, ValueSizeTest);
FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, KeyAndValueSizeTest); FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, KeyAndValueSizeTest);
class IOThreadHelper;
// Maximum size (in bytes) of value/key pair allowed for put requests. Any // Maximum size (in bytes) of value/key pair allowed for put requests. Any
// requests larger than this size will be rejected. // requests larger than this size will be rejected.
// Used by unit tests to exercise behavior without allocating huge chunks // Used by unit tests to exercise behavior without allocating huge chunks
// of memory. // of memory.
size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes;
IOThreadHelper* helper_;
std::set<int32_t> observer_ids_; std::set<int32_t> observer_ids_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; scoped_refptr<base::SingleThreadTaskRunner> callback_runner_;
indexed_db::mojom::DatabaseAssociatedPtr database_;
}; };
} // namespace content } // namespace content
......
...@@ -28,9 +28,7 @@ namespace content { ...@@ -28,9 +28,7 @@ namespace content {
WebIDBFactoryImpl::WebIDBFactoryImpl( WebIDBFactoryImpl::WebIDBFactoryImpl(
FactoryPtrInfo factory_info, FactoryPtrInfo factory_info,
scoped_refptr<base::SingleThreadTaskRunner> io_runner) scoped_refptr<base::SingleThreadTaskRunner> io_runner)
: io_runner_(std::move(io_runner)) { : io_runner_(std::move(io_runner)), factory_(std::move(factory_info)) {}
factory_.Bind(std::move(factory_info));
}
WebIDBFactoryImpl::~WebIDBFactoryImpl() = default; WebIDBFactoryImpl::~WebIDBFactoryImpl() = default;
......
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