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

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

Issue 2727733004: [IndexedDB] Closing mojo connections when renderer quits (Closed)
Patch Set: fix and rebase Created 3 years, 8 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/database_impl.cc
diff --git a/content/browser/indexed_db/database_impl.cc b/content/browser/indexed_db/database_impl.cc
index 4a22cda522deb3481d94c0ef788de132722c2970..feaec66892c446dba18123239ae5f6de3d58f510 100644
--- a/content/browser/indexed_db/database_impl.cc
+++ b/content/browser/indexed_db/database_impl.cc
@@ -6,6 +6,7 @@
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
+#include "base/sequenced_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/bad_message.h"
#include "content/browser/child_process_security_policy_impl.h"
@@ -28,13 +29,16 @@ const char kInvalidBlobUuid[] = "Blob does not exist";
const char kInvalidBlobFilePath[] = "Blob file path is invalid";
} // namespace
+// Expect to be created on IO thread, and called/destroyed on IDB thread.
jsbell 2017/04/11 16:58:03 Can you use DCHECK_CURRENTLY_ON and DCHECK(idb_run
dmurph 2017/04/11 19:32:49 Done.
class DatabaseImpl::IDBThreadHelper {
public:
IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection,
const url::Origin& origin,
- scoped_refptr<IndexedDBDispatcherHost> dispatcher_host);
+ scoped_refptr<IndexedDBContextImpl> indexed_db_context);
~IDBThreadHelper();
+ void ConnectionOpened();
+
void CreateObjectStore(int64_t transaction_id,
int64_t object_store_id,
const base::string16& name,
@@ -130,21 +134,25 @@ class DatabaseImpl::IDBThreadHelper {
void AckReceivedBlobs(const std::vector<std::string>& uuids);
private:
- scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
+ scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
std::unique_ptr<IndexedDBConnection> connection_;
const url::Origin origin_;
base::WeakPtrFactory<IDBThreadHelper> weak_factory_;
};
-DatabaseImpl::DatabaseImpl(
- std::unique_ptr<IndexedDBConnection> connection,
- const url::Origin& origin,
- scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
+DatabaseImpl::DatabaseImpl(std::unique_ptr<IndexedDBConnection> connection,
+ const url::Origin& origin,
+ IndexedDBDispatcherHost* dispatcher_host,
+ scoped_refptr<base::SequencedTaskRunner> idb_runner)
: dispatcher_host_(dispatcher_host),
origin_(origin),
- idb_runner_(base::ThreadTaskRunnerHandle::Get()) {
+ idb_runner_(std::move(idb_runner)) {
+ DCHECK(connection);
helper_ = new IDBThreadHelper(std::move(connection), origin,
- std::move(dispatcher_host));
+ dispatcher_host->context());
+ idb_runner_->PostTask(FROM_HERE,
+ base::Bind(&IDBThreadHelper::ConnectionOpened,
+ base::Unretained(helper_)));
}
DatabaseImpl::~DatabaseImpl() {
@@ -226,8 +234,9 @@ void DatabaseImpl::Get(
const IndexedDBKeyRange& key_range,
bool key_only,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_),
transaction_id, object_store_id, index_id,
@@ -242,8 +251,9 @@ void DatabaseImpl::GetAll(
bool key_only,
int64_t max_count,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE,
base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_),
@@ -262,8 +272,9 @@ void DatabaseImpl::Put(
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
std::vector<std::unique_ptr<storage::BlobDataHandle>> handles(
value->blob_or_file_info.size());
@@ -351,8 +362,9 @@ void DatabaseImpl::OpenCursor(
bool key_only,
blink::WebIDBTaskType task_type,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE,
base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_),
@@ -366,8 +378,9 @@ void DatabaseImpl::Count(
int64_t index_id,
const IndexedDBKeyRange& key_range,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_),
transaction_id, object_store_id, index_id,
@@ -379,8 +392,9 @@ void DatabaseImpl::DeleteRange(
int64_t object_store_id,
const IndexedDBKeyRange& key_range,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE,
base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_),
@@ -392,8 +406,9 @@ void DatabaseImpl::Clear(
int64_t transaction_id,
int64_t object_store_id,
::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
- scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
- dispatcher_host_.get(), origin_, std::move(callbacks_info)));
+ scoped_refptr<IndexedDBCallbacks> callbacks(
+ new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
+ std::move(callbacks_info), idb_runner_));
idb_runner_->PostTask(
FROM_HERE,
base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_),
@@ -453,18 +468,20 @@ void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) {
DatabaseImpl::IDBThreadHelper::IDBThreadHelper(
std::unique_ptr<IndexedDBConnection> connection,
const url::Origin& origin,
- scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
- : dispatcher_host_(std::move(dispatcher_host)),
+ scoped_refptr<IndexedDBContextImpl> indexed_db_context)
+ : indexed_db_context_(indexed_db_context),
connection_(std::move(connection)),
origin_(origin),
- weak_factory_(this) {
- dispatcher_host_->context()->ConnectionOpened(origin_, connection.get());
-}
+ weak_factory_(this) {}
DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() {
if (connection_->IsConnected())
connection_->Close();
- dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get());
+ indexed_db_context_->ConnectionClosed(origin_, connection_.get());
+}
+
+void DatabaseImpl::IDBThreadHelper::ConnectionOpened() {
+ indexed_db_context_->ConnectionOpened(origin_, connection_.get());
}
void DatabaseImpl::IDBThreadHelper::CreateObjectStore(
@@ -841,8 +858,8 @@ void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) {
return;
}
- dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota(
- dispatcher_host_->context()->TaskRunner(), origin_.GetURL(),
+ indexed_db_context_->quota_manager_proxy()->GetUsageAndQuota(
+ indexed_db_context_->TaskRunner(), origin_.GetURL(),
storage::kStorageTypeTemporary,
base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit,
weak_factory_.GetWeakPtr(), transaction_id));

Powered by Google App Engine
This is Rietveld 408576698