Chromium Code Reviews| 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 922feabba842b04e0821e401a99b482e556f8bad..35cb81eab70deebe167d56c9c88a6ccf4ba0d0ed 100644 |
| --- a/content/browser/indexed_db/database_impl.cc |
| +++ b/content/browser/indexed_db/database_impl.cc |
| @@ -5,6 +5,7 @@ |
| #include "content/browser/indexed_db/database_impl.h" |
| #include "base/memory/ptr_util.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" |
| @@ -26,13 +27,16 @@ const char kInvalidBlobUuid[] = "Blob UUID is invalid"; |
| const char kInvalidBlobFilePath[] = "Blob file path is invalid"; |
| } // namespace |
| +// Expect to be created on IO thread, and called/destroyed on IDB thread. |
| 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, |
| @@ -126,21 +130,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() { |
| @@ -222,8 +230,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, |
| @@ -238,8 +247,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_), |
| @@ -291,8 +301,9 @@ void DatabaseImpl::Put( |
| } |
| } |
| - 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, |
| @@ -331,8 +342,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_), |
| @@ -346,8 +358,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, |
| @@ -359,8 +372,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_), |
| @@ -372,8 +386,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_), |
| @@ -433,18 +448,24 @@ 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() { |
| + LOG(ERROR) << "in destructor"; |
| + LOG(ERROR) << "object " << connection_.get(); |
| + LOG(ERROR) << "connected: " << connection_->IsConnected(); |
| if (connection_->IsConnected()) |
| connection_->Close(); |
| - dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get()); |
| + LOG(ERROR) << "about to call closed"; |
|
Reilly Grant (use Gerrit)
2017/03/11 00:31:40
Leftover logging.
dmurph
2017/03/29 18:40:24
Done.
|
| + indexed_db_context_->ConnectionClosed(origin_, connection_.get()); |
| +} |
| + |
| +void DatabaseImpl::IDBThreadHelper::ConnectionOpened() { |
| + indexed_db_context_->ConnectionOpened(origin_, connection_.get()); |
| } |
| void DatabaseImpl::IDBThreadHelper::CreateObjectStore( |
| @@ -807,8 +828,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)); |