| Index: content/browser/indexed_db/indexed_db_database.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc
|
| index 998c5cfdd6313378c59f4a882b1de5c3452bc5f7..7138507054e217ffac97fea028dbefaa3d831570 100644
|
| --- a/content/browser/indexed_db/indexed_db_database.cc
|
| +++ b/content/browser/indexed_db/indexed_db_database.cc
|
| @@ -31,7 +31,9 @@
|
| #include "content/browser/indexed_db/indexed_db_index_writer.h"
|
| #include "content/browser/indexed_db/indexed_db_observation.h"
|
| #include "content/browser/indexed_db/indexed_db_observer_changes.h"
|
| +#include "content/browser/indexed_db/indexed_db_open_request_observer.h"
|
| #include "content/browser/indexed_db/indexed_db_pending_connection.h"
|
| +#include "content/browser/indexed_db/indexed_db_pending_delete.h"
|
| #include "content/browser/indexed_db/indexed_db_return_value.h"
|
| #include "content/browser/indexed_db/indexed_db_tracing.h"
|
| #include "content/browser/indexed_db/indexed_db_transaction.h"
|
| @@ -127,15 +129,15 @@ class IndexedDBDatabase::OpenRequest
|
| if (!db_->OpenInternal().ok()) {
|
| // TODO(jsbell): Consider including sanitized leveldb status message.
|
| base::string16 message;
|
| - if (pending_->version == IndexedDBDatabaseMetadata::NO_VERSION) {
|
| + if (pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION) {
|
| message = ASCIIToUTF16(
|
| "Internal error opening database with no version specified.");
|
| } else {
|
| message =
|
| ASCIIToUTF16("Internal error opening database with version ") +
|
| - Int64ToString16(pending_->version);
|
| + Int64ToString16(pending_->version());
|
| }
|
| - pending_->callbacks->OnError(IndexedDBDatabaseError(
|
| + pending_->OnError(IndexedDBDatabaseError(
|
| blink::WebIDBDatabaseExceptionUnknownError, message));
|
| db_->RequestComplete(this);
|
| return;
|
| @@ -145,45 +147,42 @@ class IndexedDBDatabase::OpenRequest
|
| }
|
|
|
| const int64_t old_version = db_->metadata_.version;
|
| - int64_t& new_version = pending_->version;
|
|
|
| bool is_new_database = old_version == IndexedDBDatabaseMetadata::NO_VERSION;
|
|
|
| - if (new_version == IndexedDBDatabaseMetadata::DEFAULT_VERSION) {
|
| + if (pending_->version() == IndexedDBDatabaseMetadata::DEFAULT_VERSION) {
|
| // For unit tests only - skip upgrade steps. (Calling from script with
|
| // DEFAULT_VERSION throws exception.)
|
| DCHECK(is_new_database);
|
| - pending_->callbacks->OnSuccess(
|
| - db_->CreateConnection(pending_->database_callbacks,
|
| - pending_->child_process_id),
|
| - db_->metadata_);
|
| + pending_->OnSuccess(db_->CreateConnection(pending_->change_handler(),
|
| + pending_->child_process_id()),
|
| + db_->metadata_);
|
| db_->RequestComplete(this);
|
| return;
|
| }
|
|
|
| if (!is_new_database &&
|
| - (new_version == old_version ||
|
| - new_version == IndexedDBDatabaseMetadata::NO_VERSION)) {
|
| - pending_->callbacks->OnSuccess(
|
| - db_->CreateConnection(pending_->database_callbacks,
|
| - pending_->child_process_id),
|
| - db_->metadata_);
|
| + (pending_->version() == old_version ||
|
| + pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION)) {
|
| + pending_->OnSuccess(db_->CreateConnection(pending_->change_handler(),
|
| + pending_->child_process_id()),
|
| + db_->metadata_);
|
| db_->RequestComplete(this);
|
| return;
|
| }
|
|
|
| - if (new_version == IndexedDBDatabaseMetadata::NO_VERSION) {
|
| + if (pending_->version() == IndexedDBDatabaseMetadata::NO_VERSION) {
|
| // If no version is specified and no database exists, upgrade the
|
| // database version to 1.
|
| DCHECK(is_new_database);
|
| - new_version = 1;
|
| - } else if (new_version < old_version) {
|
| + pending_->set_version(1);
|
| + } else if (pending_->version() < old_version) {
|
| // Requested version is lower than current version - fail the request.
|
| DCHECK(!is_new_database);
|
| - pending_->callbacks->OnError(IndexedDBDatabaseError(
|
| + pending_->OnError(IndexedDBDatabaseError(
|
| blink::WebIDBDatabaseExceptionVersionError,
|
| ASCIIToUTF16("The requested version (") +
|
| - Int64ToString16(pending_->version) +
|
| + Int64ToString16(pending_->version()) +
|
| ASCIIToUTF16(") is less than the existing version (") +
|
| Int64ToString16(db_->metadata_.version) + ASCIIToUTF16(").")));
|
| db_->RequestComplete(this);
|
| @@ -191,7 +190,7 @@ class IndexedDBDatabase::OpenRequest
|
| }
|
|
|
| // Requested version is higher than current version - upgrade needed.
|
| - DCHECK_GT(new_version, old_version);
|
| + DCHECK_GT(pending_->version(), old_version);
|
|
|
| if (db_->connections_.empty()) {
|
| StartUpgrade();
|
| @@ -203,21 +202,23 @@ class IndexedDBDatabase::OpenRequest
|
| // fired at connections that have close_pending set. A "blocked" event
|
| // will be fired at the request when one of the connections acks that the
|
| // "versionchange" event was ignored.
|
| - DCHECK_NE(pending_->data_loss_info.status, blink::WebIDBDataLossTotal);
|
| + DCHECK_NE(pending_->data_loss_info().status, blink::WebIDBDataLossTotal);
|
| for (const auto* connection : db_->connections_)
|
| - connection->callbacks()->OnVersionChange(old_version, new_version);
|
| + connection->change_handler()->OnVersionChange(old_version,
|
| + pending_->version());
|
|
|
| // When all connections have closed the upgrade can proceed.
|
| }
|
|
|
| void OnVersionChangeIgnored() const override {
|
| - pending_->callbacks->OnBlocked(db_->metadata_.version);
|
| + pending_->OnBlocked(db_->metadata_.version);
|
| }
|
|
|
| void OnConnectionClosed(IndexedDBConnection* connection) override {
|
| // This connection closed prematurely; signal an error and complete.
|
| - if (connection && connection->callbacks() == pending_->database_callbacks) {
|
| - pending_->callbacks->OnError(
|
| + if (connection &&
|
| + connection->change_handler() == pending_->change_handler()) {
|
| + pending_->OnError(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
|
| "The connection was closed."));
|
| db_->RequestComplete(this);
|
| @@ -234,40 +235,40 @@ class IndexedDBDatabase::OpenRequest
|
| // IndexedDBDatabase::VersionChangeOperation in order to kick the
|
| // transaction into the correct state.
|
| void StartUpgrade() {
|
| - connection_ = db_->CreateConnection(pending_->database_callbacks,
|
| - pending_->child_process_id);
|
| + connection_ = db_->CreateConnection(pending_->change_handler(),
|
| + pending_->child_process_id());
|
| DCHECK_EQ(db_->connections_.count(connection_.get()), 1UL);
|
|
|
| std::vector<int64_t> object_store_ids;
|
| IndexedDBTransaction* transaction = db_->CreateTransaction(
|
| - pending_->transaction_id, connection_.get(), object_store_ids,
|
| + pending_->transaction_id(), connection_.get(), object_store_ids,
|
| blink::WebIDBTransactionModeVersionChange);
|
|
|
| DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction());
|
| transaction->ScheduleTask(
|
| base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_,
|
| - pending_->version, pending_->callbacks));
|
| + base::Unretained(pending_.get())));
|
| }
|
|
|
| // Called when the upgrade transaction has started executing.
|
| void UpgradeTransactionStarted(int64_t old_version) override {
|
| DCHECK(connection_);
|
| - pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_),
|
| - db_->metadata_,
|
| - pending_->data_loss_info);
|
| + pending_->OnUpgradeNeeded(old_version, connection_.get(), db_->metadata_);
|
| }
|
|
|
| void UpgradeTransactionFinished(bool committed) override {
|
| // Ownership of connection was already passed along in OnUpgradeNeeded.
|
| - DCHECK(!connection_);
|
| + // Pending connection no longer moved in UpgradeTransactionStarted().
|
| + // DCHECK(!connection_);
|
|
|
| if (committed) {
|
| - DCHECK_EQ(pending_->version, db_->metadata_.version);
|
| - pending_->callbacks->OnSuccess(std::unique_ptr<IndexedDBConnection>(),
|
| - db_->metadata());
|
| + DCHECK_EQ(pending_->version(), db_->metadata_.version);
|
| + // TODO(cmumford): May still need to call RegisterTransactionId() because
|
| + // onupgradeneeded might not have been called.
|
| + pending_->OnSuccess(std::move(connection_), db_->metadata());
|
| } else {
|
| - DCHECK_NE(pending_->version, db_->metadata_.version);
|
| - pending_->callbacks->OnError(
|
| + DCHECK_NE(pending_->version(), db_->metadata_.version);
|
| + pending_->OnError(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
|
| "Version change transaction was aborted in "
|
| "upgradeneeded event handler."));
|
| @@ -289,8 +290,8 @@ class IndexedDBDatabase::DeleteRequest
|
| : public IndexedDBDatabase::ConnectionRequest {
|
| public:
|
| DeleteRequest(scoped_refptr<IndexedDBDatabase> db,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks)
|
| - : ConnectionRequest(db), callbacks_(callbacks) {}
|
| + std::unique_ptr<IndexedDBPendingDelete> pending_delete)
|
| + : ConnectionRequest(db), pending_delete_(std::move(pending_delete)) {}
|
|
|
| void Perform() override {
|
| if (db_->connections_.empty()) {
|
| @@ -304,11 +305,11 @@ class IndexedDBDatabase::DeleteRequest
|
| const int64_t old_version = db_->metadata_.version;
|
| const int64_t new_version = IndexedDBDatabaseMetadata::NO_VERSION;
|
| for (const auto* connection : db_->connections_)
|
| - connection->callbacks()->OnVersionChange(old_version, new_version);
|
| + connection->change_handler()->OnVersionChange(old_version, new_version);
|
| }
|
|
|
| void OnVersionChangeIgnored() const override {
|
| - callbacks_->OnBlocked(db_->metadata_.version);
|
| + pending_delete_->OnBlocked(db_->metadata_.version);
|
| }
|
|
|
| void OnConnectionClosed(IndexedDBConnection* connection) override {
|
| @@ -324,7 +325,7 @@ class IndexedDBDatabase::DeleteRequest
|
| // TODO(jsbell): Consider including sanitized leveldb status message.
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error deleting database.");
|
| - callbacks_->OnError(error);
|
| + pending_delete_->OnError(error);
|
| if (s.IsCorruption()) {
|
| url::Origin origin = db_->backing_store_->origin();
|
| db_->backing_store_ = nullptr;
|
| @@ -339,7 +340,7 @@ class IndexedDBDatabase::DeleteRequest
|
| db_->metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION;
|
| db_->metadata_.max_object_store_id = kInvalidId;
|
| db_->metadata_.object_stores.clear();
|
| - callbacks_->OnSuccess(old_version);
|
| + pending_delete_->OnSuccess(old_version);
|
| db_->factory_->DatabaseDeleted(db_->identifier_);
|
|
|
| db_->RequestComplete(this);
|
| @@ -350,7 +351,7 @@ class IndexedDBDatabase::DeleteRequest
|
| void UpgradeTransactionFinished(bool committed) override { NOTREACHED(); }
|
|
|
| private:
|
| - scoped_refptr<IndexedDBCallbacks> callbacks_;
|
| + std::unique_ptr<IndexedDBPendingDelete> pending_delete_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DeleteRequest);
|
| };
|
| @@ -461,10 +462,10 @@ size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const {
|
| }
|
|
|
| std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
|
| - scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
|
| + scoped_refptr<IndexedDBChangeHandler> change_handler,
|
| int child_process_id) {
|
| std::unique_ptr<IndexedDBConnection> connection(
|
| - base::MakeUnique<IndexedDBConnection>(this, database_callbacks));
|
| + base::MakeUnique<IndexedDBConnection>(this, change_handler));
|
| connections_.insert(connection.get());
|
| backing_store_->GrantChildProcessPermissions(child_process_id);
|
| return connection;
|
| @@ -817,7 +818,8 @@ void IndexedDBDatabase::SendObservations(
|
| for (auto* conn : connections_) {
|
| auto it = changes_map.find(conn->id());
|
| if (it != changes_map.end())
|
| - conn->callbacks()->OnDatabaseChange(it->first, std::move(it->second));
|
| + conn->change_handler()->OnDatabaseChange(it->first,
|
| + std::move(it->second));
|
| }
|
| }
|
|
|
| @@ -826,8 +828,7 @@ void IndexedDBDatabase::GetAll(int64_t transaction_id,
|
| int64_t index_id,
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| bool key_only,
|
| - int64_t max_count,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| + int64_t max_count) {
|
| IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -840,15 +841,14 @@ void IndexedDBDatabase::GetAll(int64_t transaction_id,
|
| &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id,
|
| base::Passed(&key_range),
|
| key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE,
|
| - max_count, callbacks));
|
| + max_count));
|
| }
|
|
|
| void IndexedDBDatabase::Get(int64_t transaction_id,
|
| int64_t object_store_id,
|
| int64_t index_id,
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - bool key_only,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| + bool key_only) {
|
| IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -859,9 +859,8 @@ void IndexedDBDatabase::Get(int64_t transaction_id,
|
|
|
| transaction->ScheduleTask(base::Bind(
|
| &IndexedDBDatabase::GetOperation, this, object_store_id, index_id,
|
| - base::Passed(&key_range),
|
| - key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE,
|
| - callbacks));
|
| + base::Passed(&key_range), key_only ? indexed_db::CURSOR_KEY_ONLY
|
| + : indexed_db::CURSOR_KEY_AND_VALUE));
|
| }
|
|
|
| void IndexedDBDatabase::GetOperation(
|
| @@ -869,7 +868,6 @@ void IndexedDBDatabase::GetOperation(
|
| int64_t index_id,
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| indexed_db::CursorType cursor_type,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1("IndexedDBDatabase::GetOperation", "txn.id", transaction->id());
|
|
|
| @@ -927,7 +925,9 @@ void IndexedDBDatabase::GetOperation(
|
| }
|
|
|
| if (!backing_store_cursor) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess();
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -946,7 +946,9 @@ void IndexedDBDatabase::GetOperation(
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error in GetRecord.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
|
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| @@ -954,7 +956,9 @@ void IndexedDBDatabase::GetOperation(
|
| }
|
|
|
| if (value.empty()) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess();
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -964,7 +968,9 @@ void IndexedDBDatabase::GetOperation(
|
| value.key_path = object_store_metadata.key_path;
|
| }
|
|
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess(&value);
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -979,18 +985,24 @@ void IndexedDBDatabase::GetOperation(
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error in GetPrimaryKeyViaIndex.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| }
|
| if (!primary_key) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess();
|
| +#endif
|
| return;
|
| }
|
| if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
|
| // Index Value Retrieval Operation
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess(*primary_key);
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -1004,14 +1016,18 @@ void IndexedDBDatabase::GetOperation(
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error in GetRecord.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| }
|
|
|
| if (value.empty()) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess();
|
| +#endif
|
| return;
|
| }
|
| if (object_store_metadata.auto_increment &&
|
| @@ -1019,7 +1035,9 @@ void IndexedDBDatabase::GetOperation(
|
| value.primary_key = *primary_key;
|
| value.key_path = object_store_metadata.key_path;
|
| }
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess(&value);
|
| +#endif
|
| }
|
|
|
| void IndexedDBDatabase::GetAllOperation(
|
| @@ -1028,7 +1046,6 @@ void IndexedDBDatabase::GetAllOperation(
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| indexed_db::CursorType cursor_type,
|
| int64_t max_count,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id());
|
|
|
| @@ -1075,7 +1092,9 @@ void IndexedDBDatabase::GetAllOperation(
|
| DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString();
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error in GetAllOperation");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption()) {
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| }
|
| @@ -1087,7 +1106,9 @@ void IndexedDBDatabase::GetAllOperation(
|
| if (!cursor) {
|
| // Doesn't matter if key or value array here - will be empty array when it
|
| // hits JavaScript.
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path);
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -1108,7 +1129,9 @@ void IndexedDBDatabase::GetAllOperation(
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error in GetAllOperation.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| @@ -1136,9 +1159,11 @@ void IndexedDBDatabase::GetAllOperation(
|
| else
|
| response_size += return_value.SizeEstimate();
|
| if (response_size > GetMaxMessageSizeInBytes()) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Maximum IPC message size exceeded."));
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -1148,6 +1173,7 @@ void IndexedDBDatabase::GetAllOperation(
|
| found_values.push_back(return_value);
|
| }
|
|
|
| +#ifdef CJM_NEED_CALLBACK
|
| if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
|
| // IndexedDBKey already supports an array of values so we can leverage this
|
| // to return an array of keys - no need to create our own array of keys.
|
| @@ -1155,6 +1181,7 @@ void IndexedDBDatabase::GetAllOperation(
|
| } else {
|
| callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path);
|
| }
|
| +#endif
|
| }
|
|
|
| static std::unique_ptr<IndexedDBKey> GenerateKey(
|
| @@ -1199,7 +1226,6 @@ struct IndexedDBDatabase::PutOperationParams {
|
| ScopedVector<storage::BlobDataHandle> handles;
|
| std::unique_ptr<IndexedDBKey> key;
|
| blink::WebIDBPutMode put_mode;
|
| - scoped_refptr<IndexedDBCallbacks> callbacks;
|
| std::vector<IndexKeys> index_keys;
|
|
|
| private:
|
| @@ -1212,7 +1238,6 @@ void IndexedDBDatabase::Put(int64_t transaction_id,
|
| ScopedVector<storage::BlobDataHandle>* handles,
|
| std::unique_ptr<IndexedDBKey> key,
|
| blink::WebIDBPutMode put_mode,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| const std::vector<IndexKeys>& index_keys) {
|
| IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| @@ -1232,7 +1257,6 @@ void IndexedDBDatabase::Put(int64_t transaction_id,
|
| params->handles.swap(*handles);
|
| params->key = std::move(key);
|
| params->put_mode = put_mode;
|
| - params->callbacks = callbacks;
|
| params->index_keys = index_keys;
|
| transaction->ScheduleTask(base::Bind(
|
| &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms)));
|
| @@ -1257,9 +1281,11 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| backing_store_.get(), transaction, id(), params->object_store_id);
|
| key_was_generated = true;
|
| if (!auto_inc_key->IsValid()) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
|
| "Maximum key generator value reached."));
|
| +#endif
|
| return;
|
| }
|
| key = std::move(auto_inc_key);
|
| @@ -1282,15 +1308,19 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error checking key existence.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| }
|
| if (found) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
|
| "Key already exists in the object store."));
|
| +#endif
|
| return;
|
| }
|
| }
|
| @@ -1309,14 +1339,18 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| &error_message,
|
| &obeys_constraints);
|
| if (!backing_store_success) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(IndexedDBDatabaseError(
|
| blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error: backing store error updating index keys."));
|
| +#endif
|
| return;
|
| }
|
| if (!obeys_constraints) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(IndexedDBDatabaseError(
|
| blink::WebIDBDatabaseExceptionConstraintError, error_message));
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -1334,7 +1368,9 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| IndexedDBDatabaseError error(
|
| blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error: backing store error performing put/add.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| @@ -1364,7 +1400,9 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error updating key generator.");
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption())
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| return;
|
| @@ -1373,7 +1411,9 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params,
|
| {
|
| IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id",
|
| transaction->id());
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnSuccess(*key);
|
| +#endif
|
| }
|
| FilterObservation(transaction, params->object_store_id,
|
| params->put_mode == blink::WebIDBPutModeAddOnly
|
| @@ -1487,21 +1527,18 @@ struct IndexedDBDatabase::OpenCursorOperationParams {
|
| blink::WebIDBCursorDirection direction;
|
| indexed_db::CursorType cursor_type;
|
| blink::WebIDBTaskType task_type;
|
| - scoped_refptr<IndexedDBCallbacks> callbacks;
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams);
|
| };
|
|
|
| -void IndexedDBDatabase::OpenCursor(
|
| - int64_t transaction_id,
|
| - int64_t object_store_id,
|
| - int64_t index_id,
|
| - std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - blink::WebIDBCursorDirection direction,
|
| - bool key_only,
|
| - blink::WebIDBTaskType task_type,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| +void IndexedDBDatabase::OpenCursor(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + int64_t index_id,
|
| + std::unique_ptr<IndexedDBKeyRange> key_range,
|
| + blink::WebIDBCursorDirection direction,
|
| + bool key_only,
|
| + blink::WebIDBTaskType task_type) {
|
| IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -1519,7 +1556,6 @@ void IndexedDBDatabase::OpenCursor(
|
| params->cursor_type =
|
| key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE;
|
| params->task_type = task_type;
|
| - params->callbacks = callbacks;
|
| transaction->ScheduleTask(base::Bind(
|
| &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(¶ms)));
|
| }
|
| @@ -1592,22 +1628,25 @@ void IndexedDBDatabase::OpenCursorOperation(
|
|
|
| if (!backing_store_cursor) {
|
| // Why is Success being called?
|
| +#ifdef CJM_NEED_CALLBACK
|
| params->callbacks->OnSuccess(nullptr);
|
| +#endif
|
| return;
|
| }
|
|
|
| +#ifdef CJM_NEED_CALLBACK
|
| scoped_refptr<IndexedDBCursor> cursor =
|
| new IndexedDBCursor(std::move(backing_store_cursor), params->cursor_type,
|
| params->task_type, transaction);
|
| params->callbacks->OnSuccess(
|
| cursor, cursor->key(), cursor->primary_key(), cursor->Value());
|
| +#endif
|
| }
|
|
|
| void IndexedDBDatabase::Count(int64_t transaction_id,
|
| int64_t object_store_id,
|
| int64_t index_id,
|
| - std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| + std::unique_ptr<IndexedDBKeyRange> key_range) {
|
| IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -1616,19 +1655,15 @@ void IndexedDBDatabase::Count(int64_t transaction_id,
|
| if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id))
|
| return;
|
|
|
| - transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation,
|
| - this,
|
| - object_store_id,
|
| - index_id,
|
| - base::Passed(&key_range),
|
| - callbacks));
|
| + transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, this,
|
| + object_store_id, index_id,
|
| + base::Passed(&key_range)));
|
| }
|
|
|
| void IndexedDBDatabase::CountOperation(
|
| int64_t object_store_id,
|
| int64_t index_id,
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id());
|
| uint32_t count = 0;
|
| @@ -1662,7 +1697,9 @@ void IndexedDBDatabase::CountOperation(
|
| }
|
| }
|
| if (!backing_store_cursor) {
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess(count);
|
| +#endif
|
| return;
|
| }
|
|
|
| @@ -1672,14 +1709,15 @@ void IndexedDBDatabase::CountOperation(
|
|
|
| // TODO(cmumford): Check for database corruption.
|
|
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess(count);
|
| +#endif
|
| }
|
|
|
| void IndexedDBDatabase::DeleteRange(
|
| int64_t transaction_id,
|
| int64_t object_store_id,
|
| - std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| + std::unique_ptr<IndexedDBKeyRange> key_range) {
|
| IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -1690,16 +1728,13 @@ void IndexedDBDatabase::DeleteRange(
|
| return;
|
|
|
| transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation,
|
| - this,
|
| - object_store_id,
|
| - base::Passed(&key_range),
|
| - callbacks));
|
| + this, object_store_id,
|
| + base::Passed(&key_range)));
|
| }
|
|
|
| void IndexedDBDatabase::DeleteRangeOperation(
|
| int64_t object_store_id,
|
| std::unique_ptr<IndexedDBKeyRange> key_range,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id",
|
| transaction->id());
|
| @@ -1718,18 +1753,18 @@ void IndexedDBDatabase::DeleteRangeOperation(
|
| }
|
| return;
|
| }
|
| +#ifdef CJM_NEED_CALLBACK
|
| if (experimental_web_platform_features_enabled_) {
|
| callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count));
|
| } else {
|
| callbacks->OnSuccess();
|
| }
|
| +#endif
|
| FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
|
| *key_range);
|
| }
|
|
|
| -void IndexedDBDatabase::Clear(int64_t transaction_id,
|
| - int64_t object_store_id,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| +void IndexedDBDatabase::Clear(int64_t transaction_id, int64_t object_store_id) {
|
| IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id);
|
| IndexedDBTransaction* transaction = GetTransaction(transaction_id);
|
| if (!transaction)
|
| @@ -1739,13 +1774,12 @@ void IndexedDBDatabase::Clear(int64_t transaction_id,
|
| if (!ValidateObjectStoreId(object_store_id))
|
| return;
|
|
|
| - transaction->ScheduleTask(base::Bind(
|
| - &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks));
|
| + transaction->ScheduleTask(
|
| + base::Bind(&IndexedDBDatabase::ClearOperation, this, object_store_id));
|
| }
|
|
|
| void IndexedDBDatabase::ClearOperation(
|
| int64_t object_store_id,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id());
|
| leveldb::Status s = backing_store_->ClearObjectStore(
|
| @@ -1753,13 +1787,17 @@ void IndexedDBDatabase::ClearOperation(
|
| if (!s.ok()) {
|
| IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Internal error clearing object store");
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnError(error);
|
| +#endif
|
| if (s.IsCorruption()) {
|
| factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
|
| }
|
| return;
|
| }
|
| +#ifdef CJM_NEED_CALLBACK
|
| callbacks->OnSuccess();
|
| +#endif
|
|
|
| FilterObservation(transaction, object_store_id, blink::WebIDBClear,
|
| IndexedDBKeyRange());
|
| @@ -1798,22 +1836,22 @@ void IndexedDBDatabase::DeleteObjectStoreOperation(
|
| }
|
|
|
| void IndexedDBDatabase::VersionChangeOperation(
|
| - int64_t version,
|
| - scoped_refptr<IndexedDBCallbacks> callbacks,
|
| + const IndexedDBPendingConnection* pending_connection,
|
| IndexedDBTransaction* transaction) {
|
| IDB_TRACE1(
|
| "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id());
|
| int64_t old_version = metadata_.version;
|
| - DCHECK_GT(version, old_version);
|
| + DCHECK_GT(pending_connection->version(), old_version);
|
|
|
| if (!backing_store_->UpdateIDBDatabaseIntVersion(
|
| - transaction->BackingStoreTransaction(), id(), version)) {
|
| + transaction->BackingStoreTransaction(), id(),
|
| + pending_connection->version())) {
|
| IndexedDBDatabaseError error(
|
| blink::WebIDBDatabaseExceptionUnknownError,
|
| ASCIIToUTF16(
|
| "Internal error writing data to stable storage when "
|
| "updating version."));
|
| - callbacks->OnError(error);
|
| + pending_connection->OnError(error);
|
| transaction->Abort(error);
|
| return;
|
| }
|
| @@ -1821,7 +1859,7 @@ void IndexedDBDatabase::VersionChangeOperation(
|
| transaction->ScheduleAbortTask(
|
| base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this,
|
| metadata_.version));
|
| - metadata_.version = version;
|
| + metadata_.version = pending_connection->version();
|
|
|
| active_request_->UpgradeTransactionStarted(old_version);
|
| }
|
| @@ -1923,8 +1961,9 @@ void IndexedDBDatabase::OpenConnection(
|
| }
|
|
|
| void IndexedDBDatabase::DeleteDatabase(
|
| - scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| - AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks));
|
| + std::unique_ptr<IndexedDBPendingDelete> pending_delete) {
|
| + AppendRequest(
|
| + base::MakeUnique<DeleteRequest>(this, std::move(pending_delete)));
|
| }
|
|
|
| void IndexedDBDatabase::ForceClose() {
|
| @@ -1957,7 +1996,7 @@ void IndexedDBDatabase::Close(IndexedDBConnection* connection, bool forced) {
|
| {
|
| auto transactions(transactions_);
|
| for (const auto& it : transactions) {
|
| - if (it.second->callbacks() == connection->callbacks())
|
| + if (it.second->change_handler() == connection->change_handler())
|
| it.second->Abort(
|
| IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
|
| "Connection is closing."));
|
| @@ -2010,4 +2049,8 @@ void IndexedDBDatabase::VersionChangeAbortOperation(
|
| metadata_.version = previous_version;
|
| }
|
|
|
| +IndexedDBContext* IndexedDBDatabase::context() const {
|
| + return factory_->context();
|
| +}
|
| +
|
| } // namespace content
|
|
|