diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn index 134e72bad6ae4..6cb30216d0896 100644 --- a/content/renderer/BUILD.gn +++ b/content/renderer/BUILD.gn @@ -141,20 +141,6 @@ target(link_target_type, "renderer") { "ime_event_guard.h", "in_process_renderer_thread.cc", "in_process_renderer_thread.h", - "indexed_db/indexed_db_callbacks_impl.cc", - "indexed_db/indexed_db_callbacks_impl.h", - "indexed_db/indexed_db_database_callbacks_impl.cc", - "indexed_db/indexed_db_database_callbacks_impl.h", - "indexed_db/indexed_db_dispatcher.cc", - "indexed_db/indexed_db_dispatcher.h", - "indexed_db/indexed_db_key_builders.cc", - "indexed_db/indexed_db_key_builders.h", - "indexed_db/webidbcursor_impl.cc", - "indexed_db/webidbcursor_impl.h", - "indexed_db/webidbdatabase_impl.cc", - "indexed_db/webidbdatabase_impl.h", - "indexed_db/webidbfactory_impl.cc", - "indexed_db/webidbfactory_impl.h", "input/frame_input_handler_impl.cc", "input/frame_input_handler_impl.h", "input/input_event_prediction.cc", diff --git a/content/renderer/indexed_db/OWNERS b/content/renderer/indexed_db/OWNERS deleted file mode 100644 index a740487227f3a..0000000000000 --- a/content/renderer/indexed_db/OWNERS +++ /dev/null @@ -1,4 +0,0 @@ -file://content/browser/indexed_db/OWNERS - -# TEAM: storage-dev@chromium.org -# COMPONENT: Blink>Storage>IndexedDB diff --git a/content/renderer/indexed_db/indexed_db_callbacks_impl.cc b/content/renderer/indexed_db/indexed_db_callbacks_impl.cc deleted file mode 100644 index 9bc567157aee0..0000000000000 --- a/content/renderer/indexed_db/indexed_db_callbacks_impl.cc +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright 2016 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. - -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" - -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.h" -#include "content/renderer/indexed_db/webidbcursor_impl.h" -#include "content/renderer/indexed_db/webidbdatabase_impl.h" -#include "third_party/blink/public/platform/file_path_conversion.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" - -using blink::IndexedDBDatabaseMetadata; -using blink::WebBlobInfo; -using blink::WebData; -using blink::WebIDBCallbacks; -using blink::WebIDBDatabase; -using blink::WebIDBMetadata; -using blink::WebIDBNameAndVersion; -using blink::WebIDBValue; -using blink::WebString; -using blink::WebVector; -using blink::mojom::IDBDatabaseAssociatedPtrInfo; - -namespace content { - -namespace { - -void ConvertIndexMetadata(const blink::IndexedDBIndexMetadata& metadata, - WebIDBMetadata::Index* output) { - output->id = metadata.id; - output->name = WebString::FromUTF16(metadata.name); - output->key_path = WebIDBKeyPathBuilder::Build(metadata.key_path); - output->unique = metadata.unique; - output->multi_entry = metadata.multi_entry; -} - -void ConvertObjectStoreMetadata( - const blink::IndexedDBObjectStoreMetadata& metadata, - WebIDBMetadata::ObjectStore* output) { - output->id = metadata.id; - output->name = WebString::FromUTF16(metadata.name); - output->key_path = WebIDBKeyPathBuilder::Build(metadata.key_path); - output->auto_increment = metadata.auto_increment; - output->max_index_id = metadata.max_index_id; - output->indexes = WebVector<WebIDBMetadata::Index>(metadata.indexes.size()); - size_t i = 0; - for (const auto& iter : metadata.indexes) - ConvertIndexMetadata(iter.second, &output->indexes[i++]); -} - -void ConvertDatabaseMetadata(const IndexedDBDatabaseMetadata& metadata, - WebIDBMetadata* output) { - output->id = metadata.id; - output->name = WebString::FromUTF16(metadata.name); - output->version = metadata.version; - output->max_object_store_id = metadata.max_object_store_id; - output->object_stores = - WebVector<WebIDBMetadata::ObjectStore>(metadata.object_stores.size()); - size_t i = 0; - for (const auto& iter : metadata.object_stores) - ConvertObjectStoreMetadata(iter.second, &output->object_stores[i++]); -} - -WebIDBValue ConvertReturnValue(const blink::mojom::IDBReturnValuePtr& value) { - if (!value) - return WebIDBValue(WebData(), WebVector<WebBlobInfo>()); - - WebIDBValue web_value = IndexedDBCallbacksImpl::ConvertValue(value->value); - web_value.SetInjectedPrimaryKey(WebIDBKeyBuilder::Build(value->primary_key), - WebIDBKeyPathBuilder::Build(value->key_path)); - return web_value; -} - -WebIDBNameAndVersion ConvertNameVersion( - const blink::mojom::IDBNameAndVersionPtr& name_and_version) { - return WebIDBNameAndVersion(WebString::FromUTF16(name_and_version->name), - name_and_version->version); -} - -} // namespace - -// static -WebIDBValue IndexedDBCallbacksImpl::ConvertValue( - const blink::mojom::IDBValuePtr& value) { - if (!value || value->bits.empty()) - return WebIDBValue(WebData(), WebVector<WebBlobInfo>()); - - WebVector<WebBlobInfo> local_blob_info; - local_blob_info.reserve(value->blob_or_file_info.size()); - for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { - const auto& info = value->blob_or_file_info[i]; - if (info->file) { - local_blob_info.emplace_back(WebString::FromUTF8(info->uuid), - blink::FilePathToWebString(info->file->path), - WebString::FromUTF16(info->file->name), - WebString::FromUTF16(info->mime_type), - info->file->last_modified.ToDoubleT(), - info->size, info->blob.PassHandle()); - } else { - local_blob_info.emplace_back(WebString::FromUTF8(info->uuid), - WebString::FromUTF16(info->mime_type), - info->size, info->blob.PassHandle()); - } - } - - // TODO(crbug.com/902498): Use mojom traits to map directly to WebData. - WebData web_data(reinterpret_cast<const char*>(value->bits.data()), - value->bits.size()); - // Release value->bits std::vector. - value->bits.clear(); - return WebIDBValue(std::move(web_data), std::move(local_blob_info)); -} - -IndexedDBCallbacksImpl::IndexedDBCallbacksImpl( - std::unique_ptr<WebIDBCallbacks> callbacks, - int64_t transaction_id, - const base::WeakPtr<WebIDBCursorImpl>& cursor) - : callbacks_(std::move(callbacks)), - cursor_(cursor), - transaction_id_(transaction_id) {} - -IndexedDBCallbacksImpl::~IndexedDBCallbacksImpl() = default; - -void IndexedDBCallbacksImpl::Error(int32_t code, - const base::string16& message) { - callbacks_->OnError( - blink::WebIDBDatabaseError(code, WebString::FromUTF16(message))); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessNamesAndVersionsList( - std::vector<blink::mojom::IDBNameAndVersionPtr> names_and_versions) { - WebVector<WebIDBNameAndVersion> web_names_and_versions; - web_names_and_versions.reserve(names_and_versions.size()); - for (const blink::mojom::IDBNameAndVersionPtr& name_version : - names_and_versions) - web_names_and_versions.emplace_back(ConvertNameVersion(name_version)); - callbacks_->OnSuccess(web_names_and_versions); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessStringList( - const std::vector<base::string16>& value) { - WebVector<WebString> web_value(value.size()); - std::transform( - value.begin(), value.end(), web_value.begin(), - [](const base::string16& s) { return WebString::FromUTF16(s); }); - callbacks_->OnSuccess(web_value); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::Blocked(int64_t existing_version) { - callbacks_->OnBlocked(existing_version); - // Not resetting |callbacks_|. -} - -void IndexedDBCallbacksImpl::UpgradeNeeded( - IDBDatabaseAssociatedPtrInfo database_info, - int64_t old_version, - blink::WebIDBDataLoss data_loss, - const std::string& data_loss_message, - const IndexedDBDatabaseMetadata& metadata) { - WebIDBDatabase* database = new WebIDBDatabaseImpl(std::move(database_info)); - WebIDBMetadata web_metadata; - ConvertDatabaseMetadata(metadata, &web_metadata); - callbacks_->OnUpgradeNeeded(old_version, database, web_metadata, data_loss, - WebString::FromUTF8(data_loss_message)); - // Not resetting |callbacks_|. -} - -void IndexedDBCallbacksImpl::SuccessDatabase( - IDBDatabaseAssociatedPtrInfo database_info, - const IndexedDBDatabaseMetadata& metadata) { - WebIDBDatabase* database = nullptr; - if (database_info.is_valid()) { - database = new WebIDBDatabaseImpl(std::move(database_info)); - } - - WebIDBMetadata web_metadata; - ConvertDatabaseMetadata(metadata, &web_metadata); - callbacks_->OnSuccess(database, web_metadata); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessCursor( - blink::mojom::IDBCursorAssociatedPtrInfo cursor_info, - const IndexedDBKey& key, - const IndexedDBKey& primary_key, - blink::mojom::IDBValuePtr value) { - WebIDBCursorImpl* cursor = - new WebIDBCursorImpl(std::move(cursor_info), transaction_id_); - callbacks_->OnSuccess(cursor, WebIDBKeyBuilder::Build(key), - WebIDBKeyBuilder::Build(primary_key), - ConvertValue(value)); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessValue( - blink::mojom::IDBReturnValuePtr value) { - callbacks_->OnSuccess(ConvertReturnValue(value)); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessCursorContinue( - const IndexedDBKey& key, - const IndexedDBKey& primary_key, - blink::mojom::IDBValuePtr value) { - callbacks_->OnSuccess(WebIDBKeyBuilder::Build(key), - WebIDBKeyBuilder::Build(primary_key), - ConvertValue(value)); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessCursorPrefetch( - const std::vector<IndexedDBKey>& keys, - const std::vector<IndexedDBKey>& primary_keys, - std::vector<blink::mojom::IDBValuePtr> values) { - std::vector<WebIDBValue> web_values; - web_values.reserve(values.size()); - for (const blink::mojom::IDBValuePtr& value : values) - web_values.emplace_back(ConvertValue(value)); - - if (cursor_) { - cursor_->SetPrefetchData(keys, primary_keys, std::move(web_values)); - cursor_->CachedContinue(callbacks_.get()); - } - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessArray( - std::vector<blink::mojom::IDBReturnValuePtr> values) { - WebVector<WebIDBValue> web_values; - web_values.reserve(values.size()); - for (const blink::mojom::IDBReturnValuePtr& value : values) - web_values.emplace_back(ConvertReturnValue(value)); - callbacks_->OnSuccess(std::move(web_values)); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessKey(const IndexedDBKey& key) { - callbacks_->OnSuccess(WebIDBKeyBuilder::Build(key)); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::SuccessInteger(int64_t value) { - callbacks_->OnSuccess(value); - callbacks_.reset(); -} - -void IndexedDBCallbacksImpl::Success() { - callbacks_->OnSuccess(); - callbacks_.reset(); -} - -} // namespace content diff --git a/content/renderer/indexed_db/indexed_db_callbacks_impl.h b/content/renderer/indexed_db/indexed_db_callbacks_impl.h deleted file mode 100644 index 27052f49ee96e..0000000000000 --- a/content/renderer/indexed_db/indexed_db_callbacks_impl.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2016 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 CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ -#define CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ - -#include "mojo/public/cpp/bindings/associated_binding.h" -#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" -#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" - -using blink::IndexedDBKey; - -namespace blink { -class WebIDBCallbacks; -class WebIDBValue; -} // namespace blink - -namespace content { - -class WebIDBCursorImpl; - -// Implements the child-process end of the pipe used to deliver callbacks. It -// is owned by the IO thread. |callback_runner_| is used to post tasks back to -// the thread which owns the blink::WebIDBCallbacks. -class IndexedDBCallbacksImpl : public blink::mojom::IDBCallbacks { - public: - enum : int64_t { kNoTransaction = -1 }; - - static blink::WebIDBValue ConvertValue( - const blink::mojom::IDBValuePtr& value); - - IndexedDBCallbacksImpl(std::unique_ptr<blink::WebIDBCallbacks> callbacks, - int64_t transaction_id, - const base::WeakPtr<WebIDBCursorImpl>& cursor); - ~IndexedDBCallbacksImpl() override; - - // blink::mojom::IDBCallbacks implementation: - void Error(int32_t code, const base::string16& message) override; - void SuccessNamesAndVersionsList( - std::vector<blink::mojom::IDBNameAndVersionPtr> names_and_versions) - override; - void SuccessStringList(const std::vector<base::string16>& value) override; - void Blocked(int64_t existing_version) override; - void UpgradeNeeded(blink::mojom::IDBDatabaseAssociatedPtrInfo database_info, - int64_t old_version, - blink::WebIDBDataLoss data_loss, - const std::string& data_loss_message, - const blink::IndexedDBDatabaseMetadata& metadata) override; - void SuccessDatabase( - blink::mojom::IDBDatabaseAssociatedPtrInfo database_info, - const blink::IndexedDBDatabaseMetadata& metadata) override; - void SuccessCursor(blink::mojom::IDBCursorAssociatedPtrInfo cursor, - const IndexedDBKey& key, - const IndexedDBKey& primary_key, - blink::mojom::IDBValuePtr value) override; - void SuccessValue(blink::mojom::IDBReturnValuePtr value) override; - void SuccessCursorContinue(const IndexedDBKey& key, - const IndexedDBKey& primary_key, - blink::mojom::IDBValuePtr value) override; - void SuccessCursorPrefetch( - const std::vector<IndexedDBKey>& keys, - const std::vector<IndexedDBKey>& primary_keys, - std::vector<blink::mojom::IDBValuePtr> values) override; - void SuccessArray( - std::vector<blink::mojom::IDBReturnValuePtr> values) override; - void SuccessKey(const IndexedDBKey& key) override; - void SuccessInteger(int64_t value) override; - void Success() override; - - private: - scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; - std::unique_ptr<blink::WebIDBCallbacks> callbacks_; - base::WeakPtr<WebIDBCursorImpl> cursor_; - int64_t transaction_id_; - - DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacksImpl); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ diff --git a/content/renderer/indexed_db/indexed_db_dispatcher.cc b/content/renderer/indexed_db/indexed_db_dispatcher.cc deleted file mode 100644 index 6237adbb228dc..0000000000000 --- a/content/renderer/indexed_db/indexed_db_dispatcher.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2013 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. - -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" - -#include <utility> - -#include "base/lazy_instance.h" -#include "base/memory/ptr_util.h" -#include "base/threading/thread_local.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.h" -#include "content/renderer/indexed_db/webidbcursor_impl.h" -#include "ipc/ipc_channel.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" - -using blink::WebIDBKey; -using blink::WebIDBObservation; -using base::ThreadLocalPointer; - -namespace content { -static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher>>::Leaky - g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; - -namespace { - -IndexedDBDispatcher* const kDeletedIndexedDBDispatcherMarker = - reinterpret_cast<IndexedDBDispatcher*>(0x1); - -} // unnamed namespace - -IndexedDBDispatcher::IndexedDBDispatcher() { - g_idb_dispatcher_tls.Pointer()->Set(this); -} - -IndexedDBDispatcher::~IndexedDBDispatcher() { - g_idb_dispatcher_tls.Pointer()->Set(kDeletedIndexedDBDispatcherMarker); -} - -IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() { - if (g_idb_dispatcher_tls.Pointer()->Get() == - kDeletedIndexedDBDispatcherMarker) { - NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; - g_idb_dispatcher_tls.Pointer()->Set(nullptr); - } - if (g_idb_dispatcher_tls.Pointer()->Get()) - return g_idb_dispatcher_tls.Pointer()->Get(); - - IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher(); - if (WorkerThread::GetCurrentId()) - WorkerThread::AddObserver(dispatcher); - return dispatcher; -} - -void IndexedDBDispatcher::WillStopCurrentWorkerThread() { - delete this; -} - -void IndexedDBDispatcher::RegisterCursor(WebIDBCursorImpl* cursor) { - DCHECK(!base::ContainsKey(cursors_, cursor)); - cursors_.insert(cursor); -} - -void IndexedDBDispatcher::UnregisterCursor(WebIDBCursorImpl* cursor) { - DCHECK(base::ContainsKey(cursors_, cursor)); - cursors_.erase(cursor); -} - -void IndexedDBDispatcher::ResetCursorPrefetchCaches( - int64_t transaction_id, - WebIDBCursorImpl* exception_cursor) { - for (WebIDBCursorImpl* cursor : cursors_) { - if (cursor != exception_cursor && - cursor->transaction_id() == transaction_id) - cursor->ResetPrefetchCache(); - } -} - -} // namespace content diff --git a/content/renderer/indexed_db/indexed_db_dispatcher.h b/content/renderer/indexed_db/indexed_db_dispatcher.h deleted file mode 100644 index 18637782ba918..0000000000000 --- a/content/renderer/indexed_db/indexed_db_dispatcher.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 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 CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ -#define CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ - -#include <stddef.h> -#include <stdint.h> - -#include "base/gtest_prod_util.h" -#include "base/macros.h" -#include "base/strings/nullable_string16.h" -#include "content/common/content_export.h" -#include "content/public/renderer/worker_thread.h" -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" -#include "content/renderer/indexed_db/indexed_db_database_callbacks_impl.h" -#include "ipc/ipc_sync_message_filter.h" -#include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" -#include "url/origin.h" - -namespace content { -class WebIDBCursorImpl; - -// Handle the indexed db related communication for this context thread - the -// main thread and each worker thread have their own copies. -class CONTENT_EXPORT IndexedDBDispatcher : public WorkerThread::Observer { - public: - // Constructor made public to allow RenderThreadImpl to own a copy without - // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate - // two copies of RenderThreadImpl on the same thread. Everyone else probably - // wants to use ThreadSpecificInstance(). - IndexedDBDispatcher(); - ~IndexedDBDispatcher() override; - - static IndexedDBDispatcher* ThreadSpecificInstance(); - - // WorkerThread::Observer implementation. - void WillStopCurrentWorkerThread() override; - - void RegisterCursor(WebIDBCursorImpl* cursor); - void UnregisterCursor(WebIDBCursorImpl* cursor); - // Reset cursor prefetch caches for all cursors except exception_cursor. - void ResetCursorPrefetchCaches(int64_t transaction_id, - WebIDBCursorImpl* exception_cursor); - - private: - FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); - FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); - - std::unordered_set<WebIDBCursorImpl*> cursors_; - - DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ diff --git a/content/renderer/indexed_db/indexed_db_key_builders.h b/content/renderer/indexed_db/indexed_db_key_builders.h deleted file mode 100644 index 841dbb413b716..0000000000000 --- a/content/renderer/indexed_db/indexed_db_key_builders.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2013 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 CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_KEY_BUILDERS_H_ -#define CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_KEY_BUILDERS_H_ - -#include "base/macros.h" -#include "content/common/content_export.h" -#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" -#include "third_party/blink/public/common/indexeddb/indexeddb_key_path.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" - -namespace blink { - -class IndexedDBKeyRange; -class WebIDBKeyPath; -class WebIDBKeyRange; - -} // namespace blink - -namespace content { - -class CONTENT_EXPORT IndexedDBKeyBuilder { - public: - static blink::IndexedDBKey Build(blink::WebIDBKeyView key); - - private: - DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyBuilder); -}; - -class CONTENT_EXPORT WebIDBKeyBuilder { - public: - static blink::WebIDBKey Build(const blink::IndexedDBKey& key); - - private: - DISALLOW_COPY_AND_ASSIGN(WebIDBKeyBuilder); -}; - -class CONTENT_EXPORT IndexedDBKeyRangeBuilder { - public: - static blink::IndexedDBKeyRange Build(const blink::WebIDBKeyRange& key_range); - - // Builds a point range (containing a single key). - static blink::IndexedDBKeyRange Build(blink::WebIDBKeyView key); - - private: - DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyRangeBuilder); -}; - -class CONTENT_EXPORT WebIDBKeyRangeBuilder { - public: - static blink::WebIDBKeyRange Build(const blink::IndexedDBKeyRange& key); - - private: - DISALLOW_COPY_AND_ASSIGN(WebIDBKeyRangeBuilder); -}; - -class CONTENT_EXPORT IndexedDBKeyPathBuilder { - public: - static blink::IndexedDBKeyPath Build(const blink::WebIDBKeyPath& key_path); - - private: - DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyPathBuilder); -}; - -class CONTENT_EXPORT WebIDBKeyPathBuilder { - public: - static blink::WebIDBKeyPath Build(const blink::IndexedDBKeyPath& key_path); - - private: - DISALLOW_COPY_AND_ASSIGN(WebIDBKeyPathBuilder); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_KEY_BUILDERS_H_ diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index ca3e62dbfb695..22beddb89477b 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -88,7 +88,6 @@ #include "content/renderer/dom_storage/webstoragenamespace_impl.h" #include "content/renderer/effective_connection_type_helper.h" #include "content/renderer/gpu/frame_swap_message_queue.h" -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" #include "content/renderer/input/widget_input_handler_manager.h" #include "content/renderer/loader/resource_dispatcher.h" #include "content/renderer/low_memory_mode_controller.h" @@ -764,7 +763,6 @@ void RenderThreadImpl::Init() { base::Unretained(appcache_dispatcher())), GetWebMainThreadScheduler()->IPCTaskRunner()); dom_storage_dispatcher_.reset(new DomStorageDispatcher()); - main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); vc_manager_.reset(new VideoCaptureImplManager()); diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 886a283139a01..37ed299f06f1d 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -125,7 +125,6 @@ class CategorizedWorkerPool; class DomStorageDispatcher; class FrameSwapMessageQueue; class GpuVideoAcceleratorFactoriesImpl; -class IndexedDBDispatcher; class LowMemoryModeController; class MidiMessageFilter; class P2PSocketDispatcher; @@ -597,7 +596,6 @@ class CONTENT_EXPORT RenderThreadImpl // These objects live solely on the render thread. std::unique_ptr<AppCacheDispatcher> appcache_dispatcher_; std::unique_ptr<DomStorageDispatcher> dom_storage_dispatcher_; - std::unique_ptr<IndexedDBDispatcher> main_thread_indexed_db_dispatcher_; std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_; std::unique_ptr<RendererBlinkPlatformImpl> blink_platform_impl_; std::unique_ptr<ResourceDispatcher> resource_dispatcher_; diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc index 8324f0c43c199..0a22404b89d57 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -46,7 +46,6 @@ #include "content/renderer/dom_storage/session_web_storage_namespace_impl.h" #include "content/renderer/dom_storage/webstoragenamespace_impl.h" #include "content/renderer/image_capture/image_capture_frame_grabber.h" -#include "content/renderer/indexed_db/webidbfactory_impl.h" #include "content/renderer/loader/child_url_loader_factory_bundle.h" #include "content/renderer/loader/code_cache_loader_impl.h" #include "content/renderer/loader/resource_dispatcher.h" @@ -140,7 +139,6 @@ using blink::WebAudioLatencyHint; using blink::WebBlobRegistry; using blink::WebCanvasCaptureHandler; using blink::WebDatabaseObserver; -using blink::WebIDBFactory; using blink::WebImageCaptureFrameGrabber; using blink::WebMediaPlayer; using blink::WebMediaRecorderHandler; @@ -563,17 +561,6 @@ void RendererBlinkPlatformImpl::CloneSessionStorageNamespace( //------------------------------------------------------------------------------ -std::unique_ptr<blink::WebIDBFactory> -RendererBlinkPlatformImpl::CreateIdbFactory() { - blink::mojom::IDBFactoryPtrInfo web_idb_factory_host_info; - GetInterfaceProvider()->GetInterface( - mojo::MakeRequest(&web_idb_factory_host_info)); - return std::make_unique<WebIDBFactoryImpl>( - std::move(web_idb_factory_host_info)); -} - -//------------------------------------------------------------------------------ - WebString RendererBlinkPlatformImpl::FileSystemCreateOriginIdentifier( const blink::WebSecurityOrigin& origin) { return WebString::FromUTF8( diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h index 4ec814fd92c5a..d12e1fc7ebbf3 100644 --- a/content/renderer/renderer_blink_platform_impl.h +++ b/content/renderer/renderer_blink_platform_impl.h @@ -27,7 +27,6 @@ #include "third_party/blink/public/common/screen_orientation/web_screen_orientation_type.h" #include "third_party/blink/public/mojom/loader/code_cache.mojom.h" #include "third_party/blink/public/platform/modules/cache_storage/cache_storage.mojom.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/public/platform/modules/webdatabase/web_database.mojom.h" #if defined(OS_LINUX) @@ -125,7 +124,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { viz::FrameSinkId GenerateFrameSinkId() override; bool IsLockedToSite() const override; - std::unique_ptr<blink::WebIDBFactory> CreateIdbFactory() override; blink::WebString FileSystemCreateOriginIdentifier( const blink::WebSecurityOrigin& origin) override; diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn index acbc468afef33..2539260eca626 100644 --- a/content/test/BUILD.gn +++ b/content/test/BUILD.gn @@ -1704,10 +1704,6 @@ test("content_unittests") { "../renderer/gpu/layer_tree_view_unittest.cc", "../renderer/gpu/queue_message_swap_promise_unittest.cc", "../renderer/ico_image_decoder_unittest.cc", - "../renderer/indexed_db/mock_webidbcallbacks.cc", - "../renderer/indexed_db/mock_webidbcallbacks.h", - "../renderer/indexed_db/webidbcursor_impl_unittest.cc", - "../renderer/indexed_db/webidbdatabase_impl_unittest.cc", "../renderer/input/input_event_prediction_unittest.cc", "../renderer/input/main_thread_event_queue_unittest.cc", "../renderer/loader/resource_dispatcher_unittest.cc", diff --git a/content/test/data/indexeddb/cursor_prefetch.js b/content/test/data/indexeddb/cursor_prefetch.js index 076e6a9598fd3..772f5c0d0ae59 100644 --- a/content/test/data/indexeddb/cursor_prefetch.js +++ b/content/test/data/indexeddb/cursor_prefetch.js @@ -3,8 +3,8 @@ // found in the LICENSE file. // These constants should match the ones in -// content/child/indexed_db/webidbcursor_impl.h to make sure the test hits the -// right code paths. +// third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h to +// make sure the test hits the right code paths. var kPrefetchThreshold = 2; var kMinPrefetchAmount = 5; diff --git a/content/test/test_blink_web_unit_test_support.cc b/content/test/test_blink_web_unit_test_support.cc index 98a8fc1f92234..4d75061f092d2 100644 --- a/content/test/test_blink_web_unit_test_support.cc +++ b/content/test/test_blink_web_unit_test_support.cc @@ -214,12 +214,6 @@ blink::WebBlobRegistry* TestBlinkWebUnitTestSupport::GetBlobRegistry() { return &blob_registry_; } -std::unique_ptr<blink::WebIDBFactory> -TestBlinkWebUnitTestSupport::CreateIdbFactory() { - NOTREACHED() << "IndexedDB cannot be tested with in-process harnesses."; - return nullptr; -} - std::unique_ptr<blink::WebURLLoaderFactory> TestBlinkWebUnitTestSupport::CreateDefaultURLLoaderFactory() { return std::make_unique<WebURLLoaderFactoryWithMock>( diff --git a/content/test/test_blink_web_unit_test_support.h b/content/test/test_blink_web_unit_test_support.h index 75010ad587338..44e7e9594f9a6 100644 --- a/content/test/test_blink_web_unit_test_support.h +++ b/content/test/test_blink_web_unit_test_support.h @@ -34,7 +34,6 @@ class TestBlinkWebUnitTestSupport : public BlinkPlatformImpl { ~TestBlinkWebUnitTestSupport() override; blink::WebBlobRegistry* GetBlobRegistry() override; - std::unique_ptr<blink::WebIDBFactory> CreateIdbFactory() override; std::unique_ptr<blink::WebURLLoaderFactory> CreateDefaultURLLoaderFactory() override; diff --git a/third_party/blink/common/BUILD.gn b/third_party/blink/common/BUILD.gn index 6da01ea57ace9..a810c195e6a55 100644 --- a/third_party/blink/common/BUILD.gn +++ b/third_party/blink/common/BUILD.gn @@ -33,11 +33,11 @@ jumbo_source_set("common") { "frame/frame_policy.cc", "frame/from_ad_state.cc", "frame/user_activation_state.cc", + "indexeddb/indexed_db_default_mojom_traits.cc", "indexeddb/indexeddb_key.cc", "indexeddb/indexeddb_key_path.cc", "indexeddb/indexeddb_key_range.cc", "indexeddb/indexeddb_metadata.cc", - "indexeddb/indexeddb_mojom_traits.cc", "manifest/manifest.cc", "manifest/manifest_icon_selector.cc", "messaging/cloneable_message.cc", diff --git a/third_party/blink/common/indexeddb/indexeddb_mojom_traits.cc b/third_party/blink/common/indexeddb/indexed_db_default_mojom_traits.cc similarity index 99% rename from third_party/blink/common/indexeddb/indexeddb_mojom_traits.cc rename to third_party/blink/common/indexeddb/indexed_db_default_mojom_traits.cc index b1b6d00555e59..f8386d852fc97 100644 --- a/third_party/blink/common/indexeddb/indexeddb_mojom_traits.cc +++ b/third_party/blink/common/indexeddb/indexed_db_default_mojom_traits.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "third_party/blink/public/common/indexeddb/indexeddb_mojom_traits.h" +#include "third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h" #include <utility> diff --git a/third_party/blink/common/indexeddb/indexeddb_key.cc b/third_party/blink/common/indexeddb/indexeddb_key.cc index 99f2fce6dff2a..b5c331d0f8cf9 100644 --- a/third_party/blink/common/indexeddb/indexeddb_key.cc +++ b/third_party/blink/common/indexeddb/indexeddb_key.cc @@ -24,10 +24,10 @@ namespace { // Very rough estimate of minimum key size overhead. const size_t kOverheadSize = 16; -static size_t CalculateArraySize(const IndexedDBKey::KeyArray& keys) { +size_t CalculateArraySize(const IndexedDBKey::KeyArray& keys) { size_t size(0); - for (size_t i = 0; i < keys.size(); ++i) - size += keys[i].size_estimate(); + for (const auto& key : keys) + size += key.size_estimate(); return size; } diff --git a/third_party/blink/public/BUILD.gn b/third_party/blink/public/BUILD.gn index 6c2aeb26e3d8d..0fe66079bd0f9 100644 --- a/third_party/blink/public/BUILD.gn +++ b/third_party/blink/public/BUILD.gn @@ -128,13 +128,11 @@ source_set("blink_headers") { "platform/mac/web_sandbox_support.h", "platform/mac/web_scrollbar_theme.h", "platform/modules/background_fetch/web_background_fetch_registration.h", + "platform/modules/indexeddb/indexed_db_key_builder.h", "platform/modules/indexeddb/web_idb_callbacks.h", - "platform/modules/indexeddb/web_idb_cursor.h", - "platform/modules/indexeddb/web_idb_database.h", "platform/modules/indexeddb/web_idb_database_callbacks.h", "platform/modules/indexeddb/web_idb_database_error.h", "platform/modules/indexeddb/web_idb_database_exception.h", - "platform/modules/indexeddb/web_idb_factory.h", "platform/modules/indexeddb/web_idb_key.h", "platform/modules/indexeddb/web_idb_key_path.h", "platform/modules/indexeddb/web_idb_key_range.h", diff --git a/third_party/blink/public/common/BUILD.gn b/third_party/blink/public/common/BUILD.gn index 9917892c64777..89dc9ca24b539 100644 --- a/third_party/blink/public/common/BUILD.gn +++ b/third_party/blink/public/common/BUILD.gn @@ -52,11 +52,11 @@ source_set("headers") { "frame/user_activation_state.h", "frame/user_activation_update_source.h", "frame/user_activation_update_type.h", + "indexeddb/indexed_db_default_mojom_traits.h", "indexeddb/indexeddb_key.h", "indexeddb/indexeddb_key_path.h", "indexeddb/indexeddb_key_range.h", "indexeddb/indexeddb_metadata.h", - "indexeddb/indexeddb_mojom_traits.h", "indexeddb/web_idb_types.h", "manifest/manifest.h", "manifest/manifest_icon_selector.h", diff --git a/third_party/blink/public/common/indexeddb/indexed_db_default.typemap b/third_party/blink/public/common/indexeddb/indexed_db_default.typemap new file mode 100644 index 0000000000000..76bb446c2742c --- /dev/null +++ b/third_party/blink/public/common/indexeddb/indexed_db_default.typemap @@ -0,0 +1,31 @@ +# Copyright 2018 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. + +mojom = "//third_party/blink/public/mojom/indexeddb/indexeddb.mojom" +public_headers = [ + "//third_party/blink/public/common/indexeddb/indexeddb_key.h", + "//third_party/blink/public/common/indexeddb/indexeddb_key_path.h", + "//third_party/blink/public/common/indexeddb/indexeddb_key_range.h", + "//third_party/blink/public/common/indexeddb/indexeddb_metadata.h", + "//third_party/blink/public/common/indexeddb/web_idb_types.h", +] +traits_headers = [ + "//mojo/public/cpp/bindings/array_traits_span.h", + "//third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h", +] +type_mappings = [ + "blink.mojom.IDBCursorDirection=::blink::WebIDBCursorDirection", + "blink.mojom.IDBDataLoss=::blink::WebIDBDataLoss", + "blink.mojom.IDBDatabaseMetadata=::blink::IndexedDBDatabaseMetadata", + "blink.mojom.IDBIndexKeys=::blink::IndexedDBIndexKeys", + "blink.mojom.IDBIndexMetadata=::blink::IndexedDBIndexMetadata", + "blink.mojom.IDBKey=::blink::IndexedDBKey", + "blink.mojom.IDBKeyPath=::blink::IndexedDBKeyPath", + "blink.mojom.IDBKeyRange=::blink::IndexedDBKeyRange", + "blink.mojom.IDBObjectStoreMetadata=::blink::IndexedDBObjectStoreMetadata", + "blink.mojom.IDBOperationType=::blink::WebIDBOperationType", + "blink.mojom.IDBPutMode=::blink::WebIDBPutMode", + "blink.mojom.IDBTaskType=::blink::WebIDBTaskType", + "blink.mojom.IDBTransactionMode=::blink::WebIDBTransactionMode", +] diff --git a/third_party/blink/public/common/indexeddb/indexeddb_mojom_traits.h b/third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h similarity index 97% rename from third_party/blink/public/common/indexeddb/indexeddb_mojom_traits.h rename to third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h index 583b2bae49d7d..b1620f4ba5cf6 100644 --- a/third_party/blink/public/common/indexeddb/indexeddb_mojom_traits.h +++ b/third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXEDDB_MOJOM_TRAITS_H_ -#define THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXEDDB_MOJOM_TRAITS_H_ +#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXED_DB_DEFAULT_MOJOM_TRAITS_H_ +#define THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXED_DB_DEFAULT_MOJOM_TRAITS_H_ #include "base/containers/span.h" #include "third_party/blink/public/common/common_export.h" @@ -232,4 +232,4 @@ struct BLINK_COMMON_EXPORT } // namespace mojo -#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXEDDB_MOJOM_TRAITS_H_ +#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_INDEXEDDB_INDEXED_DB_DEFAULT_MOJOM_TRAITS_H_ diff --git a/third_party/blink/public/common/indexeddb/indexeddb.typemap b/third_party/blink/public/common/indexeddb/indexeddb.typemap deleted file mode 100644 index 5210388b8b3bd..0000000000000 --- a/third_party/blink/public/common/indexeddb/indexeddb.typemap +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2016 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. - -mojom = "//third_party/blink/public/mojom/indexeddb/indexeddb.mojom" -public_headers = [ - "//third_party/blink/public/common/indexeddb/indexeddb_key.h", - "//third_party/blink/public/common/indexeddb/indexeddb_key_path.h", - "//third_party/blink/public/common/indexeddb/indexeddb_key_range.h", - "//third_party/blink/public/common/indexeddb/indexeddb_metadata.h", - "//third_party/blink/public/common/indexeddb/web_idb_types.h", -] -traits_headers = [ - "//mojo/public/cpp/bindings/array_traits_span.h", - "//third_party/blink/public/common/indexeddb/indexeddb_mojom_traits.h", -] -type_mappings = [ - "blink.mojom.IDBCursorDirection=blink::WebIDBCursorDirection", - "blink.mojom.IDBDataLoss=blink::WebIDBDataLoss", - "blink.mojom.IDBDatabaseMetadata=blink::IndexedDBDatabaseMetadata", - "blink.mojom.IDBIndexKeys=blink::IndexedDBIndexKeys", - "blink.mojom.IDBIndexMetadata=blink::IndexedDBIndexMetadata", - "blink.mojom.IDBKey=blink::IndexedDBKey", - "blink.mojom.IDBKeyPath=blink::IndexedDBKeyPath", - "blink.mojom.IDBKeyRange=blink::IndexedDBKeyRange", - "blink.mojom.IDBObjectStoreMetadata=blink::IndexedDBObjectStoreMetadata", - "blink.mojom.IDBOperationType=blink::WebIDBOperationType", - "blink.mojom.IDBPutMode=blink::WebIDBPutMode", - "blink.mojom.IDBTaskType=blink::WebIDBTaskType", - "blink.mojom.IDBTransactionMode=blink::WebIDBTransactionMode", -] diff --git a/third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h b/third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h new file mode 100644 index 0000000000000..28a5e8fad1952 --- /dev/null +++ b/third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h @@ -0,0 +1,76 @@ +// Copyright (c) 2013 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 THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_INDEXED_DB_KEY_BUILDER_H_ +#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_INDEXED_DB_KEY_BUILDER_H_ + +#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_key_path.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" +#include "third_party/blink/public/platform/web_common.h" + +namespace blink { + +class IndexedDBKeyRange; +class WebIDBKeyPath; +class WebIDBKeyRange; + +class BLINK_EXPORT IndexedDBKeyBuilder { + public: + static IndexedDBKey Build(WebIDBKeyView key); + + private: + DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyBuilder); +}; + +class BLINK_EXPORT WebIDBKeyBuilder { + public: + static WebIDBKey Build(const IndexedDBKey& key); + static WebIDBKey Build(const WebIDBKeyView& key); + + private: + DISALLOW_COPY_AND_ASSIGN(WebIDBKeyBuilder); +}; + +class BLINK_EXPORT IndexedDBKeyRangeBuilder { + public: + static IndexedDBKeyRange Build(const WebIDBKeyRange& key_range); + + // Builds a point range (containing a single key). + static IndexedDBKeyRange Build(WebIDBKeyView key); + + private: + DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyRangeBuilder); +}; + +class BLINK_EXPORT WebIDBKeyRangeBuilder { + public: + static WebIDBKeyRange Build(const IndexedDBKeyRange& key); + + // Builds a point range (containing a single key). + static WebIDBKeyRange Build(WebIDBKeyView key); + + private: + DISALLOW_COPY_AND_ASSIGN(WebIDBKeyRangeBuilder); +}; + +class BLINK_EXPORT IndexedDBKeyPathBuilder { + public: + static IndexedDBKeyPath Build(const WebIDBKeyPath& key_path); + + private: + DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyPathBuilder); +}; + +class BLINK_EXPORT WebIDBKeyPathBuilder { + public: + static WebIDBKeyPath Build(const IndexedDBKeyPath& key_path); + + private: + DISALLOW_COPY_AND_ASSIGN(WebIDBKeyPathBuilder); +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_INDEXED_DB_KEY_BUILDER_H_ diff --git a/third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h b/third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h index 23433150468b1..deac9f44d7347 100644 --- a/third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h +++ b/third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h @@ -40,11 +40,11 @@ struct WebIDBObservation; class WebIDBDatabaseCallbacks { public: - using ObservationIndexMap = std::unordered_map<int32_t, std::vector<int32_t>>; + using ObservationIndexMap = std::unordered_map<int32_t, WebVector<int32_t>>; // Maps observer to transaction, which needs an id and a scope. using TransactionMap = - std::unordered_map<int32_t, std::pair<int64_t, std::vector<int64_t>>>; + std::unordered_map<int32_t, std::pair<int64_t, WebVector<int64_t>>>; virtual ~WebIDBDatabaseCallbacks() = default; diff --git a/third_party/blink/public/platform/modules/indexeddb/web_idb_key.h b/third_party/blink/public/platform/modules/indexeddb/web_idb_key.h index cdacdfe42d06c..7255f7d9c00ef 100644 --- a/third_party/blink/public/platform/modules/indexeddb/web_idb_key.h +++ b/third_party/blink/public/platform/modules/indexeddb/web_idb_key.h @@ -62,7 +62,7 @@ class WebIDBKeyArrayView { // The Blink object wrapped by WebIDBKey is immutable, so WebIDBKeyView // instances are implicitly const references. // -// Having both WebIDBKeyView and WebIDBView is extra complexity, and we pay this +// Having both WebIDBKeyView and WebIDBKey is extra complexity, and we pay this // price to avoid unnecessary memory copying. Specifically, WebIDBKeyView is // used to issue requests to the IndexedDB backing store. // @@ -99,6 +99,19 @@ class WebIDBKeyView { // Only valid for NumberType. BLINK_EXPORT double Number() const; + BLINK_EXPORT size_t SizeEstimate() const; + + // TODO(cmp): Ensure |private_| can never be null. + // + // SizeEstimate() can be called when |private_| is null. That happens if and + // only if the |WebIDBKey| instance is created using WebIDBKey::CreateNull(). + // + // Eventually, WebIDBKey::CreateNull() will change so that case will lead to + // a non-null |private_|. At that time, this null check can change to a + // DCHECK that |private_| is not null and the special null case handling can + // be removed. + BLINK_EXPORT bool IsNull() const { return !private_; } + private: const IDBKey* const private_; }; @@ -124,18 +137,25 @@ class WebIDBKey { BLINK_EXPORT static WebIDBKey CreateNull() noexcept { return WebIDBKey(); } // The default constructor must not be used explicitly. - // It is only provided for WebVector's use. + // It is only provided for WebVector and Mojo's use. BLINK_EXPORT WebIDBKey() noexcept; BLINK_EXPORT WebIDBKey(WebIDBKey&&) noexcept; BLINK_EXPORT WebIDBKey& operator=(WebIDBKey&&) noexcept; + // TODO(cmp): Remove copy and assignment constructors when Vector<->WebVector + // conversions are no longer needed. + BLINK_EXPORT WebIDBKey(const WebIDBKey& rkey); + BLINK_EXPORT WebIDBKey& operator=(const WebIDBKey& rkey); + BLINK_EXPORT ~WebIDBKey(); BLINK_EXPORT WebIDBKeyView View() const { return WebIDBKeyView(private_.get()); } + BLINK_EXPORT size_t SizeEstimate() const { return View().SizeEstimate(); } + #if INSIDE_BLINK explicit WebIDBKey(std::unique_ptr<IDBKey>) noexcept; WebIDBKey& operator=(std::unique_ptr<IDBKey>) noexcept; @@ -147,11 +167,6 @@ class WebIDBKey { #endif // INSIDE_BLINK private: - // WebIDBKey has to be move-only, because std::unique_ptr is move-only. Making - // the restriction explicit results in slightly better compilation error - // messages in code that attempts copying. - WebIDBKey(const WebIDBKey&) = delete; - WebIDBKey& operator=(const WebIDBKey&) = delete; std::unique_ptr<IDBKey> private_; }; diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h index b9acf7744b61a..6225f1f5faff3 100644 --- a/third_party/blink/public/platform/platform.h +++ b/third_party/blink/public/platform/platform.h @@ -50,7 +50,6 @@ #include "third_party/blink/public/mojom/loader/code_cache.mojom-shared.h" #include "third_party/blink/public/platform/blame_context.h" #include "third_party/blink/public/platform/code_cache_loader.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/public/platform/user_metrics_action.h" #include "third_party/blink/public/platform/web_audio_device.h" #include "third_party/blink/public/platform/web_common.h" @@ -298,11 +297,6 @@ class BLINK_PLATFORM_EXPORT Platform { virtual WebString ConvertIDNToUnicode(const WebString& host) { return host; } - // IndexedDB ---------------------------------------------------------- - - // Must return non-null. - virtual std::unique_ptr<WebIDBFactory> CreateIdbFactory() { return nullptr; } - // History ------------------------------------------------------------- // Returns the hash for the given canonicalized URL for use in visited diff --git a/third_party/blink/public/public_typemaps.gni b/third_party/blink/public/public_typemaps.gni index 92a1825d091e4..d59930b8015a7 100644 --- a/third_party/blink/public/public_typemaps.gni +++ b/third_party/blink/public/public_typemaps.gni @@ -5,7 +5,7 @@ # These are typemaps which are exposed by Blink to its embedder. typemaps = [ "//third_party/blink/public/platform/content_security_policy.typemap", - "//third_party/blink/public/common/indexeddb/indexeddb.typemap", + "//third_party/blink/public/common/indexeddb/indexed_db_default.typemap", "//third_party/blink/public/common/manifest/display_mode.typemap", "//third_party/blink/public/common/manifest/manifest.typemap", "//third_party/blink/public/common/notifications/notification_types.typemap", diff --git a/third_party/blink/renderer/modules/BUILD.gn b/third_party/blink/renderer/modules/BUILD.gn index b03f4ebf53134..43e9b6676acad 100644 --- a/third_party/blink/renderer/modules/BUILD.gn +++ b/third_party/blink/renderer/modules/BUILD.gn @@ -276,10 +276,14 @@ jumbo_source_set("unit_tests") { "indexeddb/idb_test_helper.cc", "indexeddb/idb_transaction_test.cc", "indexeddb/idb_value_wrapping_test.cc", + "indexeddb/mock_web_idb_callbacks.cc", + "indexeddb/mock_web_idb_callbacks.h", "indexeddb/mock_web_idb_database.cc", "indexeddb/mock_web_idb_database.h", "indexeddb/mock_web_idb_factory.cc", "indexeddb/mock_web_idb_factory.h", + "indexeddb/web_idb_cursor_impl_unittest.cc", + "indexeddb/web_idb_database_impl_unittest.cc", "manifest/image_resource_type_converters_test.cc", "media_controls/elements/media_control_animated_arrow_container_element_test.cc", "media_controls/elements/media_control_display_cutout_fullscreen_button_element_test.cc", diff --git a/third_party/blink/renderer/modules/exported/BUILD.gn b/third_party/blink/renderer/modules/exported/BUILD.gn index f79e1d10f29da..bfc6251ccf7e1 100644 --- a/third_party/blink/renderer/modules/exported/BUILD.gn +++ b/third_party/blink/renderer/modules/exported/BUILD.gn @@ -5,6 +5,7 @@ import("//third_party/blink/renderer/modules/modules.gni") blink_modules_sources("exported") { sources = [ + "indexed_db_key_builder.cc", "web_apply_constraints_request.cc", "web_ax_context.cc", "web_ax_object.cc", diff --git a/content/renderer/indexed_db/indexed_db_key_builders.cc b/third_party/blink/renderer/modules/exported/indexed_db_key_builder.cc similarity index 63% rename from content/renderer/indexed_db/indexed_db_key_builders.cc rename to third_party/blink/renderer/modules/exported/indexed_db_key_builder.cc index 11414a0747d0f..8c2b898592591 100644 --- a/content/renderer/indexed_db/indexed_db_key_builders.cc +++ b/third_party/blink/renderer/modules/exported/indexed_db_key_builder.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/indexed_db_key_builders.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" #include <stddef.h> @@ -11,7 +11,6 @@ #include <utility> #include <vector> -#include "base/logging.h" #include "third_party/blink/public/common/indexeddb/indexeddb_key_range.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" @@ -19,32 +18,18 @@ #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" #include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" -using blink::IndexedDBKey; -using blink::IndexedDBKeyPath; -using blink::IndexedDBKeyRange; -using blink::WebIDBKey; -using blink::WebIDBKeyRange; -using blink::WebIDBKeyView; -using blink::kWebIDBKeyTypeArray; -using blink::kWebIDBKeyTypeBinary; -using blink::kWebIDBKeyTypeDate; -using blink::kWebIDBKeyTypeInvalid; -using blink::kWebIDBKeyTypeMin; -using blink::kWebIDBKeyTypeNull; -using blink::kWebIDBKeyTypeNumber; -using blink::kWebIDBKeyTypeString; -using blink::WebVector; -using blink::WebString; +namespace blink { namespace { -IndexedDBKey::KeyArray CopyKeyArray(blink::WebIDBKeyArrayView array) { +IndexedDBKey::KeyArray CopyKeyArray(WebIDBKeyArrayView array) { IndexedDBKey::KeyArray result; const size_t array_size = array.size(); result.reserve(array_size); for (size_t i = 0; i < array_size; ++i) - result.emplace_back(content::IndexedDBKeyBuilder::Build(array[i])); + result.emplace_back(IndexedDBKeyBuilder::Build(array[i])); return result; } @@ -58,15 +43,13 @@ std::vector<base::string16> CopyArray(const WebVector<WebString>& array) { } // anonymous namespace -namespace content { - // static -IndexedDBKey IndexedDBKeyBuilder::Build(blink::WebIDBKeyView key) { +IndexedDBKey IndexedDBKeyBuilder::Build(WebIDBKeyView key) { switch (key.KeyType()) { case kWebIDBKeyTypeArray: return IndexedDBKey(CopyKeyArray(key.ArrayView())); case kWebIDBKeyTypeBinary: { - const blink::WebData data = key.Binary(); + const WebData data = key.Binary(); std::string key_string; key_string.reserve(data.size()); @@ -88,12 +71,43 @@ IndexedDBKey IndexedDBKeyBuilder::Build(blink::WebIDBKeyView key) { case kWebIDBKeyTypeInvalid: return IndexedDBKey(key.KeyType()); case kWebIDBKeyTypeMin: - default: NOTREACHED(); return IndexedDBKey(); } } +// static +WebIDBKey WebIDBKeyBuilder::Build(const WebIDBKeyView& key) { + switch (key.KeyType()) { + case kWebIDBKeyTypeArray: { + const WebIDBKeyArrayView& array = key.ArrayView(); + WebVector<WebIDBKey> web_idb_keys; + const size_t array_size = array.size(); + web_idb_keys.reserve(array_size); + for (size_t i = 0; i < array_size; ++i) + web_idb_keys.emplace_back(Build(array[i])); + return WebIDBKey::CreateArray(std::move(web_idb_keys)); + } + case kWebIDBKeyTypeBinary: { + const WebData data = key.Binary(); + return WebIDBKey::CreateBinary(data); + } + case kWebIDBKeyTypeString: + return WebIDBKey::CreateString(key.String()); + case kWebIDBKeyTypeDate: + return WebIDBKey::CreateDate(key.Date()); + case kWebIDBKeyTypeNumber: + return WebIDBKey::CreateNumber(key.Number()); + case kWebIDBKeyTypeInvalid: + return WebIDBKey::CreateInvalid(); + case kWebIDBKeyTypeNull: + return WebIDBKey::CreateNull(); + case kWebIDBKeyTypeMin: + NOTREACHED(); + return WebIDBKey::CreateInvalid(); + } +} + // static WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { switch (key.type()) { @@ -105,8 +119,11 @@ WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { web_idb_keys.emplace_back(Build(array_element)); return WebIDBKey::CreateArray(std::move(web_idb_keys)); } - case kWebIDBKeyTypeBinary: - return WebIDBKey::CreateBinary(key.binary()); + case kWebIDBKeyTypeBinary: { + const std::string& str = key.binary(); + const WebData& data = WebData(str.c_str(), str.length()); + return WebIDBKey::CreateBinary(data); + } case kWebIDBKeyTypeString: return WebIDBKey::CreateString(WebString::FromUTF16(key.string())); case kWebIDBKeyTypeDate: @@ -118,7 +135,6 @@ WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) { case kWebIDBKeyTypeNull: return WebIDBKey::CreateNull(); case kWebIDBKeyTypeMin: - default: NOTREACHED(); return WebIDBKey::CreateInvalid(); } @@ -139,6 +155,13 @@ IndexedDBKeyRange IndexedDBKeyRangeBuilder::Build(WebIDBKeyView key) { false /* lower_open */, false /* upper_open */); } +// static +WebIDBKeyRange WebIDBKeyRangeBuilder::Build(WebIDBKeyView key) { + return WebIDBKeyRange(WebIDBKeyBuilder::Build(key), + WebIDBKeyBuilder::Build(key), false /* lower_open */, + false /* upper_open */); +} + // static WebIDBKeyRange WebIDBKeyRangeBuilder::Build( const IndexedDBKeyRange& key_range) { @@ -148,43 +171,31 @@ WebIDBKeyRange WebIDBKeyRangeBuilder::Build( } // static -IndexedDBKeyPath IndexedDBKeyPathBuilder::Build( - const blink::WebIDBKeyPath& key_path) { +IndexedDBKeyPath IndexedDBKeyPathBuilder::Build(const WebIDBKeyPath& key_path) { switch (key_path.KeyPathType()) { - case blink::kWebIDBKeyPathTypeString: + case kWebIDBKeyPathTypeString: return IndexedDBKeyPath(key_path.String().Utf16()); - case blink::kWebIDBKeyPathTypeArray: + case kWebIDBKeyPathTypeArray: return IndexedDBKeyPath(CopyArray(key_path.Array())); - case blink::kWebIDBKeyPathTypeNull: - return IndexedDBKeyPath(); - default: - NOTREACHED(); + case kWebIDBKeyPathTypeNull: return IndexedDBKeyPath(); } } // static -blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build( - const IndexedDBKeyPath& key_path) { +WebIDBKeyPath WebIDBKeyPathBuilder::Build(const IndexedDBKeyPath& key_path) { switch (key_path.type()) { - case blink::kWebIDBKeyPathTypeString: - return blink::WebIDBKeyPath::Create( - WebString::FromUTF16(key_path.string())); - case blink::kWebIDBKeyPathTypeArray: { + case kWebIDBKeyPathTypeString: + return WebIDBKeyPath::Create(WebString::FromUTF16(key_path.string())); + case kWebIDBKeyPathTypeArray: { WebVector<WebString> key_path_vector(key_path.array().size()); - std::transform(key_path.array().begin(), key_path.array().end(), - key_path_vector.begin(), - [](const typename base::string16& s) { - return WebString::FromUTF16(s); - }); - return blink::WebIDBKeyPath::Create(key_path_vector); + for (const auto& item : key_path.array()) + key_path_vector.emplace_back(WebString::FromUTF16(item)); + return WebIDBKeyPath::Create(key_path_vector); } - case blink::kWebIDBKeyPathTypeNull: - return blink::WebIDBKeyPath::CreateNull(); - default: - NOTREACHED(); - return blink::WebIDBKeyPath::CreateNull(); + case kWebIDBKeyPathTypeNull: + return WebIDBKeyPath::CreateNull(); } } -} // namespace content +} // namespace blink diff --git a/third_party/blink/renderer/modules/exported/web_idb_key.cc b/third_party/blink/renderer/modules/exported/web_idb_key.cc index 600bfce508072..4b2641073118e 100644 --- a/third_party/blink/renderer/modules/exported/web_idb_key.cc +++ b/third_party/blink/renderer/modules/exported/web_idb_key.cc @@ -68,6 +68,23 @@ double WebIDBKeyView::Number() const { return private_->Number(); } +size_t WebIDBKeyView::SizeEstimate() const { + // TODO(cmp): Ensure |private_| can never be null. + // + // SizeEstimate() can be called when |private_| is null. That happens if and + // only if the |WebIDBKey| instance is created using WebIDBKey::CreateNull(). + // + // Eventually, WebIDBKey::CreateNull() will change so that case will lead to + // a non-null |private_|. At that time, this null check can change to a + // DCHECK that |private_| is not null and the special null case handling can + // be removed. + if (this->IsNull()) { + return IDBKey::kIDBKeyOverheadSize; + } + + return private_->SizeEstimate(); +} + WebIDBKey WebIDBKey::CreateArray(WebVector<WebIDBKey> array) { IDBKey::KeyArray keys; keys.ReserveCapacity(SafeCast<wtf_size_t>(array.size())); @@ -112,4 +129,11 @@ WebIDBKey& WebIDBKey::operator=(std::unique_ptr<IDBKey> idb_key) noexcept { return *this; } +WebIDBKey::WebIDBKey(const WebIDBKey& rkey) + : private_(IDBKey::Clone(rkey.private_)) {} +WebIDBKey& WebIDBKey::operator=(const WebIDBKey& rkey) { + private_ = IDBKey::Clone(rkey.private_); + return *this; +} + } // namespace blink diff --git a/third_party/blink/renderer/modules/indexeddb/BUILD.gn b/third_party/blink/renderer/modules/indexeddb/BUILD.gn index b16dcc0321f08..624dbe229fb4f 100644 --- a/third_party/blink/renderer/modules/indexeddb/BUILD.gn +++ b/third_party/blink/renderer/modules/indexeddb/BUILD.gn @@ -58,13 +58,34 @@ blink_modules_sources("indexeddb") { "idb_version_change_event.cc", "idb_version_change_event.h", "indexed_db.h", + "indexed_db_blink_mojom_traits.cc", + "indexed_db_blink_mojom_traits.h", + "indexed_db_callbacks_impl.cc", + "indexed_db_callbacks_impl.h", "indexed_db_client.cc", "indexed_db_client.h", + "indexed_db_database_callbacks_impl.cc", + "indexed_db_database_callbacks_impl.h", + "indexed_db_dispatcher.cc", + "indexed_db_dispatcher.h", "inspector_indexed_db_agent.cc", "inspector_indexed_db_agent.h", "web_idb_callbacks_impl.cc", "web_idb_callbacks_impl.h", + "web_idb_cursor.h", + "web_idb_cursor_impl.cc", + "web_idb_cursor_impl.h", + "web_idb_database.h", "web_idb_database_callbacks_impl.cc", "web_idb_database_callbacks_impl.h", + "web_idb_database_impl.cc", + "web_idb_database_impl.h", + "web_idb_factory.h", + "web_idb_factory_impl.cc", + "web_idb_factory_impl.h", + ] + + public_deps = [ + "//third_party/blink/public/mojom:mojom_modules_blink", ] } diff --git a/third_party/blink/renderer/modules/indexeddb/OWNERS b/third_party/blink/renderer/modules/indexeddb/OWNERS index a740487227f3a..4d50d635c42b9 100644 --- a/third_party/blink/renderer/modules/indexeddb/OWNERS +++ b/third_party/blink/renderer/modules/indexeddb/OWNERS @@ -1,4 +1,9 @@ file://content/browser/indexed_db/OWNERS +per-file *_mojom_traits*.*=set noparent +per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS +per-file *.typemap=set noparent +per-file *.typemap=file://ipc/SECURITY_OWNERS + # TEAM: storage-dev@chromium.org # COMPONENT: Blink>Storage>IndexedDB diff --git a/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc b/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc index 8d1a9d211d765..4ee0d300acf79 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc @@ -27,7 +27,6 @@ #include <limits> #include <memory> -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" #include "third_party/blink/renderer/bindings/modules/v8/to_v8_for_modules.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h" @@ -38,6 +37,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_object_store.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/v8_private_property.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_cursor.h b/third_party/blink/renderer/modules/indexeddb/idb_cursor.h index 64cec7cd8dc5b..821aaf2363efa 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_cursor.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_cursor.h @@ -29,12 +29,12 @@ #include <memory> #include "base/memory/scoped_refptr.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/modules/v8/idb_object_store_or_idb_index.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/wtf/compiler.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h b/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h index 91223d4d4d56f..5914effa6de09 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h @@ -28,9 +28,9 @@ #include <memory> #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" namespace blink { diff --git a/third_party/blink/renderer/modules/indexeddb/idb_database.cc b/third_party/blink/renderer/modules/indexeddb/idb_database.cc index f16cf9902feac..3bad7175d516c 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_database.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_database.cc @@ -208,7 +208,7 @@ void IDBDatabase::OnChanges( IDBTransaction* transaction = nullptr; auto it = transactions.find(map_entry.first); if (it != transactions.end()) { - const std::pair<int64_t, std::vector<int64_t>>& obs_txn = it->second; + const std::pair<int64_t, WebVector<int64_t>>& obs_txn = it->second; HashSet<String> stores; for (int64_t store_id : obs_txn.second) { stores.insert(metadata_.object_stores.at(store_id)->name); diff --git a/third_party/blink/renderer/modules/indexeddb/idb_database.h b/third_party/blink/renderer/modules/indexeddb/idb_database.h index 556f2054dedc4..bf997610bd0a0 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_database.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_database.h @@ -29,7 +29,6 @@ #include <memory> #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_string_sequence.h" @@ -43,6 +42,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_object_store_parameters.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_factory.cc b/third_party/blink/renderer/modules/indexeddb/idb_factory.cc index 38167d518f68d..f1c3beb121ead 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_factory.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_factory.cc @@ -31,9 +31,10 @@ #include <memory> #include <utility> +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" +#include "third_party/blink/public/platform/interface_provider.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" #include "third_party/blink/public/platform/platform.h" @@ -53,6 +54,8 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db_client.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/histogram.h" @@ -186,8 +189,13 @@ static bool IsContextValid(ExecutionContext* context) { } WebIDBFactory* IDBFactory::GetFactory() { - if (!web_idb_factory_) - web_idb_factory_ = Platform::Current()->CreateIdbFactory(); + if (!web_idb_factory_) { + mojom::blink::IDBFactoryPtrInfo web_idb_factory_host_info; + Platform::Current()->GetInterfaceProvider()->GetInterface( + mojo::MakeRequest(&web_idb_factory_host_info)); + web_idb_factory_ = std::make_unique<WebIDBFactoryImpl>( + std::move(web_idb_factory_host_info)); + } return web_idb_factory_.get(); } diff --git a/third_party/blink/renderer/modules/indexeddb/idb_factory.h b/third_party/blink/renderer/modules/indexeddb/idb_factory.h index 3d7e36da50251..3ff9b1c9ba3c2 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_factory.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_factory.h @@ -29,9 +29,9 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_FACTORY_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_FACTORY_H_ -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/heap/handle.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_index.h b/third_party/blink/renderer/modules/indexeddb/idb_index.h index 99a4824158048..e78ec6ff4e938 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_index.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_index.h @@ -27,13 +27,13 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_INDEX_H_ #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_key.cc b/third_party/blink/renderer/modules/indexeddb/idb_key.cc index 8ed421c8c7474..d061b3e3fedd5 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_key.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_key.cc @@ -34,6 +34,40 @@ namespace blink { +namespace { + +size_t CalculateIDBKeyArraySize(const IDBKey::KeyArray& keys) { + size_t size(0); + for (const auto& key : keys) + size += key.get()->SizeEstimate(); + return size; +} + +} // namespace + +IDBKey::IDBKey() : type_(kInvalidType), size_estimate_(kIDBKeyOverheadSize) {} + +IDBKey::IDBKey(Type type, double number) + : type_(type), + number_(number), + size_estimate_(kIDBKeyOverheadSize + sizeof(number_)) {} + +IDBKey::IDBKey(const String& value) + : type_(kStringType), + string_(value), + size_estimate_(kIDBKeyOverheadSize + (string_.length() * sizeof(UChar))) { +} + +IDBKey::IDBKey(scoped_refptr<SharedBuffer> value) + : type_(kBinaryType), + binary_(std::move(value)), + size_estimate_(kIDBKeyOverheadSize + binary_.get()->size()) {} + +IDBKey::IDBKey(KeyArray key_array) + : type_(kArrayType), + array_(std::move(key_array)), + size_estimate_(kIDBKeyOverheadSize + CalculateIDBKeyArraySize(array_)) {} + IDBKey::~IDBKey() = default; bool IDBKey::IsValid() const { diff --git a/third_party/blink/renderer/modules/indexeddb/idb_key.h b/third_party/blink/renderer/modules/indexeddb/idb_key.h index 3082acad53961..9c8e9addf5d2d 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_key.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_key.h @@ -78,8 +78,50 @@ class MODULES_EXPORT IDBKey { return base::WrapUnique(new IDBKey(std::move(array))); } + // TODO(cmp): This |Clone| function is necessary for WebIDBKey's ctor + // functions. It needs to be available in this header file so + // web_idb_key.cc can use it. When the IDB Blink variant typemap + // moves to the renderer/modules/indexeddb/ types and off of the + // WebIDB* types, this |Clone| function should be removed. + static std::unique_ptr<IDBKey> Clone(const std::unique_ptr<IDBKey>& rkey_in) { + IDBKey* rkey = rkey_in.get(); + if (!rkey_in.get()) + return nullptr; + + switch (rkey->GetType()) { + case kInvalidType: + return IDBKey::CreateInvalid(); + case kArrayType: { + IDBKey::KeyArray lkey_array; + const auto& rkey_array = rkey->Array(); + for (const auto& rkey_item : rkey_array) + lkey_array.push_back(IDBKey::Clone(rkey_item)); + return IDBKey::CreateArray(std::move(lkey_array)); + } + case kBinaryType: + return IDBKey::CreateBinary(rkey->Binary()); + case kStringType: + return IDBKey::CreateString(rkey->GetString()); + case kDateType: + return IDBKey::CreateDate(rkey->Date()); + case kNumberType: + return IDBKey::CreateNumber(rkey->Number()); + + case kTypeEnumMax: + break; // Not used, NOTREACHED. + } + NOTREACHED(); + return nullptr; + } + ~IDBKey(); + // Very rough estimate of minimum key size overhead. + // + // TODO(cmp): When the reference to this in web_idb_key.cc goes away, move + // this variable back to idb_key.cc's anonymous namespace. + static const size_t kIDBKeyOverheadSize = 16; + // In order of the least to the highest precedent in terms of sort order. // These values are written to logs. New enum values can be added, but // existing enums must never be renumbered or deleted and reused. @@ -124,6 +166,7 @@ class MODULES_EXPORT IDBKey { int Compare(const IDBKey* other) const; bool IsLessThan(const IDBKey* other) const; bool IsEqual(const IDBKey* other) const; + size_t SizeEstimate() const { return size_estimate_; } // Returns a new key array with invalid keys and duplicates removed. // @@ -140,20 +183,22 @@ class MODULES_EXPORT IDBKey { private: DISALLOW_COPY_AND_ASSIGN(IDBKey); - IDBKey() : type_(kInvalidType) {} - IDBKey(Type type, double number) : type_(type), number_(number) {} - explicit IDBKey(const class String& value) - : type_(kStringType), string_(value) {} - explicit IDBKey(scoped_refptr<SharedBuffer> value) - : type_(kBinaryType), binary_(std::move(value)) {} - explicit IDBKey(KeyArray key_array) - : type_(kArrayType), array_(std::move(key_array)) {} + IDBKey(); + IDBKey(Type type, double number); + explicit IDBKey(const String& value); + explicit IDBKey(scoped_refptr<SharedBuffer> value); + explicit IDBKey(KeyArray key_array); Type type_; KeyArray array_; scoped_refptr<SharedBuffer> binary_; - const class String string_; + const String string_; const double number_ = 0; + + // Initialized in IDBKey constructors based on key type and value size (see + // idb_key.cc). Returned via SizeEstimate() and used in IndexedDB code to + // verify that a given key is small enough to pass over IPC. + size_t size_estimate_; }; } // namespace blink diff --git a/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc b/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc index 5757d7977d52d..f7d0fce90fdbb 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc @@ -30,7 +30,6 @@ #include "base/feature_list.h" #include "base/memory/scoped_refptr.h" #include "base/numerics/safe_conversions.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" #include "third_party/blink/public/platform/web_blob_info.h" @@ -49,6 +48,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/histogram.h" @@ -558,8 +558,8 @@ IDBRequest* IDBObjectStore::DoPut(ScriptState* script_state, key_type_histogram.Count(static_cast<int>(key->GetType())); } - WebVector<WebIDBIndexKeys> index_keys; - index_keys.reserve(Metadata().indexes.size()); + Vector<WebIDBIndexKeys> index_keys; + index_keys.ReserveInitialCapacity(Metadata().indexes.size()); for (const auto& it : Metadata().indexes) { if (clone.IsEmpty()) value_wrapper.Clone(script_state, &clone); @@ -754,8 +754,8 @@ class IndexPopulator final : public EventListener { const IDBKey* primary_key = cursor->IdbPrimaryKey(); ScriptValue value = cursor->value(script_state_); - WebVector<WebIDBIndexKeys> index_keys; - index_keys.reserve(1); + Vector<WebIDBIndexKeys> index_keys; + index_keys.ReserveInitialCapacity(1); index_keys.emplace_back( IndexMetadata().id, GenerateIndexKeysForValue(script_state_->GetIsolate(), diff --git a/third_party/blink/renderer/modules/indexeddb/idb_object_store.h b/third_party/blink/renderer/modules/indexeddb/idb_object_store.h index 041f0b8375ad7..0824150168686 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_object_store.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_object_store.h @@ -28,8 +28,6 @@ #include "base/memory/scoped_refptr.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_cursor.h" #include "third_party/blink/renderer/modules/indexeddb/idb_index.h" @@ -39,6 +37,8 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h b/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h index 26d3a07d6bbf0..10ca6524aabdb 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h @@ -27,8 +27,8 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_OPEN_DB_REQUEST_H_ #include <memory> -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/modules_export.h" namespace blink { diff --git a/third_party/blink/renderer/modules/indexeddb/idb_request.h b/third_party/blink/renderer/modules/indexeddb/idb_request.h index e5d5d4f28a400..f70e380c07891 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_request.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_request.h @@ -34,7 +34,6 @@ #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" @@ -49,6 +48,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/blob/blob_data.h" diff --git a/third_party/blink/renderer/modules/indexeddb/idb_request_queue_item.cc b/third_party/blink/renderer/modules/indexeddb/idb_request_queue_item.cc index cfbe57f732349..bb8753cd58a31 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_request_queue_item.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_request_queue_item.cc @@ -9,12 +9,12 @@ #include "base/callback.h" #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request_loader.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" namespace blink { diff --git a/third_party/blink/renderer/modules/indexeddb/idb_transaction.h b/third_party/blink/renderer/modules/indexeddb/idb_transaction.h index 0cd78d42fbeac..d0c50289b40be 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_transaction.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_transaction.h @@ -29,7 +29,6 @@ #include <memory> #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" @@ -38,6 +37,7 @@ #include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/wtf/deque.h" diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap new file mode 100644 index 0000000000000..3a3bd88c11550 --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap @@ -0,0 +1,41 @@ +# Copyright 2018 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. + +mojom = "//third_party/blink/public/mojom/indexeddb/indexeddb.mojom" +public_headers = [ + "//third_party/blink/public/common/indexeddb/web_idb_types.h", + "//third_party/blink/public/platform/modules/indexeddb/web_idb_key.h", + "//third_party/blink/public/platform/modules/indexeddb/web_idb_key_path.h", + "//third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h", + "//third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h", + "//third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.h", + "//third_party/blink/renderer/modules/indexeddb/idb_key_range.h", +] +traits_headers = [ + "//mojo/public/cpp/base/string16_mojom_traits.h", + "//mojo/public/cpp/bindings/array_traits_web_vector.h", + "//mojo/public/cpp/bindings/array_traits_wtf_vector.h", + "//third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h", + "//third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h", + "//third_party/blink/renderer/platform/mojo/string16_mojom_traits.h", +] +deps = [ + "//mojo/public/cpp/bindings", + "//third_party/blink/renderer/platform/wtf", +] +type_mappings = [ + "blink.mojom.IDBCursorDirection=::blink::WebIDBCursorDirection", + "blink.mojom.IDBDataLoss=::blink::WebIDBDataLoss", + "blink.mojom.IDBDatabaseMetadata=::blink::WebIDBMetadata", + "blink.mojom.IDBIndexKeys=::blink::WebIDBIndexKeys", + "blink.mojom.IDBIndexMetadata=::blink::WebIDBMetadata::Index", + "blink.mojom.IDBKey=::blink::WebIDBKey[move_only]", + "blink.mojom.IDBKeyPath=::blink::WebIDBKeyPath", + "blink.mojom.IDBKeyRange=::blink::WebIDBKeyRange", + "blink.mojom.IDBObjectStoreMetadata=::blink::WebIDBMetadata::ObjectStore", + "blink.mojom.IDBOperationType=::blink::WebIDBOperationType", + "blink.mojom.IDBPutMode=::blink::WebIDBPutMode", + "blink.mojom.IDBTaskType=::blink::WebIDBTaskType", + "blink.mojom.IDBTransactionMode=::blink::WebIDBTransactionMode", +] diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc new file mode 100644 index 0000000000000..a8806efb9a40b --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc @@ -0,0 +1,290 @@ +// Copyright 2018 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. + +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h" + +#include "base/stl_util.h" +#include "mojo/public/cpp/bindings/array_traits_web_vector.h" +#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h" +#include "third_party/blink/public/common/indexeddb/indexed_db_default_mojom_traits.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_key_range.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/platform/mojo/string16_mojom_traits.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +using blink::mojom::IDBCursorDirection; +using blink::mojom::IDBDataLoss; +using blink::mojom::IDBOperationType; + +namespace mojo { + +// static +bool StructTraits< + blink::mojom::IDBDatabaseMetadataDataView, + blink::WebIDBMetadata>::Read(blink::mojom::IDBDatabaseMetadataDataView data, + blink::WebIDBMetadata* out) { + out->id = data.id(); + String name; + if (!data.ReadName(&name)) + return false; + out->name = name; + out->version = data.version(); + out->max_object_store_id = data.max_object_store_id(); + if (!data.ReadObjectStores(&out->object_stores)) + return false; + return true; +} + +// static +bool StructTraits<blink::mojom::IDBIndexKeysDataView, blink::WebIDBIndexKeys>:: + Read(blink::mojom::IDBIndexKeysDataView data, blink::WebIDBIndexKeys* out) { + out->first = data.index_id(); + if (!data.ReadIndexKeys(&out->second)) + return false; + return true; +} + +// static +bool StructTraits<blink::mojom::IDBIndexMetadataDataView, + blink::WebIDBMetadata::Index>:: + Read(blink::mojom::IDBIndexMetadataDataView data, + blink::WebIDBMetadata::Index* out) { + out->id = data.id(); + String name; + if (!data.ReadName(&name)) + return false; + out->name = name; + if (!data.ReadKeyPath(&out->key_path)) + return false; + out->unique = data.unique(); + out->multi_entry = data.multi_entry(); + return true; +} + +// static +blink::mojom::IDBKeyDataDataView::Tag +UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::GetTag( + const blink::WebIDBKey& key) { + switch (key.View().KeyType()) { + case blink::kWebIDBKeyTypeInvalid: + return blink::mojom::IDBKeyDataDataView::Tag::OTHER; + case blink::kWebIDBKeyTypeArray: + return blink::mojom::IDBKeyDataDataView::Tag::KEY_ARRAY; + case blink::kWebIDBKeyTypeBinary: + return blink::mojom::IDBKeyDataDataView::Tag::BINARY; + case blink::kWebIDBKeyTypeString: + return blink::mojom::IDBKeyDataDataView::Tag::STRING; + case blink::kWebIDBKeyTypeDate: + return blink::mojom::IDBKeyDataDataView::Tag::DATE; + case blink::kWebIDBKeyTypeNumber: + return blink::mojom::IDBKeyDataDataView::Tag::NUMBER; + case blink::kWebIDBKeyTypeNull: + return blink::mojom::IDBKeyDataDataView::Tag::OTHER; + + // Not used, fall through to NOTREACHED. + case blink::kWebIDBKeyTypeMin:; + } + NOTREACHED(); + return blink::mojom::IDBKeyDataDataView::Tag::OTHER; +} + +// static +bool UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::Read( + blink::mojom::IDBKeyDataDataView data, + blink::WebIDBKey* out) { + switch (data.tag()) { + case blink::mojom::IDBKeyDataDataView::Tag::KEY_ARRAY: { + Vector<blink::WebIDBKey> array; + if (!data.ReadKeyArray(&array)) + return false; + blink::WebVector<blink::WebIDBKey> webvector_array; + for (const auto& item : array) { + webvector_array.emplace_back( + blink::WebIDBKeyBuilder::Build(item.View())); + } + *out = blink::WebIDBKey::CreateArray(std::move(webvector_array)); + return true; + } + case blink::mojom::IDBKeyDataDataView::Tag::BINARY: { + ArrayDataView<uint8_t> bytes; + data.GetBinaryDataView(&bytes); + *out = blink::WebIDBKey::CreateBinary(blink::WebData( + reinterpret_cast<const char*>(bytes.data()), bytes.size())); + return true; + } + case blink::mojom::IDBKeyDataDataView::Tag::STRING: { + String string; + if (!data.ReadString(&string)) + return false; + *out = blink::WebIDBKey::CreateString(blink::WebString(string)); + return true; + } + case blink::mojom::IDBKeyDataDataView::Tag::DATE: + *out = blink::WebIDBKey::CreateDate(data.date()); + return true; + case blink::mojom::IDBKeyDataDataView::Tag::NUMBER: + *out = blink::WebIDBKey::CreateNumber(data.number()); + return true; + case blink::mojom::IDBKeyDataDataView::Tag::OTHER: + switch (data.other()) { + case blink::mojom::IDBDatalessKeyType::Invalid: + *out = blink::WebIDBKey::CreateInvalid(); + return true; + case blink::mojom::IDBDatalessKeyType::Null: + *out = blink::WebIDBKey::CreateNull(); + return true; + } + } + + return false; +} + +// static +const blink::WebVector<blink::WebIDBKey> +UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::key_array( + const blink::WebIDBKey& key) { + const auto& array_view = key.View().ArrayView(); + const size_t array_size = array_view.size(); + Vector<blink::WebIDBKey> result; + result.ReserveInitialCapacity(array_view.size()); + // |array_view| is of type WebIDBKeyArrayView which only implements size() + // and operator[]. Since it doesn't have other typical array functions, we + // must use an iterator-style for loop. + for (size_t i = 0; i < array_size; ++i) + result.emplace_back(blink::WebIDBKeyBuilder::Build(array_view[i])); + return result; +} + +// static +const Vector<uint8_t> +UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::binary( + const blink::WebIDBKey& key) { + const auto& data = key.View().Binary(); + Vector<uint8_t> result; + result.ReserveInitialCapacity(data.size()); + data.ForEachSegment([&result](const char* segment, size_t segment_size, + size_t segment_offset) { + const auto& segment_span = base::make_span(segment, segment + segment_size); + result.AppendRange(segment_span.begin(), segment_span.end()); + return true; + }); + return result; +} + +// static +const blink::WebIDBKey& +StructTraits<blink::mojom::IDBKeyDataView, blink::WebIDBKey>::data( + const blink::WebIDBKey& key) { + return key; +} + +// static +bool StructTraits<blink::mojom::IDBKeyDataView, blink::WebIDBKey>::Read( + blink::mojom::IDBKeyDataView data, + blink::WebIDBKey* out) { + return data.ReadData(out); +} + +// static +blink::mojom::blink::IDBKeyPathDataPtr +StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::data( + const blink::WebIDBKeyPath& key_path) { + if (key_path.KeyPathType() == blink::kWebIDBKeyPathTypeNull) + return nullptr; + + auto data = blink::mojom::blink::IDBKeyPathData::New(); + switch (key_path.KeyPathType()) { + case blink::kWebIDBKeyPathTypeString: { + String key_path_string = key_path.String(); + if (key_path_string.IsNull()) + key_path_string = g_empty_string; + data->set_string(key_path_string); + return data; + } + case blink::kWebIDBKeyPathTypeArray: { + const auto& array = key_path.Array(); + Vector<String> result; + result.ReserveInitialCapacity(array.size()); + for (const auto& item : array) + result.push_back(item); + data->set_string_array(result); + return data; + } + + case blink::kWebIDBKeyPathTypeNull: + break; // Not used, NOTREACHED. + } + NOTREACHED(); + return data; +} + +// static +bool StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::Read( + blink::mojom::IDBKeyPathDataView data, + blink::WebIDBKeyPath* out) { + blink::mojom::IDBKeyPathDataDataView data_view; + data.GetDataDataView(&data_view); + + if (data_view.is_null()) { + *out = blink::WebIDBKeyPath(); + return true; + } + + switch (data_view.tag()) { + case blink::mojom::IDBKeyPathDataDataView::Tag::STRING: { + String string; + if (!data_view.ReadString(&string)) + return false; + *out = blink::WebIDBKeyPath(blink::WebString(string)); + return true; + } + case blink::mojom::IDBKeyPathDataDataView::Tag::STRING_ARRAY: { + Vector<String> array; + if (!data_view.ReadStringArray(&array)) + return false; + *out = blink::WebIDBKeyPath(array); + return true; + } + } + + return false; +} + +// static +bool StructTraits<blink::mojom::IDBKeyRangeDataView, blink::WebIDBKeyRange>:: + Read(blink::mojom::IDBKeyRangeDataView data, blink::WebIDBKeyRange* out) { + // TODO(cmp): Use WebIDBKey and WebIDBKeyRange directly. + blink::IndexedDBKey lower; + blink::IndexedDBKey upper; + if (!data.ReadLower(&lower) || !data.ReadUpper(&upper)) + return false; + + blink::IndexedDBKeyRange temp(lower, upper, data.lower_open(), + data.upper_open()); + *out = blink::WebIDBKeyRangeBuilder::Build(temp); + return true; +} + +// static +bool StructTraits<blink::mojom::IDBObjectStoreMetadataDataView, + blink::WebIDBMetadata::ObjectStore>:: + Read(blink::mojom::IDBObjectStoreMetadataDataView data, + blink::WebIDBMetadata::ObjectStore* out) { + out->id = data.id(); + String name; + if (!data.ReadName(&name)) + return false; + out->name = name; + if (!data.ReadKeyPath(&out->key_path)) + return false; + out->auto_increment = data.auto_increment(); + out->max_index_id = data.max_index_id(); + if (!data.ReadIndexes(&out->indexes)) + return false; + return true; +} + +} // namespace mojo diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h new file mode 100644 index 0000000000000..408631a1a40e6 --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h @@ -0,0 +1,187 @@ +// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_BLINK_MOJOM_TRAITS_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_BLINK_MOJOM_TRAITS_H_ + +#include <stdint.h> + +#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_key_range.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" +#include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/renderer/modules/modules_export.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace mojo { + +template <> +struct MODULES_EXPORT StructTraits<blink::mojom::IDBDatabaseMetadataDataView, + blink::WebIDBMetadata> { + static int64_t id(const blink::WebIDBMetadata& metadata) { + return metadata.id; + } + static WTF::String name(const blink::WebIDBMetadata& metadata) { + if (metadata.name.IsNull()) + return g_empty_string; + return metadata.name; + } + static int64_t version(const blink::WebIDBMetadata& metadata) { + return metadata.version; + } + static int64_t max_object_store_id(const blink::WebIDBMetadata& metadata) { + return metadata.max_object_store_id; + } + static const blink::WebVector<blink::WebIDBMetadata::ObjectStore>& + object_stores(const blink::WebIDBMetadata& metadata) { + return metadata.object_stores; + } + static bool Read(blink::mojom::IDBDatabaseMetadataDataView data, + blink::WebIDBMetadata* out); +}; + +template <> +struct MODULES_EXPORT + StructTraits<blink::mojom::IDBIndexKeysDataView, blink::WebIDBIndexKeys> { + static int64_t index_id(const blink::WebIDBIndexKeys& index_keys) { + return index_keys.first; + } + static const blink::WebVector<blink::WebIDBKey>& index_keys( + const blink::WebIDBIndexKeys& index_keys) { + return index_keys.second; + } + static bool Read(blink::mojom::IDBIndexKeysDataView data, + blink::WebIDBIndexKeys* out); +}; + +template <> +struct MODULES_EXPORT StructTraits<blink::mojom::IDBIndexMetadataDataView, + blink::WebIDBMetadata::Index> { + static int64_t id(const blink::WebIDBMetadata::Index& metadata) { + return metadata.id; + } + static WTF::String name(const blink::WebIDBMetadata::Index& metadata) { + if (metadata.name.IsNull()) + return g_empty_string; + return metadata.name; + } + static const blink::WebIDBKeyPath& key_path( + const blink::WebIDBMetadata::Index& metadata) { + return metadata.key_path; + } + static bool unique(const blink::WebIDBMetadata::Index& metadata) { + return metadata.unique; + } + static bool multi_entry(const blink::WebIDBMetadata::Index& metadata) { + return metadata.multi_entry; + } + static bool Read(blink::mojom::IDBIndexMetadataDataView data, + blink::WebIDBMetadata::Index* out); +}; + +template <> +struct MODULES_EXPORT + UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey> { + static blink::mojom::IDBKeyDataDataView::Tag GetTag( + const blink::WebIDBKey& key); + static bool Read(blink::mojom::IDBKeyDataDataView data, + blink::WebIDBKey* out); + static const blink::WebVector<blink::WebIDBKey> key_array( + const blink::WebIDBKey& key); + static const Vector<uint8_t> binary(const blink::WebIDBKey& key); + static const WTF::String string(const blink::WebIDBKey& key) { + String key_string = key.View().String(); + if (key_string.IsNull()) + key_string = g_empty_string; + return key_string; + } + static double date(const blink::WebIDBKey& key) { return key.View().Date(); } + static double number(const blink::WebIDBKey& key) { + return key.View().Number(); + } + static blink::mojom::IDBDatalessKeyType other(const blink::WebIDBKey& key) { + switch (key.View().KeyType()) { + case blink::kWebIDBKeyTypeInvalid: + return blink::mojom::IDBDatalessKeyType::Invalid; + case blink::kWebIDBKeyTypeNull: + return blink::mojom::IDBDatalessKeyType::Null; + default: + NOTREACHED(); + return blink::mojom::IDBDatalessKeyType::Invalid; + } + } +}; + +template <> +struct MODULES_EXPORT + StructTraits<blink::mojom::IDBKeyDataView, blink::WebIDBKey> { + static const blink::WebIDBKey& data(const blink::WebIDBKey& key); + static bool Read(blink::mojom::IDBKeyDataView data, blink::WebIDBKey* out); +}; + +template <> +struct MODULES_EXPORT + StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath> { + static blink::mojom::blink::IDBKeyPathDataPtr data( + const blink::WebIDBKeyPath& key_path); + static bool Read(blink::mojom::IDBKeyPathDataView data, + blink::WebIDBKeyPath* out); +}; + +template <> +struct MODULES_EXPORT + StructTraits<blink::mojom::IDBKeyRangeDataView, blink::WebIDBKeyRange> { + static blink::WebIDBKey lower(const blink::WebIDBKeyRange& key_range) { + return blink::WebIDBKeyBuilder::Build(key_range.Lower()); + } + static blink::WebIDBKey upper(const blink::WebIDBKeyRange& key_range) { + return blink::WebIDBKeyBuilder::Build(key_range.Upper()); + } + static bool lower_open(const blink::WebIDBKeyRange& key_range) { + return key_range.LowerOpen(); + } + static bool upper_open(const blink::WebIDBKeyRange& key_range) { + return key_range.UpperOpen(); + } + static bool Read(blink::mojom::IDBKeyRangeDataView data, + blink::WebIDBKeyRange* out); +}; + +template <> +struct MODULES_EXPORT StructTraits<blink::mojom::IDBObjectStoreMetadataDataView, + blink::WebIDBMetadata::ObjectStore> { + static int64_t id(const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.id; + } + static WTF::String name(const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.name; + } + static const blink::WebIDBKeyPath& key_path( + const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.key_path; + } + static bool auto_increment( + const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.auto_increment; + } + static int64_t max_index_id( + const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.max_index_id; + } + static const blink::WebVector<blink::WebIDBMetadata::Index>& indexes( + const blink::WebIDBMetadata::ObjectStore& metadata) { + return metadata.indexes; + } + static bool Read(blink::mojom::IDBObjectStoreMetadataDataView data, + blink::WebIDBMetadata::ObjectStore* out); +}; + +} // namespace mojo + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_BLINK_MOJOM_TRAITS_H_ diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc b/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc new file mode 100644 index 0000000000000..8b884c7adcdc8 --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc @@ -0,0 +1,216 @@ +// Copyright 2016 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. + +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" + +#include "third_party/blink/public/platform/file_path_conversion.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.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/modules/indexeddb/web_idb_cursor_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" + +using blink::IndexedDBDatabaseMetadata; +using blink::WebBlobInfo; +using blink::WebData; +using blink::WebIDBCallbacks; +using blink::WebIDBDatabase; +using blink::WebIDBMetadata; +using blink::WebIDBNameAndVersion; +using blink::WebIDBValue; +using blink::WebString; +using blink::WebVector; +using blink::mojom::blink::IDBDatabaseAssociatedPtrInfo; + +namespace blink { + +namespace { + +WebIDBValue ConvertReturnValue(const mojom::blink::IDBReturnValuePtr& value) { + if (!value) + return WebIDBValue(WebData(), WebVector<WebBlobInfo>()); + + WebIDBValue web_value = IndexedDBCallbacksImpl::ConvertValue(value->value); + web_value.SetInjectedPrimaryKey(value->primary_key, value->key_path); + return web_value; +} + +WebIDBNameAndVersion ConvertNameVersion( + const mojom::blink::IDBNameAndVersionPtr& name_and_version) { + return WebIDBNameAndVersion(name_and_version->name, + name_and_version->version); +} + +} // namespace + +// static +WebIDBValue IndexedDBCallbacksImpl::ConvertValue( + const mojom::blink::IDBValuePtr& value) { + if (!value || value->bits.IsEmpty()) + return WebIDBValue(WebData(), WebVector<WebBlobInfo>()); + + WebVector<WebBlobInfo> local_blob_info; + local_blob_info.reserve(value->blob_or_file_info.size()); + for (const auto& info : value->blob_or_file_info) { + if (info->file) { + local_blob_info.emplace_back( + WebString(info->uuid), FilePathToWebString(info->file->path), + WebString(info->file->name), WebString(info->mime_type), + info->file->last_modified.ToDoubleT(), info->size, + info->blob.PassHandle()); + } else { + local_blob_info.emplace_back(WebString(info->uuid), + WebString(info->mime_type), info->size, + info->blob.PassHandle()); + } + } + + // TODO(crbug.com/902498): Use mojom traits to map directly to WebData. + WebData web_data(reinterpret_cast<const char*>(value->bits.data()), + value->bits.size()); + // Release value->bits std::vector. + value->bits.clear(); + return WebIDBValue(std::move(web_data), std::move(local_blob_info)); +} + +IndexedDBCallbacksImpl::IndexedDBCallbacksImpl( + std::unique_ptr<WebIDBCallbacks> callbacks, + int64_t transaction_id, + const base::WeakPtr<WebIDBCursorImpl>& cursor) + : callbacks_(std::move(callbacks)), + cursor_(cursor), + transaction_id_(transaction_id) {} + +IndexedDBCallbacksImpl::~IndexedDBCallbacksImpl() = default; + +void IndexedDBCallbacksImpl::Error(int32_t code, const WTF::String& message) { + callbacks_->OnError(WebIDBDatabaseError(code, WebString(message))); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessNamesAndVersionsList( + Vector<mojom::blink::IDBNameAndVersionPtr> names_and_versions) { + WebVector<WebIDBNameAndVersion> web_names_and_versions; + web_names_and_versions.reserve(names_and_versions.size()); + for (const mojom::blink::IDBNameAndVersionPtr& name_version : + names_and_versions) + web_names_and_versions.emplace_back(ConvertNameVersion(name_version)); + callbacks_->OnSuccess(web_names_and_versions); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessStringList(const Vector<String>& value) { + WebVector<WebString> web_value(value.size()); + std::transform(value.begin(), value.end(), web_value.begin(), + [](const WTF::String& s) { return WebString(s); }); + callbacks_->OnSuccess(web_value); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::Blocked(int64_t existing_version) { + callbacks_->OnBlocked(existing_version); + // Not resetting |callbacks_|. In this instance we will have to forward at + // least one other call in the set OnUpgradeNeeded() / OnSuccess() / + // OnError(). +} + +void IndexedDBCallbacksImpl::UpgradeNeeded( + IDBDatabaseAssociatedPtrInfo database_info, + int64_t old_version, + WebIDBDataLoss data_loss, + const String& data_loss_message, + const WebIDBMetadata& web_metadata) { + WebIDBDatabase* database = new WebIDBDatabaseImpl(std::move(database_info)); + callbacks_->OnUpgradeNeeded(old_version, database, web_metadata, data_loss, + WebString(data_loss_message)); + // Not resetting |callbacks_|. In this instance we will have to forward at + // least one other call in the set OnSuccess() / OnError(). +} + +void IndexedDBCallbacksImpl::SuccessDatabase( + IDBDatabaseAssociatedPtrInfo database_info, + const WebIDBMetadata& web_metadata) { + WebIDBDatabase* database = nullptr; + if (database_info.is_valid()) + database = new WebIDBDatabaseImpl(std::move(database_info)); + + callbacks_->OnSuccess(database, web_metadata); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + WebIDBKey key, + WebIDBKey primary_key, + mojom::blink::IDBValuePtr value) { + WebIDBCursorImpl* cursor = + new WebIDBCursorImpl(std::move(cursor_info), transaction_id_); + callbacks_->OnSuccess(cursor, std::move(key), std::move(primary_key), + ConvertValue(value)); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessValue( + mojom::blink::IDBReturnValuePtr value) { + callbacks_->OnSuccess(ConvertReturnValue(value)); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessCursorContinue( + WebIDBKey key, + WebIDBKey primary_key, + mojom::blink::IDBValuePtr value) { + callbacks_->OnSuccess(std::move(key), std::move(primary_key), + ConvertValue(value)); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessCursorPrefetch( + Vector<WebIDBKey> keys, + Vector<WebIDBKey> primary_keys, + Vector<mojom::blink::IDBValuePtr> values) { + Vector<WebIDBValue> web_values; + web_values.ReserveInitialCapacity(values.size()); + for (const mojom::blink::IDBValuePtr& value : values) + web_values.emplace_back(ConvertValue(value)); + + if (cursor_) { + cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), + std::move(web_values)); + cursor_->CachedContinue(callbacks_.get()); + } + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessArray( + Vector<mojom::blink::IDBReturnValuePtr> values) { + WebVector<WebIDBValue> web_values; + web_values.reserve(values.size()); + for (const mojom::blink::IDBReturnValuePtr& value : values) + web_values.emplace_back(ConvertReturnValue(value)); + callbacks_->OnSuccess(std::move(web_values)); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessKey(WebIDBKey key) { + callbacks_->OnSuccess(std::move(key)); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::SuccessInteger(int64_t value) { + callbacks_->OnSuccess(value); + callbacks_.reset(); +} + +void IndexedDBCallbacksImpl::Success() { + callbacks_->OnSuccess(); + callbacks_.reset(); +} + +} // namespace blink diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h b/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h new file mode 100644 index 0000000000000..6138ba72c8d92 --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h @@ -0,0 +1,82 @@ +// Copyright 2016 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 THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_ + +#include <stdint.h> + +#include <memory> + +#include "base/memory/scoped_refptr.h" +#include "base/memory/weak_ptr.h" +#include "mojo/public/cpp/bindings/associated_binding.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_key.h" +#include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" + +namespace blink { + +class WebIDBCallbacks; +class WebIDBCursorImpl; +class WebIDBValue; + +// Implements the child-process end of the pipe used to deliver callbacks. +// |callback_runner_| is used to post tasks back to the thread which owns the +// blink::WebIDBCallbacks. +class IndexedDBCallbacksImpl : public mojom::blink::IDBCallbacks { + public: + // |kNoTransaction| is used as the default transaction ID when instantiating + // an IndexedDBCallbacksImpl instance. See web_idb_factory_impl.cc for those + // cases. + enum : int64_t { kNoTransaction = -1 }; + + static WebIDBValue ConvertValue(const mojom::blink::IDBValuePtr& value); + + IndexedDBCallbacksImpl(std::unique_ptr<WebIDBCallbacks> callbacks, + int64_t transaction_id, + const base::WeakPtr<WebIDBCursorImpl>& cursor); + ~IndexedDBCallbacksImpl() override; + + // mojom::blink::IDBCallbacks implementation: + void Error(int32_t code, const String& message) override; + void SuccessNamesAndVersionsList( + Vector<mojom::blink::IDBNameAndVersionPtr> names_and_versions) override; + void SuccessStringList(const Vector<String>& value) override; + void Blocked(int64_t existing_version) override; + void UpgradeNeeded(mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + int64_t old_version, + WebIDBDataLoss data_loss, + const String& data_loss_message, + const WebIDBMetadata& metadata) override; + void SuccessDatabase(mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + const WebIDBMetadata& metadata) override; + void SuccessCursor(mojom::blink::IDBCursorAssociatedPtrInfo cursor, + WebIDBKey key, + WebIDBKey primary_key, + mojom::blink::IDBValuePtr value) override; + void SuccessValue(mojom::blink::IDBReturnValuePtr value) override; + void SuccessCursorContinue(WebIDBKey key, + WebIDBKey primary_key, + mojom::blink::IDBValuePtr value) override; + void SuccessCursorPrefetch(Vector<WebIDBKey> keys, + Vector<WebIDBKey> primary_keys, + Vector<mojom::blink::IDBValuePtr> values) override; + void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr> values) override; + void SuccessKey(WebIDBKey key) override; + void SuccessInteger(int64_t value) override; + void Success() override; + + private: + scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; + std::unique_ptr<WebIDBCallbacks> callbacks_; + base::WeakPtr<WebIDBCursorImpl> cursor_; + int64_t transaction_id_; + + DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacksImpl); +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_ diff --git a/content/renderer/indexed_db/indexed_db_database_callbacks_impl.cc b/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc similarity index 62% rename from content/renderer/indexed_db/indexed_db_database_callbacks_impl.cc rename to third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc index a63c0652330bc..1149fab7b6196 100644 --- a/content/renderer/indexed_db/indexed_db_database_callbacks_impl.cc +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc @@ -2,24 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/indexed_db_database_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h" #include <unordered_map> #include <utility> -#include "base/threading/thread_task_runner_handle.h" -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" using blink::WebVector; using blink::WebIDBDatabaseCallbacks; using blink::WebIDBObservation; -namespace content { +namespace blink { IndexedDBDatabaseCallbacksImpl::IndexedDBDatabaseCallbacksImpl( std::unique_ptr<WebIDBDatabaseCallbacks> callbacks) @@ -38,10 +37,9 @@ void IndexedDBDatabaseCallbacksImpl::VersionChange(int64_t old_version, void IndexedDBDatabaseCallbacksImpl::Abort(int64_t transaction_id, int32_t code, - const base::string16& message) { - callbacks_->OnAbort( - transaction_id, - blink::WebIDBDatabaseError(code, blink::WebString::FromUTF16(message))); + const String& message) { + callbacks_->OnAbort(transaction_id, + blink::WebIDBDatabaseError(code, message)); } void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) { @@ -49,33 +47,34 @@ void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) { } void IndexedDBDatabaseCallbacksImpl::Changes( - blink::mojom::IDBObserverChangesPtr changes) { + mojom::blink::IDBObserverChangesPtr changes) { WebVector<WebIDBObservation> web_observations; web_observations.reserve(changes->observations.size()); for (const auto& observation : changes->observations) { web_observations.emplace_back( - observation->object_store_id, observation->type, - WebIDBKeyRangeBuilder::Build(observation->key_range), + observation->object_store_id, observation->type, observation->key_range, IndexedDBCallbacksImpl::ConvertValue(observation->value)); } - WebIDBDatabaseCallbacks::ObservationIndexMap observation_index_map( - changes->observation_index_map.begin(), - changes->observation_index_map.end()); + std::unordered_map<int32_t, WebVector<int32_t>> observation_index_map; + for (const auto& observation_pair : changes->observation_index_map) { + observation_index_map[observation_pair.key] = + WebVector<int32_t>(observation_pair.value); + } - std::unordered_map<int32_t, std::pair<int64_t, std::vector<int64_t>>> + std::unordered_map<int32_t, std::pair<int64_t, WebVector<int64_t>>> observer_transactions; for (const auto& transaction_pair : changes->transaction_map) { // Moving an int64_t is rather silly. Sadly, std::make_pair's overloads // accept either two rvalue arguments, or none. - observer_transactions[transaction_pair.first] = - std::make_pair<int64_t, std::vector<int64_t>>( - std::move(transaction_pair.second->id), - std::move(transaction_pair.second->scope)); + observer_transactions[transaction_pair.key] = + std::make_pair<int64_t, Vector<int64_t>>( + std::move(transaction_pair.value->id), + std::move(transaction_pair.value->scope)); } callbacks_->OnChanges(observation_index_map, std::move(web_observations), observer_transactions); } -} // namespace content +} // namespace blink diff --git a/content/renderer/indexed_db/indexed_db_database_callbacks_impl.h b/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h similarity index 52% rename from content/renderer/indexed_db/indexed_db_database_callbacks_impl.h rename to third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h index 304f9782f3ed2..702ea69e5adfb 100644 --- a/content/renderer/indexed_db/indexed_db_database_callbacks_impl.h +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h @@ -2,40 +2,41 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ -#define CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ + +#include <stdint.h> + +#include <memory> #include "base/single_thread_task_runner.h" -#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" namespace blink { class WebIDBDatabaseCallbacks; -} - -namespace content { class IndexedDBDatabaseCallbacksImpl - : public blink::mojom::IDBDatabaseCallbacks { + : public mojom::blink::IDBDatabaseCallbacks { public: explicit IndexedDBDatabaseCallbacksImpl( - std::unique_ptr<blink::WebIDBDatabaseCallbacks> callbacks); + std::unique_ptr<WebIDBDatabaseCallbacks> callbacks); ~IndexedDBDatabaseCallbacksImpl() override; - // blink::mojom::IDBDatabaseCallbacks implementation + // mojom::blink::IDBDatabaseCallbacks implementation void ForcedClose() override; void VersionChange(int64_t old_version, int64_t new_version) override; void Abort(int64_t transaction_id, int32_t code, - const base::string16& message) override; + const WTF::String& message) override; void Complete(int64_t transaction_id) override; - void Changes(blink::mojom::IDBObserverChangesPtr changes) override; + void Changes(mojom::blink::IDBObserverChangesPtr changes) override; private: - std::unique_ptr<blink::WebIDBDatabaseCallbacks> callbacks_; + std::unique_ptr<WebIDBDatabaseCallbacks> callbacks_; DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseCallbacksImpl); }; -} // namespace content +} // namespace blink -#endif // CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DATABASE_CALLBACKS_IMPL_H_ diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc b/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc new file mode 100644 index 0000000000000..84198c49edfac --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc @@ -0,0 +1,49 @@ +// Copyright 2013 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. + +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h" + +#include <utility> + +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h" + +namespace blink { +// static +IndexedDBDispatcher* IndexedDBDispatcher::GetInstanceForCurrentThread() { + DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<IndexedDBDispatcher>, + thread_specific_instance, ()); + return thread_specific_instance; +} + +IndexedDBDispatcher::IndexedDBDispatcher() = default; + +// static +void IndexedDBDispatcher::RegisterCursor(WebIDBCursorImpl* cursor) { + IndexedDBDispatcher* this_ptr = GetInstanceForCurrentThread(); + DCHECK(!this_ptr->cursors_.Contains(cursor)); + this_ptr->cursors_.insert(cursor); +} + +// static +void IndexedDBDispatcher::UnregisterCursor(WebIDBCursorImpl* cursor) { + IndexedDBDispatcher* this_ptr = GetInstanceForCurrentThread(); + DCHECK(this_ptr->cursors_.Contains(cursor)); + this_ptr->cursors_.erase(cursor); +} + +// static +void IndexedDBDispatcher::ResetCursorPrefetchCaches( + int64_t transaction_id, + WebIDBCursorImpl* except_cursor) { + IndexedDBDispatcher* this_ptr = GetInstanceForCurrentThread(); + for (WebIDBCursorImpl* cursor : this_ptr->cursors_) { + if (cursor != except_cursor && cursor->transaction_id() == transaction_id) + cursor->ResetPrefetchCache(); + } +} + +} // namespace blink diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h b/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h new file mode 100644 index 0000000000000..906d706801827 --- /dev/null +++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h @@ -0,0 +1,55 @@ +// Copyright 2013 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 THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DISPATCHER_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DISPATCHER_H_ + +#include <stdint.h> + +#include "base/gtest_prod_util.h" +#include "base/macros.h" +#include "third_party/blink/public/common/indexeddb/web_idb_types.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h" +#include "third_party/blink/renderer/modules/modules_export.h" +#include "third_party/blink/renderer/platform/wtf/hash_set.h" +#include "third_party/blink/renderer/platform/wtf/thread_specific.h" + +namespace blink { +class WebIDBCursorImpl; + +// Handle the indexed db related communication for this context thread - the +// main thread and each worker thread have their own copies. +class MODULES_EXPORT IndexedDBDispatcher { + public: + static void RegisterCursor(WebIDBCursorImpl* cursor); + static void UnregisterCursor(WebIDBCursorImpl* cursor); + + // Reset cursor prefetch caches for all cursors except |except_cursor|. + // In most callers, |except_cursor| is passed as nullptr, causing all cursors + // to have their prefetch cache to be reset. In 2 WebIDBCursorImpl callers, + // specifically from |Advance| and |CursorContinue|, these want to reset all + // cursor prefetch caches except the cursor the calls are running from. They + // get that behavior by passing |this| to |ResetCursorPrefetchCaches| which + // skips calling |ResetPrefetchCache| on them. + static void ResetCursorPrefetchCaches(int64_t transaction_id, + WebIDBCursorImpl* except_cursor); + + private: + friend class WTF::ThreadSpecific<IndexedDBDispatcher>; + + static IndexedDBDispatcher* GetInstanceForCurrentThread(); + + IndexedDBDispatcher(); + + FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); + FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); + + WTF::HashSet<WebIDBCursorImpl*> cursors_; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_DISPATCHER_H_ diff --git a/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc b/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc index f0a9d295fb0c9..58154698ae9fe 100644 --- a/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc +++ b/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc @@ -34,7 +34,6 @@ #include <utility> #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/bindings/core/v8/script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/core/dom/document.h" @@ -59,6 +58,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" diff --git a/content/renderer/indexed_db/mock_webidbcallbacks.cc b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc similarity index 89% rename from content/renderer/indexed_db/mock_webidbcallbacks.cc rename to third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc index ec05f48563e17..1f7839527ffd1 100644 --- a/content/renderer/indexed_db/mock_webidbcallbacks.cc +++ b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/mock_webidbcallbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h" -namespace content { +namespace blink { MockWebIDBCallbacks::MockWebIDBCallbacks() {} @@ -36,4 +36,4 @@ void MockWebIDBCallbacks::OnSuccess( DoOnSuccess(values); } -} // namespace content +} // namespace blink diff --git a/content/renderer/indexed_db/mock_webidbcallbacks.h b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h similarity index 91% rename from content/renderer/indexed_db/mock_webidbcallbacks.h rename to third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h index ec337180cdac6..5c9b71d76b23d 100644 --- a/content/renderer/indexed_db/mock_webidbcallbacks.h +++ b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_INDEXED_DB_MOCK_WEBIDBCALLBACKS_H_ -#define CONTENT_RENDERER_INDEXED_DB_MOCK_WEBIDBCALLBACKS_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_CALLBACKS_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_CALLBACKS_H_ #include "base/macros.h" #include "testing/gmock/include/gmock/gmock.h" @@ -15,7 +15,7 @@ #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/public/web/web_heap.h" -namespace content { +namespace blink { class MockWebIDBCallbacks : public blink::WebIDBCallbacks { public: @@ -71,6 +71,6 @@ class MockWebIDBCallbacks : public blink::WebIDBCallbacks { DISALLOW_COPY_AND_ASSIGN(MockWebIDBCallbacks); }; -} // namespace content +} // namespace blink -#endif // CONTENT_RENDERER_INDEXED_DB_MOCK_WEBIDBCALLBACKS_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_CALLBACKS_H_ diff --git a/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h index a732549863268..c38507ff56c6e 100644 --- a/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h +++ b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h @@ -7,10 +7,10 @@ #include <gmock/gmock.h> #include <memory> -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" namespace blink { @@ -23,7 +23,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { MOCK_METHOD5(CreateObjectStore, void(long long transaction_id, long long object_store_id, - const WebString& name, + const String& name, const WebIDBKeyPath&, bool auto_increment)); MOCK_METHOD2(DeleteObjectStore, @@ -31,10 +31,10 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { MOCK_METHOD3(RenameObjectStore, void(long long transaction_id, long long object_store_id, - const WebString& new_name)); + const String& new_name)); MOCK_METHOD3(CreateTransaction, void(long long id, - const WebVector<long long>& scope, + const Vector<int64_t>& scope, WebIDBTransactionMode)); MOCK_METHOD0(Close, void()); MOCK_METHOD0(VersionChangeIgnored, void()); @@ -44,7 +44,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, long long index_id, - const WebString& name, + const String& name, const WebIDBKeyPath&, bool unique, bool multi_entry)); @@ -56,7 +56,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, long long index_id, - const WebString& new_name)); + const String& new_name)); MOCK_METHOD6( AddObserver, void(long long transaction_id, @@ -67,7 +67,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { const std::bitset<kWebIDBOperationTypeCount>& operation_types)); MOCK_CONST_METHOD1(ContainsObserverId, bool(int32_t id)); MOCK_METHOD1(RemoveObservers, - void(const WebVector<int32_t>& observer_ids_to_remove)); + void(const Vector<int32_t>& observer_ids_to_remove)); MOCK_METHOD6(Get, void(long long transaction_id, long long object_store_id, @@ -88,21 +88,21 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, const WebData& value, - const WebVector<WebBlobInfo>&, + const Vector<WebBlobInfo>&, WebIDBKeyView primary_key, WebIDBPutMode, WebIDBCallbacks*, - const WebVector<WebIDBIndexKeys>&)); + const Vector<WebIDBIndexKeys>&)); MOCK_METHOD4(SetIndexKeys, void(long long transaction_id, long long object_store_id, WebIDBKeyView primary_key, - const WebVector<WebIDBIndexKeys>&)); + const Vector<WebIDBIndexKeys>&)); MOCK_METHOD3(SetIndexesReady, void(long long transaction_id, long long object_store_id, - const WebVector<long long>& index_ids)); + const Vector<int64_t>& index_ids)); MOCK_METHOD8(OpenCursor, void(long long transaction_id, long long object_store_id, diff --git a/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h index 83c890d06c891..47ffe2f93e61a 100644 --- a/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h +++ b/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h @@ -9,9 +9,9 @@ #include <memory> #include "base/single_thread_task_runner.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" #include "third_party/blink/public/platform/web_common.h" #include "third_party/blink/public/platform/web_security_origin.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" namespace base { class SingleThreadTaskRunner; diff --git a/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc index 12b0e2052cb47..aac84024af368 100644 --- a/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc @@ -31,8 +31,6 @@ #include <memory> #include "base/memory/ptr_util.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.h" @@ -43,6 +41,8 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/idb_request.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" #include "third_party/blink/renderer/platform/shared_buffer.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" diff --git a/third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h similarity index 89% rename from third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h index 248df14cdd0b2..7e03aa02a3968 100644 --- a/third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h @@ -23,18 +23,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ -#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" -#include "third_party/blink/public/platform/web_common.h" #include "third_party/blink/public/platform/web_string.h" +#include "third_party/blink/renderer/modules/modules_export.h" namespace blink { -class WebIDBCursor { +class MODULES_EXPORT WebIDBCursor { public: virtual ~WebIDBCursor() = default; @@ -65,4 +65,4 @@ class WebIDBCursor { } // namespace blink -#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_H_ diff --git a/content/renderer/indexed_db/webidbcursor_impl.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc similarity index 68% rename from content/renderer/indexed_db/webidbcursor_impl.cc rename to third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc index bdf5ce976ca89..bdf6aeb433cda 100644 --- a/content/renderer/indexed_db/webidbcursor_impl.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/webidbcursor_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h" #include <stddef.h> @@ -10,10 +10,11 @@ #include <vector> #include "base/single_thread_task_runner.h" -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.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" using blink::WebBlobInfo; using blink::WebData; @@ -21,13 +22,13 @@ using blink::WebIDBCallbacks; using blink::WebIDBKey; using blink::WebIDBKeyView; using blink::WebIDBValue; -using blink::mojom::IDBCallbacksAssociatedPtrInfo; -using blink::mojom::IDBCursorAssociatedPtrInfo; +using blink::mojom::blink::IDBCallbacksAssociatedPtrInfo; +using blink::mojom::blink::IDBCursorAssociatedPtrInfo; -namespace content { +namespace blink { WebIDBCursorImpl::WebIDBCursorImpl( - blink::mojom::IDBCursorAssociatedPtrInfo cursor_info, + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, int64_t transaction_id) : transaction_id_(transaction_id), cursor_(std::move(cursor_info)), @@ -36,7 +37,7 @@ WebIDBCursorImpl::WebIDBCursorImpl( pending_onsuccess_callbacks_(0), prefetch_amount_(kMinPrefetchAmount), weak_factory_(this) { - IndexedDBDispatcher::ThreadSpecificInstance()->RegisterCursor(this); + IndexedDBDispatcher::RegisterCursor(this); } WebIDBCursorImpl::~WebIDBCursorImpl() { @@ -44,7 +45,7 @@ WebIDBCursorImpl::~WebIDBCursorImpl() { // object since inside WebKit, they hold a reference to the object which owns // this object. But, if that ever changed, then we'd need to invalidate // any such pointers. - IndexedDBDispatcher::ThreadSpecificInstance()->UnregisterCursor(this); + IndexedDBDispatcher::UnregisterCursor(this); } void WebIDBCursorImpl::Advance(unsigned long count, @@ -57,8 +58,7 @@ void WebIDBCursorImpl::Advance(unsigned long count, ResetPrefetchCache(); // Reset all cursor prefetch caches except for this cursor. - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id_, this); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr()); @@ -70,12 +70,12 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key, WebIDBCallbacks* callbacks_ptr) { std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); - if (key.KeyType() == blink::kWebIDBKeyTypeNull && - primary_key.KeyType() == blink::kWebIDBKeyTypeNull) { + if (key.KeyType() == kWebIDBKeyTypeNull && + primary_key.KeyType() == kWebIDBKeyTypeNull) { // No key(s), so this would qualify for a prefetch. ++continue_count_; - if (!prefetch_keys_.empty()) { + if (!prefetch_keys_.IsEmpty()) { // We have a prefetch cache, so serve the result from that. CachedContinue(callbacks.get()); return; @@ -103,13 +103,12 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key, } // Reset all cursor prefetch caches except for this cursor. - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id_, this); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr()); - cursor_->CursorContinue(IndexedDBKeyBuilder::Build(key), - IndexedDBKeyBuilder::Build(primary_key), + cursor_->CursorContinue(WebIDBKeyBuilder::Build(key), + WebIDBKeyBuilder::Build(primary_key), GetCallbacksProxy(std::move(callbacks_impl))); } @@ -126,14 +125,18 @@ void WebIDBCursorImpl::PostSuccessHandlerCallback() { ResetPrefetchCache(); } -void WebIDBCursorImpl::SetPrefetchData( - const std::vector<IndexedDBKey>& keys, - const std::vector<IndexedDBKey>& primary_keys, - std::vector<WebIDBValue> values) { - prefetch_keys_.assign(keys.begin(), keys.end()); - prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); - prefetch_values_.assign(std::make_move_iterator(values.begin()), - std::make_move_iterator(values.end())); +void WebIDBCursorImpl::SetPrefetchData(Vector<WebIDBKey> keys, + Vector<WebIDBKey> primary_keys, + Vector<WebIDBValue> 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()), + std::make_move_iterator(keys.rend())); + prefetch_primary_keys_.AppendRange( + std::make_move_iterator(primary_keys.rbegin()), + std::make_move_iterator(primary_keys.rend())); + prefetch_values_.AppendRange(std::make_move_iterator(values.rbegin()), + std::make_move_iterator(values.rend())); used_prefetches_ = 0; pending_onsuccess_callbacks_ = 0; @@ -146,9 +149,9 @@ void WebIDBCursorImpl::CachedAdvance(unsigned long count, DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size()); while (count > 1) { - prefetch_keys_.pop_front(); - prefetch_primary_keys_.pop_front(); - prefetch_values_.pop_front(); + prefetch_keys_.pop_back(); + prefetch_primary_keys_.pop_back(); + prefetch_values_.pop_back(); ++used_prefetches_; --count; } @@ -161,13 +164,15 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { DCHECK_EQ(prefetch_primary_keys_.size(), prefetch_keys_.size()); DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size()); - IndexedDBKey key = prefetch_keys_.front(); - IndexedDBKey primary_key = prefetch_primary_keys_.front(); - WebIDBValue value = std::move(prefetch_values_.front()); + // 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()); - prefetch_keys_.pop_front(); - prefetch_primary_keys_.pop_front(); - prefetch_values_.pop_front(); + prefetch_keys_.pop_back(); + prefetch_primary_keys_.pop_back(); + prefetch_values_.pop_back(); ++used_prefetches_; ++pending_onsuccess_callbacks_; @@ -180,15 +185,15 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { ResetPrefetchCache(); } - callbacks->OnSuccess(WebIDBKeyBuilder::Build(key), - WebIDBKeyBuilder::Build(primary_key), std::move(value)); + callbacks->OnSuccess(std::move(key), std::move(primary_key), + std::move(value)); } void WebIDBCursorImpl::ResetPrefetchCache() { continue_count_ = 0; prefetch_amount_ = kMinPrefetchAmount; - if (prefetch_keys_.empty()) { + if (prefetch_keys_.IsEmpty()) { // No prefetch cache, so no need to reset the cursor in the back-end. return; } @@ -212,4 +217,4 @@ IDBCallbacksAssociatedPtrInfo WebIDBCursorImpl::GetCallbacksProxy( return ptr_info; } -} // namespace content +} // namespace blink diff --git a/content/renderer/indexed_db/webidbcursor_impl.h b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h similarity index 52% rename from content/renderer/indexed_db/webidbcursor_impl.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h index 39baa2c51b9b3..f9b04bee8f4fa 100644 --- a/content/renderer/indexed_db/webidbcursor_impl.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h @@ -2,47 +2,44 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ -#define CONTENT_RENDERER_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_IMPL_H_ #include <stdint.h> #include <vector> -#include "base/compiler_specific.h" -#include "base/containers/circular_deque.h" #include "base/gtest_prod_util.h" -#include "base/memory/ref_counted.h" -#include "content/common/content_export.h" #include "third_party/blink/public/common/indexeddb/indexeddb_key.h" -#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/modules_export.h" -namespace content { +namespace blink { class IndexedDBCallbacksImpl; -class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { +class MODULES_EXPORT WebIDBCursorImpl : public WebIDBCursor { public: - WebIDBCursorImpl(blink::mojom::IDBCursorAssociatedPtrInfo cursor, + WebIDBCursorImpl(mojom::blink::IDBCursorAssociatedPtrInfo cursor, int64_t transaction_id); ~WebIDBCursorImpl() override; - void Advance(unsigned long count, blink::WebIDBCallbacks* callback) override; - void CursorContinue(blink::WebIDBKeyView key, - blink::WebIDBKeyView primary_key, - blink::WebIDBCallbacks* callback) override; + void Advance(unsigned long count, WebIDBCallbacks* callback) override; + void CursorContinue(WebIDBKeyView key, + WebIDBKeyView primary_key, + WebIDBCallbacks* callback) override; void PostSuccessHandlerCallback() override; - void SetPrefetchData(const std::vector<blink::IndexedDBKey>& keys, - const std::vector<blink::IndexedDBKey>& primary_keys, - std::vector<blink::WebIDBValue> values); + void SetPrefetchData(Vector<WebIDBKey> keys, + Vector<WebIDBKey> primary_keys, + Vector<WebIDBValue> values); - void CachedAdvance(unsigned long count, blink::WebIDBCallbacks* callbacks); - void CachedContinue(blink::WebIDBCallbacks* callbacks); + void CachedAdvance(unsigned long count, WebIDBCallbacks* callbacks); + void CachedContinue(WebIDBCallbacks* callbacks); // This method is virtual so it can be overridden in unit tests. virtual void ResetPrefetchCache(); @@ -50,7 +47,7 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { int64_t transaction_id() const { return transaction_id_; } private: - blink::mojom::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( + mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( std::unique_ptr<IndexedDBCallbacksImpl> callbacks); FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); @@ -59,19 +56,20 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset); FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest); - enum { kInvalidCursorId = -1 }; - enum { kPrefetchContinueThreshold = 2 }; - enum { kMinPrefetchAmount = 5 }; - enum { kMaxPrefetchAmount = 100 }; + static constexpr int kPrefetchContinueThreshold = 2; + static constexpr int kMinPrefetchAmount = 5; + static constexpr int kMaxPrefetchAmount = 100; int64_t transaction_id_; - blink::mojom::IDBCursorAssociatedPtr cursor_; + mojom::blink::IDBCursorAssociatedPtr cursor_; - // Prefetch cache. - base::circular_deque<blink::IndexedDBKey> prefetch_keys_; - base::circular_deque<blink::IndexedDBKey> prefetch_primary_keys_; - base::circular_deque<blink::WebIDBValue> prefetch_values_; + // Prefetch cache. 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. + Vector<WebIDBKey> prefetch_keys_; + Vector<WebIDBKey> prefetch_primary_keys_; + Vector<WebIDBValue> prefetch_values_; // Number of continue calls that would qualify for a pre-fetch. int continue_count_; @@ -90,6 +88,6 @@ class CONTENT_EXPORT WebIDBCursorImpl : public blink::WebIDBCursor { DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImpl); }; -} // namespace content +} // namespace blink -#endif // CONTENT_RENDERER_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CURSOR_IMPL_H_ diff --git a/content/renderer/indexed_db/webidbcursor_impl_unittest.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc similarity index 79% rename from content/renderer/indexed_db/webidbcursor_impl_unittest.cc rename to third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc index 212b2167d5c58..76fa9b2ad2b43 100644 --- a/content/renderer/indexed_db/webidbcursor_impl_unittest.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc @@ -2,46 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/webidbcursor_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h" #include <stddef.h> #include <stdint.h> #include <memory> -#include "base/guid.h" #include "base/macros.h" -#include "base/run_loop.h" -#include "base/test/scoped_task_environment.h" -#include "base/threading/thread_task_runner_handle.h" -#include "base/values.h" -#include "content/child/thread_safe_sender.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.h" -#include "content/renderer/indexed_db/mock_webidbcallbacks.h" #include "mojo/public/cpp/bindings/associated_binding.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/web_data.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h" +#include "third_party/blink/renderer/platform/testing/testing_platform_support.h" +#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" -using blink::IndexedDBKey; -using blink::WebBlobInfo; -using blink::WebData; -using blink::WebIDBCallbacks; -using blink::WebIDBKey; -using blink::kWebIDBKeyTypeNumber; -using blink::WebIDBValue; -using blink::WebString; -using blink::WebVector; -using blink::mojom::IDBCursor; -using testing::StrictMock; - -namespace content { +namespace blink { namespace { -class MockCursorImpl : public IDBCursor { +class MockCursorImpl : public mojom::blink::IDBCursor { public: - explicit MockCursorImpl(blink::mojom::IDBCursorAssociatedRequest request) + explicit MockCursorImpl(mojom::blink::IDBCursorAssociatedRequest request) : binding_(this, std::move(request)) { binding_.set_connection_error_handler(base::BindOnce( &MockCursorImpl::CursorDestroyed, base::Unretained(this))); @@ -49,7 +34,7 @@ class MockCursorImpl : public IDBCursor { void Prefetch( int32_t count, - blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override { + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override { ++prefetch_calls_; last_prefetch_count_ = count; } @@ -61,14 +46,14 @@ class MockCursorImpl : public IDBCursor { } void Advance(uint32_t count, - blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override { + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override { ++advance_calls_; } void CursorContinue( - const IndexedDBKey& key, - const IndexedDBKey& primary_key, - blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override { + WebIDBKey key, + WebIDBKey primary_key, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override { ++continue_calls_; } @@ -94,7 +79,7 @@ class MockCursorImpl : public IDBCursor { mojo::AssociatedBinding<IDBCursor> binding_; }; -class MockContinueCallbacks : public StrictMock<MockWebIDBCallbacks> { +class MockContinueCallbacks : public testing::StrictMock<MockWebIDBCallbacks> { public: MockContinueCallbacks(IndexedDBKey* key = nullptr, WebVector<WebBlobInfo>* blobs = nullptr) @@ -119,14 +104,14 @@ class MockContinueCallbacks : public StrictMock<MockWebIDBCallbacks> { class WebIDBCursorImplTest : public testing::Test { public: WebIDBCursorImplTest() : null_key_(WebIDBKey::CreateNull()) { - blink::mojom::IDBCursorAssociatedPtr ptr; + mojom::blink::IDBCursorAssociatedPtr ptr; mock_cursor_ = std::make_unique<MockCursorImpl>( mojo::MakeRequestAssociatedWithDedicatedPipe(&ptr)); cursor_ = std::make_unique<WebIDBCursorImpl>(ptr.PassInterface(), 1); } protected: - base::test::ScopedTaskEnvironment scoped_task_environment_; + ScopedTestingPlatformSupport<TestingPlatformSupport> platform_; WebIDBKey null_key_; std::unique_ptr<WebIDBCursorImpl> cursor_; std::unique_ptr<MockCursorImpl> mock_cursor_; @@ -142,7 +127,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(++continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(0, mock_cursor_->prefetch_calls()); } @@ -157,7 +142,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { // Initiate the prefetch cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(repetitions + 1, mock_cursor_->prefetch_calls()); @@ -167,17 +152,22 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { last_prefetch_count = prefetch_count; // Fill the prefetch cache as requested. - std::vector<IndexedDBKey> keys; - std::vector<IndexedDBKey> primary_keys; - std::vector<WebIDBValue> values; + Vector<WebIDBKey> keys; + Vector<WebIDBKey> primary_keys; + Vector<WebIDBValue> values; + size_t expected_size = 0; for (int i = 0; i < prefetch_count; ++i) { - keys.emplace_back(expected_key + i, kWebIDBKeyTypeNumber); + WebIDBKey key = WebIDBKey::CreateNumber(expected_key + i); + keys.emplace_back(std::move(key)); primary_keys.emplace_back(); + expected_size++; + EXPECT_EQ(expected_size, keys.size()); + EXPECT_EQ(expected_size, primary_keys.size()); WebVector<WebBlobInfo> blob_info; blob_info.reserve(expected_key + i); for (int j = 0; j < expected_key + i; ++j) { blob_info.emplace_back(WebBlobInfo::BlobForTesting( - WebString::FromLatin1(base::GenerateGUID()), "text/plain", 123)); + WebString("blobuuid"), "text/plain", 123)); } values.emplace_back(WebData(), std::move(blob_info)); } @@ -194,7 +184,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { WebVector<WebBlobInfo> blobs; cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks(&key, &blobs)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(repetitions + 1, mock_cursor_->prefetch_calls()); @@ -205,7 +195,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { } cursor_.reset(); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_TRUE(mock_cursor_->destroyed()); } @@ -216,14 +206,14 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); } - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(0, mock_cursor_->prefetch_calls()); // Initiate the prefetch cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(1, mock_cursor_->prefetch_calls()); EXPECT_EQ(static_cast<int>(WebIDBCursorImpl::kPrefetchContinueThreshold), mock_cursor_->continue_calls()); @@ -233,17 +223,22 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { // Fill the prefetch cache as requested. int expected_key = 0; - std::vector<IndexedDBKey> keys; - std::vector<IndexedDBKey> primary_keys; - std::vector<WebIDBValue> values; + Vector<WebIDBKey> keys; + Vector<WebIDBKey> primary_keys; + Vector<WebIDBValue> values; + size_t expected_size = 0; for (int i = 0; i < prefetch_count; ++i) { - keys.emplace_back(expected_key + i, kWebIDBKeyTypeNumber); + WebIDBKey key = WebIDBKey::CreateNumber(expected_key + i); + keys.emplace_back(std::move(key)); primary_keys.emplace_back(); + expected_size++; + EXPECT_EQ(expected_size, keys.size()); + EXPECT_EQ(expected_size, primary_keys.size()); WebVector<WebBlobInfo> blob_info; blob_info.reserve(expected_key + i); for (int j = 0; j < expected_key + i; ++j) { - blob_info.emplace_back(WebBlobInfo::BlobForTesting( - WebString::FromLatin1(base::GenerateGUID()), "text/plain", 123)); + blob_info.emplace_back(WebBlobInfo::BlobForTesting(WebString("blobuuid"), + "text/plain", 123)); } values.emplace_back(WebData(), std::move(blob_info)); } @@ -261,23 +256,23 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { IndexedDBKey key; cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks(&key)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(0, key.number()); // IDBCursor.advance(1) cursor_->Advance(1, new MockContinueCallbacks(&key)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(1, key.number()); // IDBCursor.continue() cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks(&key)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(2, key.number()); // IDBCursor.advance(2) cursor_->Advance(2, new MockContinueCallbacks(&key)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(4, key.number()); EXPECT_EQ(0, mock_cursor_->advance_calls()); @@ -285,14 +280,14 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { // IDBCursor.advance(lots) - beyond the fetched amount cursor_->Advance(WebIDBCursorImpl::kMaxPrefetchAmount, new MockContinueCallbacks(&key)); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(1, mock_cursor_->advance_calls()); EXPECT_EQ(1, mock_cursor_->prefetch_calls()); EXPECT_EQ(static_cast<int>(WebIDBCursorImpl::kPrefetchContinueThreshold), mock_cursor_->continue_calls()); cursor_.reset(); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_TRUE(mock_cursor_->destroyed()); } @@ -303,7 +298,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(++continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(0, mock_cursor_->prefetch_calls()); } @@ -311,7 +306,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { // Initiate the prefetch cursor_->CursorContinue(null_key_.View(), null_key_.View(), new MockContinueCallbacks()); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(1, mock_cursor_->prefetch_calls()); EXPECT_EQ(0, mock_cursor_->reset_calls()); @@ -320,21 +315,21 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { cursor_->ResetPrefetchCache(); // No reset should have been sent since nothing has been received yet. - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(0, mock_cursor_->reset_calls()); // Fill the prefetch cache as requested. int prefetch_count = mock_cursor_->last_prefetch_count(); - std::vector<IndexedDBKey> keys(prefetch_count); - std::vector<IndexedDBKey> primary_keys(prefetch_count); - std::vector<WebIDBValue> values; + Vector<WebIDBKey> keys(prefetch_count); + Vector<WebIDBKey> primary_keys(prefetch_count); + Vector<WebIDBValue> values; for (int i = 0; i < prefetch_count; ++i) values.emplace_back(WebData(), WebVector<WebBlobInfo>()); cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), std::move(values)); // No reset should have been sent since prefetch data hasn't been used. - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(0, mock_cursor_->reset_calls()); // The real dispatcher would call cursor->CachedContinue(), so do that: @@ -342,13 +337,13 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { cursor_->CachedContinue(&callbacks); // Now the cursor should have reset the rest of the cache. - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_EQ(1, mock_cursor_->reset_calls()); EXPECT_EQ(1, mock_cursor_->last_used_count()); cursor_.reset(); - base::RunLoop().RunUntilIdle(); + platform_->RunUntilIdle(); EXPECT_TRUE(mock_cursor_->destroyed()); } -} // namespace content +} // namespace blink diff --git a/third_party/blink/public/platform/modules/indexeddb/web_idb_database.h b/third_party/blink/renderer/modules/indexeddb/web_idb_database.h similarity index 84% rename from third_party/blink/public/platform/modules/indexeddb/web_idb_database.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_database.h index 782d60fa152d2..f5e28eb33d3cc 100644 --- a/third_party/blink/public/platform/modules/indexeddb/web_idb_database.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database.h @@ -23,17 +23,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ -#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ - -#include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" -#include "third_party/blink/public/platform/web_blob_info.h" -#include "third_party/blink/public/platform/web_common.h" +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ #include <bitset> +#include "third_party/blink/public/common/indexeddb/web_idb_types.h" +#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" +#include "third_party/blink/public/platform/web_blob_info.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/modules_export.h" +#include "third_party/blink/renderer/platform/wtf/vector.h" + namespace blink { class WebData; @@ -41,22 +42,22 @@ class WebIDBCallbacks; class WebIDBKeyPath; class WebIDBKeyRange; -class WebIDBDatabase { +class MODULES_EXPORT WebIDBDatabase { public: virtual ~WebIDBDatabase() = default; virtual void CreateObjectStore(long long transaction_id, long long object_store_id, - const WebString& name, + const String& name, const WebIDBKeyPath&, bool auto_increment) = 0; virtual void DeleteObjectStore(long long transaction_id, long long object_store_id) = 0; virtual void RenameObjectStore(long long transaction_id, long long object_store_id, - const WebString& name) = 0; + const String& name) = 0; virtual void CreateTransaction(long long id, - const WebVector<long long>& scope, + const Vector<int64_t>& scope, WebIDBTransactionMode) = 0; virtual void Close() = 0; virtual void VersionChangeIgnored() = 0; @@ -67,7 +68,7 @@ class WebIDBDatabase { virtual void CreateIndex(long long transaction_id, long long object_store_id, long long index_id, - const WebString& name, + const String& name, const WebIDBKeyPath&, bool unique, bool multi_entry) = 0; @@ -77,7 +78,7 @@ class WebIDBDatabase { virtual void RenameIndex(long long transaction_id, long long object_store_id, long long index_id, - const WebString& new_name) = 0; + const String& new_name) = 0; static const long long kMinimumIndexId = 30; @@ -89,7 +90,7 @@ class WebIDBDatabase { bool values, const std::bitset<kWebIDBOperationTypeCount>& operation_types) = 0; virtual void RemoveObservers( - const WebVector<int32_t>& observer_ids_to_remove) = 0; + const Vector<int32_t>& observer_ids_to_remove) = 0; virtual void Get(long long transaction_id, long long object_store_id, long long index_id, @@ -106,18 +107,18 @@ class WebIDBDatabase { virtual void Put(long long transaction_id, long long object_store_id, const WebData& value, - const WebVector<WebBlobInfo>&, + const Vector<WebBlobInfo>&, WebIDBKeyView primary_key, WebIDBPutMode, WebIDBCallbacks*, - const WebVector<WebIDBIndexKeys>&) = 0; + const Vector<WebIDBIndexKeys>&) = 0; virtual void SetIndexKeys(long long transaction_id, long long object_store_id, WebIDBKeyView primary_key, - const WebVector<WebIDBIndexKeys>&) = 0; + const Vector<WebIDBIndexKeys>&) = 0; virtual void SetIndexesReady(long long transaction_id, long long object_store_id, - const WebVector<long long>& index_ids) = 0; + const Vector<int64_t>& index_ids) = 0; virtual void OpenCursor(long long transaction_id, long long object_store_id, long long index_id, @@ -149,4 +150,4 @@ class WebIDBDatabase { } // namespace blink -#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_H_ diff --git a/content/renderer/indexed_db/webidbdatabase_impl.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc similarity index 56% rename from content/renderer/indexed_db/webidbdatabase_impl.cc rename to third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc index 1fcec2d5537f2..872bb3b957e92 100644 --- a/content/renderer/indexed_db/webidbdatabase_impl.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/webidbdatabase_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" #include <stddef.h> @@ -11,14 +11,10 @@ #include "base/format_macros.h" #include "base/memory/ptr_util.h" -#include "base/strings/string16.h" -#include "base/strings/stringprintf.h" -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" -#include "content/renderer/indexed_db/indexed_db_dispatcher.h" -#include "content/renderer/indexed_db/indexed_db_key_builders.h" #include "mojo/public/cpp/bindings/strong_associated_binding.h" #include "third_party/blink/public/common/indexeddb/indexeddb_key.h" #include "third_party/blink/public/platform/file_path_conversion.h" +#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_exception.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_path.h" @@ -26,56 +22,24 @@ #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h" -using blink::IndexedDBKey; -using blink::IndexedDBIndexKeys; -using blink::WebBlobInfo; -using blink::WebIDBCallbacks; -using blink::WebIDBDatabase; -using blink::WebIDBDatabaseCallbacks; -using blink::WebIDBMetadata; -using blink::WebIDBKey; -using blink::WebIDBKeyPath; -using blink::WebIDBKeyRange; -using blink::WebIDBKeyView; -using blink::WebString; -using blink::WebVector; -using blink::mojom::IDBCallbacksAssociatedPtrInfo; -using blink::mojom::IDBDatabaseAssociatedPtrInfo; - -namespace content { - -namespace { - -std::vector<IndexedDBIndexKeys> ConvertWebIndexKeys( - const WebVector<blink::WebIDBIndexKeys>& index_keys) { - std::vector<IndexedDBIndexKeys> result; - result.reserve(index_keys.size()); - for (size_t i = 0, len = index_keys.size(); i < len; ++i) { - result.emplace_back(index_keys[i].first, std::vector<IndexedDBKey>()); - std::vector<IndexedDBKey>& result_keys = result.back().second; - result_keys.reserve(index_keys[i].second.size()); - for (const WebIDBKey& index_key : index_keys[i].second) - result_keys.emplace_back(IndexedDBKeyBuilder::Build(index_key.View())); - } - return result; -} - -} // namespace +namespace blink { WebIDBDatabaseImpl::WebIDBDatabaseImpl( - IDBDatabaseAssociatedPtrInfo database_info) + mojom::blink::IDBDatabaseAssociatedPtrInfo database_info) : database_(std::move(database_info)) {} WebIDBDatabaseImpl::~WebIDBDatabaseImpl() = default; void WebIDBDatabaseImpl::CreateObjectStore(long long transaction_id, long long object_store_id, - const WebString& name, + const String& name, const WebIDBKeyPath& key_path, bool auto_increment) { - database_->CreateObjectStore(transaction_id, object_store_id, name.Utf16(), - IndexedDBKeyPathBuilder::Build(key_path), + database_->CreateObjectStore(transaction_id, object_store_id, name, key_path, auto_increment); } @@ -86,19 +50,15 @@ void WebIDBDatabaseImpl::DeleteObjectStore(long long transaction_id, void WebIDBDatabaseImpl::RenameObjectStore(long long transaction_id, long long object_store_id, - const blink::WebString& new_name) { - database_->RenameObjectStore(transaction_id, object_store_id, - new_name.Utf16()); + const String& new_name) { + database_->RenameObjectStore(transaction_id, object_store_id, new_name); } void WebIDBDatabaseImpl::CreateTransaction( long long transaction_id, - const WebVector<long long>& object_store_ids, - blink::WebIDBTransactionMode mode) { - database_->CreateTransaction( - transaction_id, - std::vector<int64_t>(object_store_ids.begin(), object_store_ids.end()), - mode); + const Vector<int64_t>& object_store_ids, + WebIDBTransactionMode mode) { + database_->CreateTransaction(transaction_id, object_store_ids, mode); } void WebIDBDatabaseImpl::Close() { @@ -115,19 +75,15 @@ void WebIDBDatabaseImpl::AddObserver( bool include_transaction, bool no_records, bool values, - const std::bitset<blink::kWebIDBOperationTypeCount>& operation_types) { - static_assert(blink::kWebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT, + const std::bitset<kWebIDBOperationTypeCount>& operation_types) { + static_assert(kWebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT, "WebIDBOperationType Count exceeds size of uint16_t"); database_->AddObserver(transaction_id, observer_id, include_transaction, no_records, values, operation_types.to_ulong()); } -void WebIDBDatabaseImpl::RemoveObservers( - const WebVector<int32_t>& observer_ids_to_remove) { - std::vector<int32_t> remove_observer_ids( - observer_ids_to_remove.Data(), - observer_ids_to_remove.Data() + observer_ids_to_remove.size()); - database_->RemoveObservers(remove_observer_ids); +void WebIDBDatabaseImpl::RemoveObservers(const Vector<int32_t>& observer_ids) { + database_->RemoveObservers(observer_ids); } void WebIDBDatabaseImpl::Get(long long transaction_id, @@ -136,13 +92,11 @@ void WebIDBDatabaseImpl::Get(long long transaction_id, const WebIDBKeyRange& key_range, bool key_only, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); - database_->Get(transaction_id, object_store_id, index_id, - IndexedDBKeyRangeBuilder::Build(key_range), key_only, + database_->Get(transaction_id, object_store_id, index_id, key_range, key_only, GetCallbacksProxy(std::move(callbacks_impl))); } @@ -153,87 +107,87 @@ void WebIDBDatabaseImpl::GetAll(long long transaction_id, long long max_count, bool key_only, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); - database_->GetAll(transaction_id, object_store_id, index_id, - IndexedDBKeyRangeBuilder::Build(key_range), key_only, - max_count, GetCallbacksProxy(std::move(callbacks_impl))); + database_->GetAll(transaction_id, object_store_id, index_id, key_range, + key_only, max_count, + GetCallbacksProxy(std::move(callbacks_impl))); } -void WebIDBDatabaseImpl::Put( - long long transaction_id, - long long object_store_id, - const blink::WebData& value, - const WebVector<WebBlobInfo>& web_blob_info, - WebIDBKeyView web_primary_key, - blink::WebIDBPutMode put_mode, - WebIDBCallbacks* callbacks, - const WebVector<blink::WebIDBIndexKeys>& web_index_keys) { - IndexedDBKey primary_key = IndexedDBKeyBuilder::Build(web_primary_key); +void WebIDBDatabaseImpl::Put(long long transaction_id, + long long object_store_id, + const WebData& value, + const Vector<WebBlobInfo>& web_blob_info, + WebIDBKeyView web_primary_key, + WebIDBPutMode put_mode, + WebIDBCallbacks* callbacks, + const Vector<WebIDBIndexKeys>& index_keys) { + WebIDBKey primary_key = WebIDBKeyBuilder::Build(web_primary_key); - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); - auto mojo_value = blink::mojom::IDBValue::New(); + auto mojo_value = mojom::blink::IDBValue::New(); // mojo_value->bits initialization. value.ForEachSegment([&mojo_value](const char* segment, size_t segment_size, size_t segment_offset) { const auto& segment_span = base::make_span(segment, segment + segment_size); - mojo_value->bits.insert(mojo_value->bits.end(), segment_span.begin(), - segment_span.end()); + mojo_value->bits.AppendRange(segment_span.begin(), segment_span.end()); return true; }); // mojo_value->blob_or_file_info initialization. - mojo_value->blob_or_file_info.reserve(web_blob_info.size()); + mojo_value->blob_or_file_info.ReserveInitialCapacity(web_blob_info.size()); for (const WebBlobInfo& info : web_blob_info) { - auto blob_info = blink::mojom::IDBBlobInfo::New(); + auto blob_info = mojom::blink::IDBBlobInfo::New(); if (info.IsFile()) { - blob_info->file = blink::mojom::IDBFileInfo::New(); - blob_info->file->path = blink::WebStringToFilePath(info.FilePath()); - blob_info->file->name = info.FileName().Utf16(); + blob_info->file = mojom::blink::IDBFileInfo::New(); + blob_info->file->path = WebStringToFilePath(info.FilePath()); + String name = info.FileName(); + if (name.IsNull()) + name = g_empty_string; + blob_info->file->name = name; blob_info->file->last_modified = base::Time::FromDoubleT(info.LastModified()); } blob_info->size = info.size(); - blob_info->uuid = info.Uuid().Latin1(); - DCHECK(blob_info->uuid.size()); - blob_info->mime_type = info.GetType().Utf16(); - blob_info->blob = blink::mojom::BlobPtrInfo(info.CloneBlobHandle(), - blink::mojom::Blob::Version_); + blob_info->uuid = info.Uuid(); + DCHECK(!blob_info->uuid.IsEmpty()); + String mime_type = info.GetType(); + if (mime_type.IsNull()) + mime_type = g_empty_string; + blob_info->mime_type = mime_type; + blob_info->blob = mojom::blink::BlobPtrInfo(info.CloneBlobHandle(), + mojom::blink::Blob::Version_); mojo_value->blob_or_file_info.push_back(std::move(blob_info)); } - std::vector<blink::IndexedDBIndexKeys> index_keys = - ConvertWebIndexKeys(web_index_keys); size_t index_keys_size = 0; for (const auto& index_key : index_keys) { index_keys_size++; // Account for index_key.first (int64_t). for (const auto& key : index_key.second) { - index_keys_size += key.size_estimate(); + index_keys_size += key.SizeEstimate(); } } size_t arg_size = - mojo_value->bits.size() + primary_key.size_estimate() + index_keys_size; + mojo_value->bits.size() + primary_key.SizeEstimate() + index_keys_size; if (arg_size >= max_put_value_size_) { callbacks->OnError(blink::WebIDBDatabaseError( blink::kWebIDBDatabaseExceptionUnknownError, - WebString::FromUTF8(base::StringPrintf( - "The serialized keys and/or value are too large" - " (size=%" PRIuS " bytes, max=%" PRIuS " bytes).", - arg_size, max_put_value_size_)))); + WebString( + String::Format("The serialized keys and/or value are too large" + " (size=%" PRIuS " bytes, max=%" PRIuS " bytes).", + arg_size, max_put_value_size_)))); return; } auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); database_->Put(transaction_id, object_store_id, std::move(mojo_value), - primary_key, put_mode, std::move(index_keys), + std::move(primary_key), put_mode, index_keys, GetCallbacksProxy(std::move(callbacks_impl))); } @@ -241,18 +195,15 @@ void WebIDBDatabaseImpl::SetIndexKeys( long long transaction_id, long long object_store_id, WebIDBKeyView primary_key, - const WebVector<blink::WebIDBIndexKeys>& index_keys) { + const Vector<WebIDBIndexKeys>& index_keys) { + IndexedDBKey temp(IndexedDBKeyBuilder::Build(primary_key)); database_->SetIndexKeys(transaction_id, object_store_id, - IndexedDBKeyBuilder::Build(primary_key), - ConvertWebIndexKeys(index_keys)); + WebIDBKeyBuilder::Build(temp), std::move(index_keys)); } -void WebIDBDatabaseImpl::SetIndexesReady( - long long transaction_id, - long long object_store_id, - const WebVector<long long>& web_index_ids) { - std::vector<int64_t> index_ids(web_index_ids.Data(), - web_index_ids.Data() + web_index_ids.size()); +void WebIDBDatabaseImpl::SetIndexesReady(long long transaction_id, + long long object_store_id, + const Vector<int64_t>& index_ids) { database_->SetIndexesReady(transaction_id, object_store_id, std::move(index_ids)); } @@ -261,18 +212,16 @@ void WebIDBDatabaseImpl::OpenCursor(long long transaction_id, long long object_store_id, long long index_id, const WebIDBKeyRange& key_range, - blink::WebIDBCursorDirection direction, + WebIDBCursorDirection direction, bool key_only, - blink::WebIDBTaskType task_type, + WebIDBTaskType task_type, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); - database_->OpenCursor(transaction_id, object_store_id, index_id, - IndexedDBKeyRangeBuilder::Build(key_range), direction, - key_only, task_type, + database_->OpenCursor(transaction_id, object_store_id, index_id, key_range, + direction, key_only, task_type, GetCallbacksProxy(std::move(callbacks_impl))); } @@ -281,13 +230,11 @@ void WebIDBDatabaseImpl::Count(long long transaction_id, long long index_id, const WebIDBKeyRange& key_range, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); - database_->Count(transaction_id, object_store_id, index_id, - IndexedDBKeyRangeBuilder::Build(key_range), + database_->Count(transaction_id, object_store_id, index_id, key_range, GetCallbacksProxy(std::move(callbacks_impl))); } @@ -295,13 +242,12 @@ void WebIDBDatabaseImpl::Delete(long long transaction_id, long long object_store_id, WebIDBKeyView primary_key, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); database_->DeleteRange(transaction_id, object_store_id, - IndexedDBKeyRangeBuilder::Build(primary_key), + WebIDBKeyRangeBuilder::Build(primary_key), GetCallbacksProxy(std::move(callbacks_impl))); } @@ -309,21 +255,18 @@ void WebIDBDatabaseImpl::DeleteRange(long long transaction_id, long long object_store_id, const WebIDBKeyRange& key_range, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); - database_->DeleteRange(transaction_id, object_store_id, - IndexedDBKeyRangeBuilder::Build(key_range), + database_->DeleteRange(transaction_id, object_store_id, key_range, GetCallbacksProxy(std::move(callbacks_impl))); } void WebIDBDatabaseImpl::Clear(long long transaction_id, long long object_store_id, WebIDBCallbacks* callbacks) { - IndexedDBDispatcher::ThreadSpecificInstance()->ResetCursorPrefetchCaches( - transaction_id, nullptr); + IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), transaction_id, nullptr); @@ -334,13 +277,12 @@ void WebIDBDatabaseImpl::Clear(long long transaction_id, void WebIDBDatabaseImpl::CreateIndex(long long transaction_id, long long object_store_id, long long index_id, - const WebString& name, + const String& name, const WebIDBKeyPath& key_path, bool unique, bool multi_entry) { - database_->CreateIndex(transaction_id, object_store_id, index_id, - name.Utf16(), IndexedDBKeyPathBuilder::Build(key_path), - unique, multi_entry); + database_->CreateIndex(transaction_id, object_store_id, index_id, name, + key_path, unique, multi_entry); } void WebIDBDatabaseImpl::DeleteIndex(long long transaction_id, @@ -352,9 +294,9 @@ void WebIDBDatabaseImpl::DeleteIndex(long long transaction_id, void WebIDBDatabaseImpl::RenameIndex(long long transaction_id, long long object_store_id, long long index_id, - const WebString& new_name) { - database_->RenameIndex(transaction_id, object_store_id, index_id, - new_name.Utf16()); + const String& new_name) { + DCHECK(!new_name.IsNull()); + database_->RenameIndex(transaction_id, object_store_id, index_id, new_name); } void WebIDBDatabaseImpl::Abort(long long transaction_id) { @@ -365,12 +307,13 @@ void WebIDBDatabaseImpl::Commit(long long transaction_id) { database_->Commit(transaction_id); } -IDBCallbacksAssociatedPtrInfo WebIDBDatabaseImpl::GetCallbacksProxy( +mojom::blink::IDBCallbacksAssociatedPtrInfo +WebIDBDatabaseImpl::GetCallbacksProxy( std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { - IDBCallbacksAssociatedPtrInfo ptr_info; + mojom::blink::IDBCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); return ptr_info; } -} // namespace content +} // namespace blink diff --git a/content/renderer/indexed_db/webidbdatabase_impl.h b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h similarity index 76% rename from content/renderer/indexed_db/webidbdatabase_impl.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h index d26e1deba80d0..8ef41986a84fb 100644 --- a/content/renderer/indexed_db/webidbdatabase_impl.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h @@ -2,49 +2,43 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_INDEXED_DB_WEBIDBDATABASE_IMPL_H_ -#define CONTENT_RENDERER_INDEXED_DB_WEBIDBDATABASE_IMPL_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_IMPL_H_ #include <stdint.h> #include <set> -#include "base/memory/ref_counted.h" #include "base/single_thread_task_runner.h" -#include "content/common/content_export.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_cursor.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" +#include "third_party/blink/renderer/modules/modules_export.h" namespace blink { +class IndexedDBCallbacksImpl; class WebBlobInfo; class WebIDBCallbacks; -class WebString; -} // namespace blink -namespace content { - -class IndexedDBCallbacksImpl; - -class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { +class MODULES_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { public: - WebIDBDatabaseImpl(blink::mojom::IDBDatabaseAssociatedPtrInfo database); + WebIDBDatabaseImpl(mojom::blink::IDBDatabaseAssociatedPtrInfo database); ~WebIDBDatabaseImpl() override; // blink::WebIDBDatabase void CreateObjectStore(long long transaction_id, long long objectstore_id, - const blink::WebString& name, + const String& name, const blink::WebIDBKeyPath&, bool auto_increment) override; void DeleteObjectStore(long long transaction_id, long long object_store_id) override; void RenameObjectStore(long long transaction_id, long long object_store_id, - const blink::WebString& new_name) override; + const String& new_name) override; void CreateTransaction(long long transaction_id, - const blink::WebVector<long long>& scope, + const Vector<int64_t>& scope, blink::WebIDBTransactionMode mode) override; void Close() override; @@ -57,8 +51,7 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { bool values, const std::bitset<blink::kWebIDBOperationTypeCount>& operation_types) override; - void RemoveObservers( - const blink::WebVector<int32_t>& observer_ids_to_remove) override; + void RemoveObservers(const Vector<int32_t>& observer_ids) override; void Get(long long transaction_id, long long object_store_id, @@ -76,18 +69,18 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { void Put(long long transaction_id, long long object_store_id, const blink::WebData& value, - const blink::WebVector<blink::WebBlobInfo>&, + const Vector<blink::WebBlobInfo>&, blink::WebIDBKeyView primary_key, blink::WebIDBPutMode, blink::WebIDBCallbacks*, - const blink::WebVector<blink::WebIDBIndexKeys>&) override; + const Vector<blink::WebIDBIndexKeys>&) override; void SetIndexKeys(long long transaction_id, long long object_store_id, blink::WebIDBKeyView primary_key, - const blink::WebVector<blink::WebIDBIndexKeys>&) override; + const Vector<blink::WebIDBIndexKeys>&) override; void SetIndexesReady(long long transaction_id, long long object_store_id, - const blink::WebVector<long long>& index_ids) override; + const Vector<int64_t>& index_ids) override; void OpenCursor(long long transaction_id, long long object_store_id, long long index_id, @@ -115,7 +108,7 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { void CreateIndex(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebString& name, + const String& name, const blink::WebIDBKeyPath&, bool unique, bool multi_entry) override; @@ -125,12 +118,12 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { void RenameIndex(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebString& new_name) override; + const String& new_name) override; void Abort(long long transaction_id) override; void Commit(long long transaction_id) override; private: - blink::mojom::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( + mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( std::unique_ptr<IndexedDBCallbacksImpl> callbacks); FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, ValueSizeTest); @@ -141,12 +134,12 @@ class CONTENT_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { // Used by unit tests to exercise behavior without allocating huge chunks // of memory. size_t max_put_value_size_ = - blink::mojom::kIDBMaxMessageSize - blink::mojom::kIDBMaxMessageOverhead; + mojom::blink::kIDBMaxMessageSize - mojom::blink::kIDBMaxMessageOverhead; std::set<int32_t> observer_ids_; - blink::mojom::IDBDatabaseAssociatedPtr database_; + mojom::blink::IDBDatabaseAssociatedPtr database_; }; -} // namespace content +} // namespace blink -#endif // CONTENT_RENDERER_INDEXED_DB_WEBIDBDATABASE_IMPL_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_IMPL_H_ diff --git a/content/renderer/indexed_db/webidbdatabase_impl_unittest.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc similarity index 54% rename from content/renderer/indexed_db/webidbdatabase_impl_unittest.cc rename to third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc index 39bc0f26e3ffd..a960ec6147001 100644 --- a/content/renderer/indexed_db/webidbdatabase_impl_unittest.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc @@ -8,42 +8,24 @@ #include <memory> #include "base/macros.h" -#include "base/threading/thread_task_runner_handle.h" -#include "content/child/thread_safe_sender.h" -#include "content/public/test/test_browser_thread_bundle.h" -#include "content/renderer/indexed_db/mock_webidbcallbacks.h" -#include "content/renderer/indexed_db/webidbdatabase_impl.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/common/indexeddb/indexeddb_key.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/public/platform/web_data.h" #include "third_party/blink/public/web/web_heap.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" -using blink::IndexedDBKey; -using blink::WebBlobInfo; -using blink::WebData; -using blink::WebIDBCursor; -using blink::WebIDBKey; -using blink::WebVector; using testing::_; using testing::Invoke; using testing::StrictMock; using testing::WithArgs; -namespace content { +namespace blink { -class WebIDBDatabaseImplTest : public testing::Test { - public: - WebIDBDatabaseImplTest() {} - - void TearDown() override { blink::WebHeap::CollectAllGarbageForTesting(); } - - private: - TestBrowserThreadBundle thread_bundle_; - - DISALLOW_COPY_AND_ASSIGN(WebIDBDatabaseImplTest); -}; +class WebIDBDatabaseImplTest : public testing::Test {}; TEST_F(WebIDBDatabaseImplTest, ValueSizeTest) { // For testing use a much smaller maximum size to prevent allocating >100 MB @@ -52,20 +34,21 @@ TEST_F(WebIDBDatabaseImplTest, ValueSizeTest) { const std::vector<char> data(kMaxValueSizeForTesting + 1); const WebData value(&data.front(), data.size()); - const WebVector<WebBlobInfo> web_blob_info; - + const Vector<WebBlobInfo> blob_info; + const WebIDBKey key = WebIDBKey::CreateNumber(0); const int64_t transaction_id = 1; const int64_t object_store_id = 2; - StrictMock<MockWebIDBCallbacks> callbacks; + + ASSERT_GT(value.size() + key.SizeEstimate(), kMaxValueSizeForTesting); + ThreadState::Current()->CollectAllGarbage(); EXPECT_CALL(callbacks, OnError(_)).Times(1); WebIDBDatabaseImpl database_impl(nullptr); database_impl.max_put_value_size_ = kMaxValueSizeForTesting; - const WebIDBKey idb_key = WebIDBKey::CreateNumber(0); - database_impl.Put(transaction_id, object_store_id, value, web_blob_info, - idb_key.View(), blink::kWebIDBPutModeAddOrUpdate, - &callbacks, WebVector<blink::WebIDBIndexKeys>()); + database_impl.Put(transaction_id, object_store_id, value, blob_info, + key.View(), blink::kWebIDBPutModeAddOrUpdate, &callbacks, + Vector<blink::WebIDBIndexKeys>()); } TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { @@ -76,21 +59,35 @@ TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { const std::vector<char> data(kMaxValueSizeForTesting - kKeySize); const WebData value(&data.front(), data.size()); - const WebVector<WebBlobInfo> web_blob_info; - const WebIDBKey key = WebIDBKey::CreateString(blink::WebString::FromUTF16( - base::string16(kKeySize / sizeof(base::string16::value_type), 'x'))); - + const Vector<WebBlobInfo> blob_info; const int64_t transaction_id = 1; const int64_t object_store_id = 2; - StrictMock<MockWebIDBCallbacks> callbacks; + + // For this test, we want IDBKey::SizeEstimate() minus kKeySize to be the + // smallest value > 0. An IDBKey with a string has a size_estimate_ equal to + // kOverheadSize (~16) + (string.length * sizeof(UChar)). Create + // |kKeySize / sizeof(UChar)| characters in String. + const unsigned int number_of_chars = kKeySize / sizeof(UChar); + Vector<UChar> key_string_vector; + key_string_vector.ReserveInitialCapacity(number_of_chars); + key_string_vector.Fill(u'0', number_of_chars); + String key_string(key_string_vector); + DCHECK_EQ(key_string.length(), number_of_chars); + + WebIDBKey key = WebIDBKey::CreateString(key_string); + DCHECK_EQ(value.size(), kMaxValueSizeForTesting - kKeySize); + DCHECK_GT(key.SizeEstimate() - kKeySize, static_cast<unsigned long>(0)); + DCHECK_GT(value.size() + key.SizeEstimate(), kMaxValueSizeForTesting); + + ThreadState::Current()->CollectAllGarbage(); EXPECT_CALL(callbacks, OnError(_)).Times(1); WebIDBDatabaseImpl database_impl(nullptr); database_impl.max_put_value_size_ = kMaxValueSizeForTesting; - database_impl.Put(transaction_id, object_store_id, value, web_blob_info, + database_impl.Put(transaction_id, object_store_id, value, blob_info, key.View(), blink::kWebIDBPutModeAddOrUpdate, &callbacks, - WebVector<blink::WebIDBIndexKeys>()); + Vector<blink::WebIDBIndexKeys>()); } -} // namespace content +} // namespace blink diff --git a/third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h b/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h similarity index 89% rename from third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_factory.h index b99e5d8055f11..71a2ce00a59fa 100644 --- a/third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h @@ -26,11 +26,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ -#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ #include "base/single_thread_task_runner.h" -#include "third_party/blink/public/platform/web_common.h" +#include "third_party/blink/renderer/modules/modules_export.h" namespace base { class SingleThreadTaskRunner; @@ -43,7 +43,7 @@ class WebIDBDatabaseCallbacks; class WebSecurityOrigin; class WebString; -class WebIDBFactory { +class MODULES_EXPORT WebIDBFactory { public: virtual ~WebIDBFactory() = default; @@ -70,4 +70,4 @@ class WebIDBFactory { } // namespace blink -#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_H_ diff --git a/content/renderer/indexed_db/webidbfactory_impl.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc similarity index 71% rename from content/renderer/indexed_db/webidbfactory_impl.cc rename to third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc index 62682a005c5d6..f158e08cd1076 100644 --- a/content/renderer/indexed_db/webidbfactory_impl.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc @@ -2,29 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/renderer/indexed_db/webidbfactory_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h" #include "base/memory/ptr_util.h" -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" -#include "content/renderer/indexed_db/indexed_db_database_callbacks_impl.h" -#include "content/renderer/storage_util.h" -#include "ipc/ipc_sync_channel.h" #include "mojo/public/cpp/bindings/strong_associated_binding.h" #include "third_party/blink/public/platform/web_security_origin.h" #include "third_party/blink/public/platform/web_string.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h" -using blink::WebIDBCallbacks; -using blink::WebIDBDatabase; -using blink::WebIDBDatabaseCallbacks; -using blink::WebSecurityOrigin; -using blink::WebString; -using blink::mojom::IDBCallbacksAssociatedPtrInfo; -using blink::mojom::IDBDatabaseCallbacksAssociatedPtrInfo; -using blink::mojom::IDBFactoryPtrInfo; +namespace blink { -namespace content { - -WebIDBFactoryImpl::WebIDBFactoryImpl(IDBFactoryPtrInfo factory_info) +WebIDBFactoryImpl::WebIDBFactoryImpl( + mojom::blink::IDBFactoryPtrInfo factory_info) : factory_(std::move(factory_info)) {} WebIDBFactoryImpl::~WebIDBFactoryImpl() = default; @@ -37,7 +27,7 @@ void WebIDBFactoryImpl::GetDatabaseInfo( base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, nullptr); factory_->GetDatabaseInfo(GetCallbacksProxy(std::move(callbacks_impl)), - url::Origin(origin)); + origin); } void WebIDBFactoryImpl::GetDatabaseNames( @@ -48,7 +38,7 @@ void WebIDBFactoryImpl::GetDatabaseNames( base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, nullptr); factory_->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks_impl)), - url::Origin(origin)); + origin); } void WebIDBFactoryImpl::Open( @@ -64,9 +54,10 @@ void WebIDBFactoryImpl::Open( auto database_callbacks_impl = std::make_unique<IndexedDBDatabaseCallbacksImpl>( base::WrapUnique(database_callbacks)); + DCHECK(!name.IsNull()); factory_->Open(GetCallbacksProxy(std::move(callbacks_impl)), GetDatabaseCallbacksProxy(std::move(database_callbacks_impl)), - url::Origin(origin), name.Utf16(), version, transaction_id); + origin, name, version, transaction_id); } void WebIDBFactoryImpl::DeleteDatabase( @@ -78,25 +69,27 @@ void WebIDBFactoryImpl::DeleteDatabase( auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, nullptr); - factory_->DeleteDatabase(GetCallbacksProxy(std::move(callbacks_impl)), - url::Origin(origin), name.Utf16(), force_close); + DCHECK(!name.IsNull()); + factory_->DeleteDatabase(GetCallbacksProxy(std::move(callbacks_impl)), origin, + name, force_close); } -IDBCallbacksAssociatedPtrInfo WebIDBFactoryImpl::GetCallbacksProxy( +mojom::blink::IDBCallbacksAssociatedPtrInfo +WebIDBFactoryImpl::GetCallbacksProxy( std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { - IDBCallbacksAssociatedPtrInfo ptr_info; + mojom::blink::IDBCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); return ptr_info; } -IDBDatabaseCallbacksAssociatedPtrInfo +mojom::blink::IDBDatabaseCallbacksAssociatedPtrInfo WebIDBFactoryImpl::GetDatabaseCallbacksProxy( std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) { - IDBDatabaseCallbacksAssociatedPtrInfo ptr_info; + mojom::blink::IDBDatabaseCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); return ptr_info; } -} // namespace content +} // namespace blink diff --git a/content/renderer/indexed_db/webidbfactory_impl.h b/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h similarity index 63% rename from content/renderer/indexed_db/webidbfactory_impl.h rename to third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h index 619ea19bfb27e..dbc69d838e311 100644 --- a/content/renderer/indexed_db/webidbfactory_impl.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h @@ -2,28 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_RENDERER_INDEXED_DB_WEBIDBFACTORY_IMPL_H_ -#define CONTENT_RENDERER_INDEXED_DB_WEBIDBFACTORY_IMPL_H_ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_IMPL_H_ -#include "base/memory/ref_counted.h" -#include "base/single_thread_task_runner.h" -#include "content/renderer/indexed_db/indexed_db_callbacks_impl.h" -#include "content/renderer/indexed_db/indexed_db_database_callbacks_impl.h" -#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_factory.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" namespace blink { class WebSecurityOrigin; class WebString; -} // namespace blink - -namespace content { class WebIDBFactoryImpl : public blink::WebIDBFactory { public: - explicit WebIDBFactoryImpl(blink::mojom::IDBFactoryPtrInfo factory_info); + explicit WebIDBFactoryImpl(mojom::blink::IDBFactoryPtrInfo factory_info); ~WebIDBFactoryImpl() override; // See WebIDBFactory.h for documentation on these functions. @@ -50,14 +46,14 @@ class WebIDBFactoryImpl : public blink::WebIDBFactory { scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; private: - blink::mojom::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks); - blink::mojom::IDBDatabaseCallbacksAssociatedPtrInfo GetDatabaseCallbacksProxy( - std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks); + mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( + std::unique_ptr<blink::IndexedDBCallbacksImpl> callbacks); + mojom::blink::IDBDatabaseCallbacksAssociatedPtrInfo GetDatabaseCallbacksProxy( + std::unique_ptr<blink::IndexedDBDatabaseCallbacksImpl> callbacks); - blink::mojom::IDBFactoryPtr factory_; + mojom::blink::IDBFactoryPtr factory_; }; -} // namespace content +} // namespace blink -#endif // CONTENT_RENDERER_INDEXED_DB_WEBIDBFACTORY_IMPL_H_ +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_IMPL_H_ diff --git a/third_party/blink/renderer/platform/mojo/blink_typemaps.gni b/third_party/blink/renderer/platform/mojo/blink_typemaps.gni index 54610032c3b78..c7fab1a50eb28 100644 --- a/third_party/blink/renderer/platform/mojo/blink_typemaps.gni +++ b/third_party/blink/renderer/platform/mojo/blink_typemaps.gni @@ -10,6 +10,7 @@ typemaps = [ "//mojo/public/cpp/base/unguessable_token.typemap", "//third_party/blink/renderer/core/messaging/blink_cloneable_message.typemap", "//third_party/blink/renderer/core/messaging/blink_transferable_message.typemap", + "//third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap", "//third_party/blink/renderer/platform/blob/serialized_blob.typemap", "//third_party/blink/renderer/platform/mojo/big_buffer.typemap", "//third_party/blink/renderer/platform/mojo/big_string.typemap", diff --git a/third_party/blink/renderer/platform/testing/testing_platform_support.cc b/third_party/blink/renderer/platform/testing/testing_platform_support.cc index a9d9b23b2eebc..f44a0dc1480ee 100644 --- a/third_party/blink/renderer/platform/testing/testing_platform_support.cc +++ b/third_party/blink/renderer/platform/testing/testing_platform_support.cc @@ -110,10 +110,6 @@ WebBlobRegistry* TestingPlatformSupport::GetBlobRegistry() { return old_platform_ ? old_platform_->GetBlobRegistry() : nullptr; } -std::unique_ptr<WebIDBFactory> TestingPlatformSupport::CreateIdbFactory() { - return old_platform_ ? old_platform_->CreateIdbFactory() : nullptr; -} - WebURLLoaderMockFactory* TestingPlatformSupport::GetURLLoaderMockFactory() { return old_platform_ ? old_platform_->GetURLLoaderMockFactory() : nullptr; } diff --git a/third_party/blink/renderer/platform/testing/testing_platform_support.h b/third_party/blink/renderer/platform/testing/testing_platform_support.h index 87cfa93fc18d8..38bf52010e7fd 100644 --- a/third_party/blink/renderer/platform/testing/testing_platform_support.h +++ b/third_party/blink/renderer/platform/testing/testing_platform_support.h @@ -61,7 +61,6 @@ class TestingPlatformSupport : public Platform { // Platform: WebString DefaultLocale() override; WebBlobRegistry* GetBlobRegistry() override; - std::unique_ptr<WebIDBFactory> CreateIdbFactory() override; WebURLLoaderMockFactory* GetURLLoaderMockFactory() override; std::unique_ptr<blink::WebURLLoaderFactory> CreateDefaultURLLoaderFactory() override;