Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1197)

Unified Diff: content/browser/indexed_db/indexed_db_connection.cc

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_connection.cc
diff --git a/content/browser/indexed_db/indexed_db_connection.cc b/content/browser/indexed_db/indexed_db_connection.cc
index 45f3e81feed54d42f54c83f1ab12e4c43379f4db..c537384404d28fc8ffe5aef3d00600417d72332e 100644
--- a/content/browser/indexed_db/indexed_db_connection.cc
+++ b/content/browser/indexed_db/indexed_db_connection.cc
@@ -4,15 +4,33 @@
#include "content/browser/indexed_db/indexed_db_connection.h"
+#include <utility>
+
#include "base/logging.h"
#include "base/stl_util.h"
+#include "content/browser/indexed_db/database_factory_impl.h"
+#include "content/public/browser/indexed_db_context.h"
+#include "storage/browser/quota/quota_manager_proxy.h"
+#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
+
+using ::indexed_db::mojom::BlobInfoPtr;
+using ::indexed_db::mojom::CursorDirection;
+using ::indexed_db::mojom::KeyPtr;
+using ::indexed_db::mojom::KeyRangePtr;
+using ::indexed_db::mojom::PutMode;
+using ::indexed_db::mojom::TaskType;
+using ::indexed_db::mojom::TransactionMode;
namespace content {
IndexedDBConnection::IndexedDBConnection(
scoped_refptr<IndexedDBDatabase> database,
- scoped_refptr<IndexedDBDatabaseCallbacks> callbacks)
- : database_(database), callbacks_(callbacks), weak_factory_(this) {}
+ scoped_refptr<IndexedDBChangeHandler> change_handler)
+ : database_(database),
+ change_handler_(change_handler),
+ weak_factory_(this) {
+ change_handler->SetConnection(GetWeakPtr());
+}
IndexedDBConnection::~IndexedDBConnection() {}
@@ -21,32 +39,49 @@ void IndexedDBConnection::set_id(int32_t id) {
id_ = id;
}
-void IndexedDBConnection::Close() {
- if (!callbacks_.get())
+void IndexedDBConnection::ForceClose() {
+ if (!change_handler_.get())
return;
+
+ // IndexedDBDatabase::Close() can delete this instance.
base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr();
- database_->Close(this, false /* forced */);
+ scoped_refptr<IndexedDBChangeHandler> change_handler(change_handler_);
+ database_->Close(this, true /* forced */);
if (this_obj) {
database_ = nullptr;
- callbacks_ = nullptr;
+ change_handler_ = nullptr;
active_observers_.clear();
}
+ change_handler->OnForcedClose();
}
-void IndexedDBConnection::ForceClose() {
- if (!callbacks_.get())
- return;
+bool IndexedDBConnection::IsConnected() {
+ return database_.get() != NULL;
+}
- // IndexedDBDatabase::Close() can delete this instance.
+void IndexedDBConnection::CreateObjectStore(int64_t transaction_id,
+ int64_t object_store_id,
+ const std::string& name,
+ const IndexedDBKeyPath& key_path,
+ bool auto_increment) {}
+
+void IndexedDBConnection::DeleteObjectStore(int64_t transaction_id,
+ int64_t object_store_id) {}
+
+void IndexedDBConnection::CreateTransaction(int64_t transaction_id,
+ const std::vector<int64_t>& scope,
+ TransactionMode transaction_mode) {}
+
+void IndexedDBConnection::Close() {
+ if (!change_handler_.get())
+ return;
base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr();
- scoped_refptr<IndexedDBDatabaseCallbacks> callbacks(callbacks_);
- database_->Close(this, true /* forced */);
+ database_->Close(this, false /* forced */);
if (this_obj) {
database_ = nullptr;
- callbacks_ = nullptr;
+ change_handler_ = nullptr;
active_observers_.clear();
}
- callbacks->OnForcedClose();
}
void IndexedDBConnection::VersionChangeIgnored() {
@@ -55,8 +90,160 @@ void IndexedDBConnection::VersionChangeIgnored() {
database_->VersionChangeIgnored();
}
-bool IndexedDBConnection::IsConnected() {
- return database_.get() != NULL;
+void IndexedDBConnection::Abort(int64_t transaction_id) {}
+
+void IndexedDBConnection::OnGotUsageAndQuotaForCommit(
+ int64_t transaction_id,
+ storage::QuotaStatusCode status,
+ int64_t usage,
+ int64_t quota) {
+ DCHECK(context()->TaskRunner()->RunsTasksOnCurrentThread());
+ // May have disconnected while quota check was pending.
+ if (!IsConnected())
+ return;
+ // May have aborted while quota check was pending.
+ if (!base::ContainsKey(transaction_id_to_size_, transaction_id))
+ return;
+ int64_t transaction_size = transaction_id_to_size_[transaction_id];
+
+ if (status == storage::kQuotaStatusOk && usage + transaction_size <= quota) {
+ database()->Commit(transaction_id);
+ } else {
+ database()->Abort(
+ transaction_id,
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError));
+ }
+}
+
+void IndexedDBConnection::Commit(int64_t transaction_id) {
+ if (!IsConnected())
+ return;
+
+ // May have been aborted by back end before front-end could request commit.
+ if (!base::ContainsKey(transaction_id_to_size_, transaction_id))
+ return;
+ int64_t transaction_size = transaction_id_to_size_[transaction_id];
+
+ // Always allow empty or delete-only transactions.
+ if (!transaction_size) {
+ database()->Commit(transaction_id);
+ return;
+ }
+
+ context()->quota_manager_proxy()->GetUsageAndQuota(
+ context()->TaskRunner(),
+ GURL(transaction_id_to_origin_[transaction_id].Serialize()),
+ storage::kStorageTypeTemporary,
+ base::Bind(&IndexedDBConnection::OnGotUsageAndQuotaForCommit,
+ weak_factory_.GetWeakPtr(), transaction_id));
+}
+
+void IndexedDBConnection::CreateIndex(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ const std::string& name,
+ const IndexedDBKeyPath& key_path,
+ bool unique,
+ bool multi_entry) {}
+
+void IndexedDBConnection::DeleteIndex(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id) {}
+
+void IndexedDBConnection::Get(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ KeyRangePtr key_range,
+ bool key_only,
+ const GetCallback& callback) {
+ if (!IsConnected())
+ return;
+
+#if 0
+ connection->database()->Get(
+ HostTransactionId(transaction_id), object_store_id,
+ index_id,
+ base::WrapUnique(new IndexedDBKeyRange(key_range)),
+ params.key_only, callbacks);
+#endif
+#if 0
+ DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
+ IndexedDBConnection* connection =
+ parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
+ if (!connection || !connection->IsConnected())
+ return;
+
+ scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
+ parent_, params.ipc_thread_id, params.ipc_callbacks_id));
+ connection->database()->Get(
+ parent_->HostTransactionId(params.transaction_id), params.object_store_id,
+ params.index_id,
+ base::WrapUnique(new IndexedDBKeyRange(params.key_range)),
+ params.key_only, callbacks);
+#endif
+
+ // TODO(cmumford): Set the error data.
+ content::IndexedDBDatabaseError error;
+ // TODO(cmumford): Can we somehow use GetResult::From()?
+ ::indexed_db::mojom::GetResultPtr result =
+ ::indexed_db::mojom::GetResult::New();
+ result->set_error(error);
+ callback.Run(std::move(result));
+}
+
+void IndexedDBConnection::GetAll(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ KeyRangePtr key_range,
+ int64_t max_count,
+ bool key_only) {}
+
+void IndexedDBConnection::Put(int64_t transaction_id,
+ int64_t object_store_id,
+ const std::vector<int8_t>& value,
+ std::vector<BlobInfoPtr> blob_info,
+ KeyPtr key,
+ PutMode put_mode,
+ const std::vector<int64_t>& index_ids,
+ std::vector<std::vector<KeyPtr>> index_keys) {}
+
+void IndexedDBConnection::DeleteRange(int64_t transaction_id,
+ int64_t object_store_id,
+ KeyRangePtr key_range) {}
+
+void IndexedDBConnection::Clear(int64_t transaction_id,
+ int64_t object_store_id) {}
+
+void IndexedDBConnection::SetIndexKeys(
+ int64_t transaction_id,
+ int64_t object_store_id,
+ KeyPtr primary_key,
+ const std::vector<int64_t>& index_ids,
+ std::vector<std::vector<KeyPtr>> index_keys) {}
+
+void IndexedDBConnection::SetIndexesReady(
+ int64_t transaction_id,
+ int64_t object_store_id,
+ const std::vector<int64_t>& index_ids) {}
+
+void IndexedDBConnection::OpenCursor(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ KeyRangePtr key_range,
+ CursorDirection direction,
+ bool key_only,
+ TaskType task_type) {}
+
+void IndexedDBConnection::Count(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ KeyRangePtr key_range) {}
+
+void IndexedDBConnection::AckReceivedBlobs(
+ const std::vector<std::string>& uuids) {}
+
+void IndexedDBConnection::Bind(::indexed_db::mojom::DatabaseRequest request) {
+ binding_.AddBinding(this, std::move(request));
}
// The observers begin listening to changes only once they are activated.
@@ -86,4 +273,24 @@ void IndexedDBConnection::RemoveObservers(
database_->RemovePendingObservers(this, pending_observer_ids);
}
+void IndexedDBConnection::RegisterTransactionId(int64_t transaction_id,
+ const url::Origin& origin) {
+ transaction_id_to_size_[transaction_id] = 0;
+ transaction_id_to_origin_[transaction_id] = origin;
+}
+
+void IndexedDBConnection::FinishTransaction(int64_t transaction_id,
+ bool committed) {
+ if (committed)
+ context()->TransactionComplete(transaction_id_to_origin_[transaction_id]);
+ transaction_id_to_origin_.erase(transaction_id);
+ transaction_id_to_size_.erase(transaction_id);
+ // TODO(cmumford): transaction_id_to_database_id_ is not currently being set.
+ transaction_id_to_database_id_.erase(transaction_id);
+}
+
+IndexedDBContext* IndexedDBConnection::context() const {
+ return database_->context();
+}
+
} // namespace content
« no previous file with comments | « content/browser/indexed_db/indexed_db_connection.h ('k') | content/browser/indexed_db/indexed_db_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698