diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/third_party/blink/renderer/modules/indexeddb | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/indexeddb')
76 files changed, 2034 insertions, 1852 deletions
diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn b/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn index 624dbe229fb..f520827568b 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn +++ b/chromium/third_party/blink/renderer/modules/indexeddb/BUILD.gn @@ -18,6 +18,7 @@ blink_modules_sources("indexeddb") { "idb_database.h", "idb_database_callbacks.cc", "idb_database_callbacks.h", + "idb_database_error.h", "idb_event_dispatcher.cc", "idb_event_dispatcher.h", "idb_factory.cc", @@ -32,6 +33,7 @@ blink_modules_sources("indexeddb") { "idb_key_range.h", "idb_metadata.cc", "idb_metadata.h", + "idb_name_and_version.h", "idb_object_store.cc", "idb_object_store.h", "idb_observation.cc", @@ -60,8 +62,6 @@ blink_modules_sources("indexeddb") { "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", @@ -70,12 +70,14 @@ blink_modules_sources("indexeddb") { "indexed_db_dispatcher.h", "inspector_indexed_db_agent.cc", "inspector_indexed_db_agent.h", + "web_idb_callbacks.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.h", "web_idb_database_callbacks_impl.cc", "web_idb_database_callbacks_impl.h", "web_idb_database_impl.cc", diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/DEPS b/chromium/third_party/blink/renderer/modules/indexeddb/DEPS index db25c26f962..d75469e0e5e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/DEPS +++ b/chromium/third_party/blink/renderer/modules/indexeddb/DEPS @@ -1,4 +1,7 @@ include_rules = [ + "+mojo/public/cpp/base/file_path_mojom_traits.h", + "+mojo/public/cpp/base/string16_mojom_traits.h", + "+mojo/public/cpp/base/time_mojom_traits.h", "-third_party/blink/renderer/modules", "+third_party/blink/renderer/modules/event_modules.h", "+third_party/blink/renderer/modules/event_target_modules.h", diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc b/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc index c967e423941..ea3e68ce721 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/global_indexed_db.cc @@ -27,12 +27,14 @@ class GlobalIndexedDBImpl final GlobalIndexedDBImpl* supplement = Supplement<T>::template From<GlobalIndexedDBImpl>(supplementable); if (!supplement) { - supplement = new GlobalIndexedDBImpl; + supplement = MakeGarbageCollected<GlobalIndexedDBImpl>(); Supplement<T>::ProvideTo(supplementable, supplement); } return *supplement; } + GlobalIndexedDBImpl() = default; + IDBFactory* IdbFactory(T& fetching_scope) { if (!idb_factory_) idb_factory_ = IDBFactory::Create(); @@ -45,8 +47,6 @@ class GlobalIndexedDBImpl final } private: - GlobalIndexedDBImpl() = default; - Member<IDBFactory> idb_factory_; }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc index 07bad6af1d3..7e97b25d2f7 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.cc +++ b/chromium/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_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" #include "third_party/blink/renderer/bindings/modules/v8/v8_idb_request.h" @@ -42,9 +41,6 @@ #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/v8_private_property.h" -using blink::WebIDBCursor; -using blink::WebIDBDatabase; - namespace blink { IDBCursor* IDBCursor::Create(std::unique_ptr<WebIDBCursor> backend, @@ -281,7 +277,10 @@ void IDBCursor::Continue(std::unique_ptr<IDBKey> key, const IDBKey* current_primary_key = IdbPrimaryKey(); - if (key) { + if (!key) + key = IDBKey::CreateNull(); + + if (key->GetType() != mojom::IDBKeyType::Null) { DCHECK(key_); if (direction_ == mojom::IDBCursorDirection::Next || direction_ == mojom::IDBCursorDirection::NextNoDuplicate) { @@ -308,14 +307,16 @@ void IDBCursor::Continue(std::unique_ptr<IDBKey> key, } } + if (!primary_key) + primary_key = IDBKey::CreateNull(); + // FIXME: We're not using the context from when continue was called, which // means the callback will be on the original context openCursor was called // on. Is this right? request_->SetPendingCursor(this); request_->AssignNewMetrics(std::move(metrics)); got_value_ = false; - backend_->CursorContinue(WebIDBKeyView(key.get()), - WebIDBKeyView(primary_key.get()), + backend_->CursorContinue(key.get(), primary_key.get(), request_->CreateWebCallbacks().release()); } @@ -359,8 +360,8 @@ IDBRequest* IDBCursor::Delete(ScriptState* script_state, IDBRequest* request = IDBRequest::Create( script_state, this, transaction_.Get(), std::move(metrics)); transaction_->BackendDB()->Delete( - transaction_->Id(), EffectiveObjectStore()->Id(), - WebIDBKeyView(IdbPrimaryKey()), request->CreateWebCallbacks().release()); + transaction_->Id(), EffectiveObjectStore()->Id(), IdbPrimaryKey(), + request->CreateWebCallbacks().release()); return request; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl index b5d5b6383bc..aa1ce76c453 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor.idl @@ -43,7 +43,7 @@ enum IDBCursorDirection { [CallWith=ScriptState, CachedAttribute=isPrimaryKeyDirty] readonly attribute any primaryKey; [RaisesException] void advance([EnforceRange] unsigned long count); - [CallWith=ScriptState, ImplementedAs=Continue, RaisesException] void continue([Default=Undefined] optional any key); + [CallWith=ScriptState, ImplementedAs=Continue, RaisesException] void continue([DefaultValue=Undefined] optional any key); [CallWith=ScriptState, RaisesException] void continuePrimaryKey(any key, any primaryKey); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest update(any value); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.cc index b9bad7823eb..7df7371d33f 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.cc @@ -28,8 +28,6 @@ #include <memory> #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" -using blink::WebIDBCursor; - namespace blink { IDBCursorWithValue* IDBCursorWithValue::Create( diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc index c8764dc38ca..6c48bda9eab 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.cc @@ -25,13 +25,13 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_database.h" +#include <limits> +#include <memory> + #include "base/atomic_sequence_num.h" #include "base/optional.h" #include "third_party/blink/public/common/indexeddb/web_idb_types.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_exception.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_path.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_idb_observer_callback.h" @@ -45,17 +45,13 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h" #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/histogram.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" -#include <limits> -#include <memory> - -using blink::WebIDBDatabase; - namespace blink { const char IDBDatabase::kCannotObserveVersionChangeTransaction[] = @@ -190,14 +186,10 @@ void IDBDatabase::OnComplete(int64_t transaction_id) { void IDBDatabase::OnChanges( const WebIDBDatabaseCallbacks::ObservationIndexMap& observation_index_map, - WebVector<WebIDBObservation> web_observations, + Vector<Persistent<IDBObservation>> observations, const WebIDBDatabaseCallbacks::TransactionMap& transactions) { - HeapVector<Member<IDBObservation>> observations; - observations.ReserveInitialCapacity( - SafeCast<wtf_size_t>(web_observations.size())); - for (WebIDBObservation& web_observation : web_observations) { - observations.emplace_back( - IDBObservation::Create(std::move(web_observation), isolate_)); + for (const auto& observation : observations) { + observation->SetIsolate(isolate_); } for (const auto& map_entry : observation_index_map) { @@ -208,7 +200,7 @@ void IDBDatabase::OnChanges( IDBTransaction* transaction = nullptr; auto it = transactions.find(map_entry.first); if (it != transactions.end()) { - const std::pair<int64_t, WebVector<int64_t>>& obs_txn = it->second; + const std::pair<int64_t, Vector<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); @@ -219,9 +211,8 @@ void IDBDatabase::OnChanges( } observer->Callback()->InvokeAndReportException( - observer, - IDBObserverChanges::Create(this, transaction, web_observations, - observations, map_entry.second)); + observer, IDBObserverChanges::Create(this, transaction, observations, + map_entry.second)); if (transaction) transaction->SetActive(false); } @@ -295,9 +286,9 @@ IDBObjectStore* IDBDatabase::createObjectStore( return nullptr; } - if (auto_increment && ((key_path.GetType() == IDBKeyPath::kStringType && + if (auto_increment && ((key_path.GetType() == mojom::IDBKeyPathType::String && key_path.GetString().IsEmpty()) || - key_path.GetType() == IDBKeyPath::kArrayType)) { + key_path.GetType() == mojom::IDBKeyPathType::Array)) { exception_state.ThrowDOMException( DOMExceptionCode::kInvalidAccessError, "The autoIncrement option was set but the " diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h index 1e2f20782d1..d68c2b78c53 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database.h +++ b/chromium/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_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" #include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h" @@ -43,6 +42,7 @@ #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/indexeddb/web_idb_database_callbacks.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" @@ -53,8 +53,8 @@ namespace blink { class DOMException; class ExceptionState; class ExecutionContext; +class IDBObservation; class IDBObserver; -struct WebIDBObservation; class MODULES_EXPORT IDBDatabase final : public EventTargetWithInlineData, @@ -123,7 +123,7 @@ class MODULES_EXPORT IDBDatabase final void OnAbort(int64_t, DOMException*); void OnComplete(int64_t); void OnChanges(const WebIDBDatabaseCallbacks::ObservationIndexMap&, - WebVector<WebIDBObservation> observations, + Vector<Persistent<IDBObservation>> observations, const WebIDBDatabaseCallbacks::TransactionMap& transactions); // ScriptWrappable diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc index 7fa1f036ed7..284072da599 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.cc @@ -25,8 +25,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" -#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h" @@ -68,7 +66,7 @@ void IDBDatabaseCallbacks::OnComplete(int64_t transaction_id) { void IDBDatabaseCallbacks::OnChanges( const WebIDBDatabaseCallbacks::ObservationIndexMap& observation_index_map, - WebVector<WebIDBObservation> observations, + Vector<Persistent<IDBObservation>> observations, const WebIDBDatabaseCallbacks::TransactionMap& transactions) { if (!database_) return; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h index 2a4a0c30890..1da199ae00e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h @@ -26,8 +26,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_DATABASE_CALLBACKS_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_DATABASE_CALLBACKS_H_ -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_callbacks.h" -#include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/heap/handle.h" @@ -37,7 +36,7 @@ namespace blink { class DOMException; class IDBDatabase; -struct WebIDBObservation; +class IDBObservation; class MODULES_EXPORT IDBDatabaseCallbacks : public GarbageCollectedFinalized<IDBDatabaseCallbacks> { @@ -56,7 +55,7 @@ class MODULES_EXPORT IDBDatabaseCallbacks virtual void OnComplete(int64_t transaction_id); virtual void OnChanges( const WebIDBDatabaseCallbacks::ObservationIndexMap&, - WebVector<WebIDBObservation> observations, + Vector<Persistent<IDBObservation>> observations, const WebIDBDatabaseCallbacks::TransactionMap& transactions); void Connect(IDBDatabase*); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_error.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_error.h new file mode 100644 index 00000000000..fed841d671d --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_database_error.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_DATABASE_ERROR_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_DATABASE_ERROR_H_ + +#include "third_party/blink/renderer/modules/modules_export.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +class IDBDatabaseError { + public: + explicit IDBDatabaseError(unsigned short code) : code_(code) {} + + IDBDatabaseError(unsigned short code, String message) + : code_(code), message_(std::move(message)) {} + + IDBDatabaseError(const IDBDatabaseError& error) = default; + + ~IDBDatabaseError() = default; + + IDBDatabaseError& operator=(const IDBDatabaseError& error) = default; + + unsigned short Code() const { return code_; } + const String& Message() const { return message_; } + + private: + unsigned short code_; + String message_; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_DATABASE_ERROR_H_ diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc index 45b8196e6fc..ac2d5cae2d6 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.cc @@ -31,15 +31,11 @@ #include <memory> #include <utility> +#include "services/service_manager/public/cpp/interface_provider.h" #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_name_and_version.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/task_type.h" -#include "third_party/blink/public/platform/web_security_origin.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_binding_for_modules.h" #include "third_party/blink/renderer/core/dom/document.h" @@ -52,8 +48,11 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_info.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.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_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.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" @@ -93,7 +92,10 @@ class WebIDBGetDBNamesCallbacksImpl : public WebIDBCallbacks { } } - void OnError(const WebIDBDatabaseError& error) override { + void SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) override {} + + void Error(int32_t code, const String& message) override { if (!promise_resolver_) return; @@ -106,66 +108,84 @@ class WebIDBGetDBNamesCallbacksImpl : public WebIDBCallbacks { promise_resolver_.Clear(); } - void OnSuccess(const WebVector<WebIDBNameAndVersion>& - web_database_name_and_version_list) override { + void SuccessNamesAndVersionsList( + Vector<mojom::blink::IDBNameAndVersionPtr> names_and_versions) override { if (!promise_resolver_) return; - HeapVector<Member<IDBDatabaseInfo>> database_name_and_version_list; - for (size_t i = 0; i < web_database_name_and_version_list.size(); ++i) { + HeapVector<Member<IDBDatabaseInfo>> name_and_version_list; + name_and_version_list.ReserveInitialCapacity(name_and_version_list.size()); + for (const mojom::blink::IDBNameAndVersionPtr& name_version : + names_and_versions) { + const IDBNameAndVersion idb_name_and_version(name_version->name, + name_version->version); IDBDatabaseInfo* idb_info = IDBDatabaseInfo::Create(); - idb_info->setName(web_database_name_and_version_list[i].name); - idb_info->setVersion(web_database_name_and_version_list[i].version); - database_name_and_version_list.push_back(idb_info); + idb_info->setName(name_version->name); + idb_info->setVersion(name_version->version); + name_and_version_list.push_back(idb_info); } + probe::AsyncTask async_task( ExecutionContext::From(promise_resolver_->GetScriptState()), this, "success"); - promise_resolver_->Resolve(database_name_and_version_list); + promise_resolver_->Resolve(name_and_version_list); promise_resolver_.Clear(); } - void OnSuccess(const WebVector<WebString>&) override { NOTREACHED(); } + void SuccessStringList(const Vector<String>&) override { NOTREACHED(); } - void OnSuccess(WebIDBCursor* cursor, - WebIDBKey key, - WebIDBKey primary_key, - WebIDBValue value) override { + void SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) override { NOTREACHED(); } - void OnSuccess(WebIDBDatabase* backend, - const WebIDBMetadata& metadata) override { + void SuccessCursorPrefetch( + Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values) override { NOTREACHED(); } - void OnSuccess(WebIDBKey key) override { NOTREACHED(); } + void SuccessDatabase(mojom::blink::IDBDatabaseAssociatedPtrInfo backend, + const IDBDatabaseMetadata& metadata) override { + NOTREACHED(); + } - void OnSuccess(WebIDBValue value) override { NOTREACHED(); } + void SuccessKey(std::unique_ptr<IDBKey> key) override { NOTREACHED(); } - void OnSuccess(WebVector<WebIDBValue> values) override { NOTREACHED(); } + void SuccessValue(mojom::blink::IDBReturnValuePtr return_value) override { + NOTREACHED(); + } + + void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr> values) override { + NOTREACHED(); + } - void OnSuccess(long long value) override { NOTREACHED(); } + void SuccessInteger(int64_t value) override { NOTREACHED(); } - void OnSuccess() override { NOTREACHED(); } + void Success() override { NOTREACHED(); } - void OnSuccess(WebIDBKey key, - WebIDBKey primary_key, - WebIDBValue value) override { + void SuccessCursorContinue( + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> value) override { NOTREACHED(); } - void OnBlocked(long long old_version) override { NOTREACHED(); } + void Blocked(int64_t old_version) override { NOTREACHED(); } - void OnUpgradeNeeded(long long old_version, - WebIDBDatabase* database, - const WebIDBMetadata& metadata, - mojom::IDBDataLoss data_loss, - WebString data_loss_message) override { + void UpgradeNeeded(mojom::blink::IDBDatabaseAssociatedPtrInfo database, + int64_t old_version, + mojom::IDBDataLoss data_loss, + const String& data_loss_message, + const IDBDatabaseMetadata& metadata) override { NOTREACHED(); } - void Detach() override { NOTREACHED(); } + void DetachRequestFromCallback() override { NOTREACHED(); } private: Persistent<ScriptPromiseResolver> promise_resolver_; @@ -188,13 +208,18 @@ static bool IsContextValid(ExecutionContext* context) { return true; } -WebIDBFactory* IDBFactory::GetFactory() { +WebIDBFactory* IDBFactory::GetFactory(ExecutionContext* execution_context) { if (!web_idb_factory_) { mojom::blink::IDBFactoryPtrInfo web_idb_factory_host_info; - Platform::Current()->GetInterfaceProvider()->GetInterface( + service_manager::InterfaceProvider* interface_provider = + execution_context->GetInterfaceProvider(); + if (!interface_provider) + return nullptr; + interface_provider->GetInterface( mojo::MakeRequest(&web_idb_factory_host_info)); web_idb_factory_ = std::make_unique<WebIDBFactoryImpl>( - std::move(web_idb_factory_host_info)); + std::move(web_idb_factory_host_info), + execution_context->GetTaskRunner(TaskType::kInternalIndexedDB)); } return web_idb_factory_.get(); } @@ -212,12 +237,14 @@ ScriptPromise IDBFactory::GetDatabaseInfo(ScriptState* script_state, return resolver->Promise(); } - GetFactory()->GetDatabaseInfo( - WebIDBGetDBNamesCallbacksImpl::Create(resolver).release(), - WebSecurityOrigin( - ExecutionContext::From(script_state)->GetSecurityOrigin()), - ExecutionContext::From(script_state) - ->GetTaskRunner(TaskType::kInternalIndexedDB)); + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + resolver->Reject(); + return resolver->Promise(); + } + factory->GetDatabaseInfo(WebIDBGetDBNamesCallbacksImpl::Create(resolver)); ScriptPromise promise = resolver->Promise(); return promise; } @@ -251,12 +278,13 @@ IDBRequest* IDBFactory::GetDatabaseNames(ScriptState* script_state, return request; } - GetFactory()->GetDatabaseNames( - request->CreateWebCallbacks().release(), - WebSecurityOrigin( - ExecutionContext::From(script_state)->GetSecurityOrigin()), - ExecutionContext::From(script_state) - ->GetTaskRunner(TaskType::kInternalIndexedDB)); + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + return nullptr; + } + factory->GetDatabaseNames(request->CreateWebCallbacks()); return request; } @@ -306,13 +334,14 @@ IDBOpenDBRequest* IDBFactory::OpenInternal(ScriptState* script_state, return request; } - GetFactory()->Open( - name, version, transaction_id, request->CreateWebCallbacks().release(), - database_callbacks->CreateWebCallbacks().release(), - WebSecurityOrigin( - ExecutionContext::From(script_state)->GetSecurityOrigin()), - ExecutionContext::From(script_state) - ->GetTaskRunner(TaskType::kInternalIndexedDB)); + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + return nullptr; + } + factory->Open(name, version, transaction_id, request->CreateWebCallbacks(), + database_callbacks->CreateWebCallbacks()); return request; } @@ -372,13 +401,13 @@ IDBOpenDBRequest* IDBFactory::DeleteDatabaseInternal( return request; } - GetFactory()->DeleteDatabase( - name, request->CreateWebCallbacks().release(), - WebSecurityOrigin( - ExecutionContext::From(script_state)->GetSecurityOrigin()), - force_close, - ExecutionContext::From(script_state) - ->GetTaskRunner(TaskType::kInternalIndexedDB)); + ExecutionContext* execution_context = ExecutionContext::From(script_state); + WebIDBFactory* factory = GetFactory(execution_context); + if (!factory) { + exception_state.ThrowSecurityError("An internal error occurred."); + return nullptr; + } + factory->DeleteDatabase(name, request->CreateWebCallbacks(), force_close); return request; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.h index 68b8234455c..46485497b4a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.h @@ -78,7 +78,7 @@ class MODULES_EXPORT IDBFactory final : public ScriptWrappable { ScriptPromise GetDatabaseInfo(ScriptState*, ExceptionState&); private: - WebIDBFactory* GetFactory(); + WebIDBFactory* GetFactory(ExecutionContext* execution_context); IDBOpenDBRequest* OpenInternal(ScriptState*, const String& name, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.idl index 291900fde26..c4c19c5c047 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory.idl @@ -40,6 +40,7 @@ [ CallWith=ScriptState, ImplementedAs=GetDatabaseInfo, + Measure, RaisesException ] Promise<sequence<IDBDatabaseInfo>> databases(); }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory_test.cc index 7cdb287cb84..ec0725a2795 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_factory_test.cc @@ -9,8 +9,7 @@ #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_database_error.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_name_and_version.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/public/platform/web_security_origin.h" #include "third_party/blink/renderer/bindings/core/v8/script_function.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" @@ -18,6 +17,8 @@ #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_database_error.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h" #include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" @@ -29,14 +30,15 @@ class TestHelperFunction : public ScriptFunction { public: static v8::Local<v8::Function> CreateFunction(ScriptState* script_state, bool* called_flag) { - auto* self = new TestHelperFunction(script_state, called_flag); + auto* self = + MakeGarbageCollected<TestHelperFunction>(script_state, called_flag); return self->BindToV8Function(); } - private: TestHelperFunction(ScriptState* script_state, bool* called_flag) : ScriptFunction(script_state), called_flag_(called_flag) {} + private: ScriptValue Call(ScriptValue value) override { *called_flag_ = true; return value; @@ -52,21 +54,13 @@ class IDBFactoryTest : public testing::Test { ~IDBFactoryTest() override {} }; -ACTION_TEMPLATE(SaveUniquePointer, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_1_VALUE_PARAMS(unique_pointer)) { - *unique_pointer = base::WrapUnique(std::get<k>(args)); -} - TEST_F(IDBFactoryTest, WebIDBGetDBInfoCallbacksResolvesPromise) { V8TestingScope scope; scope.GetDocument().SetSecurityOrigin( SecurityOrigin::Create(KURL("https://example.com"))); std::unique_ptr<MockWebIDBFactory> web_factory = MockWebIDBFactory::Create(); - std::unique_ptr<WebIDBCallbacks> wc; - EXPECT_CALL(*web_factory, GetDatabaseInfo(testing::_, testing::_, testing::_)) - .Times(1) - .WillOnce(SaveUniquePointer<0>(&wc)); + std::unique_ptr<WebIDBCallbacks> callbacks; + web_factory->SetCallbacksPointer(&callbacks); IDBFactory* factory = IDBFactory::CreateForTest(std::move(web_factory)); DummyExceptionStateForTesting exception_state; @@ -81,8 +75,8 @@ TEST_F(IDBFactoryTest, WebIDBGetDBInfoCallbacksResolvesPromise) { EXPECT_FALSE(on_fulfilled); EXPECT_FALSE(on_rejected); - const WebVector<WebIDBNameAndVersion> wv; - wc->OnSuccess(wv); + Vector<mojom::blink::IDBNameAndVersionPtr> name_and_info_list; + callbacks->SuccessNamesAndVersionsList(std::move(name_and_info_list)); EXPECT_FALSE(on_fulfilled); EXPECT_FALSE(on_rejected); @@ -98,10 +92,8 @@ TEST_F(IDBFactoryTest, WebIDBGetDBNamesCallbacksRejectsPromise) { scope.GetDocument().SetSecurityOrigin( SecurityOrigin::Create(KURL("https://example.com"))); std::unique_ptr<MockWebIDBFactory> web_factory = MockWebIDBFactory::Create(); - std::unique_ptr<WebIDBCallbacks> wc; - EXPECT_CALL(*web_factory, GetDatabaseInfo(testing::_, testing::_, testing::_)) - .Times(1) - .WillOnce(SaveUniquePointer<0>(&wc)); + std::unique_ptr<WebIDBCallbacks> callbacks; + web_factory->SetCallbacksPointer(&callbacks); IDBFactory* factory = IDBFactory::CreateForTest(std::move(web_factory)); DummyExceptionStateForTesting exception_state; @@ -116,8 +108,7 @@ TEST_F(IDBFactoryTest, WebIDBGetDBNamesCallbacksRejectsPromise) { EXPECT_FALSE(on_fulfilled); EXPECT_FALSE(on_rejected); - const WebVector<WebIDBNameAndVersion> wv; - wc->OnError(WebIDBDatabaseError(1)); + callbacks->Error(0, String()); EXPECT_FALSE(on_fulfilled); EXPECT_FALSE(on_rejected); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc index 06564cbfadc..a20657b0031 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.cc @@ -26,7 +26,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_index.h" #include <memory> -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_range.h" + #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h" #include "third_party/blink/renderer/bindings/modules/v8/idb_object_store_or_idb_index_or_idb_cursor.h" #include "third_party/blink/renderer/bindings/modules/v8/to_v8_for_modules.h" @@ -39,10 +39,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h" -using blink::WebIDBCallbacks; -using blink::WebIDBCursor; -using blink::WebIDBDatabase; - namespace blink { IDBIndex::IDBIndex(scoped_refptr<IDBIndexMetadata> metadata, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl index 84eca6dfafa..cc8becb0227 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_index.idl @@ -36,14 +36,14 @@ [NewObject, CallWith=ScriptState, RaisesException] IDBRequest get(any key); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getKey(any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll([Default=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll([DefaultValue=Undefined] optional any query, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys([Default=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys([DefaultValue=Undefined] optional any query, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count([Default=Undefined] optional any key); + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count([DefaultValue=Undefined] optional any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor([Default=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor([DefaultValue=Undefined] optional any range, optional IDBCursorDirection direction = "next"); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor([Default=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor([DefaultValue=Undefined] optional any range, optional IDBCursorDirection direction = "next"); }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.cc index d061b3e3fed..3223cc205a1 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.cc @@ -29,13 +29,15 @@ #include <memory> #include "third_party/blink/public/common/indexeddb/web_idb_types.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" #include "third_party/blink/renderer/platform/wtf/assertions.h" namespace blink { namespace { +// Very rough estimate of minimum key size overhead. +const size_t kIDBKeyOverheadSize = 16; + size_t CalculateIDBKeyArraySize(const IDBKey::KeyArray& keys) { size_t size(0); for (const auto& key : keys) @@ -45,36 +47,81 @@ size_t CalculateIDBKeyArraySize(const IDBKey::KeyArray& keys) { } // namespace -IDBKey::IDBKey() : type_(kInvalidType), size_estimate_(kIDBKeyOverheadSize) {} +// static +std::unique_ptr<IDBKey> IDBKey::Clone(const IDBKey* rkey) { + if (!rkey) + return IDBKey::CreateNull(); + + switch (rkey->GetType()) { + case mojom::IDBKeyType::Invalid: + return IDBKey::CreateInvalid(); + case mojom::IDBKeyType::Null: + return IDBKey::CreateNull(); + case mojom::IDBKeyType::Array: { + 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 mojom::IDBKeyType::Binary: + return IDBKey::CreateBinary(rkey->Binary()); + case mojom::IDBKeyType::String: + return IDBKey::CreateString(rkey->GetString()); + case mojom::IDBKeyType::Date: + return IDBKey::CreateDate(rkey->Date()); + case mojom::IDBKeyType::Number: + return IDBKey::CreateNumber(rkey->Number()); + + case mojom::IDBKeyType::Min: + break; // Not used, NOTREACHED. + } + NOTREACHED(); + return nullptr; +} + +IDBKey::IDBKey() + : type_(mojom::IDBKeyType::Invalid), size_estimate_(kIDBKeyOverheadSize) {} + +// Must be Invalid or Null. +IDBKey::IDBKey(mojom::IDBKeyType type) + : type_(type), size_estimate_(kIDBKeyOverheadSize) { + DCHECK(type_ == mojom::IDBKeyType::Invalid || + type_ == mojom::IDBKeyType::Null); +} -IDBKey::IDBKey(Type type, double number) +// Must be Number or Date. +IDBKey::IDBKey(mojom::IDBKeyType type, double number) : type_(type), number_(number), - size_estimate_(kIDBKeyOverheadSize + sizeof(number_)) {} + size_estimate_(kIDBKeyOverheadSize + sizeof(number_)) { + DCHECK(type_ == mojom::IDBKeyType::Number || + type_ == mojom::IDBKeyType::Date); +} IDBKey::IDBKey(const String& value) - : type_(kStringType), + : type_(mojom::IDBKeyType::String), string_(value), size_estimate_(kIDBKeyOverheadSize + (string_.length() * sizeof(UChar))) { } IDBKey::IDBKey(scoped_refptr<SharedBuffer> value) - : type_(kBinaryType), + : type_(mojom::IDBKeyType::Binary), binary_(std::move(value)), size_estimate_(kIDBKeyOverheadSize + binary_.get()->size()) {} IDBKey::IDBKey(KeyArray key_array) - : type_(kArrayType), + : type_(mojom::IDBKeyType::Array), array_(std::move(key_array)), size_estimate_(kIDBKeyOverheadSize + CalculateIDBKeyArraySize(array_)) {} IDBKey::~IDBKey() = default; bool IDBKey::IsValid() const { - if (type_ == kInvalidType) + if (type_ == mojom::IDBKeyType::Invalid) return false; - if (type_ == kArrayType) { + if (type_ == mojom::IDBKeyType::Array) { for (const auto& element : array_) { if (!element->IsValid()) return false; @@ -100,26 +147,29 @@ int IDBKey::Compare(const IDBKey* other) const { return type_ > other->type_ ? -1 : 1; switch (type_) { - case kArrayType: + case mojom::IDBKeyType::Array: for (wtf_size_t i = 0; i < array_.size() && i < other->array_.size(); ++i) { if (int result = array_[i]->Compare(other->array_[i].get())) return result; } return CompareNumbers(array_.size(), other->array_.size()); - case kBinaryType: + case mojom::IDBKeyType::Binary: if (int result = memcmp(binary_->Data(), other->binary_->Data(), std::min(binary_->size(), other->binary_->size()))) return result < 0 ? -1 : 1; return CompareNumbers(binary_->size(), other->binary_->size()); - case kStringType: + case mojom::IDBKeyType::String: return CodePointCompare(string_, other->string_); - case kDateType: - case kNumberType: + case mojom::IDBKeyType::Date: + case mojom::IDBKeyType::Number: return CompareNumbers(number_, other->number_); - case kInvalidType: - case kTypeEnumMax: + + // These values cannot be compared to each other. + case mojom::IDBKeyType::Invalid: + case mojom::IDBKeyType::Null: + case mojom::IDBKeyType::Min: NOTREACHED(); return 0; } @@ -141,11 +191,11 @@ bool IDBKey::IsEqual(const IDBKey* other) const { } // static -WebVector<WebIDBKey> IDBKey::ToMultiEntryArray( +Vector<std::unique_ptr<IDBKey>> IDBKey::ToMultiEntryArray( std::unique_ptr<IDBKey> array_key) { - DCHECK_EQ(array_key->type_, kArrayType); - WebVector<WebIDBKey> result; - result.reserve(array_key->array_.size()); + DCHECK_EQ(array_key->type_, mojom::IDBKeyType::Array); + Vector<std::unique_ptr<IDBKey>> result; + result.ReserveInitialCapacity(array_key->array_.size()); for (std::unique_ptr<IDBKey>& key : array_key->array_) { if (key->IsValid()) result.emplace_back(std::move(key)); @@ -154,21 +204,15 @@ WebVector<WebIDBKey> IDBKey::ToMultiEntryArray( // Remove duplicates using std::sort/std::unique rather than a hashtable to // avoid the complexity of implementing DefaultHash<IDBKey>. std::sort( - result.begin(), result.end(), [](const WebIDBKey& a, const WebIDBKey& b) { - return static_cast<IDBKey*>(a)->IsLessThan(static_cast<IDBKey*>(b)); + result.begin(), result.end(), + [](const std::unique_ptr<IDBKey>& a, const std::unique_ptr<IDBKey>& b) { + return (a)->IsLessThan(b.get()); }); - const auto end = std::unique(result.begin(), result.end()); + std::unique_ptr<IDBKey>* end = std::unique(result.begin(), result.end()); DCHECK_LE(static_cast<wtf_size_t>(end - result.begin()), result.size()); - result.resize(end - result.begin()); + result.resize(static_cast<wtf_size_t>(end - result.begin())); return result; } -STATIC_ASSERT_ENUM(kWebIDBKeyTypeInvalid, IDBKey::kInvalidType); -STATIC_ASSERT_ENUM(kWebIDBKeyTypeArray, IDBKey::kArrayType); -STATIC_ASSERT_ENUM(kWebIDBKeyTypeBinary, IDBKey::kBinaryType); -STATIC_ASSERT_ENUM(kWebIDBKeyTypeString, IDBKey::kStringType); -STATIC_ASSERT_ENUM(kWebIDBKeyTypeDate, IDBKey::kDateType); -STATIC_ASSERT_ENUM(kWebIDBKeyTypeNumber, IDBKey::kNumberType); - } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.h index 9c8e9addf5d..2bfada42877 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key.h @@ -32,8 +32,7 @@ #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key.h" -#include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-shared.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/shared_buffer.h" #include "third_party/blink/renderer/platform/wtf/forward.h" @@ -57,8 +56,12 @@ class MODULES_EXPORT IDBKey { return base::WrapUnique(new IDBKey()); } + static std::unique_ptr<IDBKey> CreateNull() { + return base::WrapUnique(new IDBKey(mojom::IDBKeyType::Null)); + } + static std::unique_ptr<IDBKey> CreateNumber(double number) { - return base::WrapUnique(new IDBKey(kNumberType, number)); + return base::WrapUnique(new IDBKey(mojom::IDBKeyType::Number, number)); } static std::unique_ptr<IDBKey> CreateBinary( @@ -71,95 +74,46 @@ class MODULES_EXPORT IDBKey { } static std::unique_ptr<IDBKey> CreateDate(double date) { - return base::WrapUnique(new IDBKey(kDateType, date)); + return base::WrapUnique(new IDBKey(mojom::IDBKeyType::Date, date)); } static std::unique_ptr<IDBKey> CreateArray(KeyArray array) { 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; + return IDBKey::Clone(rkey_in.get()); } + static std::unique_ptr<IDBKey> Clone(const IDBKey* rkey); + ~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. - enum Type { - kInvalidType = 0, - kArrayType = 1, - kBinaryType = 2, - kStringType = 3, - kDateType = 4, - kNumberType = 5, - kTypeEnumMax, - }; - - Type GetType() const { return type_; } + mojom::IDBKeyType GetType() const { return type_; } bool IsValid() const; const KeyArray& Array() const { - DCHECK_EQ(type_, kArrayType); + DCHECK_EQ(type_, mojom::IDBKeyType::Array); return array_; } scoped_refptr<SharedBuffer> Binary() const { - DCHECK_EQ(type_, kBinaryType); + DCHECK_EQ(type_, mojom::IDBKeyType::Binary); return binary_; } const String& GetString() const { - DCHECK_EQ(type_, kStringType); + DCHECK_EQ(type_, mojom::IDBKeyType::String); return string_; } double Date() const { - DCHECK_EQ(type_, kDateType); + DCHECK_EQ(type_, mojom::IDBKeyType::Date); return number_; } double Number() const { - DCHECK_EQ(type_, kNumberType); + DCHECK_EQ(type_, mojom::IDBKeyType::Number); return number_; } @@ -177,19 +131,20 @@ class MODULES_EXPORT IDBKey { // The return value will be pasesd to the backing store, which requires // Web types. Returning the correct types directly avoids copying later on // (wasted CPU cycles and code size). - static WebVector<WebIDBKey> ToMultiEntryArray( + static Vector<std::unique_ptr<IDBKey>> ToMultiEntryArray( std::unique_ptr<IDBKey> array_key); private: DISALLOW_COPY_AND_ASSIGN(IDBKey); IDBKey(); - IDBKey(Type type, double number); + IDBKey(mojom::IDBKeyType type); + IDBKey(mojom::IDBKeyType type, double number); explicit IDBKey(const String& value); explicit IDBKey(scoped_refptr<SharedBuffer> value); explicit IDBKey(KeyArray key_array); - Type type_; + mojom::IDBKeyType type_; KeyArray array_; scoped_refptr<SharedBuffer> binary_; const String string_; @@ -201,6 +156,8 @@ class MODULES_EXPORT IDBKey { size_t size_estimate_; }; +using IDBIndexKeys = std::pair<int64_t, Vector<std::unique_ptr<IDBKey>>>; + } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_KEY_H_ diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.cc index ca3f5c67ced..5ac71bf54a0 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.cc @@ -103,12 +103,12 @@ void IDBParseKeyPath(const String& key_path, } IDBKeyPath::IDBKeyPath(const class String& string) - : type_(kStringType), string_(string) { + : type_(mojom::IDBKeyPathType::String), string_(string) { DCHECK(!string_.IsNull()); } IDBKeyPath::IDBKeyPath(const Vector<class String>& array) - : type_(kArrayType), array_(array) { + : type_(mojom::IDBKeyPathType::Array), array_(array) { #if DCHECK_IS_ON() for (const auto& element : array_) DCHECK(!element.IsNull()); @@ -117,14 +117,14 @@ IDBKeyPath::IDBKeyPath(const Vector<class String>& array) IDBKeyPath::IDBKeyPath(const StringOrStringSequence& key_path) { if (key_path.IsNull()) { - type_ = kNullType; + type_ = mojom::IDBKeyPathType::Null; } else if (key_path.IsString()) { - type_ = kStringType; + type_ = mojom::IDBKeyPathType::String; string_ = key_path.GetAsString(); DCHECK(!string_.IsNull()); } else { DCHECK(key_path.IsStringSequence()); - type_ = kArrayType; + type_ = mojom::IDBKeyPathType::Array; array_ = key_path.GetAsStringSequence(); #if DCHECK_IS_ON() for (const auto& element : array_) @@ -133,48 +133,15 @@ IDBKeyPath::IDBKeyPath(const StringOrStringSequence& key_path) { } } -IDBKeyPath::IDBKeyPath(const WebIDBKeyPath& key_path) { - switch (key_path.KeyPathType()) { - case kWebIDBKeyPathTypeNull: - type_ = kNullType; - return; - - case kWebIDBKeyPathTypeString: - type_ = kStringType; - string_ = key_path.String(); - return; - - case kWebIDBKeyPathTypeArray: - type_ = kArrayType; - for (size_t i = 0, size = key_path.Array().size(); i < size; ++i) - array_.push_back(key_path.Array()[i]); - return; - } - NOTREACHED(); -} - -IDBKeyPath::operator WebIDBKeyPath() const { - switch (type_) { - case kNullType: - return WebIDBKeyPath(); - case kStringType: - return WebIDBKeyPath(WebString(string_)); - case kArrayType: - return WebIDBKeyPath(array_); - } - NOTREACHED(); - return WebIDBKeyPath(); -} - bool IDBKeyPath::IsValid() const { switch (type_) { - case kNullType: + case mojom::IDBKeyPathType::Null: return false; - case kStringType: + case mojom::IDBKeyPathType::String: return IDBIsValidKeyPath(string_); - case kArrayType: + case mojom::IDBKeyPathType::Array: if (array_.IsEmpty()) return false; for (const auto& element : array_) { @@ -192,19 +159,15 @@ bool IDBKeyPath::operator==(const IDBKeyPath& other) const { return false; switch (type_) { - case kNullType: + case mojom::IDBKeyPathType::Null: return true; - case kStringType: + case mojom::IDBKeyPathType::String: return string_ == other.string_; - case kArrayType: + case mojom::IDBKeyPathType::Array: return array_ == other.array_; } NOTREACHED(); return false; } -STATIC_ASSERT_ENUM(kWebIDBKeyPathTypeNull, IDBKeyPath::kNullType); -STATIC_ASSERT_ENUM(kWebIDBKeyPathTypeString, IDBKeyPath::kStringType); -STATIC_ASSERT_ENUM(kWebIDBKeyPathTypeArray, IDBKeyPath::kArrayType); - } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.h index f78a1dda2ef..c31407fca36 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path.h @@ -26,7 +26,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_KEY_PATH_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_KEY_PATH_H_ -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_key_path.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-shared.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_string_sequence.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" @@ -48,34 +48,29 @@ class MODULES_EXPORT IDBKeyPath { DISALLOW_NEW(); public: - IDBKeyPath() : type_(kNullType) {} + IDBKeyPath() : type_(mojom::IDBKeyPathType::Null) {} explicit IDBKeyPath(const String&); explicit IDBKeyPath(const Vector<String>& array); explicit IDBKeyPath(const StringOrStringSequence& key_path); - IDBKeyPath(const WebIDBKeyPath&); - operator WebIDBKeyPath() const; - - enum Type { kNullType = 0, kStringType, kArrayType }; - - Type GetType() const { return type_; } + mojom::IDBKeyPathType GetType() const { return type_; } const Vector<String>& Array() const { - DCHECK_EQ(type_, kArrayType); + DCHECK_EQ(type_, mojom::IDBKeyPathType::Array); return array_; } const String& GetString() const { - DCHECK_EQ(type_, kStringType); + DCHECK_EQ(type_, mojom::IDBKeyPathType::String); return string_; } - bool IsNull() const { return type_ == kNullType; } + bool IsNull() const { return type_ == mojom::IDBKeyPathType::Null; } bool IsValid() const; bool operator==(const IDBKeyPath& other) const; private: - Type type_; + mojom::IDBKeyPathType type_; class String string_; Vector<class String> array_; }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path_test.cc index 92e1f492f9d..9524c19e451 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_path_test.cc @@ -38,7 +38,7 @@ void CheckKeyPath(const String& key_path, const Vector<String>& expected, int parser_error) { IDBKeyPath idb_key_path(key_path); - ASSERT_EQ(idb_key_path.GetType(), IDBKeyPath::kStringType); + ASSERT_EQ(idb_key_path.GetType(), mojom::IDBKeyPathType::String); ASSERT_EQ(idb_key_path.IsValid(), (parser_error == kIDBKeyPathParseErrorNone)); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.cc index 193c0cfaf43..f9af24895aa 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.cc @@ -40,13 +40,13 @@ IDBKeyRange* IDBKeyRange::FromScriptValue(ExecutionContext* context, if (value.IsUndefined() || value.IsNull()) return nullptr; - IDBKeyRange* const range = - ScriptValue::To<IDBKeyRange*>(ToIsolate(context), value, exception_state); + IDBKeyRange* const range = ScriptValue::To<IDBKeyRange*>( + context->GetIsolate(), value, exception_state); if (range) return range; std::unique_ptr<IDBKey> key = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(context), value, exception_state); + context->GetIsolate(), value, exception_state); if (exception_state.HadException()) return nullptr; if (!key || !key->IsValid()) { @@ -105,8 +105,7 @@ IDBKeyRange* IDBKeyRange::only(ScriptState* script_state, const ScriptValue& key_value, ExceptionState& exception_state) { std::unique_ptr<IDBKey> key = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), key_value, - exception_state); + script_state->GetIsolate(), key_value, exception_state); if (exception_state.HadException()) return nullptr; if (!key || !key->IsValid()) { @@ -126,7 +125,7 @@ IDBKeyRange* IDBKeyRange::lowerBound(ScriptState* script_state, bool open, ExceptionState& exception_state) { std::unique_ptr<IDBKey> bound = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), bound_value, + ExecutionContext::From(script_state)->GetIsolate(), bound_value, exception_state); if (exception_state.HadException()) return nullptr; @@ -146,7 +145,7 @@ IDBKeyRange* IDBKeyRange::upperBound(ScriptState* script_state, bool open, ExceptionState& exception_state) { std::unique_ptr<IDBKey> bound = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), bound_value, + ExecutionContext::From(script_state)->GetIsolate(), bound_value, exception_state); if (exception_state.HadException()) return nullptr; @@ -167,7 +166,7 @@ IDBKeyRange* IDBKeyRange::bound(ScriptState* script_state, bool upper_open, ExceptionState& exception_state) { std::unique_ptr<IDBKey> lower = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), lower_value, + ExecutionContext::From(script_state)->GetIsolate(), lower_value, exception_state); if (exception_state.HadException()) return nullptr; @@ -178,7 +177,7 @@ IDBKeyRange* IDBKeyRange::bound(ScriptState* script_state, } std::unique_ptr<IDBKey> upper = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), upper_value, + ExecutionContext::From(script_state)->GetIsolate(), upper_value, exception_state); if (exception_state.HadException()) @@ -214,7 +213,7 @@ bool IDBKeyRange::includes(ScriptState* script_state, const ScriptValue& key_value, ExceptionState& exception_state) { std::unique_ptr<IDBKey> key = ScriptValue::To<std::unique_ptr<IDBKey>>( - ToIsolate(ExecutionContext::From(script_state)), key_value, + ExecutionContext::From(script_state)->GetIsolate(), key_value, exception_state); if (exception_state.HadException()) return false; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h index fb8132b90d7..80fb9535737 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_key_range.h @@ -44,10 +44,20 @@ class MODULES_EXPORT IDBKeyRange final : public ScriptWrappable { enum LowerBoundType { kLowerBoundOpen, kLowerBoundClosed }; enum UpperBoundType { kUpperBoundOpen, kUpperBoundClosed }; + static IDBKeyRange* Create(const IDBKey* key) { + std::unique_ptr<IDBKey> lower_key = IDBKey::Clone(key); + std::unique_ptr<IDBKey> upper_key = IDBKey::Clone(key); + return IDBKeyRange::Create(std::move(lower_key), std::move(upper_key), + kLowerBoundClosed, kUpperBoundClosed); + } + static IDBKeyRange* Create(std::unique_ptr<IDBKey> lower, std::unique_ptr<IDBKey> upper, LowerBoundType lower_type, UpperBoundType upper_type) { + if ((!lower || !lower->IsValid()) && (!upper || !upper->IsValid())) + return nullptr; + IDBKey* upper_compressed = upper.get(); return MakeGarbageCollected<IDBKeyRange>(std::move(lower), upper_compressed, std::move(upper), lower_type, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.cc index c49a735a2b2..0f7f8d8129e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.cc @@ -4,9 +4,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" -#include "third_party/blink/renderer/platform/wtf/assertions.h" - namespace blink { constexpr int64_t IDBIndexMetadata::kInvalidId; @@ -26,6 +23,11 @@ IDBIndexMetadata::IDBIndexMetadata(const String& name, unique(unique), multi_entry(multi_entry) {} +// static +scoped_refptr<IDBIndexMetadata> IDBIndexMetadata::Create() { + return base::AdoptRef(new IDBIndexMetadata()); +} + IDBObjectStoreMetadata::IDBObjectStoreMetadata() = default; IDBObjectStoreMetadata::IDBObjectStoreMetadata(const String& name, @@ -39,6 +41,11 @@ IDBObjectStoreMetadata::IDBObjectStoreMetadata(const String& name, auto_increment(auto_increment), max_index_id(max_index_id) {} +// static +scoped_refptr<IDBObjectStoreMetadata> IDBObjectStoreMetadata::Create() { + return base::AdoptRef(new IDBObjectStoreMetadata()); +} + scoped_refptr<IDBObjectStoreMetadata> IDBObjectStoreMetadata::CreateCopy() const { scoped_refptr<IDBObjectStoreMetadata> copy = @@ -67,32 +74,6 @@ IDBDatabaseMetadata::IDBDatabaseMetadata(const String& name, version(version), max_object_store_id(max_object_store_id) {} -IDBDatabaseMetadata::IDBDatabaseMetadata(const WebIDBMetadata& web_metadata) - : name(web_metadata.name), - id(web_metadata.id), - version(web_metadata.version), - max_object_store_id(web_metadata.max_object_store_id) { - for (size_t i = 0; i < web_metadata.object_stores.size(); ++i) { - const WebIDBMetadata::ObjectStore& web_object_store = - web_metadata.object_stores[i]; - scoped_refptr<IDBObjectStoreMetadata> object_store = - base::AdoptRef(new IDBObjectStoreMetadata( - web_object_store.name, web_object_store.id, - IDBKeyPath(web_object_store.key_path), - web_object_store.auto_increment, web_object_store.max_index_id)); - - for (size_t j = 0; j < web_object_store.indexes.size(); ++j) { - const WebIDBMetadata::Index& web_index = web_object_store.indexes[j]; - scoped_refptr<IDBIndexMetadata> index = - base::AdoptRef(new IDBIndexMetadata( - web_index.name, web_index.id, IDBKeyPath(web_index.key_path), - web_index.unique, web_index.multi_entry)); - object_store->indexes.Set(web_index.id, std::move(index)); - } - object_stores.Set(web_object_store.id, std::move(object_store)); - } -} - void IDBDatabaseMetadata::CopyFrom(const IDBDatabaseMetadata& metadata) { name = metadata.name; id = metadata.id; @@ -100,6 +81,4 @@ void IDBDatabaseMetadata::CopyFrom(const IDBDatabaseMetadata& metadata) { max_object_store_id = metadata.max_object_store_id; } -STATIC_ASSERT_ENUM(WebIDBMetadata::kNoVersion, IDBDatabaseMetadata::kNoVersion); - } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.h index c20cf15f79d..6bda5a227a5 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_metadata.h @@ -30,7 +30,6 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_METADATA_H_ #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_metadata.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h" @@ -58,6 +57,8 @@ class IDBIndexMetadata : public RefCounted<IDBIndexMetadata> { bool unique, bool multi_entry); + static scoped_refptr<IDBIndexMetadata> Create(); + String name; int64_t id; IDBKeyPath key_path; @@ -79,6 +80,8 @@ class MODULES_EXPORT IDBObjectStoreMetadata bool auto_increment, int64_t max_index_id); + static scoped_refptr<IDBObjectStoreMetadata> Create(); + // Creates a deep copy of the object metadata, which includes copies of index // metadata items. scoped_refptr<IDBObjectStoreMetadata> CreateCopy() const; @@ -103,8 +106,6 @@ struct MODULES_EXPORT IDBDatabaseMetadata { int64_t version, int64_t max_object_store_id); - explicit IDBDatabaseMetadata(const WebIDBMetadata&); - // Overwrites the database metadata, but does not change the object store and // index metadata. void CopyFrom(const IDBDatabaseMetadata&); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h new file mode 100644 index 00000000000..ac96affd8ba --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h @@ -0,0 +1,20 @@ +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_NAME_AND_VERSION_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_NAME_AND_VERSION_H_ + +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +struct IDBNameAndVersion { + enum { kNoVersion = -1 }; + String name; + int64_t version; + + IDBNameAndVersion() : version(kNoVersion) {} + IDBNameAndVersion(String name, int64_t version) + : name(name), version(version) {} +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_NAME_AND_VERSION_H_ diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc index 7f2f23dc118..0fe51333559 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc @@ -30,16 +30,13 @@ #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_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" -#include "third_party/blink/public/platform/web_data.h" -#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value_factory.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.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" #include "third_party/blink/renderer/core/dom/dom_string_list.h" +#include "third_party/blink/renderer/core/dom/events/native_event_listener.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" #include "third_party/blink/renderer/modules/indexeddb/idb_cursor_with_value.h" @@ -55,11 +52,6 @@ #include "third_party/blink/renderer/platform/shared_buffer.h" #include "v8/include/v8.h" -using blink::WebBlobInfo; -using blink::WebIDBCallbacks; -using blink::WebIDBCursor; -using blink::WebIDBDatabase; - namespace blink { IDBObjectStore::IDBObjectStore(scoped_refptr<IDBObjectStoreMetadata> metadata, @@ -306,7 +298,7 @@ IDBRequest* IDBObjectStore::getAllKeys(ScriptState* script_state, return request; } -static WebVector<WebIDBKey> GenerateIndexKeysForValue( +static Vector<std::unique_ptr<IDBKey>> GenerateIndexKeysForValue( v8::Isolate* isolate, const IDBIndexMetadata& index_metadata, const ScriptValue& object_value) { @@ -314,30 +306,30 @@ static WebVector<WebIDBKey> GenerateIndexKeysForValue( std::unique_ptr<IDBKey> index_key = ScriptValue::To<std::unique_ptr<IDBKey>>( isolate, object_value, exception_state, index_metadata.key_path); if (!index_key) - return WebVector<WebIDBKey>(); + return Vector<std::unique_ptr<IDBKey>>(); DEFINE_THREAD_SAFE_STATIC_LOCAL( EnumerationHistogram, key_type_histogram, ("WebCore.IndexedDB.ObjectStore.IndexEntry.KeyType", - static_cast<int>(IDBKey::kTypeEnumMax))); + static_cast<int>(mojom::IDBKeyType::kMaxValue))); if (!index_metadata.multi_entry || - index_key->GetType() != IDBKey::kArrayType) { + index_key->GetType() != mojom::IDBKeyType::Array) { if (!index_key->IsValid()) - return WebVector<WebIDBKey>(); + return Vector<std::unique_ptr<IDBKey>>(); - WebVector<WebIDBKey> index_keys; - index_keys.reserve(1); + Vector<std::unique_ptr<IDBKey>> index_keys; + index_keys.ReserveInitialCapacity(1); index_keys.emplace_back(std::move(index_key)); - key_type_histogram.Count(static_cast<int>(index_keys[0].View().KeyType())); - return WebVector<WebIDBKey>(std::move(index_keys)); + key_type_histogram.Count(static_cast<int>(index_keys[0]->GetType())); + return index_keys; } else { DCHECK(index_metadata.multi_entry); - DCHECK_EQ(index_key->GetType(), IDBKey::kArrayType); - WebVector<WebIDBKey> index_keys = + DCHECK_EQ(index_key->GetType(), mojom::IDBKeyType::Array); + Vector<std::unique_ptr<IDBKey>> index_keys = IDBKey::ToMultiEntryArray(std::move(index_key)); - for (const WebIDBKey& key : index_keys) - key_type_histogram.Count(static_cast<int>(key.View().KeyType())); + for (std::unique_ptr<IDBKey>& key : index_keys) + key_type_histogram.Count(static_cast<int>(key->GetType())); return index_keys; } } @@ -554,11 +546,11 @@ IDBRequest* IDBObjectStore::DoPut(ScriptState* script_state, DEFINE_THREAD_SAFE_STATIC_LOCAL( EnumerationHistogram, key_type_histogram, ("WebCore.IndexedDB.ObjectStore.Record.KeyType", - static_cast<int>(IDBKey::kTypeEnumMax))); + static_cast<int>(mojom::IDBKeyType::kMaxValue))); key_type_histogram.Count(static_cast<int>(key->GetType())); } - Vector<WebIDBIndexKeys> index_keys; + Vector<IDBIndexKeys> index_keys; index_keys.ReserveInitialCapacity(Metadata().indexes.size()); for (const auto& it : Metadata().indexes) { if (clone.IsEmpty()) @@ -581,11 +573,13 @@ IDBRequest* IDBObjectStore::DoPut(ScriptState* script_state, if (base::FeatureList::IsEnabled(kIndexedDBLargeValueWrapping)) value_wrapper.WrapIfBiggerThan(IDBValueWrapper::kWrapThreshold); + std::unique_ptr<IDBValue> idb_value = IDBValue::Create( + value_wrapper.TakeWireBytes(), value_wrapper.TakeBlobInfo()); + request->transit_blob_handles() = value_wrapper.TakeBlobDataHandles(); BackendDB()->Put( - transaction_->Id(), Id(), WebData(value_wrapper.TakeWireBytes()), - value_wrapper.TakeBlobInfo(), WebIDBKeyView(key), put_mode, - request->CreateWebCallbacks().release(), std::move(index_keys)); + transaction_->Id(), Id(), std::move(idb_value), IDBKey::Clone(key), + put_mode, request->CreateWebCallbacks().release(), std::move(index_keys)); return request; } @@ -687,7 +681,7 @@ namespace { // the object store. It only needs to be kept alive by virtue of being // a listener on an IDBRequest object, in the same way that JavaScript // cursor success handlers are kept alive. -class IndexPopulator final : public EventListener { +class IndexPopulator final : public NativeEventListener { public: static IndexPopulator* Create( ScriptState* script_state, @@ -695,28 +689,17 @@ class IndexPopulator final : public EventListener { int64_t transaction_id, int64_t object_store_id, scoped_refptr<const IDBIndexMetadata> index_metadata) { - return new IndexPopulator(script_state, database, transaction_id, - object_store_id, std::move(index_metadata)); - } - - bool operator==(const EventListener& other) const override { - return this == &other; + return MakeGarbageCollected<IndexPopulator>(script_state, database, + transaction_id, object_store_id, + std::move(index_metadata)); } - void Trace(blink::Visitor* visitor) override { - visitor->Trace(script_state_); - visitor->Trace(database_); - EventListener::Trace(visitor); - } - - private: IndexPopulator(ScriptState* script_state, IDBDatabase* database, int64_t transaction_id, int64_t object_store_id, scoped_refptr<const IDBIndexMetadata> index_metadata) - : EventListener(kCPPEventListenerType), - script_state_(script_state), + : script_state_(script_state), database_(database), transaction_id_(transaction_id), object_store_id_(object_store_id), @@ -724,6 +707,13 @@ class IndexPopulator final : public EventListener { DCHECK(index_metadata_.get()); } + void Trace(blink::Visitor* visitor) override { + visitor->Trace(script_state_); + visitor->Trace(database_); + NativeEventListener::Trace(visitor); + } + + private: const IDBIndexMetadata& IndexMetadata() const { return *index_metadata_; } void Invoke(ExecutionContext* execution_context, Event* event) override { @@ -753,7 +743,7 @@ class IndexPopulator final : public EventListener { const IDBKey* primary_key = cursor->IdbPrimaryKey(); ScriptValue value = cursor->value(script_state_); - Vector<WebIDBIndexKeys> index_keys; + Vector<IDBIndexKeys> index_keys; index_keys.ReserveInitialCapacity(1); index_keys.emplace_back( IndexMetadata().id, @@ -761,7 +751,7 @@ class IndexPopulator final : public EventListener { IndexMetadata(), value)); database_->Backend()->SetIndexKeys(transaction_id_, object_store_id_, - WebIDBKeyView(primary_key), + IDBKey::Clone(primary_key), std::move(index_keys)); } else { // Now that we are done indexing, tell the backend to go @@ -819,7 +809,8 @@ IDBIndex* IDBObjectStore::createIndex(ScriptState* script_state, "The keyPath argument contains an invalid key path."); return nullptr; } - if (key_path.GetType() == IDBKeyPath::kArrayType && options->multiEntry()) { + if (key_path.GetType() == mojom::IDBKeyPathType::Array && + options->multiEntry()) { exception_state.ThrowDOMException( DOMExceptionCode::kInvalidAccessError, "The keyPath argument was an array and the multiEntry option is true."); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl index 24c6371df38..c113f5fe3a7 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_object_store.idl @@ -34,21 +34,21 @@ [SameObject] readonly attribute IDBTransaction transaction; readonly attribute boolean autoIncrement; - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest put(any value, [Default=Undefined] optional any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest add(any value, [Default=Undefined] optional any key); + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest put(any value, [DefaultValue=Undefined] optional any key); + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest add(any value, [DefaultValue=Undefined] optional any key); [NewObject, CallWith=ScriptState, ImplementedAs=Delete, RaisesException] IDBRequest delete(any key); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest clear(); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest get(any key); [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getKey(any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll([Default=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAll([DefaultValue=Undefined] optional any query, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys([Default=Undefined] optional any query, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest getAllKeys([DefaultValue=Undefined] optional any query, optional [EnforceRange] unsigned long count); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count([Default=Undefined] optional any key); + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest count([DefaultValue=Undefined] optional any key); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor([Default=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openCursor([DefaultValue=Undefined] optional any range, optional IDBCursorDirection direction = "next"); - [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor([Default=Undefined] optional any range, + [NewObject, CallWith=ScriptState, RaisesException] IDBRequest openKeyCursor([DefaultValue=Undefined] optional any range, optional IDBCursorDirection direction = "next"); [RaisesException] IDBIndex index(DOMString name); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc index 1c67cf44264..6abddbad083 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.cc @@ -4,7 +4,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_observation.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.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" @@ -66,19 +65,29 @@ const String& IDBObservation::type() const { } } -IDBObservation* IDBObservation::Create(WebIDBObservation observation, - v8::Isolate* isolate) { - return MakeGarbageCollected<IDBObservation>(std::move(observation), isolate); +IDBObservation* IDBObservation::Create(int64_t object_store_id, + mojom::IDBOperationType type, + IDBKeyRange* key_range, + std::unique_ptr<IDBValue> value) { + return MakeGarbageCollected<IDBObservation>(object_store_id, type, key_range, + std::move(value)); } -IDBObservation::IDBObservation(WebIDBObservation observation, - v8::Isolate* isolate) - : key_range_(observation.key_range), operation_type_(observation.type) { - std::unique_ptr<IDBValue> value = observation.value.ReleaseIdbValue(); - value->SetIsolate(isolate); +IDBObservation::IDBObservation(int64_t object_store_id, + mojom::IDBOperationType type, + IDBKeyRange* key_range, + std::unique_ptr<IDBValue> value) + : object_store_id_(object_store_id), + operation_type_(type), + key_range_(key_range) { value_ = IDBAny::Create(std::move(value)); } +void IDBObservation::SetIsolate(v8::Isolate* isolate) { + DCHECK(value_ && value_->Value()); + value_->Value()->SetIsolate(isolate); +} + void IDBObservation::Trace(blink::Visitor* visitor) { visitor->Trace(key_range_); visitor->Trace(value_); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h index 339043ee3c9..8964fd9e79c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observation.h @@ -18,7 +18,6 @@ namespace blink { class IDBAny; class IDBKeyRange; class ScriptState; -struct WebIDBObservation; class IDBObservation final : public ScriptWrappable { DEFINE_WRAPPERTYPEINFO(); @@ -26,12 +25,18 @@ class IDBObservation final : public ScriptWrappable { public: static mojom::IDBOperationType StringToOperationType(const String&); - // Consumes the WebIDBObservation. - static IDBObservation* Create(WebIDBObservation, v8::Isolate*); + static IDBObservation* Create(int64_t object_store_id, + mojom::IDBOperationType type, + IDBKeyRange* key_range, + std::unique_ptr<IDBValue> value); - IDBObservation(WebIDBObservation, v8::Isolate*); + IDBObservation(int64_t object_store_id, + mojom::IDBOperationType type, + IDBKeyRange* key_range, + std::unique_ptr<IDBValue> value); ~IDBObservation() override; + void SetIsolate(v8::Isolate* isolate); void Trace(blink::Visitor*) override; // Implement the IDL @@ -39,10 +44,14 @@ class IDBObservation final : public ScriptWrappable { ScriptValue value(ScriptState*); const String& type() const; + // Helpers. + int64_t object_store_id() const { return object_store_id_; } + private: + int64_t object_store_id_; + const mojom::IDBOperationType operation_type_; Member<IDBKeyRange> key_range_; Member<IDBAny> value_; - const mojom::IDBOperationType operation_type_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc index af876c85b10..cbf4b7337d4 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.cc @@ -4,7 +4,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_observation.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/modules/v8/to_v8_for_modules.h" @@ -32,36 +31,28 @@ ScriptValue IDBObserverChanges::records(ScriptState* script_state) { IDBObserverChanges* IDBObserverChanges::Create( IDBDatabase* database, IDBTransaction* transaction, - const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices) { - DCHECK_EQ(web_observations.size(), observations.size()); + const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices) { return MakeGarbageCollected<IDBObserverChanges>( - database, transaction, web_observations, observations, - observation_indices); + database, transaction, observations, observation_indices); } IDBObserverChanges::IDBObserverChanges( IDBDatabase* database, IDBTransaction* transaction, - const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices) + const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices) : database_(database), transaction_(transaction) { - DCHECK_EQ(web_observations.size(), observations.size()); - ExtractChanges(web_observations, observations, observation_indices); + ExtractChanges(observations, observation_indices); } void IDBObserverChanges::ExtractChanges( - const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices) { - DCHECK_EQ(web_observations.size(), observations.size()); - + const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices) { // TODO(dmurph): Avoid getting and setting repeated times. for (const auto& idx : observation_indices) { records_ - .insert(web_observations[idx].object_store_id, + .insert(observations[idx]->object_store_id(), HeapVector<Member<IDBObservation>>()) .stored_value->value.emplace_back(observations[idx]); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h index 53bc5deebb4..aa7a3a078de 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_observer_changes.h @@ -5,7 +5,6 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_OBSERVER_CHANGES_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_IDB_OBSERVER_CHANGES_H_ -#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database.h" #include "third_party/blink/renderer/modules/indexeddb/idb_observation.h" @@ -24,16 +23,13 @@ class IDBObserverChanges final : public ScriptWrappable { static IDBObserverChanges* Create( IDBDatabase*, IDBTransaction*, - const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices); + const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices); IDBObserverChanges(IDBDatabase*, IDBTransaction*, - - const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices); + const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices); void Trace(blink::Visitor*) override; @@ -43,9 +39,8 @@ class IDBObserverChanges final : public ScriptWrappable { ScriptValue records(ScriptState*); private: - void ExtractChanges(const WebVector<WebIDBObservation>& web_observations, - const HeapVector<Member<IDBObservation>>& observations, - const WebVector<int32_t>& observation_indices); + void ExtractChanges(const Vector<Persistent<IDBObservation>>& observations, + const Vector<int32_t>& observation_indices); Member<IDBDatabase> database_; Member<IDBTransaction> transaction_; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc index f8a81ea7ed1..9e8fcda38d4 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_open_db_request.cc @@ -26,6 +26,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_open_db_request.h" #include <memory> + #include "base/optional.h" #include "third_party/blink/renderer/bindings/modules/v8/idb_object_store_or_idb_index_or_idb_cursor.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" @@ -35,8 +36,6 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_tracing.h" #include "third_party/blink/renderer/modules/indexeddb/idb_version_change_event.h" -using blink::WebIDBDatabase; - namespace blink { IDBOpenDBRequest* IDBOpenDBRequest::Create( @@ -45,10 +44,8 @@ IDBOpenDBRequest* IDBOpenDBRequest::Create( int64_t transaction_id, int64_t version, IDBRequest::AsyncTraceState metrics) { - IDBOpenDBRequest* request = MakeGarbageCollected<IDBOpenDBRequest>( + return MakeGarbageCollected<IDBOpenDBRequest>( script_state, callbacks, transaction_id, version, std::move(metrics)); - request->PauseIfNeeded(); - return request; } IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* script_state, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc index a457f84c9d5..0434292ce7f 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.cc @@ -55,8 +55,6 @@ #include "third_party/blink/renderer/platform/shared_buffer.h" #include "third_party/blink/renderer/platform/wtf/functional.h" -using blink::WebIDBCursor; - namespace blink { IDBRequest::AsyncTraceState::AsyncTraceState(const char* trace_event_name) @@ -122,7 +120,6 @@ IDBRequest* IDBRequest::Create(ScriptState* script_state, IDBRequest::AsyncTraceState metrics) { IDBRequest* request = MakeGarbageCollected<IDBRequest>( script_state, source, transaction, std::move(metrics)); - request->PauseIfNeeded(); // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames) // do not have an associated transaction. if (transaction) @@ -134,7 +131,7 @@ IDBRequest::IDBRequest(ScriptState* script_state, const Source& source, IDBTransaction* transaction, AsyncTraceState metrics) - : PausableObject(ExecutionContext::From(script_state)), + : ContextLifecycleObserver(ExecutionContext::From(script_state)), transaction_(transaction), isolate_(script_state->GetIsolate()), metrics_(std::move(metrics)), @@ -155,7 +152,7 @@ void IDBRequest::Trace(blink::Visitor* visitor) { visitor->Trace(event_queue_); visitor->Trace(pending_cursor_); EventTargetWithInlineData::Trace(visitor); - PausableObject::Trace(visitor); + ContextLifecycleObserver::Trace(visitor); } ScriptValue IDBRequest::result(ScriptState* script_state, @@ -619,7 +616,7 @@ void IDBRequest::ContextDestroyed(ExecutionContext*) { if (pending_cursor_) pending_cursor_->ContextWillBeDestroyed(); if (web_callbacks_) { - web_callbacks_->Detach(); + web_callbacks_->DetachRequestFromCallback(); web_callbacks_ = nullptr; } } @@ -629,7 +626,7 @@ const AtomicString& IDBRequest::InterfaceName() const { } ExecutionContext* IDBRequest::GetExecutionContext() const { - return PausableObject::GetExecutionContext(); + return ContextLifecycleObserver::GetExecutionContext(); } DispatchEventResult IDBRequest::DispatchEventInternal(Event& event) { @@ -694,6 +691,9 @@ DispatchEventResult IDBRequest::DispatchEventInternal(Event& event) { if (transaction_ && ready_state_ == DONE) transaction_->UnregisterRequest(this); + if (event.type() == event_type_names::kError && transaction_) + transaction_->IncrementNumErrorsHandled(); + event.SetTarget(this); DispatchEventResult dispatch_result = IDBEventDispatcher::Dispatch(event, targets); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h index 48226908cce..640051ef99a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request.h @@ -40,11 +40,11 @@ #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/bindings/modules/v8/idb_object_store_or_idb_index_or_idb_cursor.h" +#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" #include "third_party/blink/renderer/core/dom/events/event_listener.h" #include "third_party/blink/renderer/core/dom/events/event_queue.h" #include "third_party/blink/renderer/core/dom/events/event_target.h" -#include "third_party/blink/renderer/core/dom/pausable_object.h" #include "third_party/blink/renderer/modules/event_modules.h" #include "third_party/blink/renderer/modules/indexeddb/idb_any.h" #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" @@ -67,7 +67,7 @@ class IDBValue; class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, public ActiveScriptWrappable<IDBRequest>, - public PausableObject { + public ContextLifecycleObserver { DEFINE_WRAPPERTYPEINFO(); USING_GARBAGE_COLLECTED_MIXIN(IDBRequest); @@ -155,7 +155,7 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, // cannot be null. const char* trace_event_name_ = nullptr; // Uniquely generated ID that ties an async trace's begin and end events. - size_t id_; + size_t id_ = 0; DISALLOW_COPY_AND_ASSIGN(AsyncTraceState); }; @@ -292,7 +292,7 @@ class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, // ScriptWrappable bool HasPendingActivity() const final; - // PausableObject + // ContextLifecycleObserver void ContextDestroyed(ExecutionContext*) override; // EventTarget diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc index 1556b71144f..a8067877426 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc @@ -28,8 +28,10 @@ #include <memory> #include "base/memory/scoped_refptr.h" +#include "mojo/public/cpp/bindings/associated_binding.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/public/platform/web_url_loader_mock_factory.h" #include "third_party/blink/public/platform/web_url_response.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" @@ -49,6 +51,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value_wrapping.h" #include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/shared_buffer.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support.h" @@ -59,12 +62,120 @@ namespace blink { namespace { +class BackendDatabaseWithMockedClose + : public testing::StrictMock<mojom::blink::IDBDatabase> { + public: + explicit BackendDatabaseWithMockedClose( + mojom::blink::IDBDatabaseAssociatedRequest request) + : binding_(this, std::move(request)) { + binding_.set_connection_error_handler( + base::BindOnce(&BackendDatabaseWithMockedClose::DatabaseDestroyed, + base::Unretained(this))); + } + + void DatabaseDestroyed() { destroyed_ = true; } + + void CreateObjectStore(int64_t transaction_id, + int64_t object_store_id, + const WTF::String& name, + const ::blink::IDBKeyPath& key_path, + bool auto_increment) override {} + void DeleteObjectStore(int64_t transaction_id, + int64_t object_store_id) override {} + void RenameObjectStore(int64_t transaction_id, + int64_t object_store_id, + const WTF::String& new_name) override {} + void CreateTransaction(int64_t transaction_id, + const WTF::Vector<int64_t>& object_store_ids, + mojom::blink::IDBTransactionMode mode) override {} + MOCK_METHOD0(Close, void()); + void VersionChangeIgnored() override {} + void AddObserver(int64_t transaction_id, + int32_t observer_id, + bool include_transaction, + bool no_records, + bool values, + uint32_t operation_types) override {} + void RemoveObservers(const WTF::Vector<int32_t>& observers) override {} + void Get(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + mojom::blink::IDBKeyRangePtr key_range, + bool key_only, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void GetAll(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + mojom::blink::IDBKeyRangePtr key_range, + bool key_only, + int64_t max_count, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void Put(int64_t transaction_id, + int64_t object_store_id, + std::unique_ptr<::blink::IDBValue> value, + std::unique_ptr<::blink::IDBKey> key, + mojom::blink::IDBPutMode mode, + WTF::Vector<::blink::IDBIndexKeys> index_keys, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void SetIndexKeys(int64_t transaction_id, + int64_t object_store_id, + std::unique_ptr<::blink::IDBKey> primary_key, + WTF::Vector<::blink::IDBIndexKeys> index_keys) override {} + void SetIndexesReady(int64_t transaction_id, + int64_t object_store_id, + const WTF::Vector<int64_t>& index_ids) override {} + void OpenCursor( + int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + mojom::blink::IDBKeyRangePtr key_range, + mojom::blink::IDBCursorDirection direction, + bool key_only, + mojom::blink::IDBTaskType task_type, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void Count(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + mojom::blink::IDBKeyRangePtr key_range, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void DeleteRange( + int64_t transaction_id, + int64_t object_store_id, + mojom::blink::IDBKeyRangePtr key_range, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void Clear(int64_t transaction_id, + int64_t object_store_id, + mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} + void CreateIndex(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + const WTF::String& name, + const ::blink::IDBKeyPath& key_path, + bool unique, + bool multi_entry) override {} + void DeleteIndex(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id) override {} + void RenameIndex(int64_t transaction_id, + int64_t object_store_id, + int64_t index_id, + const WTF::String& new_name) override {} + void Abort(int64_t transaction_id) override {} + void Commit(int64_t transaction_id, int64_t num_errors_handled) override {} + + bool destroyed() { return destroyed_; } + + private: + bool destroyed_ = false; + mojo::AssociatedBinding<mojom::blink::IDBDatabase> binding_; +}; + class IDBRequestTest : public testing::Test { protected: void SetUp() override { url_loader_mock_factory_ = platform_->GetURLLoaderMockFactory(); WebURLResponse response; - response.SetURL(KURL("blob:")); + response.SetCurrentRequestUrl(KURL("blob:")); url_loader_mock_factory_->RegisterURLProtocol(WebString("blob"), response, ""); } @@ -243,12 +354,16 @@ TEST_F(IDBRequestTest, ConnectionsAfterStopping) { const int64_t kTransactionId = 1234; const int64_t kVersion = 1; const int64_t kOldVersion = 0; - const WebIDBMetadata metadata; + const IDBDatabaseMetadata metadata; Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::Create(); { - std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); - EXPECT_CALL(*backend, Close()).Times(1); + mojom::blink::IDBDatabaseAssociatedPtr ptr; + std::unique_ptr<BackendDatabaseWithMockedClose> mock_database = + std::make_unique<BackendDatabaseWithMockedClose>( + mojo::MakeRequestAssociatedWithDedicatedPipe(&ptr)); + EXPECT_CALL(*mock_database, Close()).Times(1); + IDBOpenDBRequest* request = IDBOpenDBRequest::Create( scope.GetScriptState(), callbacks, kTransactionId, kVersion, IDBRequest::AsyncTraceState()); @@ -256,13 +371,18 @@ TEST_F(IDBRequestTest, ConnectionsAfterStopping) { std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); scope.GetExecutionContext()->NotifyContextDestroyed(); - callbacks->OnUpgradeNeeded(kOldVersion, backend.release(), metadata, - mojom::IDBDataLoss::None, String()); + callbacks->UpgradeNeeded(ptr.PassInterface(), kOldVersion, + mojom::IDBDataLoss::None, String(), metadata); + platform_->RunUntilIdle(); } { - std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); - EXPECT_CALL(*backend, Close()).Times(1); + mojom::blink::IDBDatabaseAssociatedPtr ptr; + std::unique_ptr<BackendDatabaseWithMockedClose> mock_database = + std::make_unique<BackendDatabaseWithMockedClose>( + mojo::MakeRequestAssociatedWithDedicatedPipe(&ptr)); + EXPECT_CALL(*mock_database, Close()).Times(1); + IDBOpenDBRequest* request = IDBOpenDBRequest::Create( scope.GetScriptState(), callbacks, kTransactionId, kVersion, IDBRequest::AsyncTraceState()); @@ -270,7 +390,8 @@ TEST_F(IDBRequestTest, ConnectionsAfterStopping) { std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); scope.GetExecutionContext()->NotifyContextDestroyed(); - callbacks->OnSuccess(backend.release(), metadata); + callbacks->SuccessDatabase(ptr.PassInterface(), metadata); + platform_->RunUntilIdle(); } } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc index f04b84cc5fa..c962574f1ef 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.cc @@ -26,6 +26,7 @@ #include "third_party/blink/renderer/modules/indexeddb/idb_transaction.h" #include <memory> +#include <utility> #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/events/event_queue.h" @@ -43,8 +44,6 @@ #include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" #include "third_party/blink/renderer/platform/wtf/functional.h" -using blink::WebIDBDatabase; - namespace blink { IDBTransaction* IDBTransaction::CreateObserver( @@ -338,7 +337,7 @@ void IDBTransaction::SetActive(bool active) { state_ = active ? kActive : kInactive; if (!active && request_list_.IsEmpty() && BackendDB()) - BackendDB()->Commit(id_); + BackendDB()->Commit(id_, num_errors_handled_); } void IDBTransaction::abort(ExceptionState& exception_state) { @@ -361,6 +360,30 @@ void IDBTransaction::abort(ExceptionState& exception_state) { BackendDB()->Abort(id_); } +void IDBTransaction::commit(ExceptionState& exception_state) { + if (state_ == kFinishing || state_ == kFinished) { + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + IDBDatabase::kTransactionFinishedErrorMessage); + return; + } + + if (state_ == kInactive) { + exception_state.ThrowDOMException( + DOMExceptionCode::kInvalidStateError, + IDBDatabase::kTransactionInactiveErrorMessage); + return; + } + + if (!GetExecutionContext()) + return; + + state_ = kFinishing; + + if (BackendDB()) + BackendDB()->Commit(id_, num_errors_handled_); +} + void IDBTransaction::RegisterRequest(IDBRequest* request) { DCHECK(request); DCHECK(!request_list_.Contains(request)); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h index f589fe3ed16..86ddff0a00c 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.h @@ -120,6 +120,8 @@ class MODULES_EXPORT IDBTransaction final bool IsVersionChange() const { return mode_ == mojom::IDBTransactionMode::VersionChange; } + int64_t NumErrorsHandled() const { return num_errors_handled_; } + void IncrementNumErrorsHandled() { ++num_errors_handled_; } // Implement the IDBTransaction IDL const String& mode() const; @@ -128,6 +130,7 @@ class MODULES_EXPORT IDBTransaction final DOMException* error() const { return error_; } IDBObjectStore* objectStore(const String& name, ExceptionState&); void abort(ExceptionState&); + void commit(ExceptionState&); void RegisterRequest(IDBRequest*); void UnregisterRequest(IDBRequest*); @@ -224,6 +227,7 @@ class MODULES_EXPORT IDBTransaction final State state_ = kActive; bool has_pending_activity_ = true; + int64_t num_errors_handled_ = 0; Member<DOMException> error_; HeapListHashSet<Member<IDBRequest>> request_list_; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.idl b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.idl index 7bf4f8f3e1e..4a09acb0f46 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.idl +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction.idl @@ -46,8 +46,12 @@ enum IDBTransactionMode { readonly attribute DOMException error; // Methods - [RaisesException] IDBObjectStore objectStore (DOMString name); - [RaisesException] void abort (); + [RaisesException] IDBObjectStore objectStore(DOMString name); + [ + RaisesException, + RuntimeEnabled=IDBTransactionCommit + ] void commit(); + [RaisesException] void abort(); // Events attribute EventHandler onabort; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc index 075397815ed..889759b1874 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_transaction_test.cc @@ -64,15 +64,13 @@ void DeactivateNewTransactions(v8::Isolate* isolate) { class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { public: static FakeIDBDatabaseCallbacks* Create() { - return new FakeIDBDatabaseCallbacks(); + return MakeGarbageCollected<FakeIDBDatabaseCallbacks>(); } + FakeIDBDatabaseCallbacks() = default; void OnVersionChange(int64_t old_version, int64_t new_version) override {} void OnForcedClose() override {} void OnAbort(int64_t transaction_id, DOMException* error) override {} void OnComplete(int64_t transaction_id) override {} - - private: - FakeIDBDatabaseCallbacks() = default; }; class IDBTransactionTest : public testing::Test { @@ -80,7 +78,7 @@ class IDBTransactionTest : public testing::Test { void SetUp() override { url_loader_mock_factory_ = platform_->GetURLLoaderMockFactory(); WebURLResponse response; - response.SetURL(KURL("blob:")); + response.SetCurrentRequestUrl(KURL("blob:")); url_loader_mock_factory_->RegisterURLProtocol(WebString("blob"), response, ""); } @@ -326,7 +324,7 @@ TEST_F(IDBTransactionTest, DocumentShutdownWithQueuedAndBlockedResults) { TEST_F(IDBTransactionTest, TransactionFinish) { V8TestingScope scope; std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); - EXPECT_CALL(*backend, Commit(kTransactionId)).Times(1); + EXPECT_CALL(*backend, Commit(kTransactionId, 0)).Times(1); EXPECT_CALL(*backend, Close()).Times(1); BuildTransaction(scope, std::move(backend)); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc index 21626735dde..74a851e38f5 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.cc @@ -9,7 +9,6 @@ #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/platform/blob/blob_data.h" @@ -18,44 +17,18 @@ namespace blink { -IDBValue::IDBValue(const WebData& data, - const WebVector<WebBlobInfo>& web_blob_info) - : data_(data) { - blob_info_.ReserveInitialCapacity(SafeCast<wtf_size_t>(web_blob_info.size())); - - for (const WebBlobInfo& info : web_blob_info) { - blob_info_.push_back(info); - } -} - -IDBValue::IDBValue(scoped_refptr<SharedBuffer> unwrapped_data, +IDBValue::IDBValue(scoped_refptr<SharedBuffer> data, Vector<WebBlobInfo> blob_info) - : data_(std::move(unwrapped_data)), - blob_info_(std::move(blob_info)) { -} + : data_(std::move(data)), blob_info_(std::move(blob_info)) {} IDBValue::~IDBValue() { -#if DCHECK_IS_ON() - DCHECK_EQ(!!is_owned_by_web_idb_value_, !isolate_) - << "IDBValues shold have associated isolates if and only if not owned by " - "an WebIDBValue"; -#endif // DCHECK_IS_ON() - if (isolate_ && external_allocated_size_) isolate_->AdjustAmountOfExternalAllocatedMemory(-external_allocated_size_); } -std::unique_ptr<IDBValue> IDBValue::Create( - const WebData& data, - const WebVector<WebBlobInfo>& web_blob_info) { - return base::WrapUnique(new IDBValue(data, web_blob_info)); -} - -std::unique_ptr<IDBValue> IDBValue::Create( - scoped_refptr<SharedBuffer> unwrapped_data, - Vector<WebBlobInfo> blob_info) { - return base::WrapUnique( - new IDBValue(std::move(unwrapped_data), std::move(blob_info))); +std::unique_ptr<IDBValue> IDBValue::Create(scoped_refptr<SharedBuffer> data, + Vector<WebBlobInfo> blob_info) { + return base::WrapUnique(new IDBValue(std::move(data), std::move(blob_info))); } scoped_refptr<SerializedScriptValue> IDBValue::CreateSerializedValue() const { @@ -70,11 +43,6 @@ void IDBValue::SetIsolate(v8::Isolate* isolate) { DCHECK(isolate); DCHECK(!isolate_) << "SetIsolate must be called at most once"; -#if DCHECK_IS_ON() - DCHECK(!is_owned_by_web_idb_value_) - << "IDBValues owned by an WebIDBValue cannot have associated isolates"; -#endif // DCHECK_IS_ON() - isolate_ = isolate; external_allocated_size_ = data_ ? static_cast<int64_t>(data_->size()) : 0l; if (external_allocated_size_) @@ -105,14 +73,4 @@ scoped_refptr<BlobDataHandle> IDBValue::TakeLastBlob() { return return_value; } -#if DCHECK_IS_ON() - -void IDBValue::SetIsOwnedByWebIDBValue(bool is_owned_by_web_idb_value) { - DCHECK(!isolate_ || !is_owned_by_web_idb_value) - << "IDBValues owned by an WebIDBValue cannot have associated isolates"; - is_owned_by_web_idb_value_ = is_owned_by_web_idb_value; -} - -#endif // DCHECK_IS_ON() - } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h index fd54d85d966..f5ffd05c64a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value.h @@ -9,7 +9,6 @@ #include "base/macros.h" #include "base/memory/scoped_refptr.h" -#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h" #include "third_party/blink/renderer/modules/modules_export.h" @@ -20,7 +19,6 @@ namespace blink { class BlobDataHandle; class SerializedScriptValue; class WebBlobInfo; -class WebIDBValue; // Represents an IndexedDB Object Store value retrieved from the backing store. // @@ -38,14 +36,8 @@ class WebIDBValue; // the values before returning them to the user. class MODULES_EXPORT IDBValue final { public: - // Creates an IDBValue from backing store information. - static std::unique_ptr<IDBValue> Create(const WebData&, - const WebVector<WebBlobInfo>&); - - // Used by IDBValueUnwrapper tests. - static std::unique_ptr<IDBValue> Create( - scoped_refptr<SharedBuffer> unwrapped_data, - Vector<WebBlobInfo>); + static std::unique_ptr<IDBValue> Create(scoped_refptr<SharedBuffer>, + Vector<WebBlobInfo>); ~IDBValue(); @@ -54,12 +46,16 @@ class MODULES_EXPORT IDBValue final { bool IsNull() const; scoped_refptr<SerializedScriptValue> CreateSerializedValue() const; const Vector<WebBlobInfo>& BlobInfo() const { return blob_info_; } + const scoped_refptr<SharedBuffer>& Data() const { return data_; } const IDBKey* PrimaryKey() const { return primary_key_.get(); } const IDBKeyPath& KeyPath() const { return key_path_; } // Injects a primary key into a value coming from the backend. void SetInjectedPrimaryKey(std::unique_ptr<IDBKey> primary_key, IDBKeyPath primary_key_path) { + // If the given key is type Null, ignore it. + if (primary_key && primary_key->GetType() == mojom::IDBKeyType::Null) + primary_key.reset(); primary_key_ = std::move(primary_key); key_path_ = std::move(primary_key_path); } @@ -84,19 +80,12 @@ class MODULES_EXPORT IDBValue final { // last Blob from an IDBValue is used when unwrapping values. scoped_refptr<BlobDataHandle> TakeLastBlob(); -#if DCHECK_IS_ON() - // Called by WebIDBValue to inform IDBValue of owneship changes. - void SetIsOwnedByWebIDBValue(bool); -#endif // DCHECK_IS_ON() - private: DISALLOW_COPY_AND_ASSIGN(IDBValue); friend class IDBValueUnwrapper; - IDBValue(const WebData&, const WebVector<WebBlobInfo>&); - IDBValue(scoped_refptr<SharedBuffer> unwrapped_data, - Vector<WebBlobInfo>); + IDBValue(scoped_refptr<SharedBuffer>, Vector<WebBlobInfo>); // Keep this private to prevent new refs because we manually bookkeep the // memory to V8. @@ -107,18 +96,11 @@ class MODULES_EXPORT IDBValue final { std::unique_ptr<IDBKey> primary_key_; IDBKeyPath key_path_; - // Used to register memory externally allocated by the WebIDBValue, and to + // Used to register memory externally allocated by the IDBValue, and to // unregister that memory in the destructor. Unused in other construction // paths. v8::Isolate* isolate_ = nullptr; int64_t external_allocated_size_ = 0; -#if DCHECK_IS_ON() - // True if the IDBValue is owned by a WebIDBValue. - // - // IDBValue instances that are not owned by WebIDBValue are owned by Blink - // objects, and must have a V8 isolate associated with them. - bool is_owned_by_web_idb_value_ = false; -#endif // DCHECK_IS_ON() }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping_test.cc index f78b2600392..f06e7ce3417 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping_test.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/idb_value_wrapping_test.cc @@ -483,23 +483,24 @@ TEST(IDBValueUnwrapperTest, IsWrapped) { scoped_refptr<SharedBuffer> wrapped_marker_buffer = wrapper.TakeWireBytes(); IDBKeyPath key_path(String("primaryKey")); - std::unique_ptr<IDBValue> wrapped_value = - IDBValue::Create(wrapped_marker_buffer, blob_infos); - wrapped_value->SetIsolate(scope.GetIsolate()); - EXPECT_TRUE(IDBValueUnwrapper::IsWrapped(wrapped_value.get())); - Vector<char> wrapped_marker_bytes( static_cast<wtf_size_t>(wrapped_marker_buffer->size())); ASSERT_TRUE(wrapped_marker_buffer->GetBytes(wrapped_marker_bytes.data(), wrapped_marker_bytes.size())); + std::unique_ptr<IDBValue> wrapped_value = + IDBValue::Create(std::move(wrapped_marker_buffer), std::move(blob_infos)); + wrapped_value->SetIsolate(scope.GetIsolate()); + EXPECT_TRUE(IDBValueUnwrapper::IsWrapped(wrapped_value.get())); + // IsWrapped() looks at the first 3 bytes in the value's byte array. // Truncating the array to fewer than 3 bytes should cause IsWrapped() to // return false. ASSERT_LT(3U, wrapped_marker_bytes.size()); for (wtf_size_t i = 0; i < 3; ++i) { - std::unique_ptr<IDBValue> mutant_value = IDBValue::Create( - SharedBuffer::Create(wrapped_marker_bytes.data(), i), blob_infos); + std::unique_ptr<IDBValue> mutant_value = + IDBValue::Create(SharedBuffer::Create(wrapped_marker_bytes.data(), i), + std::move(blob_infos)); mutant_value->SetIsolate(scope.GetIsolate()); EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.get())); @@ -515,7 +516,7 @@ TEST(IDBValueUnwrapperTest, IsWrapped) { std::unique_ptr<IDBValue> mutant_value = IDBValue::Create(SharedBuffer::Create(wrapped_marker_bytes.data(), wrapped_marker_bytes.size()), - blob_infos); + std::move(blob_infos)); mutant_value->SetIsolate(scope.GetIsolate()); EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.get())); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap index fd306fa458d..536050efa78 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap @@ -5,18 +5,15 @@ 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_path.h", "//third_party/blink/renderer/modules/indexeddb/idb_key_range.h", + "//third_party/blink/renderer/modules/indexeddb/idb_metadata.h", + "//third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h", + "//third_party/blink/renderer/modules/indexeddb/idb_value.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", ] @@ -25,11 +22,11 @@ deps = [ "//third_party/blink/renderer/platform/wtf", ] type_mappings = [ - "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.IDBDatabaseMetadata=::blink::IDBDatabaseMetadata", + "blink.mojom.IDBIndexKeys=::blink::IDBIndexKeys[move_only]", + "blink.mojom.IDBIndexMetadata=scoped_refptr<::blink::IDBIndexMetadata>", + "blink.mojom.IDBKey=std::unique_ptr<::blink::IDBKey>[move_only]", + "blink.mojom.IDBKeyPath=::blink::IDBKeyPath", + "blink.mojom.IDBObjectStoreMetadata=scoped_refptr<::blink::IDBObjectStoreMetadata>", + "blink.mojom.IDBValue=std::unique_ptr<::blink::IDBValue>[move_only]", ] diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc index 280c6462210..4e253d1816a 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.cc @@ -5,12 +5,9 @@ #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/public/platform/file_path_conversion.h" +#include "third_party/blink/public/platform/web_blob_info.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/std_lib_extras.h" @@ -23,10 +20,10 @@ using blink::mojom::IDBOperationType; namespace mojo { // static -bool StructTraits< - blink::mojom::IDBDatabaseMetadataDataView, - blink::WebIDBMetadata>::Read(blink::mojom::IDBDatabaseMetadataDataView data, - blink::WebIDBMetadata* out) { +bool StructTraits<blink::mojom::IDBDatabaseMetadataDataView, + blink::IDBDatabaseMetadata>:: + Read(blink::mojom::IDBDatabaseMetadataDataView data, + blink::IDBDatabaseMetadata* out) { out->id = data.id(); String name; if (!data.ReadName(&name)) @@ -34,14 +31,26 @@ bool StructTraits< 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; + MapDataView<int64_t, blink::mojom::IDBObjectStoreMetadataDataView> + object_stores; + data.GetObjectStoresDataView(&object_stores); + out->object_stores.ReserveCapacityForSize( + SafeCast<wtf_size_t>(object_stores.size())); + for (size_t i = 0; i < object_stores.size(); ++i) { + const int64_t key = object_stores.keys()[i]; + scoped_refptr<blink::IDBObjectStoreMetadata> object_store; + if (!object_stores.values().Read(i, &object_store)) { + return false; + } + DCHECK(!out->object_stores.Contains(key)); + out->object_stores.insert(key, object_store); + } return true; } // static -bool StructTraits<blink::mojom::IDBIndexKeysDataView, blink::WebIDBIndexKeys>:: - Read(blink::mojom::IDBIndexKeysDataView data, blink::WebIDBIndexKeys* out) { +bool StructTraits<blink::mojom::IDBIndexKeysDataView, blink::IDBIndexKeys>:: + Read(blink::mojom::IDBIndexKeysDataView data, blink::IDBIndexKeys* out) { out->first = data.index_id(); if (!data.ReadIndexKeys(&out->second)) return false; @@ -50,69 +59,69 @@ bool StructTraits<blink::mojom::IDBIndexKeysDataView, blink::WebIDBIndexKeys>:: // static bool StructTraits<blink::mojom::IDBIndexMetadataDataView, - blink::WebIDBMetadata::Index>:: + scoped_refptr<blink::IDBIndexMetadata>>:: Read(blink::mojom::IDBIndexMetadataDataView data, - blink::WebIDBMetadata::Index* out) { - out->id = data.id(); + scoped_refptr<blink::IDBIndexMetadata>* out) { + scoped_refptr<blink::IDBIndexMetadata> value = + blink::IDBIndexMetadata::Create(); + value->id = data.id(); String name; if (!data.ReadName(&name)) return false; - out->name = name; - if (!data.ReadKeyPath(&out->key_path)) + value->name = name; + if (!data.ReadKeyPath(&value->key_path)) return false; - out->unique = data.unique(); - out->multi_entry = data.multi_entry(); + value->unique = data.unique(); + value->multi_entry = data.multi_entry(); + *out = std::move(value); 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: +UnionTraits<blink::mojom::IDBKeyDataDataView, std::unique_ptr<blink::IDBKey>>:: + GetTag(const std::unique_ptr<blink::IDBKey>& key) { + DCHECK(key.get()); + switch (key->GetType()) { + case blink::mojom::IDBKeyType::Invalid: + return blink::mojom::IDBKeyDataDataView::Tag::OTHER_INVALID; + case blink::mojom::IDBKeyType::Array: return blink::mojom::IDBKeyDataDataView::Tag::KEY_ARRAY; - case blink::kWebIDBKeyTypeBinary: + case blink::mojom::IDBKeyType::Binary: return blink::mojom::IDBKeyDataDataView::Tag::BINARY; - case blink::kWebIDBKeyTypeString: + case blink::mojom::IDBKeyType::String: return blink::mojom::IDBKeyDataDataView::Tag::STRING; - case blink::kWebIDBKeyTypeDate: + case blink::mojom::IDBKeyType::Date: return blink::mojom::IDBKeyDataDataView::Tag::DATE; - case blink::kWebIDBKeyTypeNumber: + case blink::mojom::IDBKeyType::Number: return blink::mojom::IDBKeyDataDataView::Tag::NUMBER; - case blink::kWebIDBKeyTypeNull: - return blink::mojom::IDBKeyDataDataView::Tag::OTHER; + case blink::mojom::IDBKeyType::Null: + return blink::mojom::IDBKeyDataDataView::Tag::OTHER_NULL; // Not used, fall through to NOTREACHED. - case blink::kWebIDBKeyTypeMin:; + case blink::mojom::IDBKeyType::Min:; } NOTREACHED(); - return blink::mojom::IDBKeyDataDataView::Tag::OTHER; + return blink::mojom::IDBKeyDataDataView::Tag::OTHER_INVALID; } // static -bool UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::Read( - blink::mojom::IDBKeyDataDataView data, - blink::WebIDBKey* out) { +bool UnionTraits< + blink::mojom::IDBKeyDataDataView, + std::unique_ptr<blink::IDBKey>>::Read(blink::mojom::IDBKeyDataDataView data, + std::unique_ptr<blink::IDBKey>* out) { switch (data.tag()) { case blink::mojom::IDBKeyDataDataView::Tag::KEY_ARRAY: { - Vector<blink::WebIDBKey> array; + Vector<std::unique_ptr<blink::IDBKey>> 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)); + *out = blink::IDBKey::CreateArray(std::move(array)); return true; } case blink::mojom::IDBKeyDataDataView::Tag::BINARY: { ArrayDataView<uint8_t> bytes; data.GetBinaryDataView(&bytes); - *out = blink::WebIDBKey::CreateBinary(blink::WebData( + *out = blink::IDBKey::CreateBinary(blink::SharedBuffer::Create( reinterpret_cast<const char*>(bytes.data()), bytes.size())); return true; } @@ -120,92 +129,153 @@ bool UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey>::Read( String string; if (!data.ReadString(&string)) return false; - *out = blink::WebIDBKey::CreateString(blink::WebString(string)); + *out = blink::IDBKey::CreateString(String(string)); return true; } case blink::mojom::IDBKeyDataDataView::Tag::DATE: - *out = blink::WebIDBKey::CreateDate(data.date()); + *out = blink::IDBKey::CreateDate(data.date()); return true; case blink::mojom::IDBKeyDataDataView::Tag::NUMBER: - *out = blink::WebIDBKey::CreateNumber(data.number()); + *out = blink::IDBKey::CreateNumber(data.number()); + return true; + case blink::mojom::IDBKeyDataDataView::Tag::OTHER_INVALID: + *out = blink::IDBKey::CreateInvalid(); + return true; + case blink::mojom::IDBKeyDataDataView::Tag::OTHER_NULL: + *out = blink::IDBKey::CreateNull(); 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(SafeCast<wtf_size_t>(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; +const Vector<std::unique_ptr<blink::IDBKey>>& +UnionTraits<blink::mojom::IDBKeyDataDataView, std::unique_ptr<blink::IDBKey>>:: + key_array(const std::unique_ptr<blink::IDBKey>& key) { + return key->Array(); } // 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(SafeCast<wtf_size_t>(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; +Vector<uint8_t> +UnionTraits<blink::mojom::IDBKeyDataDataView, std::unique_ptr<blink::IDBKey>>:: + binary(const std::unique_ptr<blink::IDBKey>& key) { + return key->Binary()->CopyAs<Vector<uint8_t>>(); } // static -const blink::WebIDBKey& -StructTraits<blink::mojom::IDBKeyDataView, blink::WebIDBKey>::data( - const blink::WebIDBKey& key) { +const std::unique_ptr<blink::IDBKey>& +StructTraits<blink::mojom::IDBKeyDataView, std::unique_ptr<blink::IDBKey>>:: + data(const std::unique_ptr<blink::IDBKey>& key) { return key; } // static -bool StructTraits<blink::mojom::IDBKeyDataView, blink::WebIDBKey>::Read( - blink::mojom::IDBKeyDataView data, - blink::WebIDBKey* out) { +bool StructTraits< + blink::mojom::IDBKeyDataView, + std::unique_ptr<blink::IDBKey>>::Read(blink::mojom::IDBKeyDataView data, + std::unique_ptr<blink::IDBKey>* out) { return data.ReadData(out); } // static +Vector<uint8_t> +StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>>:: + bits(const std::unique_ptr<blink::IDBValue>& input) { + return input->Data()->CopyAs<Vector<uint8_t>>(); +} + +// static +Vector<blink::mojom::blink::IDBBlobInfoPtr> +StructTraits<blink::mojom::IDBValueDataView, std::unique_ptr<blink::IDBValue>>:: + blob_or_file_info(const std::unique_ptr<blink::IDBValue>& input) { + Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info; + blob_or_file_info.ReserveInitialCapacity(input->BlobInfo().size()); + for (const blink::WebBlobInfo& info : input->BlobInfo()) { + auto blob_info = blink::mojom::blink::IDBBlobInfo::New(); + if (info.IsFile()) { + blob_info->file = blink::mojom::blink::IDBFileInfo::New(); + blob_info->file->path = blink::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(); + 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 = blink::mojom::blink::BlobPtrInfo( + info.CloneBlobHandle(), blink::mojom::blink::Blob::Version_); + blob_or_file_info.push_back(std::move(blob_info)); + } + return blob_or_file_info; +} + +// static +bool StructTraits<blink::mojom::IDBValueDataView, + std::unique_ptr<blink::IDBValue>>:: + Read(blink::mojom::IDBValueDataView data, + std::unique_ptr<blink::IDBValue>* out) { + Vector<uint8_t> value_bits; + if (!data.ReadBits(&value_bits)) + return false; + + if (value_bits.IsEmpty()) { + *out = blink::IDBValue::Create(scoped_refptr<blink::SharedBuffer>(), + Vector<blink::WebBlobInfo>()); + return true; + } + + scoped_refptr<blink::SharedBuffer> value_buffer = blink::SharedBuffer::Create( + reinterpret_cast<const char*>(value_bits.data()), value_bits.size()); + + Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info; + if (!data.ReadBlobOrFileInfo(&blob_or_file_info)) + return false; + + Vector<blink::WebBlobInfo> value_blob_info; + value_blob_info.ReserveInitialCapacity(blob_or_file_info.size()); + for (const auto& info : blob_or_file_info) { + if (info->file) { + value_blob_info.emplace_back(info->uuid, + blink::FilePathToWebString(info->file->path), + info->file->name, info->mime_type, + info->file->last_modified.ToDoubleT(), + info->size, info->blob.PassHandle()); + } else { + value_blob_info.emplace_back(info->uuid, info->mime_type, info->size, + info->blob.PassHandle()); + } + } + + *out = blink::IDBValue::Create(std::move(value_buffer), + std::move(value_blob_info)); + return true; +} + +// static blink::mojom::blink::IDBKeyPathDataPtr -StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::data( - const blink::WebIDBKeyPath& key_path) { - if (key_path.KeyPathType() == blink::kWebIDBKeyPathTypeNull) +StructTraits<blink::mojom::IDBKeyPathDataView, blink::IDBKeyPath>::data( + const blink::IDBKeyPath& key_path) { + if (key_path.GetType() == blink::mojom::IDBKeyPathType::Null) return nullptr; auto data = blink::mojom::blink::IDBKeyPathData::New(); - switch (key_path.KeyPathType()) { - case blink::kWebIDBKeyPathTypeString: { - String key_path_string = key_path.String(); + switch (key_path.GetType()) { + case blink::mojom::IDBKeyPathType::String: { + String key_path_string = key_path.GetString(); if (key_path_string.IsNull()) key_path_string = g_empty_string; data->set_string(key_path_string); return data; } - case blink::kWebIDBKeyPathTypeArray: { + case blink::mojom::IDBKeyPathType::Array: { const auto& array = key_path.Array(); Vector<String> result; result.ReserveInitialCapacity(SafeCast<wtf_size_t>(array.size())); @@ -215,7 +285,7 @@ StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::data( return data; } - case blink::kWebIDBKeyPathTypeNull: + case blink::mojom::IDBKeyPathType::Null: break; // Not used, NOTREACHED. } NOTREACHED(); @@ -223,14 +293,14 @@ StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::data( } // static -bool StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::Read( +bool StructTraits<blink::mojom::IDBKeyPathDataView, blink::IDBKeyPath>::Read( blink::mojom::IDBKeyPathDataView data, - blink::WebIDBKeyPath* out) { + blink::IDBKeyPath* out) { blink::mojom::IDBKeyPathDataDataView data_view; data.GetDataDataView(&data_view); if (data_view.is_null()) { - *out = blink::WebIDBKeyPath(); + *out = blink::IDBKeyPath(); return true; } @@ -239,14 +309,14 @@ bool StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::Read( String string; if (!data_view.ReadString(&string)) return false; - *out = blink::WebIDBKeyPath(blink::WebString(string)); + *out = blink::IDBKeyPath(string); return true; } case blink::mojom::IDBKeyPathDataDataView::Tag::STRING_ARRAY: { Vector<String> array; if (!data_view.ReadStringArray(&array)) return false; - *out = blink::WebIDBKeyPath(array); + *out = blink::IDBKeyPath(array); return true; } } @@ -255,37 +325,91 @@ bool StructTraits<blink::mojom::IDBKeyPathDataView, blink::WebIDBKeyPath>::Read( } // 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>:: + scoped_refptr<blink::IDBObjectStoreMetadata>>:: Read(blink::mojom::IDBObjectStoreMetadataDataView data, - blink::WebIDBMetadata::ObjectStore* out) { - out->id = data.id(); + scoped_refptr<blink::IDBObjectStoreMetadata>* out) { + scoped_refptr<blink::IDBObjectStoreMetadata> value = + blink::IDBObjectStoreMetadata::Create(); + value->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)) + value->name = name; + if (!data.ReadKeyPath(&value->key_path)) return false; + value->auto_increment = data.auto_increment(); + value->max_index_id = data.max_index_id(); + MapDataView<int64_t, blink::mojom::IDBIndexMetadataDataView> indexes; + data.GetIndexesDataView(&indexes); + value->indexes.ReserveCapacityForSize(SafeCast<wtf_size_t>(indexes.size())); + for (size_t i = 0; i < indexes.size(); ++i) { + const int64_t key = indexes.keys()[i]; + scoped_refptr<blink::IDBIndexMetadata> index; + if (!indexes.values().Read(i, &index)) + return false; + DCHECK(!value->indexes.Contains(key)); + value->indexes.insert(key, index); + } + *out = std::move(value); return true; } +// static +blink::mojom::blink::IDBKeyRangePtr TypeConverter< + blink::mojom::blink::IDBKeyRangePtr, + const blink::IDBKeyRange*>::Convert(const blink::IDBKeyRange* input) { + if (!input) { + std::unique_ptr<blink::IDBKey> lower = blink::IDBKey::CreateNull(); + std::unique_ptr<blink::IDBKey> upper = blink::IDBKey::CreateNull(); + return blink::mojom::blink::IDBKeyRange::New( + std::move(lower), std::move(upper), false /* lower_open */, + false /* upper_open */); + } + + return blink::mojom::blink::IDBKeyRange::New( + blink::IDBKey::Clone(input->Lower()), + blink::IDBKey::Clone(input->Upper()), input->lowerOpen(), + input->upperOpen()); +} + +// static +blink::mojom::blink::IDBKeyRangePtr +TypeConverter<blink::mojom::blink::IDBKeyRangePtr, + blink::IDBKeyRange*>::Convert(blink::IDBKeyRange* input) { + if (!input) { + std::unique_ptr<blink::IDBKey> lower = blink::IDBKey::CreateNull(); + std::unique_ptr<blink::IDBKey> upper = blink::IDBKey::CreateNull(); + return blink::mojom::blink::IDBKeyRange::New( + std::move(lower), std::move(upper), false /* lower_open */, + false /* upper_open */); + } + + return blink::mojom::blink::IDBKeyRange::New( + blink::IDBKey::Clone(input->Lower()), + blink::IDBKey::Clone(input->Upper()), input->lowerOpen(), + input->upperOpen()); +} + +// static +blink::IDBKeyRange* +TypeConverter<blink::IDBKeyRange*, blink::mojom::blink::IDBKeyRangePtr>:: + Convert(const blink::mojom::blink::IDBKeyRangePtr& input) { + if (!input) + return nullptr; + + blink::IDBKeyRange::LowerBoundType lower_type = + blink::IDBKeyRange::kLowerBoundClosed; + if (input->lower_open) + lower_type = blink::IDBKeyRange::kLowerBoundOpen; + + blink::IDBKeyRange::UpperBoundType upper_type = + blink::IDBKeyRange::kUpperBoundClosed; + if (input->upper_open) + upper_type = blink::IDBKeyRange::kUpperBoundOpen; + + return blink::IDBKeyRange::Create( + std::move(input->lower), std::move(input->upper), lower_type, upper_type); +} + } // namespace mojo diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h index 408631a1a40..946b20c78be 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h @@ -7,15 +7,9 @@ #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 "mojo/public/cpp/bindings/map_traits_wtf_hash_map.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/indexeddb/idb_metadata.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" @@ -23,163 +17,179 @@ namespace mojo { template <> struct MODULES_EXPORT StructTraits<blink::mojom::IDBDatabaseMetadataDataView, - blink::WebIDBMetadata> { - static int64_t id(const blink::WebIDBMetadata& metadata) { + blink::IDBDatabaseMetadata> { + static int64_t id(const blink::IDBDatabaseMetadata& metadata) { return metadata.id; } - static WTF::String name(const blink::WebIDBMetadata& metadata) { + static WTF::String name(const blink::IDBDatabaseMetadata& metadata) { if (metadata.name.IsNull()) return g_empty_string; return metadata.name; } - static int64_t version(const blink::WebIDBMetadata& metadata) { + static int64_t version(const blink::IDBDatabaseMetadata& metadata) { return metadata.version; } - static int64_t max_object_store_id(const blink::WebIDBMetadata& metadata) { + static int64_t max_object_store_id( + const blink::IDBDatabaseMetadata& metadata) { return metadata.max_object_store_id; } - static const blink::WebVector<blink::WebIDBMetadata::ObjectStore>& - object_stores(const blink::WebIDBMetadata& metadata) { + static const HashMap<int64_t, scoped_refptr<blink::IDBObjectStoreMetadata>>& + object_stores(const blink::IDBDatabaseMetadata& metadata) { return metadata.object_stores; } static bool Read(blink::mojom::IDBDatabaseMetadataDataView data, - blink::WebIDBMetadata* out); + blink::IDBDatabaseMetadata* out); }; template <> struct MODULES_EXPORT - StructTraits<blink::mojom::IDBIndexKeysDataView, blink::WebIDBIndexKeys> { - static int64_t index_id(const blink::WebIDBIndexKeys& index_keys) { + StructTraits<blink::mojom::IDBIndexKeysDataView, blink::IDBIndexKeys> { + static int64_t index_id(const blink::IDBIndexKeys& index_keys) { return index_keys.first; } - static const blink::WebVector<blink::WebIDBKey>& index_keys( - const blink::WebIDBIndexKeys& index_keys) { + static const Vector<std::unique_ptr<blink::IDBKey>>& index_keys( + const blink::IDBIndexKeys& index_keys) { return index_keys.second; } static bool Read(blink::mojom::IDBIndexKeysDataView data, - blink::WebIDBIndexKeys* out); + blink::IDBIndexKeys* out); }; template <> struct MODULES_EXPORT StructTraits<blink::mojom::IDBIndexMetadataDataView, - blink::WebIDBMetadata::Index> { - static int64_t id(const blink::WebIDBMetadata::Index& metadata) { - return metadata.id; + scoped_refptr<blink::IDBIndexMetadata>> { + static int64_t id(const scoped_refptr<blink::IDBIndexMetadata>& metadata) { + return metadata->id; } - static WTF::String name(const blink::WebIDBMetadata::Index& metadata) { - if (metadata.name.IsNull()) + static WTF::String name( + const scoped_refptr<blink::IDBIndexMetadata>& metadata) { + if (metadata->name.IsNull()) return g_empty_string; - return metadata.name; + return metadata->name; } - static const blink::WebIDBKeyPath& key_path( - const blink::WebIDBMetadata::Index& metadata) { - return metadata.key_path; + static const blink::IDBKeyPath& key_path( + const scoped_refptr<blink::IDBIndexMetadata>& metadata) { + return metadata->key_path; } - static bool unique(const blink::WebIDBMetadata::Index& metadata) { - return metadata.unique; + static bool unique(const scoped_refptr<blink::IDBIndexMetadata>& metadata) { + return metadata->unique; } - static bool multi_entry(const blink::WebIDBMetadata::Index& metadata) { - return metadata.multi_entry; + static bool multi_entry( + const scoped_refptr<blink::IDBIndexMetadata>& metadata) { + return metadata->multi_entry; } static bool Read(blink::mojom::IDBIndexMetadataDataView data, - blink::WebIDBMetadata::Index* out); + scoped_refptr<blink::IDBIndexMetadata>* out); }; template <> -struct MODULES_EXPORT - UnionTraits<blink::mojom::IDBKeyDataDataView, blink::WebIDBKey> { +struct MODULES_EXPORT UnionTraits<blink::mojom::IDBKeyDataDataView, + std::unique_ptr<blink::IDBKey>> { static blink::mojom::IDBKeyDataDataView::Tag GetTag( - const blink::WebIDBKey& key); + const std::unique_ptr<blink::IDBKey>& 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(); + std::unique_ptr<blink::IDBKey>* out); + static const Vector<std::unique_ptr<blink::IDBKey>>& key_array( + const std::unique_ptr<blink::IDBKey>& key); + static Vector<uint8_t> binary(const std::unique_ptr<blink::IDBKey>& key); + static const WTF::String string(const std::unique_ptr<blink::IDBKey>& key) { + String key_string = key->GetString(); 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; - } + static double date(const std::unique_ptr<blink::IDBKey>& key) { + return key->Date(); + } + static double number(const std::unique_ptr<blink::IDBKey>& key) { + return key->Number(); + } + static bool other_invalid(const std::unique_ptr<blink::IDBKey>& key) { + return key->GetType() == blink::mojom::IDBKeyType::Invalid; + } + static bool other_null(const std::unique_ptr<blink::IDBKey>& key) { + return key->GetType() == blink::mojom::IDBKeyType::Null; } }; 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); + StructTraits<blink::mojom::IDBKeyDataView, std::unique_ptr<blink::IDBKey>> { + static const std::unique_ptr<blink::IDBKey>& data( + const std::unique_ptr<blink::IDBKey>& key); + static bool Read(blink::mojom::IDBKeyDataView data, + std::unique_ptr<blink::IDBKey>* 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); +struct MODULES_EXPORT StructTraits<blink::mojom::IDBValueDataView, + std::unique_ptr<blink::IDBValue>> { + static Vector<uint8_t> bits(const std::unique_ptr<blink::IDBValue>& input); + static Vector<blink::mojom::blink::IDBBlobInfoPtr> blob_or_file_info( + const std::unique_ptr<blink::IDBValue>& input); + static bool Read(blink::mojom::IDBValueDataView data, + std::unique_ptr<blink::IDBValue>* 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); + StructTraits<blink::mojom::IDBKeyPathDataView, blink::IDBKeyPath> { + static blink::mojom::blink::IDBKeyPathDataPtr data( + const blink::IDBKeyPath& key_path); + static bool Read(blink::mojom::IDBKeyPathDataView data, + blink::IDBKeyPath* 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; +struct MODULES_EXPORT + StructTraits<blink::mojom::IDBObjectStoreMetadataDataView, + scoped_refptr<blink::IDBObjectStoreMetadata>> { + static int64_t id( + const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + return metadata->id; + } + static WTF::String name( + const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + if (metadata->name.IsNull()) + return g_empty_string; + return metadata->name; } - static const blink::WebIDBKeyPath& key_path( - const blink::WebIDBMetadata::ObjectStore& metadata) { - return metadata.key_path; + static const blink::IDBKeyPath& key_path( + const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + return metadata->key_path; } static bool auto_increment( - const blink::WebIDBMetadata::ObjectStore& metadata) { - return metadata.auto_increment; + const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + return metadata->auto_increment; } static int64_t max_index_id( - const blink::WebIDBMetadata::ObjectStore& metadata) { - return metadata.max_index_id; + const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + return metadata->max_index_id; } - static const blink::WebVector<blink::WebIDBMetadata::Index>& indexes( - const blink::WebIDBMetadata::ObjectStore& metadata) { - return metadata.indexes; + static const HashMap<int64_t, scoped_refptr<blink::IDBIndexMetadata>>& + indexes(const scoped_refptr<blink::IDBObjectStoreMetadata>& metadata) { + return metadata->indexes; } static bool Read(blink::mojom::IDBObjectStoreMetadataDataView data, - blink::WebIDBMetadata::ObjectStore* out); + scoped_refptr<blink::IDBObjectStoreMetadata>* out); +}; + +template <> +struct TypeConverter<blink::mojom::blink::IDBKeyRangePtr, + const blink::IDBKeyRange*> { + static blink::mojom::blink::IDBKeyRangePtr Convert( + const blink::IDBKeyRange* input); +}; + +template <> +struct TypeConverter<blink::mojom::blink::IDBKeyRangePtr, blink::IDBKeyRange*> { + static blink::mojom::blink::IDBKeyRangePtr Convert(blink::IDBKeyRange* input); +}; + +template <> +struct TypeConverter<blink::IDBKeyRange*, blink::mojom::blink::IDBKeyRangePtr> { + static blink::IDBKeyRange* Convert( + const blink::mojom::blink::IDBKeyRangePtr& input); }; } // namespace mojo diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits_test.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits_test.cc new file mode 100644 index 00000000000..98b29dd6b2e --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits_test.cc @@ -0,0 +1,88 @@ +// 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 <random> + +#include "base/macros.h" +#include "base/memory/scoped_refptr.h" +#include "mojo/public/cpp/base/file_path_mojom_traits.h" +#include "mojo/public/cpp/base/string16_mojom_traits.h" +#include "mojo/public/cpp/base/time_mojom_traits.h" +#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h" +#include "mojo/public/cpp/bindings/string_traits_wtf.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/public/platform/web_blob_info.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_value.h" +#include "third_party/blink/renderer/platform/mojo/string16_mojom_traits.h" + +namespace blink { + +TEST(IDBMojomTraitsTest, IDBKeyBinary) { + // Generate test data. + std::mt19937 rng(5); + size_t test_data_size = 10000; + Vector<char> test_data(test_data_size); + std::generate(test_data.begin(), test_data.end(), rng); + scoped_refptr<SharedBuffer> input_data = + SharedBuffer::Create(test_data.data(), test_data.size()); + Vector<uint8_t> input_vector = input_data->CopyAs<Vector<uint8_t>>(); + + // Verify expectations. + ASSERT_EQ(input_data->size(), test_data_size); + ASSERT_EQ(input_vector.size(), test_data_size); + + // Create IDBKey binary key type mojom message. + std::unique_ptr<IDBKey> input = IDBKey::CreateBinary(input_data); + mojo::Message mojo_message = mojom::blink::IDBKey::SerializeAsMessage(&input); + + // Deserialize the mojo message. + std::unique_ptr<IDBKey> output; + ASSERT_TRUE(mojom::blink::IDBKey::DeserializeFromMessage( + std::move(mojo_message), &output)); + scoped_refptr<SharedBuffer> output_data = output->Binary(); + Vector<uint8_t> output_vector = output_data->CopyAs<Vector<uint8_t>>(); + + // Verify expectations. + ASSERT_EQ(output_data->size(), test_data_size); + ASSERT_EQ(output_vector.size(), test_data_size); + ASSERT_EQ(input_vector, output_vector); +} + +TEST(IDBMojomTraitsTest, IDBValue) { + // Generate test data. + std::mt19937 rng(5); + size_t test_data_size = 10000; + Vector<char> test_data(test_data_size); + std::generate(test_data.begin(), test_data.end(), rng); + scoped_refptr<SharedBuffer> input_data = + SharedBuffer::Create(test_data.data(), test_data.size()); + Vector<uint8_t> input_vector = input_data->CopyAs<Vector<uint8_t>>(); + + // Verify expectations. + ASSERT_EQ(input_data->size(), test_data_size); + ASSERT_EQ(input_vector.size(), test_data_size); + + // Create IDBValue mojom message. + std::unique_ptr<IDBValue> input = + IDBValue::Create(std::move(input_data), Vector<WebBlobInfo>()); + mojo::Message mojo_message = + mojom::blink::IDBValue::SerializeAsMessage(&input); + + // Deserialize the mojo message. + std::unique_ptr<IDBValue> output; + ASSERT_TRUE(mojom::blink::IDBValue::DeserializeFromMessage( + std::move(mojo_message), &output)); + scoped_refptr<SharedBuffer> output_data = output->Data(); + Vector<uint8_t> output_vector = output_data->CopyAs<Vector<uint8_t>>(); + + // Verify expectations. + ASSERT_EQ(output_data->size(), test_data_size); + ASSERT_EQ(output_vector.size(), test_data_size); + ASSERT_EQ(input_vector, output_vector); +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc deleted file mode 100644 index 360bdffd726..00000000000 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.cc +++ /dev/null @@ -1,216 +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 "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, - mojom::IDBDataLoss 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/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h deleted file mode 100644 index efbaeb80604..00000000000 --- a/chromium/third_party/blink/renderer/modules/indexeddb/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 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, - mojom::IDBDataLoss 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/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc index 1149fab7b61..a73dcb5011e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_database_callbacks_impl.cc @@ -7,16 +7,11 @@ #include <unordered_map> #include <utility> -#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/public/platform/web_blob_info.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; +#include "third_party/blink/renderer/modules/indexeddb/idb_observation.h" +#include "third_party/blink/renderer/modules/indexeddb/indexed_db_blink_mojom_traits.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" namespace blink { @@ -38,8 +33,7 @@ void IndexedDBDatabaseCallbacksImpl::VersionChange(int64_t old_version, void IndexedDBDatabaseCallbacksImpl::Abort(int64_t transaction_id, int32_t code, const String& message) { - callbacks_->OnAbort(transaction_id, - blink::WebIDBDatabaseError(code, message)); + callbacks_->OnAbort(transaction_id, IDBDatabaseError(code, message)); } void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) { @@ -48,21 +42,29 @@ void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) { void IndexedDBDatabaseCallbacksImpl::Changes( mojom::blink::IDBObserverChangesPtr changes) { - WebVector<WebIDBObservation> web_observations; - web_observations.reserve(changes->observations.size()); + Vector<Persistent<IDBObservation>> observations; + observations.ReserveInitialCapacity(changes->observations.size()); for (const auto& observation : changes->observations) { - web_observations.emplace_back( - observation->object_store_id, observation->type, observation->key_range, - IndexedDBCallbacksImpl::ConvertValue(observation->value)); + IDBKeyRange* key_range = observation->key_range.To<IDBKeyRange*>(); + std::unique_ptr<IDBValue> value; + if (observation->value.has_value()) + value = std::move(observation->value.value()); + if (!value || value->Data()->IsEmpty()) { + value = IDBValue::Create(scoped_refptr<SharedBuffer>(), + Vector<WebBlobInfo>()); + } + observations.emplace_back( + IDBObservation::Create(observation->object_store_id, observation->type, + key_range, std::move(value))); } - std::unordered_map<int32_t, WebVector<int32_t>> observation_index_map; + std::unordered_map<int32_t, Vector<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); + Vector<int32_t>(observation_pair.value); } - std::unordered_map<int32_t, std::pair<int64_t, WebVector<int64_t>>> + std::unordered_map<int32_t, std::pair<int64_t, Vector<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 @@ -73,7 +75,7 @@ void IndexedDBDatabaseCallbacksImpl::Changes( std::move(transaction_pair.value->scope)); } - callbacks_->OnChanges(observation_index_map, std::move(web_observations), + callbacks_->OnChanges(observation_index_map, std::move(observations), observer_transactions); } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc index 84198c49edf..46ae0a7dec3 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.cc @@ -6,10 +6,9 @@ #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" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" namespace blink { // static diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h index 906d7068018..8d7b07f6137 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h @@ -10,9 +10,8 @@ #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/indexeddb/web_idb_callbacks.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" diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc index 5cf1906a645..426c2f7d39e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/inspector_indexed_db_agent.cc @@ -38,7 +38,7 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/dom_string_list.h" -#include "third_party/blink/renderer/core/dom/events/event_listener.h" +#include "third_party/blink/renderer/core/dom/events/native_event_listener.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/inspector/inspected_frames.h" @@ -107,23 +107,22 @@ Response AssertIDBFactory(Document* document, IDBFactory*& result) { return Response::OK(); } -class GetDatabaseNamesCallback final : public EventListener { - WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback); - +class GetDatabaseNamesCallback final : public NativeEventListener { public: static GetDatabaseNamesCallback* Create( std::unique_ptr<RequestDatabaseNamesCallback> request_callback, const String& security_origin) { - return new GetDatabaseNamesCallback(std::move(request_callback), - security_origin); + return MakeGarbageCollected<GetDatabaseNamesCallback>( + std::move(request_callback), security_origin); } + GetDatabaseNamesCallback( + std::unique_ptr<RequestDatabaseNamesCallback> request_callback, + const String& security_origin) + : request_callback_(std::move(request_callback)), + security_origin_(security_origin) {} ~GetDatabaseNamesCallback() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { request_callback_->sendFailure(Response::Error("Unexpected event type.")); @@ -147,32 +146,25 @@ class GetDatabaseNamesCallback final : public EventListener { } private: - GetDatabaseNamesCallback( - std::unique_ptr<RequestDatabaseNamesCallback> request_callback, - const String& security_origin) - : EventListener(EventListener::kCPPEventListenerType), - request_callback_(std::move(request_callback)), - security_origin_(security_origin) {} std::unique_ptr<RequestDatabaseNamesCallback> request_callback_; String security_origin_; }; -class DeleteCallback final : public EventListener { - WTF_MAKE_NONCOPYABLE(DeleteCallback); - +class DeleteCallback final : public NativeEventListener { public: static DeleteCallback* Create( std::unique_ptr<DeleteDatabaseCallback> request_callback, const String& security_origin) { - return new DeleteCallback(std::move(request_callback), security_origin); + return MakeGarbageCollected<DeleteCallback>(std::move(request_callback), + security_origin); } + DeleteCallback(std::unique_ptr<DeleteDatabaseCallback> request_callback, + const String& security_origin) + : request_callback_(std::move(request_callback)), + security_origin_(security_origin) {} ~DeleteCallback() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { request_callback_->sendFailure( @@ -183,11 +175,6 @@ class DeleteCallback final : public EventListener { } private: - DeleteCallback(std::unique_ptr<DeleteDatabaseCallback> request_callback, - const String& security_origin) - : EventListener(EventListener::kCPPEventListenerType), - request_callback_(std::move(request_callback)), - security_origin_(security_origin) {} std::unique_ptr<DeleteDatabaseCallback> request_callback_; String security_origin_; }; @@ -256,20 +243,22 @@ class ExecutableWithDatabase }; template <typename RequestCallback> -class OpenDatabaseCallback final : public EventListener { +class OpenDatabaseCallback final : public NativeEventListener { public: static OpenDatabaseCallback* Create( ExecutableWithDatabase<RequestCallback>* executable_with_database, ScriptState* script_state) { - return new OpenDatabaseCallback(executable_with_database, script_state); + return MakeGarbageCollected<OpenDatabaseCallback>(executable_with_database, + script_state); } + OpenDatabaseCallback( + ExecutableWithDatabase<RequestCallback>* executable_with_database, + ScriptState* script_state) + : executable_with_database_(executable_with_database), + script_state_(script_state) {} ~OpenDatabaseCallback() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext* context, Event* event) override { if (event->type() != event_type_names::kSuccess) { executable_with_database_->GetRequestCallback()->sendFailure( @@ -294,35 +283,29 @@ class OpenDatabaseCallback final : public EventListener { void Trace(blink::Visitor* visitor) override { visitor->Trace(script_state_); - EventListener::Trace(visitor); + NativeEventListener::Trace(visitor); } private: - OpenDatabaseCallback( - ExecutableWithDatabase<RequestCallback>* executable_with_database, - ScriptState* script_state) - : EventListener(EventListener::kCPPEventListenerType), - executable_with_database_(executable_with_database), - script_state_(script_state) {} scoped_refptr<ExecutableWithDatabase<RequestCallback>> executable_with_database_; Member<ScriptState> script_state_; }; template <typename RequestCallback> -class UpgradeDatabaseCallback final : public EventListener { +class UpgradeDatabaseCallback final : public NativeEventListener { public: static UpgradeDatabaseCallback* Create( ExecutableWithDatabase<RequestCallback>* executable_with_database) { - return new UpgradeDatabaseCallback(executable_with_database); + return MakeGarbageCollected<UpgradeDatabaseCallback>( + executable_with_database); } + UpgradeDatabaseCallback( + ExecutableWithDatabase<RequestCallback>* executable_with_database) + : executable_with_database_(executable_with_database) {} ~UpgradeDatabaseCallback() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext* context, Event* event) override { if (event->type() != event_type_names::kUpgradeneeded) { executable_with_database_->GetRequestCallback()->sendFailure( @@ -342,10 +325,6 @@ class UpgradeDatabaseCallback final : public EventListener { } private: - UpgradeDatabaseCallback( - ExecutableWithDatabase<RequestCallback>* executable_with_database) - : EventListener(EventListener::kCPPEventListenerType), - executable_with_database_(executable_with_database) {} scoped_refptr<ExecutableWithDatabase<RequestCallback>> executable_with_database_; }; @@ -387,16 +366,16 @@ IDBIndex* IndexForObjectStore(IDBObjectStore* idb_object_store, std::unique_ptr<KeyPath> KeyPathFromIDBKeyPath(const IDBKeyPath& idb_key_path) { std::unique_ptr<KeyPath> key_path; switch (idb_key_path.GetType()) { - case IDBKeyPath::kNullType: + case mojom::IDBKeyPathType::Null: key_path = KeyPath::create().setType(KeyPath::TypeEnum::Null).build(); break; - case IDBKeyPath::kStringType: + case mojom::IDBKeyPathType::String: key_path = KeyPath::create() .setType(KeyPath::TypeEnum::String) .setString(idb_key_path.GetString()) .build(); break; - case IDBKeyPath::kArrayType: { + case mojom::IDBKeyPathType::Array: { key_path = KeyPath::create().setType(KeyPath::TypeEnum::Array).build(); std::unique_ptr<protocol::Array<String>> array = protocol::Array<String>::create(); @@ -463,7 +442,8 @@ class DatabaseLoader final std::unique_ptr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::create() .setName(idb_database->name()) - .setVersion(static_cast<int>(idb_database->version())) + .setVersion( + static_cast<unsigned long long>(idb_database->version())) .setObjectStores(std::move(object_stores)) .build(); @@ -542,7 +522,7 @@ static IDBKeyRange* IdbKeyRangeFromKeyRange( class DataLoader; -class OpenCursorCallback final : public EventListener { +class OpenCursorCallback final : public NativeEventListener { public: static OpenCursorCallback* Create( v8_inspector::V8InspectorSession* v8_session, @@ -550,16 +530,24 @@ class OpenCursorCallback final : public EventListener { std::unique_ptr<RequestDataCallback> request_callback, int skip_count, unsigned page_size) { - return new OpenCursorCallback(v8_session, script_state, - std::move(request_callback), skip_count, - page_size); + return MakeGarbageCollected<OpenCursorCallback>(v8_session, script_state, + std::move(request_callback), + skip_count, page_size); } - ~OpenCursorCallback() override = default; - - bool operator==(const EventListener& other) const override { - return this == &other; + OpenCursorCallback(v8_inspector::V8InspectorSession* v8_session, + ScriptState* script_state, + std::unique_ptr<RequestDataCallback> request_callback, + int skip_count, + unsigned page_size) + : v8_session_(v8_session), + script_state_(script_state), + request_callback_(std::move(request_callback)), + skip_count_(skip_count), + page_size_(page_size) { + result_ = Array<DataEntry>::create(); } + ~OpenCursorCallback() override = default; void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { @@ -636,24 +624,10 @@ class OpenCursorCallback final : public EventListener { void Trace(blink::Visitor* visitor) override { visitor->Trace(script_state_); - EventListener::Trace(visitor); + NativeEventListener::Trace(visitor); } private: - OpenCursorCallback(v8_inspector::V8InspectorSession* v8_session, - ScriptState* script_state, - std::unique_ptr<RequestDataCallback> request_callback, - int skip_count, - unsigned page_size) - : EventListener(EventListener::kCPPEventListenerType), - v8_session_(v8_session), - script_state_(script_state), - request_callback_(std::move(request_callback)), - skip_count_(skip_count), - page_size_(page_size) { - result_ = Array<DataEntry>::create(); - } - v8_inspector::V8InspectorSession* v8_session_; Member<ScriptState> script_state_; std::unique_ptr<RequestDataCallback> request_callback_; @@ -855,9 +829,7 @@ void InspectorIndexedDBAgent::requestData( database_name); } -class DeleteObjectStoreEntriesListener final : public EventListener { - WTF_MAKE_NONCOPYABLE(DeleteObjectStoreEntriesListener); - +class DeleteObjectStoreEntriesListener final : public NativeEventListener { public: static DeleteObjectStoreEntriesListener* Create( std::unique_ptr<DeleteObjectStoreEntriesCallback> request_callback) { @@ -867,14 +839,9 @@ class DeleteObjectStoreEntriesListener final : public EventListener { DeleteObjectStoreEntriesListener( std::unique_ptr<DeleteObjectStoreEntriesCallback> request_callback) - : EventListener(EventListener::kCPPEventListenerType), - request_callback_(std::move(request_callback)) {} + : request_callback_(std::move(request_callback)) {} ~DeleteObjectStoreEntriesListener() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kSuccess) { request_callback_->sendFailure( @@ -962,21 +929,19 @@ void InspectorIndexedDBAgent::deleteObjectStoreEntries( database_name); } -class ClearObjectStoreListener final : public EventListener { - WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); - +class ClearObjectStoreListener final : public NativeEventListener { public: static ClearObjectStoreListener* Create( std::unique_ptr<ClearObjectStoreCallback> request_callback) { - return new ClearObjectStoreListener(std::move(request_callback)); + return MakeGarbageCollected<ClearObjectStoreListener>( + std::move(request_callback)); } + ClearObjectStoreListener( + std::unique_ptr<ClearObjectStoreCallback> request_callback) + : request_callback_(std::move(request_callback)) {} ~ClearObjectStoreListener() override = default; - bool operator==(const EventListener& other) const override { - return this == &other; - } - void Invoke(ExecutionContext*, Event* event) override { if (event->type() != event_type_names::kComplete) { request_callback_->sendFailure(Response::Error("Unexpected event type.")); @@ -987,11 +952,6 @@ class ClearObjectStoreListener final : public EventListener { } private: - ClearObjectStoreListener( - std::unique_ptr<ClearObjectStoreCallback> request_callback) - : EventListener(EventListener::kCPPEventListenerType), - request_callback_(std::move(request_callback)) {} - std::unique_ptr<ClearObjectStoreCallback> request_callback_; }; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc index 1f7839527ff..3a4254d8eee 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.cc @@ -4,36 +4,44 @@ #include "third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_key.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_value.h" + namespace blink { MockWebIDBCallbacks::MockWebIDBCallbacks() {} MockWebIDBCallbacks::~MockWebIDBCallbacks() {} -void MockWebIDBCallbacks::OnSuccess(blink::WebIDBKey key, - blink::WebIDBKey primaryKey, - blink::WebIDBValue value) { - DoOnSuccess(key, primaryKey, value); +void MockWebIDBCallbacks::SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) {} + +void MockWebIDBCallbacks::SuccessCursorContinue( + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> value) { + DoSuccessCursorContinue(key, primary_key, value); } -void MockWebIDBCallbacks::OnSuccess(blink::WebIDBCursor* cursor, - blink::WebIDBKey key, - blink::WebIDBKey primaryKey, - blink::WebIDBValue value) { - DoOnSuccess(cursor, key, primaryKey, value); +void MockWebIDBCallbacks::SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) { + DoSuccessCursor(cursor_info, key, primary_key, optional_value); } -void MockWebIDBCallbacks::OnSuccess(blink::WebIDBKey key) { - DoOnSuccess(key); +void MockWebIDBCallbacks::SuccessKey(std::unique_ptr<IDBKey> key) { + DoSuccessKey(key); } -void MockWebIDBCallbacks::OnSuccess(blink::WebIDBValue value) { - DoOnSuccess(value); +void MockWebIDBCallbacks::SuccessValue(mojom::blink::IDBReturnValuePtr value) { + DoSuccessValue(value); } -void MockWebIDBCallbacks::OnSuccess( - blink::WebVector<blink::WebIDBValue> values) { - DoOnSuccess(values); +void MockWebIDBCallbacks::SuccessArray( + Vector<mojom::blink::IDBReturnValuePtr> values) { + DoSuccessArray(values); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h index 97fe12544ea..14b466b1ea2 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_callbacks.h @@ -6,66 +6,86 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_CALLBACKS_H_ #include "base/macros.h" +#include "base/optional.h" #include "testing/gmock/include/gmock/gmock.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/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/public/platform/web_blob_info.h" #include "third_party/blink/public/web/web_heap.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_database_error.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" namespace blink { -class MockWebIDBCallbacks : public blink::WebIDBCallbacks { +class MockWebIDBCallbacks : public WebIDBCallbacks { public: MockWebIDBCallbacks(); ~MockWebIDBCallbacks() override; - MOCK_METHOD1(OnError, void(const blink::WebIDBDatabaseError&)); - - void OnSuccess(blink::WebIDBKey, - blink::WebIDBKey primaryKey, - blink::WebIDBValue) override; - MOCK_METHOD3(DoOnSuccess, - void(const blink::WebIDBKey& key, - const blink::WebIDBKey& primaryKey, - const blink::WebIDBValue& value)); - - MOCK_METHOD1(OnSuccess, - void(const blink::WebVector<blink::WebIDBNameAndVersion>&)); - MOCK_METHOD1(OnSuccess, void(const blink::WebVector<blink::WebString>&)); - - void OnSuccess(blink::WebIDBCursor* cursor, - blink::WebIDBKey key, - blink::WebIDBKey primaryKey, - blink::WebIDBValue value) override; - MOCK_METHOD4(DoOnSuccess, - void(blink::WebIDBCursor*, - const blink::WebIDBKey&, - const blink::WebIDBKey& primaryKey, - const blink::WebIDBValue&)); - - MOCK_METHOD2(OnSuccess, - void(blink::WebIDBDatabase*, const blink::WebIDBMetadata&)); - void OnSuccess(blink::WebIDBKey) override; - MOCK_METHOD1(DoOnSuccess, void(const blink::WebIDBKey&)); - - void OnSuccess(blink::WebIDBValue) override; - MOCK_METHOD1(DoOnSuccess, void(const blink::WebIDBValue&)); - - void OnSuccess(blink::WebVector<blink::WebIDBValue>) override; - MOCK_METHOD1(DoOnSuccess, void(const blink::WebVector<blink::WebIDBValue>&)); - - MOCK_METHOD1(OnSuccess, void(long long)); - MOCK_METHOD0(OnSuccess, void()); - MOCK_METHOD1(OnBlocked, void(long long oldVersion)); - MOCK_METHOD5(OnUpgradeNeeded, - void(long long oldVersion, - blink::WebIDBDatabase*, - const blink::WebIDBMetadata&, + + void SetState(base::WeakPtr<WebIDBCursorImpl>, int64_t); + + MOCK_METHOD2(Error, void(int32_t, const String&)); + + void SuccessCursorContinue( + std::unique_ptr<IDBKey>, + std::unique_ptr<IDBKey> primaryKey, + base::Optional<std::unique_ptr<IDBValue>>) override; + MOCK_METHOD3(DoSuccessCursorContinue, + void(const std::unique_ptr<IDBKey>& key, + const std::unique_ptr<IDBKey>& primaryKey, + const base::Optional<std::unique_ptr<IDBValue>>& value)); + + MOCK_METHOD1(SuccessNamesAndVersionsList, + void(Vector<mojom::blink::IDBNameAndVersionPtr>)); + + MOCK_METHOD1(SuccessStringList, void(const Vector<String>&)); + + void SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) override; + MOCK_METHOD4( + DoSuccessCursor, + void(const mojom::blink::IDBCursorAssociatedPtrInfo& cursor_info, + const std::unique_ptr<IDBKey>& key, + const std::unique_ptr<IDBKey>& primary_key, + const base::Optional<std::unique_ptr<IDBValue>>& optional_value)); + + MOCK_METHOD3(SuccessCursorPrefetch, + void(Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values)); + + MOCK_METHOD2(SuccessDatabase, + void(mojom::blink::IDBDatabaseAssociatedPtrInfo, + const IDBDatabaseMetadata&)); + + void SuccessKey(std::unique_ptr<IDBKey>) override; + MOCK_METHOD1(DoSuccessKey, void(const std::unique_ptr<IDBKey>&)); + + void SuccessValue(mojom::blink::IDBReturnValuePtr) override; + MOCK_METHOD1(DoSuccessValue, void(const mojom::blink::IDBReturnValuePtr&)); + + void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr>) override; + MOCK_METHOD1(DoSuccessArray, + void(const Vector<mojom::blink::IDBReturnValuePtr>&)); + + MOCK_METHOD1(SuccessInteger, void(int64_t)); + + MOCK_METHOD0(Success, void()); + + MOCK_METHOD1(Blocked, void(int64_t oldVersion)); + + MOCK_METHOD5(UpgradeNeeded, + void(mojom::blink::IDBDatabaseAssociatedPtrInfo, + int64_t oldVersion, mojom::IDBDataLoss dataLoss, - blink::WebString dataLossMessage)); - MOCK_METHOD0(Detach, void()); + const String& dataLossMessage, + const IDBDatabaseMetadata&)); + + MOCK_METHOD0(DetachRequestFromCallback, void()); private: DISALLOW_COPY_AND_ASSIGN(MockWebIDBCallbacks); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h index 04f7a5acda6..0ed42f39503 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_database.h @@ -7,7 +7,6 @@ #include <gmock/gmock.h> #include <memory> -#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" @@ -24,7 +23,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, const String& name, - const WebIDBKeyPath&, + const IDBKeyPath&, bool auto_increment)); MOCK_METHOD2(DeleteObjectStore, void(long long transaction_id, long long object_store_id)); @@ -39,13 +38,14 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { MOCK_METHOD0(Close, void()); MOCK_METHOD0(VersionChangeIgnored, void()); MOCK_METHOD1(Abort, void(long long transaction_id)); - MOCK_METHOD1(Commit, void(long long transaction_id)); + MOCK_METHOD2(Commit, + void(long long transaction_id, long long num_errors_handled)); MOCK_METHOD7(CreateIndex, void(long long transaction_id, long long object_store_id, long long index_id, const String& name, - const WebIDBKeyPath&, + const IDBKeyPath&, bool unique, bool multi_entry)); MOCK_METHOD3(DeleteIndex, @@ -72,33 +72,32 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, bool key_only, WebIDBCallbacks*)); MOCK_METHOD7(GetAll, void(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, long long max_count, bool key_only, WebIDBCallbacks*)); - MOCK_METHOD8(Put, + MOCK_METHOD7(Put, void(long long transaction_id, long long object_store_id, - const WebData& value, - const Vector<WebBlobInfo>&, - WebIDBKeyView primary_key, + std::unique_ptr<IDBValue> value, + std::unique_ptr<IDBKey> primary_key, mojom::IDBPutMode, WebIDBCallbacks*, - const Vector<WebIDBIndexKeys>&)); + Vector<IDBIndexKeys>)); MOCK_METHOD4(SetIndexKeys, void(long long transaction_id, long long object_store_id, - WebIDBKeyView primary_key, - const Vector<WebIDBIndexKeys>&)); + std::unique_ptr<IDBKey> primary_key, + Vector<IDBIndexKeys>)); MOCK_METHOD3(SetIndexesReady, void(long long transaction_id, long long object_store_id, @@ -107,7 +106,7 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, mojom::IDBCursorDirection, bool key_only, mojom::IDBTaskType, @@ -116,17 +115,17 @@ class MockWebIDBDatabase : public testing::StrictMock<WebIDBDatabase> { void(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, WebIDBCallbacks*)); MOCK_METHOD4(Delete, void(long long transaction_id, long long object_store_id, - WebIDBKeyView primary_key, + const IDBKey* primary_key, WebIDBCallbacks*)); MOCK_METHOD4(DeleteRange, void(long long transaction_id, long long object_store_id, - const WebIDBKeyRange&, + const IDBKeyRange*, WebIDBCallbacks*)); MOCK_METHOD3(Clear, void(long long transaction_id, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.cc b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.cc index 80cf343612e..a1ce311907f 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.cc @@ -7,6 +7,7 @@ #include <memory> #include "base/memory/ptr_util.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { @@ -17,4 +18,15 @@ MockWebIDBFactory::~MockWebIDBFactory() = default; std::unique_ptr<MockWebIDBFactory> MockWebIDBFactory::Create() { return base::WrapUnique(new MockWebIDBFactory()); } + +void MockWebIDBFactory::GetDatabaseInfo( + std::unique_ptr<WebIDBCallbacks> callbacks) { + *callbacks_ptr_ = std::move(callbacks); +} + +void MockWebIDBFactory::SetCallbacksPointer( + std::unique_ptr<WebIDBCallbacks>* callbacks_ptr) { + callbacks_ptr_ = callbacks_ptr; +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h index 47ffe2f93e6..bf0bea1c734 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/mock_web_idb_factory.h @@ -5,56 +5,44 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_FACTORY_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_MOCK_WEB_IDB_FACTORY_H_ -#include <gmock/gmock.h> #include <memory> -#include "base/single_thread_task_runner.h" -#include "third_party/blink/public/platform/web_common.h" -#include "third_party/blink/public/platform/web_security_origin.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" +#include "third_party/blink/renderer/modules/modules_export.h" -namespace base { -class SingleThreadTaskRunner; +namespace WTF { +class String; } namespace blink { -class WebIDBCallbacks; -class WebIDBDatabaseCallbacks; -class WebSecurityOrigin; -class WebString; - class MockWebIDBFactory : public testing::StrictMock<blink::WebIDBFactory> { public: ~MockWebIDBFactory() override; static std::unique_ptr<MockWebIDBFactory> Create(); - MOCK_METHOD3(GetDatabaseInfo, - void(WebIDBCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>)); - MOCK_METHOD3(GetDatabaseNames, - void(WebIDBCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>)); - MOCK_METHOD7(Open, - void(const WebString& name, + void GetDatabaseInfo(std::unique_ptr<WebIDBCallbacks>); + MOCK_METHOD1(GetDatabaseNames, void(std::unique_ptr<WebIDBCallbacks>)); + MOCK_METHOD5(Open, + void(const WTF::String& name, long long version, long long transaction_id, - WebIDBCallbacks*, - WebIDBDatabaseCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>)); - MOCK_METHOD5(DeleteDatabase, - void(const WebString& name, - WebIDBCallbacks*, - const WebSecurityOrigin&, - bool force_close, - scoped_refptr<base::SingleThreadTaskRunner>)); + std::unique_ptr<WebIDBCallbacks>, + std::unique_ptr<WebIDBDatabaseCallbacks>)); + MOCK_METHOD3(DeleteDatabase, + void(const WTF::String& name, + std::unique_ptr<WebIDBCallbacks>, + bool force_close)); + + void SetCallbacksPointer(std::unique_ptr<WebIDBCallbacks>* callbacks); private: MockWebIDBFactory(); + std::unique_ptr<WebIDBCallbacks>* callbacks_ptr_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h new file mode 100644 index 00000000000..ff1a49d08ad --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CALLBACKS_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CALLBACKS_H_ + +#include "base/memory/weak_ptr.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" +#include "third_party/blink/renderer/modules/modules_export.h" + +namespace blink { + +class WebIDBCursorImpl; + +class WebIDBCallbacks : public mojom::blink::IDBCallbacks { + public: + virtual void DetachRequestFromCallback() = 0; + virtual void SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) = 0; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_CALLBACKS_H_ diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc index b4904837f97..2e1709ebd5d 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.cc @@ -31,33 +31,39 @@ #include <memory> #include "base/memory/ptr_util.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" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/modules/indexed_db_names.h" #include "third_party/blink/renderer/modules/indexeddb/idb_metadata.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_name_and_version.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_cursor_impl.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_database.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" #include "third_party/blink/renderer/platform/shared_buffer.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" -using blink::WebIDBCursor; -using blink::WebIDBDatabase; -using blink::WebIDBDatabaseError; -using blink::WebIDBKey; -using blink::WebIDBKeyPath; -using blink::WebIDBMetadata; -using blink::WebIDBNameAndVersion; -using blink::WebIDBValue; -using blink::WebVector; - namespace blink { +namespace { + +std::unique_ptr<IDBValue> ConvertReturnValue( + const mojom::blink::IDBReturnValuePtr& input) { + if (!input) { + return IDBValue::Create(scoped_refptr<SharedBuffer>(), + Vector<WebBlobInfo>()); + } + + std::unique_ptr<IDBValue> output = std::move(input->value); + output->SetInjectedPrimaryKey(std::move(input->primary_key), input->key_path); + return output; +} + +} // namespace + // static std::unique_ptr<WebIDBCallbacksImpl> WebIDBCallbacksImpl::Create( IDBRequest* request) { @@ -66,11 +72,22 @@ std::unique_ptr<WebIDBCallbacksImpl> WebIDBCallbacksImpl::Create( WebIDBCallbacksImpl::WebIDBCallbacksImpl(IDBRequest* request) : request_(request) { + task_runner_ = request_->GetExecutionContext()->GetTaskRunner( + TaskType::kInternalIndexedDB); probe::AsyncTaskScheduled(request_->GetExecutionContext(), indexed_db_names::kIndexedDB, this); } WebIDBCallbacksImpl::~WebIDBCallbacksImpl() { + Detach(); +} + +void WebIDBCallbacksImpl::Detach() { + DetachCallbackFromRequest(); + DetachRequestFromCallback(); +} + +void WebIDBCallbacksImpl::DetachCallbackFromRequest() { if (request_) { probe::AsyncTaskCanceled(request_->GetExecutionContext(), this); #if DCHECK_IS_ON() @@ -80,53 +97,90 @@ WebIDBCallbacksImpl::~WebIDBCallbacksImpl() { } } -void WebIDBCallbacksImpl::OnError(const WebIDBDatabaseError& error) { +void WebIDBCallbacksImpl::DetachRequestFromCallback() { + request_.Clear(); +} + +void WebIDBCallbacksImpl::SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) { + cursor_ = cursor; + transaction_id_ = transaction_id; +} + +void WebIDBCallbacksImpl::Error(int32_t code, const String& message) { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "error"); - request_->HandleResponse(DOMException::Create( - static_cast<DOMExceptionCode>(error.Code()), error.Message())); + request_->HandleResponse( + DOMException::Create(static_cast<DOMExceptionCode>(code), message)); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess( - const WebVector<WebIDBNameAndVersion>& web_name_and_version_list) { +void WebIDBCallbacksImpl::SuccessNamesAndVersionsList( + Vector<mojom::blink::IDBNameAndVersionPtr> name_and_version_list) { // Only implemented in idb_factory.cc for the promise-based databases() call. NOTREACHED(); } -void WebIDBCallbacksImpl::OnSuccess( - const WebVector<WebString>& web_string_list) { +void WebIDBCallbacksImpl::SuccessStringList(const Vector<String>& string_list) { if (!request_) return; - Vector<String> string_list; - for (size_t i = 0; i < web_string_list.size(); ++i) - string_list.push_back(web_string_list[i]); probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); #if DCHECK_IS_ON() DCHECK(!request_->TransactionHasQueuedResults()); #endif // DCHECK_IS_ON() - request_->EnqueueResponse(string_list); + request_->EnqueueResponse(std::move(string_list)); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(WebIDBCursor* cursor, - WebIDBKey key, - WebIDBKey primary_key, - WebIDBValue value) { +void WebIDBCallbacksImpl::SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) { if (!request_) return; + std::unique_ptr<WebIDBCursorImpl> cursor = std::make_unique<WebIDBCursorImpl>( + std::move(cursor_info), transaction_id_, task_runner_); + std::unique_ptr<IDBValue> value; + if (optional_value.has_value()) { + value = std::move(optional_value.value()); + } else { + value = + IDBValue::Create(scoped_refptr<SharedBuffer>(), Vector<WebBlobInfo>()); + } + DCHECK(value); + probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); - std::unique_ptr<IDBValue> idb_value = value.ReleaseIdbValue(); - idb_value->SetIsolate(request_->GetIsolate()); - request_->HandleResponse(base::WrapUnique(cursor), key.ReleaseIdbKey(), - primary_key.ReleaseIdbKey(), std::move(idb_value)); + value->SetIsolate(request_->GetIsolate()); + request_->HandleResponse(std::move(cursor), std::move(key), + std::move(primary_key), std::move(value)); + Detach(); +} + +void WebIDBCallbacksImpl::SuccessCursorPrefetch( + Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values) { + if (cursor_) { + cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), + std::move(values)); + cursor_->CachedContinue(this); + } + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(WebIDBDatabase* backend, - const WebIDBMetadata& metadata) { - std::unique_ptr<WebIDBDatabase> db = base::WrapUnique(backend); +void WebIDBCallbacksImpl::SuccessDatabase( + mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + const IDBDatabaseMetadata& metadata) { + std::unique_ptr<WebIDBDatabase> db; + if (database_info.is_valid()) { + db = std::make_unique<WebIDBDatabaseImpl>(std::move(database_info), + task_runner_); + } if (request_) { probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); @@ -134,74 +188,91 @@ void WebIDBCallbacksImpl::OnSuccess(WebIDBDatabase* backend, DCHECK(!request_->TransactionHasQueuedResults()); #endif // DCHECK_IS_ON() request_->EnqueueResponse(std::move(db), IDBDatabaseMetadata(metadata)); + Detach(); } else if (db) { db->Close(); } } -void WebIDBCallbacksImpl::OnSuccess(WebIDBKey key) { +void WebIDBCallbacksImpl::SuccessKey(std::unique_ptr<IDBKey> key) { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); - request_->HandleResponse(key.ReleaseIdbKey()); + request_->HandleResponse(std::move(key)); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(WebIDBValue value) { +void WebIDBCallbacksImpl::SuccessValue( + mojom::blink::IDBReturnValuePtr return_value) { if (!request_) return; + std::unique_ptr<IDBValue> value = ConvertReturnValue(return_value); probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); - std::unique_ptr<IDBValue> idb_value = value.ReleaseIdbValue(); - idb_value->SetIsolate(request_->GetIsolate()); - request_->HandleResponse(std::move(idb_value)); + value->SetIsolate(request_->GetIsolate()); + request_->HandleResponse(std::move(value)); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(WebVector<WebIDBValue> values) { +void WebIDBCallbacksImpl::SuccessArray( + Vector<mojom::blink::IDBReturnValuePtr> values) { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); Vector<std::unique_ptr<IDBValue>> idb_values; - idb_values.ReserveInitialCapacity(SafeCast<wtf_size_t>(values.size())); - for (WebIDBValue& value : values) { - std::unique_ptr<IDBValue> idb_value = value.ReleaseIdbValue(); + idb_values.ReserveInitialCapacity(values.size()); + for (const mojom::blink::IDBReturnValuePtr& value : values) { + std::unique_ptr<IDBValue> idb_value = ConvertReturnValue(value); idb_value->SetIsolate(request_->GetIsolate()); idb_values.emplace_back(std::move(idb_value)); } request_->HandleResponse(std::move(idb_values)); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(long long value) { +void WebIDBCallbacksImpl::SuccessInteger(int64_t value) { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); request_->HandleResponse(value); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess() { +void WebIDBCallbacksImpl::Success() { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); request_->HandleResponse(); + Detach(); } -void WebIDBCallbacksImpl::OnSuccess(WebIDBKey key, - WebIDBKey primary_key, - WebIDBValue value) { +void WebIDBCallbacksImpl::SuccessCursorContinue( + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) { if (!request_) return; probe::AsyncTask async_task(request_->GetExecutionContext(), this, "success"); - std::unique_ptr<IDBValue> idb_value = value.ReleaseIdbValue(); - idb_value->SetIsolate(request_->GetIsolate()); - request_->HandleResponse(key.ReleaseIdbKey(), primary_key.ReleaseIdbKey(), - std::move(idb_value)); + std::unique_ptr<IDBValue> value; + if (optional_value.has_value()) { + value = std::move(optional_value.value()); + } else { + value = + IDBValue::Create(scoped_refptr<SharedBuffer>(), Vector<WebBlobInfo>()); + } + DCHECK(value); + value->SetIsolate(request_->GetIsolate()); + request_->HandleResponse(std::move(key), std::move(primary_key), + std::move(value)); + Detach(); } -void WebIDBCallbacksImpl::OnBlocked(long long old_version) { +void WebIDBCallbacksImpl::Blocked(int64_t old_version) { if (!request_) return; @@ -210,14 +281,22 @@ void WebIDBCallbacksImpl::OnBlocked(long long old_version) { DCHECK(!request_->TransactionHasQueuedResults()); #endif // DCHECK_IS_ON() request_->EnqueueBlocked(old_version); + // Not resetting |request_|. In this instance we will have to forward at + // least one other call in the set UpgradeNeeded() / Success() / + // Error(). } -void WebIDBCallbacksImpl::OnUpgradeNeeded(long long old_version, - WebIDBDatabase* database, - const WebIDBMetadata& metadata, - mojom::IDBDataLoss data_loss, - WebString data_loss_message) { - std::unique_ptr<WebIDBDatabase> db = base::WrapUnique(database); +void WebIDBCallbacksImpl::UpgradeNeeded( + mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + int64_t old_version, + mojom::IDBDataLoss data_loss, + const String& data_loss_message, + const IDBDatabaseMetadata& metadata) { + std::unique_ptr<WebIDBDatabase> db; + if (database_info.is_valid()) { + db = std::make_unique<WebIDBDatabaseImpl>(std::move(database_info), + task_runner_); + } if (request_) { probe::AsyncTask async_task(request_->GetExecutionContext(), this, "upgradeNeeded"); @@ -227,13 +306,12 @@ void WebIDBCallbacksImpl::OnUpgradeNeeded(long long old_version, request_->EnqueueUpgradeNeeded(old_version, std::move(db), IDBDatabaseMetadata(metadata), data_loss, data_loss_message); - } else { + // Not resetting |request_|. In this instance we will have to forward at + // least one other call in the set UpgradeNeeded() / Success() / + // Error(). + } else if (db) { db->Close(); } } -void WebIDBCallbacksImpl::Detach() { - request_.Clear(); -} - } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.h index 8cf4cb7ac8a..cc8dc628be5 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.h @@ -31,56 +31,78 @@ #include <memory> -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_callbacks.h" +#include "base/memory/weak_ptr.h" +#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" namespace blink { +class IDBKey; class IDBRequest; -class WebIDBCursor; -class WebIDBDatabase; -class WebIDBDatabaseError; -class WebIDBKey; -struct WebIDBMetadata; -struct WebIDBNameAndVersion; -class WebIDBValue; +class IDBValue; +class WebIDBCursorImpl; +struct IDBDatabaseMetadata; class WebIDBCallbacksImpl final : public WebIDBCallbacks { USING_FAST_MALLOC(WebIDBCallbacksImpl); public: + // |kNoTransaction| is used as the default transaction ID when instantiating + // an WebIDBCallbacksImpl instance. See web_idb_factory_impl.cc for those + // cases. + enum : int64_t { kNoTransaction = -1 }; + static std::unique_ptr<WebIDBCallbacksImpl> Create(IDBRequest*); ~WebIDBCallbacksImpl() override; + void SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) override; + // Pointers transfer ownership. - void OnError(const WebIDBDatabaseError&) override; - void OnSuccess(const WebVector<WebIDBNameAndVersion>&) override; - void OnSuccess(const WebVector<WebString>&) override; - void OnSuccess(WebIDBCursor*, - WebIDBKey, - WebIDBKey primary_key, - WebIDBValue) override; - void OnSuccess(WebIDBDatabase*, const WebIDBMetadata&) override; - void OnSuccess(WebIDBKey) override; - void OnSuccess(WebIDBValue) override; - void OnSuccess(WebVector<WebIDBValue>) override; - void OnSuccess(long long) override; - void OnSuccess() override; - void OnSuccess(WebIDBKey, WebIDBKey primary_key, WebIDBValue) override; - void OnBlocked(long long old_version) override; - void OnUpgradeNeeded(long long old_version, - WebIDBDatabase*, - const WebIDBMetadata&, - mojom::IDBDataLoss data_loss, - WebString data_loss_message) override; - void Detach() override; + void Error(int32_t code, const String& message) override; + void SuccessNamesAndVersionsList( + Vector<mojom::blink::IDBNameAndVersionPtr>) override; + void SuccessStringList(const Vector<String>&) override; + void SuccessCursor( + mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>> optional_value) override; + void SuccessCursorPrefetch(Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values) override; + void SuccessDatabase(mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + const IDBDatabaseMetadata& metadata) override; + void SuccessKey(std::unique_ptr<IDBKey>) override; + void SuccessValue(mojom::blink::IDBReturnValuePtr) override; + void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr>) override; + void SuccessInteger(int64_t) override; + void Success() override; + void SuccessCursorContinue( + std::unique_ptr<IDBKey>, + std::unique_ptr<IDBKey> primary_key, + base::Optional<std::unique_ptr<IDBValue>>) override; + void Blocked(int64_t old_version) override; + void UpgradeNeeded(mojom::blink::IDBDatabaseAssociatedPtrInfo, + int64_t old_version, + mojom::IDBDataLoss data_loss, + const String& data_loss_message, + const IDBDatabaseMetadata&) override; + void DetachRequestFromCallback() override; private: explicit WebIDBCallbacksImpl(IDBRequest*); + void Detach(); + void DetachCallbackFromRequest(); + Persistent<IDBRequest> request_; + base::WeakPtr<WebIDBCursorImpl> cursor_; + int64_t transaction_id_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h index 998daa93b4c..786a51f18d5 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h @@ -27,9 +27,7 @@ #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_string.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/renderer/modules/modules_export.h" namespace blink { @@ -47,10 +45,10 @@ class MODULES_EXPORT WebIDBCursor { // application. When both arguments are null, the cursor advances by one // entry. // - // The keys pointed to by WebIDBKeyView are only guaranteed to be alive for + // The keys pointed to by IDBKey* are only guaranteed to be alive for // the duration of the call. - virtual void CursorContinue(WebIDBKeyView, - WebIDBKeyView primary_key, + virtual void CursorContinue(const IDBKey*, + const IDBKey* primary_key, WebIDBCallbacks*) = 0; // Called after a cursor request's success handler is executed. diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc index c308cf7cab9..e65a8840ba8 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.cc @@ -11,17 +11,10 @@ #include "base/single_thread_task_runner.h" #include "mojo/public/cpp/bindings/strong_associated_binding.h" -#include "third_party/blink/public/platform/modules/indexeddb/indexed_db_key_builder.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h" +#include "third_party/blink/renderer/platform/wtf/functional.h" -using blink::WebBlobInfo; -using blink::WebData; -using blink::WebIDBCallbacks; -using blink::WebIDBKey; -using blink::WebIDBKeyView; -using blink::WebIDBValue; using blink::mojom::blink::IDBCallbacksAssociatedPtrInfo; using blink::mojom::blink::IDBCursorAssociatedPtrInfo; @@ -29,14 +22,16 @@ namespace blink { WebIDBCursorImpl::WebIDBCursorImpl( mojom::blink::IDBCursorAssociatedPtrInfo cursor_info, - int64_t transaction_id) + int64_t transaction_id, + scoped_refptr<base::SingleThreadTaskRunner> task_runner) : transaction_id_(transaction_id), - cursor_(std::move(cursor_info)), continue_count_(0), used_prefetches_(0), pending_onsuccess_callbacks_(0), prefetch_amount_(kMinPrefetchAmount), + task_runner_(task_runner), weak_factory_(this) { + cursor_.Bind(std::move(cursor_info), std::move(task_runner)); IndexedDBDispatcher::RegisterCursor(this); } @@ -56,21 +51,42 @@ void WebIDBCursorImpl::Advance(uint32_t count, WebIDBCallbacks* callbacks_ptr) { } ResetPrefetchCache(); - // Reset all cursor prefetch caches except for this cursor. - IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this); + callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_); + cursor_->Advance(count, + WTF::Bind(&WebIDBCursorImpl::AdvanceCallback, + WTF::Unretained(this), std::move(callbacks))); +} + +void WebIDBCursorImpl::AdvanceCallback( + std::unique_ptr<WebIDBCallbacks> callbacks, + mojom::blink::IDBErrorPtr error, + mojom::blink::IDBCursorValuePtr cursor_value) { + if (error) { + callbacks->Error(error->error_code, error->error_message); + callbacks.reset(); + return; + } - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr()); - cursor_->Advance(count, GetCallbacksProxy(std::move(callbacks_impl))); + if (!cursor_value) { + callbacks->SuccessValue(nullptr); + callbacks.reset(); + return; + } + + callbacks->SuccessCursorContinue(std::move(cursor_value->key), + std::move(cursor_value->primary_key), + std::move(cursor_value->value)); + callbacks.reset(); } -void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key, - WebIDBKeyView primary_key, +void WebIDBCursorImpl::CursorContinue(const IDBKey* key, + const IDBKey* primary_key, WebIDBCallbacks* callbacks_ptr) { + DCHECK(key && primary_key); std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); - if (key.KeyType() == kWebIDBKeyTypeNull && - primary_key.KeyType() == kWebIDBKeyTypeNull) { + if (key->GetType() == mojom::IDBKeyType::Null && + primary_key->GetType() == mojom::IDBKeyType::Null) { // No key(s), so this would qualify for a prefetch. ++continue_count_; @@ -84,10 +100,9 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key, // Request pre-fetch. ++pending_onsuccess_callbacks_; - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr()); + callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_); cursor_->Prefetch(prefetch_amount_, - GetCallbacksProxy(std::move(callbacks_impl))); + GetCallbacksProxy(std::move(callbacks))); // Increase prefetch_amount_ exponentially. prefetch_amount_ *= 2; @@ -101,14 +116,9 @@ void WebIDBCursorImpl::CursorContinue(WebIDBKeyView key, ResetPrefetchCache(); } - // Reset all cursor prefetch caches except for this cursor. - IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id_, this); - - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - std::move(callbacks), transaction_id_, weak_factory_.GetWeakPtr()); - cursor_->CursorContinue(WebIDBKeyBuilder::Build(key), - WebIDBKeyBuilder::Build(primary_key), - GetCallbacksProxy(std::move(callbacks_impl))); + callbacks->SetState(weak_factory_.GetWeakPtr(), transaction_id_); + cursor_->CursorContinue(IDBKey::Clone(key), IDBKey::Clone(primary_key), + GetCallbacksProxy(std::move(callbacks))); } void WebIDBCursorImpl::PostSuccessHandlerCallback() { @@ -124,9 +134,10 @@ void WebIDBCursorImpl::PostSuccessHandlerCallback() { ResetPrefetchCache(); } -void WebIDBCursorImpl::SetPrefetchData(Vector<WebIDBKey> keys, - Vector<WebIDBKey> primary_keys, - Vector<WebIDBValue> values) { +void WebIDBCursorImpl::SetPrefetchData( + Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values) { // Keys and values are stored in reverse order so that a cache'd continue can // pop a value off of the back and prevent new memory allocations. prefetch_keys_.AppendRange(std::make_move_iterator(keys.rbegin()), @@ -165,9 +176,10 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { // Keys and values are stored in reverse order so that a cache'd continue can // pop a value off of the back and prevent new memory allocations. - WebIDBKey key = std::move(prefetch_keys_.back()); - WebIDBKey primary_key = std::move(prefetch_primary_keys_.back()); - WebIDBValue value = std::move(prefetch_values_.back()); + std::unique_ptr<IDBKey> key = std::move(prefetch_keys_.back()); + std::unique_ptr<IDBKey> primary_key = + std::move(prefetch_primary_keys_.back()); + std::unique_ptr<IDBValue> value = std::move(prefetch_values_.back()); prefetch_keys_.pop_back(); prefetch_primary_keys_.pop_back(); @@ -184,8 +196,8 @@ void WebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { ResetPrefetchCache(); } - callbacks->OnSuccess(std::move(key), std::move(primary_key), - std::move(value)); + callbacks->SuccessCursorContinue(std::move(key), std::move(primary_key), + std::move(value)); } void WebIDBCursorImpl::ResetPrefetchCache() { @@ -209,10 +221,11 @@ void WebIDBCursorImpl::ResetPrefetchCache() { } IDBCallbacksAssociatedPtrInfo WebIDBCursorImpl::GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { + std::unique_ptr<WebIDBCallbacks> callbacks) { IDBCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); - mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); + mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request), + task_runner_); return ptr_info; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h index 58e953fa26e..746c8d5b450 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl.h @@ -10,33 +10,31 @@ #include <vector> #include "base/gtest_prod_util.h" -#include "third_party/blink/public/common/indexeddb/indexeddb_key.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_key.h" -#include "third_party/blink/public/platform/modules/indexeddb/web_idb_value.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_value.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_cursor.h" #include "third_party/blink/renderer/modules/modules_export.h" namespace blink { -class IndexedDBCallbacksImpl; - class MODULES_EXPORT WebIDBCursorImpl : public WebIDBCursor { public: WebIDBCursorImpl(mojom::blink::IDBCursorAssociatedPtrInfo cursor, - int64_t transaction_id); + int64_t transaction_id, + scoped_refptr<base::SingleThreadTaskRunner> task_runner); ~WebIDBCursorImpl() override; void Advance(uint32_t count, WebIDBCallbacks* callback) override; - void CursorContinue(WebIDBKeyView key, - WebIDBKeyView primary_key, + + void CursorContinue(const IDBKey* key, + const IDBKey* primary_key, WebIDBCallbacks* callback) override; void PostSuccessHandlerCallback() override; - void SetPrefetchData(Vector<WebIDBKey> keys, - Vector<WebIDBKey> primary_keys, - Vector<WebIDBValue> values); + void SetPrefetchData(Vector<std::unique_ptr<IDBKey>> keys, + Vector<std::unique_ptr<IDBKey>> primary_keys, + Vector<std::unique_ptr<IDBValue>> values); void CachedAdvance(unsigned long count, WebIDBCallbacks* callbacks); void CachedContinue(WebIDBCallbacks* callbacks); @@ -47,8 +45,11 @@ class MODULES_EXPORT WebIDBCursorImpl : public WebIDBCursor { int64_t transaction_id() const { return transaction_id_; } private: + void AdvanceCallback(std::unique_ptr<WebIDBCallbacks> callbacks, + mojom::blink::IDBErrorPtr error, + mojom::blink::IDBCursorValuePtr value); mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks); + std::unique_ptr<WebIDBCallbacks> callbacks); FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); @@ -67,9 +68,9 @@ class MODULES_EXPORT WebIDBCursorImpl : public WebIDBCursor { // 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_; + Vector<std::unique_ptr<IDBKey>> prefetch_keys_; + Vector<std::unique_ptr<IDBKey>> prefetch_primary_keys_; + Vector<std::unique_ptr<IDBValue>> prefetch_values_; // Number of continue calls that would qualify for a pre-fetch. int continue_count_; @@ -83,6 +84,8 @@ class MODULES_EXPORT WebIDBCursorImpl : public WebIDBCursor { // Number of items to request in next prefetch. int prefetch_amount_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; + base::WeakPtrFactory<WebIDBCursorImpl> weak_factory_; DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImpl); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc index 76fa9b2ad2b..8ddd4e5b2e4 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_cursor_impl_unittest.cc @@ -12,9 +12,7 @@ #include "base/macros.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" @@ -46,13 +44,15 @@ class MockCursorImpl : public mojom::blink::IDBCursor { } void Advance(uint32_t count, - mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override { + mojom::blink::IDBCursor::AdvanceCallback callback) override { ++advance_calls_; + std::move(callback).Run(mojom::blink::IDBErrorPtr(), + mojom::blink::IDBCursorValuePtr()); } void CursorContinue( - WebIDBKey key, - WebIDBKey primary_key, + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primary_key, mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override { ++continue_calls_; } @@ -81,38 +81,45 @@ class MockCursorImpl : public mojom::blink::IDBCursor { class MockContinueCallbacks : public testing::StrictMock<MockWebIDBCallbacks> { public: - MockContinueCallbacks(IndexedDBKey* key = nullptr, - WebVector<WebBlobInfo>* blobs = nullptr) + MockContinueCallbacks(std::unique_ptr<IDBKey>* key = nullptr, + Vector<WebBlobInfo>* blobs = nullptr) : key_(key), blobs_(blobs) {} - void OnSuccess(WebIDBKey key, - WebIDBKey primaryKey, - WebIDBValue value) override { + void SetState(base::WeakPtr<WebIDBCursorImpl> cursor, + int64_t transaction_id) override {} + void SuccessValue(mojom::blink::IDBReturnValuePtr return_value) override {} + + void SuccessCursorContinue( + std::unique_ptr<IDBKey> key, + std::unique_ptr<IDBKey> primaryKey, + base::Optional<std::unique_ptr<IDBValue>> value) override { if (key_) - *key_ = IndexedDBKeyBuilder::Build(key.View()); - if (blobs_) - *blobs_ = value.BlobInfoForTesting(); + *key_ = IDBKey::Clone(key); + if (blobs_ && value.has_value()) + *blobs_ = value.value()->BlobInfo(); } private: - IndexedDBKey* key_; - WebVector<WebBlobInfo>* blobs_; + std::unique_ptr<IDBKey>* key_; + Vector<WebBlobInfo>* blobs_; }; } // namespace class WebIDBCursorImplTest : public testing::Test { public: - WebIDBCursorImplTest() : null_key_(WebIDBKey::CreateNull()) { + WebIDBCursorImplTest() : null_key_(IDBKey::CreateNull()) { mojom::blink::IDBCursorAssociatedPtr ptr; mock_cursor_ = std::make_unique<MockCursorImpl>( mojo::MakeRequestAssociatedWithDedicatedPipe(&ptr)); - cursor_ = std::make_unique<WebIDBCursorImpl>(ptr.PassInterface(), 1); + cursor_ = std::make_unique<WebIDBCursorImpl>( + ptr.PassInterface(), 1, + blink::scheduler::GetSingleThreadTaskRunnerForTesting()); } protected: ScopedTestingPlatformSupport<TestingPlatformSupport> platform_; - WebIDBKey null_key_; + std::unique_ptr<IDBKey> null_key_; std::unique_ptr<WebIDBCursorImpl> cursor_; std::unique_ptr<MockCursorImpl> mock_cursor_; @@ -125,7 +132,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { int continue_calls = 0; EXPECT_EQ(mock_cursor_->continue_calls(), 0); for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); platform_->RunUntilIdle(); EXPECT_EQ(++continue_calls, mock_cursor_->continue_calls()); @@ -140,7 +147,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { int last_prefetch_count = 0; for (int repetitions = 0; repetitions < kPrefetchRepetitions; ++repetitions) { // Initiate the prefetch - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); @@ -152,24 +159,25 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { last_prefetch_count = prefetch_count; // Fill the prefetch cache as requested. - Vector<WebIDBKey> keys; - Vector<WebIDBKey> primary_keys; - Vector<WebIDBValue> values; + Vector<std::unique_ptr<IDBKey>> keys; + Vector<std::unique_ptr<IDBKey>> primary_keys; + Vector<std::unique_ptr<IDBValue>> values; size_t expected_size = 0; for (int i = 0; i < prefetch_count; ++i) { - WebIDBKey key = WebIDBKey::CreateNumber(expected_key + i); + std::unique_ptr<IDBKey> key = IDBKey::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); + Vector<WebBlobInfo> blob_info; + blob_info.ReserveInitialCapacity(expected_key + i); for (int j = 0; j < expected_key + i; ++j) { blob_info.emplace_back(WebBlobInfo::BlobForTesting( WebString("blobuuid"), "text/plain", 123)); } - values.emplace_back(WebData(), std::move(blob_info)); + values.emplace_back(IDBValue::Create(scoped_refptr<SharedBuffer>(), + std::move(blob_info))); } cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), std::move(values)); @@ -180,17 +188,17 @@ TEST_F(WebIDBCursorImplTest, PrefetchTest) { // Verify that the cache is used for subsequent continue() calls. for (int i = 0; i < prefetch_count; ++i) { - IndexedDBKey key; - WebVector<WebBlobInfo> blobs; - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + std::unique_ptr<IDBKey> key; + Vector<WebBlobInfo> blobs; + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks(&key, &blobs)); platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); EXPECT_EQ(repetitions + 1, mock_cursor_->prefetch_calls()); - EXPECT_EQ(kWebIDBKeyTypeNumber, key.type()); + EXPECT_EQ(mojom::IDBKeyType::Number, key->GetType()); EXPECT_EQ(expected_key, static_cast<int>(blobs.size())); - EXPECT_EQ(expected_key++, key.number()); + EXPECT_EQ(expected_key++, key->Number()); } } @@ -203,14 +211,14 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { // Call continue() until prefetching should kick in. EXPECT_EQ(0, mock_cursor_->continue_calls()); for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); } platform_->RunUntilIdle(); EXPECT_EQ(0, mock_cursor_->prefetch_calls()); // Initiate the prefetch - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); platform_->RunUntilIdle(); @@ -223,24 +231,25 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { // Fill the prefetch cache as requested. int expected_key = 0; - Vector<WebIDBKey> keys; - Vector<WebIDBKey> primary_keys; - Vector<WebIDBValue> values; + Vector<std::unique_ptr<IDBKey>> keys; + Vector<std::unique_ptr<IDBKey>> primary_keys; + Vector<std::unique_ptr<IDBValue>> values; size_t expected_size = 0; for (int i = 0; i < prefetch_count; ++i) { - WebIDBKey key = WebIDBKey::CreateNumber(expected_key + i); + std::unique_ptr<IDBKey> key = IDBKey::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); + Vector<WebBlobInfo> blob_info; + blob_info.ReserveInitialCapacity(expected_key + i); for (int j = 0; j < expected_key + i; ++j) { blob_info.emplace_back(WebBlobInfo::BlobForTesting(WebString("blobuuid"), "text/plain", 123)); } - values.emplace_back(WebData(), std::move(blob_info)); + values.emplace_back( + IDBValue::Create(scoped_refptr<SharedBuffer>(), std::move(blob_info))); } cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), std::move(values)); @@ -253,27 +262,27 @@ TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { ASSERT_GE(prefetch_count, 5); // IDBCursor.continue() - IndexedDBKey key; - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + std::unique_ptr<IDBKey> key; + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks(&key)); platform_->RunUntilIdle(); - EXPECT_EQ(0, key.number()); + EXPECT_EQ(0, key->Number()); // IDBCursor.advance(1) cursor_->Advance(1, new MockContinueCallbacks(&key)); platform_->RunUntilIdle(); - EXPECT_EQ(1, key.number()); + EXPECT_EQ(1, key->Number()); // IDBCursor.continue() - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks(&key)); platform_->RunUntilIdle(); - EXPECT_EQ(2, key.number()); + EXPECT_EQ(2, key->Number()); // IDBCursor.advance(2) cursor_->Advance(2, new MockContinueCallbacks(&key)); platform_->RunUntilIdle(); - EXPECT_EQ(4, key.number()); + EXPECT_EQ(4, key->Number()); EXPECT_EQ(0, mock_cursor_->advance_calls()); @@ -296,7 +305,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { int continue_calls = 0; EXPECT_EQ(mock_cursor_->continue_calls(), 0); for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); platform_->RunUntilIdle(); EXPECT_EQ(++continue_calls, mock_cursor_->continue_calls()); @@ -304,7 +313,7 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { } // Initiate the prefetch - cursor_->CursorContinue(null_key_.View(), null_key_.View(), + cursor_->CursorContinue(null_key_.get(), null_key_.get(), new MockContinueCallbacks()); platform_->RunUntilIdle(); EXPECT_EQ(continue_calls, mock_cursor_->continue_calls()); @@ -320,11 +329,13 @@ TEST_F(WebIDBCursorImplTest, PrefetchReset) { // Fill the prefetch cache as requested. int prefetch_count = mock_cursor_->last_prefetch_count(); - 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>()); + Vector<std::unique_ptr<IDBKey>> keys(prefetch_count); + Vector<std::unique_ptr<IDBKey>> primary_keys(prefetch_count); + Vector<std::unique_ptr<IDBValue>> values; + for (int i = 0; i < prefetch_count; ++i) { + values.emplace_back( + IDBValue::Create(scoped_refptr<SharedBuffer>(), Vector<WebBlobInfo>())); + } cursor_->SetPrefetchData(std::move(keys), std::move(primary_keys), std::move(values)); diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database.h index c98ae6098ff..f2b70896ae3 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database.h @@ -30,18 +30,14 @@ #include "third_party/blink/public/common/indexeddb/web_idb_types.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.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; +class IDBKeyRange; class WebIDBCallbacks; -class WebIDBKeyPath; -class WebIDBKeyRange; class MODULES_EXPORT WebIDBDatabase { public: @@ -50,7 +46,7 @@ class MODULES_EXPORT WebIDBDatabase { virtual void CreateObjectStore(long long transaction_id, long long object_store_id, const String& name, - const WebIDBKeyPath&, + const IDBKeyPath&, bool auto_increment) = 0; virtual void DeleteObjectStore(long long transaction_id, long long object_store_id) = 0; @@ -64,13 +60,14 @@ class MODULES_EXPORT WebIDBDatabase { virtual void VersionChangeIgnored() = 0; virtual void Abort(long long transaction_id) = 0; - virtual void Commit(long long transaction_id) = 0; + virtual void Commit(long long transaction_id, + long long num_errors_handled) = 0; virtual void CreateIndex(long long transaction_id, long long object_store_id, long long index_id, const String& name, - const WebIDBKeyPath&, + const IDBKeyPath&, bool unique, bool multi_entry) = 0; virtual void DeleteIndex(long long transaction_id, @@ -95,35 +92,34 @@ class MODULES_EXPORT WebIDBDatabase { virtual void Get(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, bool key_only, WebIDBCallbacks*) = 0; virtual void GetAll(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, long long max_count, bool key_only, WebIDBCallbacks*) = 0; virtual void Put(long long transaction_id, long long object_store_id, - const WebData& value, - const Vector<WebBlobInfo>&, - WebIDBKeyView primary_key, + std::unique_ptr<IDBValue> value, + std::unique_ptr<IDBKey> primary_key, mojom::IDBPutMode, WebIDBCallbacks*, - const Vector<WebIDBIndexKeys>&) = 0; + Vector<IDBIndexKeys>) = 0; virtual void SetIndexKeys(long long transaction_id, long long object_store_id, - WebIDBKeyView primary_key, - const Vector<WebIDBIndexKeys>&) = 0; + std::unique_ptr<IDBKey> primary_key, + Vector<IDBIndexKeys>) = 0; virtual void SetIndexesReady(long long transaction_id, long long object_store_id, const Vector<int64_t>& index_ids) = 0; virtual void OpenCursor(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, mojom::IDBCursorDirection, bool key_only, mojom::IDBTaskType, @@ -131,15 +127,15 @@ class MODULES_EXPORT WebIDBDatabase { virtual void Count(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange&, + const IDBKeyRange*, WebIDBCallbacks*) = 0; virtual void Delete(long long transaction_id, long long object_store_id, - WebIDBKeyView primary_key, + const IDBKey* primary_key, WebIDBCallbacks*) = 0; virtual void DeleteRange(long long transaction_id, long long object_store_id, - const WebIDBKeyRange&, + const IDBKeyRange*, WebIDBCallbacks*) = 0; virtual void Clear(long long transaction_id, long long object_store_id, diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h new file mode 100644 index 00000000000..88a5513961c --- /dev/null +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_CALLBACKS_H_ +#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_CALLBACKS_H_ + +#include <unordered_map> +#include <utility> +#include <vector> + +#include "third_party/blink/renderer/modules/indexeddb/idb_database_error.h" +#include "third_party/blink/renderer/modules/modules_export.h" +#include "third_party/blink/renderer/platform/heap/persistent.h" + +namespace blink { + +class IDBObservation; + +class WebIDBDatabaseCallbacks { + public: + using ObservationIndexMap = std::unordered_map<int32_t, Vector<int32_t>>; + + // Maps observer to transaction, which needs an id and a scope. + using TransactionMap = + std::unordered_map<int32_t, std::pair<int64_t, Vector<int64_t>>>; + + virtual ~WebIDBDatabaseCallbacks() = default; + + virtual void OnForcedClose() = 0; + virtual void OnVersionChange(long long old_version, + long long new_version) = 0; + + virtual void OnAbort(long long transaction_id, const IDBDatabaseError&) = 0; + virtual void OnComplete(long long transaction_id) = 0; + virtual void OnChanges(const ObservationIndexMap&, + Vector<Persistent<IDBObservation>> observations, + const TransactionMap& transactions) = 0; + virtual void Detach() = 0; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_DATABASE_CALLBACKS_H_ diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.cc index fc7c46b8722..ec213953425 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.cc @@ -29,12 +29,8 @@ #include "base/memory/ptr_util.h" #include "third_party/blink/renderer/core/dom/dom_exception.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/public/platform/web_vector.h" -#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_database_error.h" #include "third_party/blink/renderer/modules/indexeddb/idb_key_range.h" #include "third_party/blink/renderer/modules/indexeddb/idb_observation.h" #include "third_party/blink/renderer/modules/indexeddb/idb_value.h" @@ -68,7 +64,7 @@ void WebIDBDatabaseCallbacksImpl::OnVersionChange(long long old_version, } void WebIDBDatabaseCallbacksImpl::OnAbort(long long transaction_id, - const WebIDBDatabaseError& error) { + const IDBDatabaseError& error) { if (callbacks_) { callbacks_->OnAbort( transaction_id, @@ -84,7 +80,7 @@ void WebIDBDatabaseCallbacksImpl::OnComplete(long long transaction_id) { void WebIDBDatabaseCallbacksImpl::OnChanges( const ObservationIndexMap& observation_index_map, - WebVector<WebIDBObservation> observations, + Vector<Persistent<IDBObservation>> observations, const TransactionMap& transactions) { if (callbacks_) { callbacks_->OnChanges(observation_index_map, std::move(observations), diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h index 0bd37944e50..e4cd614c2cc 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks_impl.h @@ -28,12 +28,8 @@ #include <memory> -#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/public/platform/web_string.h" -#include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/renderer/modules/indexeddb/idb_database_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/wtf/allocator.h" @@ -50,10 +46,10 @@ class WebIDBDatabaseCallbacksImpl final : public WebIDBDatabaseCallbacks { void OnForcedClose() override; void OnVersionChange(long long old_version, long long new_version) override; - void OnAbort(long long transaction_id, const WebIDBDatabaseError&) override; + void OnAbort(long long transaction_id, const IDBDatabaseError&) override; void OnComplete(long long transaction_id) override; void OnChanges(const ObservationIndexMap&, - WebVector<WebIDBObservation> observations, + Vector<Persistent<IDBObservation>> observations, const TransactionMap& transactions) override; void Detach() override; diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc index c41c23e249f..c8f5339954e 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.cc @@ -4,40 +4,30 @@ #include "third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h" -#include <stddef.h> - -#include <string> -#include <vector> - #include "base/format_macros.h" -#include "base/memory/ptr_util.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" -#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_string.h" -#include "third_party/blink/public/platform/web_vector.h" +#include "third_party/blink/renderer/modules/indexeddb/idb_database_error.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_blink_mojom_traits.h" #include "third_party/blink/renderer/modules/indexeddb/indexed_db_dispatcher.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { WebIDBDatabaseImpl::WebIDBDatabaseImpl( - mojom::blink::IDBDatabaseAssociatedPtrInfo database_info) - : database_(std::move(database_info)) {} + mojom::blink::IDBDatabaseAssociatedPtrInfo database_info, + scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : task_runner_(std::move(task_runner)) { + database_.Bind(std::move(database_info), task_runner_); +} WebIDBDatabaseImpl::~WebIDBDatabaseImpl() = default; void WebIDBDatabaseImpl::CreateObjectStore(long long transaction_id, long long object_store_id, const String& name, - const WebIDBKeyPath& key_path, + const IDBKeyPath& key_path, bool auto_increment) { database_->CreateObjectStore(transaction_id, object_store_id, name, key_path, auto_increment); @@ -90,116 +80,76 @@ void WebIDBDatabaseImpl::RemoveObservers(const Vector<int32_t>& observer_ids) { void WebIDBDatabaseImpl::Get(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange& key_range, + const IDBKeyRange* key_range, bool key_only, WebIDBCallbacks* callbacks) { 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, key_range, key_only, - GetCallbacksProxy(std::move(callbacks_impl))); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(key_range); + callbacks->SetState(nullptr, transaction_id); + database_->Get(transaction_id, object_store_id, index_id, + std::move(key_range_ptr), key_only, + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::GetAll(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange& key_range, + const IDBKeyRange* key_range, long long max_count, bool key_only, WebIDBCallbacks* callbacks) { 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, key_range, - key_only, max_count, - GetCallbacksProxy(std::move(callbacks_impl))); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(key_range); + callbacks->SetState(nullptr, transaction_id); + database_->GetAll(transaction_id, object_store_id, index_id, + std::move(key_range_ptr), key_only, max_count, + GetCallbacksProxy(base::WrapUnique(callbacks))); } 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, + std::unique_ptr<IDBValue> value, + std::unique_ptr<IDBKey> primary_key, mojom::IDBPutMode put_mode, WebIDBCallbacks* callbacks, - const Vector<WebIDBIndexKeys>& index_keys) { - WebIDBKey primary_key = WebIDBKeyBuilder::Build(web_primary_key); - + Vector<IDBIndexKeys> index_keys) { IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); - 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.AppendRange(segment_span.begin(), segment_span.end()); - return true; - }); - - // mojo_value->blob_or_file_info initialization. - mojo_value->blob_or_file_info.ReserveInitialCapacity(web_blob_info.size()); - for (const WebBlobInfo& info : web_blob_info) { - auto blob_info = mojom::blink::IDBBlobInfo::New(); - if (info.IsFile()) { - 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(); - 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)); - } - 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.SizeEstimate(); + index_keys_size += key->SizeEstimate(); } } size_t arg_size = - mojo_value->bits.size() + primary_key.SizeEstimate() + index_keys_size; + value->DataSize() + primary_key->SizeEstimate() + index_keys_size; if (arg_size >= max_put_value_size_) { - callbacks->OnError(blink::WebIDBDatabaseError( + callbacks->Error( blink::kWebIDBDatabaseExceptionUnknownError, - WebString( - String::Format("The serialized keys and/or value are too large" - " (size=%" PRIuS " bytes, max=%" PRIuS " bytes).", - arg_size, max_put_value_size_)))); + 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), - std::move(primary_key), put_mode, index_keys, - GetCallbacksProxy(std::move(callbacks_impl))); + callbacks->SetState(nullptr, transaction_id); + database_->Put(transaction_id, object_store_id, std::move(value), + std::move(primary_key), put_mode, std::move(index_keys), + GetCallbacksProxy(base::WrapUnique(callbacks))); } -void WebIDBDatabaseImpl::SetIndexKeys( - long long transaction_id, - long long object_store_id, - WebIDBKeyView primary_key, - const Vector<WebIDBIndexKeys>& index_keys) { - IndexedDBKey temp(IndexedDBKeyBuilder::Build(primary_key)); +void WebIDBDatabaseImpl::SetIndexKeys(long long transaction_id, + long long object_store_id, + std::unique_ptr<IDBKey> primary_key, + Vector<IDBIndexKeys> index_keys) { database_->SetIndexKeys(transaction_id, object_store_id, - WebIDBKeyBuilder::Build(temp), std::move(index_keys)); + std::move(primary_key), std::move(index_keys)); } void WebIDBDatabaseImpl::SetIndexesReady(long long transaction_id, @@ -212,56 +162,63 @@ void WebIDBDatabaseImpl::SetIndexesReady(long long transaction_id, void WebIDBDatabaseImpl::OpenCursor(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange& key_range, + const IDBKeyRange* key_range, mojom::IDBCursorDirection direction, bool key_only, mojom::IDBTaskType task_type, WebIDBCallbacks* callbacks) { 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, key_range, - direction, key_only, task_type, - GetCallbacksProxy(std::move(callbacks_impl))); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(key_range); + callbacks->SetState(nullptr, transaction_id); + database_->OpenCursor(transaction_id, object_store_id, index_id, + std::move(key_range_ptr), direction, key_only, + task_type, + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::Count(long long transaction_id, long long object_store_id, long long index_id, - const WebIDBKeyRange& key_range, + const IDBKeyRange* key_range, WebIDBCallbacks* callbacks) { 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, key_range, - GetCallbacksProxy(std::move(callbacks_impl))); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(key_range); + callbacks->SetState(nullptr, transaction_id); + database_->Count(transaction_id, object_store_id, index_id, + std::move(key_range_ptr), + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::Delete(long long transaction_id, long long object_store_id, - WebIDBKeyView primary_key, + const IDBKey* primary_key, WebIDBCallbacks* callbacks) { IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), transaction_id, nullptr); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(IDBKeyRange::Create(primary_key)); + callbacks->SetState(nullptr, transaction_id); database_->DeleteRange(transaction_id, object_store_id, - WebIDBKeyRangeBuilder::Build(primary_key), - GetCallbacksProxy(std::move(callbacks_impl))); + std::move(key_range_ptr), + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::DeleteRange(long long transaction_id, long long object_store_id, - const WebIDBKeyRange& key_range, + const IDBKeyRange* key_range, WebIDBCallbacks* callbacks) { 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, key_range, - GetCallbacksProxy(std::move(callbacks_impl))); + mojom::blink::IDBKeyRangePtr key_range_ptr = + mojom::blink::IDBKeyRange::From(key_range); + callbacks->SetState(nullptr, transaction_id); + database_->DeleteRange(transaction_id, object_store_id, + std::move(key_range_ptr), + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::Clear(long long transaction_id, @@ -269,17 +226,16 @@ void WebIDBDatabaseImpl::Clear(long long transaction_id, WebIDBCallbacks* callbacks) { IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), transaction_id, nullptr); + callbacks->SetState(nullptr, transaction_id); database_->Clear(transaction_id, object_store_id, - GetCallbacksProxy(std::move(callbacks_impl))); + GetCallbacksProxy(base::WrapUnique(callbacks))); } void WebIDBDatabaseImpl::CreateIndex(long long transaction_id, long long object_store_id, long long index_id, const String& name, - const WebIDBKeyPath& key_path, + const IDBKeyPath& key_path, bool unique, bool multi_entry) { database_->CreateIndex(transaction_id, object_store_id, index_id, name, @@ -304,16 +260,18 @@ void WebIDBDatabaseImpl::Abort(long long transaction_id) { database_->Abort(transaction_id); } -void WebIDBDatabaseImpl::Commit(long long transaction_id) { - database_->Commit(transaction_id); +void WebIDBDatabaseImpl::Commit(long long transaction_id, + long long num_errors_handled) { + database_->Commit(transaction_id, num_errors_handled); } mojom::blink::IDBCallbacksAssociatedPtrInfo WebIDBDatabaseImpl::GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { + std::unique_ptr<WebIDBCallbacks> callbacks) { mojom::blink::IDBCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); - mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); + mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request), + task_runner_); return ptr_info; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h index b4df30eb822..a69c90e0951 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl.h @@ -17,20 +17,19 @@ #include "third_party/blink/renderer/modules/modules_export.h" namespace blink { -class IndexedDBCallbacksImpl; -class WebBlobInfo; class WebIDBCallbacks; -class MODULES_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { +class MODULES_EXPORT WebIDBDatabaseImpl : public WebIDBDatabase { public: - WebIDBDatabaseImpl(mojom::blink::IDBDatabaseAssociatedPtrInfo database); + WebIDBDatabaseImpl(mojom::blink::IDBDatabaseAssociatedPtrInfo database, + scoped_refptr<base::SingleThreadTaskRunner> task_runner); ~WebIDBDatabaseImpl() override; - // blink::WebIDBDatabase + // WebIDBDatabase void CreateObjectStore(long long transaction_id, long long objectstore_id, const String& name, - const blink::WebIDBKeyPath&, + const IDBKeyPath&, bool auto_increment) override; void DeleteObjectStore(long long transaction_id, long long object_store_id) override; @@ -50,66 +49,65 @@ class MODULES_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { bool include_transaction, bool no_records, bool values, - std::bitset<blink::kIDBOperationTypeCount> operation_types) override; + std::bitset<kIDBOperationTypeCount> operation_types) override; void RemoveObservers(const Vector<int32_t>& observer_ids) override; void Get(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebIDBKeyRange&, + const IDBKeyRange*, bool key_only, - blink::WebIDBCallbacks*) override; + WebIDBCallbacks*) override; void GetAll(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebIDBKeyRange&, + const IDBKeyRange*, long long max_count, bool key_only, - blink::WebIDBCallbacks*) override; + WebIDBCallbacks*) override; void Put(long long transaction_id, long long object_store_id, - const blink::WebData& value, - const Vector<blink::WebBlobInfo>&, - blink::WebIDBKeyView primary_key, + std::unique_ptr<IDBValue> value, + std::unique_ptr<IDBKey> primary_key, mojom::IDBPutMode, - blink::WebIDBCallbacks*, - const Vector<blink::WebIDBIndexKeys>&) override; + WebIDBCallbacks*, + Vector<IDBIndexKeys>) override; void SetIndexKeys(long long transaction_id, long long object_store_id, - blink::WebIDBKeyView primary_key, - const Vector<blink::WebIDBIndexKeys>&) override; + std::unique_ptr<IDBKey> primary_key, + Vector<IDBIndexKeys>) override; void SetIndexesReady(long long transaction_id, long long object_store_id, const Vector<int64_t>& index_ids) override; void OpenCursor(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebIDBKeyRange&, + const IDBKeyRange*, mojom::IDBCursorDirection direction, bool key_only, mojom::IDBTaskType, - blink::WebIDBCallbacks*) override; + WebIDBCallbacks*) override; void Count(long long transaction_id, long long object_store_id, long long index_id, - const blink::WebIDBKeyRange&, - blink::WebIDBCallbacks*) override; + const IDBKeyRange*, + WebIDBCallbacks*) override; void Delete(long long transaction_id, long long object_store_id, - blink::WebIDBKeyView primary_key, - blink::WebIDBCallbacks*) override; + const IDBKey* primary_key, + WebIDBCallbacks*) override; void DeleteRange(long long transaction_id, long long object_store_id, - const blink::WebIDBKeyRange&, - blink::WebIDBCallbacks*) override; + const IDBKeyRange*, + WebIDBCallbacks*) override; void Clear(long long transaction_id, long long object_store_id, - blink::WebIDBCallbacks*) override; + WebIDBCallbacks*) override; void CreateIndex(long long transaction_id, long long object_store_id, long long index_id, const String& name, - const blink::WebIDBKeyPath&, + const IDBKeyPath&, bool unique, bool multi_entry) override; void DeleteIndex(long long transaction_id, @@ -120,11 +118,11 @@ class MODULES_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { long long index_id, const String& new_name) override; void Abort(long long transaction_id) override; - void Commit(long long transaction_id) override; + void Commit(long long transaction_id, long long num_errors_handled) override; private: mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks); + std::unique_ptr<WebIDBCallbacks> callbacks); FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, ValueSizeTest); FRIEND_TEST_ALL_PREFIXES(WebIDBDatabaseImplTest, KeyAndValueSizeTest); @@ -138,6 +136,7 @@ class MODULES_EXPORT WebIDBDatabaseImpl : public blink::WebIDBDatabase { std::set<int32_t> observer_ids_; mojom::blink::IDBDatabaseAssociatedPtr database_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc index 42f434233c4..4b27268cf51 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_database_impl_unittest.cc @@ -9,10 +9,8 @@ #include "base/macros.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" @@ -33,22 +31,25 @@ TEST_F(WebIDBDatabaseImplTest, ValueSizeTest) { const size_t kMaxValueSizeForTesting = 10 * 1024 * 1024; // 10 MB const std::vector<char> data(kMaxValueSizeForTesting + 1); - const WebData value(&data.front(), data.size()); + const scoped_refptr<SharedBuffer> value_data = + SharedBuffer::Create(&data.front(), data.size()); const Vector<WebBlobInfo> blob_info; - const WebIDBKey key = WebIDBKey::CreateNumber(0); + std::unique_ptr<IDBValue> value = IDBValue::Create(value_data, blob_info); + std::unique_ptr<IDBKey> key = IDBKey::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); + ASSERT_GT(value_data->size() + key->SizeEstimate(), kMaxValueSizeForTesting); ThreadState::Current()->CollectAllGarbage(); - EXPECT_CALL(callbacks, OnError(_)).Times(1); + EXPECT_CALL(callbacks, Error(_, _)).Times(1); - WebIDBDatabaseImpl database_impl(nullptr); + WebIDBDatabaseImpl database_impl( + nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting()); database_impl.max_put_value_size_ = kMaxValueSizeForTesting; - database_impl.Put(transaction_id, object_store_id, value, blob_info, - key.View(), mojom::IDBPutMode::AddOrUpdate, &callbacks, - Vector<blink::WebIDBIndexKeys>()); + database_impl.Put(transaction_id, object_store_id, std::move(value), + std::move(key), mojom::IDBPutMode::AddOrUpdate, &callbacks, + Vector<IDBIndexKeys>()); } TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { @@ -58,8 +59,10 @@ TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { const size_t kKeySize = 1024 * 1024; const std::vector<char> data(kMaxValueSizeForTesting - kKeySize); - const WebData value(&data.front(), data.size()); + const scoped_refptr<SharedBuffer> value_data = + SharedBuffer::Create(&data.front(), data.size()); const Vector<WebBlobInfo> blob_info; + std::unique_ptr<IDBValue> value = IDBValue::Create(value_data, blob_info); const int64_t transaction_id = 1; const int64_t object_store_id = 2; StrictMock<MockWebIDBCallbacks> callbacks; @@ -75,19 +78,20 @@ TEST_F(WebIDBDatabaseImplTest, KeyAndValueSizeTest) { 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); + std::unique_ptr<IDBKey> key = IDBKey::CreateString(key_string); + DCHECK_EQ(value_data->size(), kMaxValueSizeForTesting - kKeySize); + DCHECK_GT(key->SizeEstimate() - kKeySize, static_cast<unsigned long>(0)); + DCHECK_GT(value_data->size() + key->SizeEstimate(), kMaxValueSizeForTesting); ThreadState::Current()->CollectAllGarbage(); - EXPECT_CALL(callbacks, OnError(_)).Times(1); + EXPECT_CALL(callbacks, Error(_, _)).Times(1); - WebIDBDatabaseImpl database_impl(nullptr); + WebIDBDatabaseImpl database_impl( + nullptr, blink::scheduler::GetSingleThreadTaskRunnerForTesting()); database_impl.max_put_value_size_ = kMaxValueSizeForTesting; - database_impl.Put(transaction_id, object_store_id, value, blob_info, - key.View(), mojom::IDBPutMode::AddOrUpdate, &callbacks, - Vector<blink::WebIDBIndexKeys>()); + database_impl.Put(transaction_id, object_store_id, std::move(value), + std::move(key), mojom::IDBPutMode::AddOrUpdate, &callbacks, + Vector<IDBIndexKeys>()); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h index 71a2ce00a59..a18d051aaca 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory.h @@ -29,43 +29,31 @@ #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/renderer/modules/modules_export.h" -namespace base { -class SingleThreadTaskRunner; +namespace WTF { +class String; } namespace blink { class WebIDBCallbacks; class WebIDBDatabaseCallbacks; -class WebSecurityOrigin; -class WebString; class MODULES_EXPORT WebIDBFactory { public: virtual ~WebIDBFactory() = default; - virtual void GetDatabaseInfo(WebIDBCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>) = 0; - virtual void GetDatabaseNames( - WebIDBCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>) = 0; - virtual void Open(const WebString& name, + virtual void GetDatabaseInfo(std::unique_ptr<WebIDBCallbacks>) = 0; + virtual void GetDatabaseNames(std::unique_ptr<WebIDBCallbacks>) = 0; + virtual void Open(const WTF::String& name, long long version, long long transaction_id, - WebIDBCallbacks*, - WebIDBDatabaseCallbacks*, - const WebSecurityOrigin&, - scoped_refptr<base::SingleThreadTaskRunner>) = 0; - virtual void DeleteDatabase(const WebString& name, - WebIDBCallbacks*, - const WebSecurityOrigin&, - bool force_close, - scoped_refptr<base::SingleThreadTaskRunner>) = 0; + std::unique_ptr<WebIDBCallbacks>, + std::unique_ptr<WebIDBDatabaseCallbacks>) = 0; + virtual void DeleteDatabase(const WTF::String& name, + std::unique_ptr<WebIDBCallbacks>, + bool force_close) = 0; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc index f158e08cd10..ebf933214e6 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.cc @@ -6,80 +6,66 @@ #include "base/memory/ptr_util.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" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_callbacks_impl.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { WebIDBFactoryImpl::WebIDBFactoryImpl( - mojom::blink::IDBFactoryPtrInfo factory_info) - : factory_(std::move(factory_info)) {} + mojom::blink::IDBFactoryPtrInfo factory_info, + scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : task_runner_(std::move(task_runner)) { + factory_.Bind(std::move(factory_info), task_runner_); +} WebIDBFactoryImpl::~WebIDBFactoryImpl() = default; void WebIDBFactoryImpl::GetDatabaseInfo( - WebIDBCallbacks* callbacks, - const WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, - nullptr); - factory_->GetDatabaseInfo(GetCallbacksProxy(std::move(callbacks_impl)), - origin); + std::unique_ptr<WebIDBCallbacks> callbacks) { + callbacks->SetState(nullptr, WebIDBCallbacksImpl::kNoTransaction); + factory_->GetDatabaseInfo(GetCallbacksProxy(std::move(callbacks))); } void WebIDBFactoryImpl::GetDatabaseNames( - WebIDBCallbacks* callbacks, - const WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, - nullptr); - factory_->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks_impl)), - origin); + std::unique_ptr<WebIDBCallbacks> callbacks) { + callbacks->SetState(nullptr, WebIDBCallbacksImpl::kNoTransaction); + factory_->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks))); } void WebIDBFactoryImpl::Open( - const WebString& name, + const String& name, long long version, long long transaction_id, - WebIDBCallbacks* callbacks, - WebIDBDatabaseCallbacks* database_callbacks, - const WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), transaction_id, nullptr); + std::unique_ptr<WebIDBCallbacks> callbacks, + std::unique_ptr<WebIDBDatabaseCallbacks> database_callbacks) { + callbacks->SetState(nullptr, WebIDBCallbacksImpl::kNoTransaction); auto database_callbacks_impl = std::make_unique<IndexedDBDatabaseCallbacksImpl>( - base::WrapUnique(database_callbacks)); + std::move(database_callbacks)); DCHECK(!name.IsNull()); - factory_->Open(GetCallbacksProxy(std::move(callbacks_impl)), + factory_->Open(GetCallbacksProxy(std::move(callbacks)), GetDatabaseCallbacksProxy(std::move(database_callbacks_impl)), - origin, name, version, transaction_id); + name, version, transaction_id); } void WebIDBFactoryImpl::DeleteDatabase( - const WebString& name, - WebIDBCallbacks* callbacks, - const WebSecurityOrigin& origin, - bool force_close, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - auto callbacks_impl = std::make_unique<IndexedDBCallbacksImpl>( - base::WrapUnique(callbacks), IndexedDBCallbacksImpl::kNoTransaction, - nullptr); + const String& name, + std::unique_ptr<WebIDBCallbacks> callbacks, + bool force_close) { + callbacks->SetState(nullptr, WebIDBCallbacksImpl::kNoTransaction); DCHECK(!name.IsNull()); - factory_->DeleteDatabase(GetCallbacksProxy(std::move(callbacks_impl)), origin, - name, force_close); + factory_->DeleteDatabase(GetCallbacksProxy(std::move(callbacks)), name, + force_close); } mojom::blink::IDBCallbacksAssociatedPtrInfo WebIDBFactoryImpl::GetCallbacksProxy( - std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { + std::unique_ptr<WebIDBCallbacks> callbacks) { mojom::blink::IDBCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); - mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); + mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request), + task_runner_); return ptr_info; } @@ -88,7 +74,8 @@ WebIDBFactoryImpl::GetDatabaseCallbacksProxy( std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) { mojom::blink::IDBDatabaseCallbacksAssociatedPtrInfo ptr_info; auto request = mojo::MakeRequest(&ptr_info); - mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); + mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request), + task_runner_); return ptr_info; } diff --git a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h index dbc69d838e3..692d92013b7 100644 --- a/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h +++ b/chromium/third_party/blink/renderer/modules/indexeddb/web_idb_factory_impl.h @@ -6,52 +6,46 @@ #define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_WEB_IDB_FACTORY_IMPL_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/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_callbacks.h" +#include "third_party/blink/renderer/modules/indexeddb/web_idb_database_callbacks.h" #include "third_party/blink/renderer/modules/indexeddb/web_idb_factory.h" +namespace WTF { +class String; +} + namespace blink { -class WebSecurityOrigin; -class WebString; -class WebIDBFactoryImpl : public blink::WebIDBFactory { +class WebIDBFactoryImpl : public WebIDBFactory { public: - explicit WebIDBFactoryImpl(mojom::blink::IDBFactoryPtrInfo factory_info); + explicit WebIDBFactoryImpl( + mojom::blink::IDBFactoryPtrInfo factory_info, + scoped_refptr<base::SingleThreadTaskRunner> task_runner); ~WebIDBFactoryImpl() override; - // See WebIDBFactory.h for documentation on these functions. - void GetDatabaseInfo( - blink::WebIDBCallbacks* callbacks, - const blink::WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void GetDatabaseNames( - blink::WebIDBCallbacks* callbacks, - const blink::WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void Open(const blink::WebString& name, - long long version, - long long transaction_id, - blink::WebIDBCallbacks* callbacks, - blink::WebIDBDatabaseCallbacks* databaseCallbacks, - const blink::WebSecurityOrigin& origin, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void DeleteDatabase( - const blink::WebString& name, - blink::WebIDBCallbacks* callbacks, - const blink::WebSecurityOrigin& origin, - bool force_close, - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; + // See web_idb_factory.h for documentation on these functions. + void GetDatabaseInfo(std::unique_ptr<WebIDBCallbacks> callbacks) override; + void GetDatabaseNames(std::unique_ptr<WebIDBCallbacks> callbacks) override; + void Open( + const WTF::String& name, + long long version, + long long transaction_id, + std::unique_ptr<WebIDBCallbacks> callbacks, + std::unique_ptr<WebIDBDatabaseCallbacks> database_callbacks) override; + void DeleteDatabase(const WTF::String& name, + std::unique_ptr<WebIDBCallbacks> callbacks, + bool force_close) override; private: mojom::blink::IDBCallbacksAssociatedPtrInfo GetCallbacksProxy( - std::unique_ptr<blink::IndexedDBCallbacksImpl> callbacks); + std::unique_ptr<WebIDBCallbacks> callbacks); mojom::blink::IDBDatabaseCallbacksAssociatedPtrInfo GetDatabaseCallbacksProxy( - std::unique_ptr<blink::IndexedDBDatabaseCallbacksImpl> callbacks); + std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks); mojom::blink::IDBFactoryPtr factory_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; }; } // namespace blink |