| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper); | 68 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 71 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 72 int ipc_process_id, | 72 int ipc_process_id, |
| 73 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 73 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 74 scoped_refptr<IndexedDBContextImpl> indexed_db_context, | 74 scoped_refptr<IndexedDBContextImpl> indexed_db_context, |
| 75 scoped_refptr<ChromeBlobStorageContext> blob_storage_context) | 75 scoped_refptr<ChromeBlobStorageContext> blob_storage_context) |
| 76 : indexed_db_context_(std::move(indexed_db_context)), | 76 : indexed_db_context_(std::move(indexed_db_context)), |
| 77 blob_storage_context_(std::move(blob_storage_context)), | 77 blob_storage_context_(std::move(blob_storage_context)), |
| 78 idb_runner_(indexed_db_context_->TaskRunner()), | |
| 79 ipc_process_id_(ipc_process_id), | 78 ipc_process_id_(ipc_process_id), |
| 79 idb_helper_(new IDBSequenceHelper(ipc_process_id_, |
| 80 std::move(request_context_getter), |
| 81 indexed_db_context_)), |
| 80 weak_factory_(this) { | 82 weak_factory_(this) { |
| 81 // Can be null in unittests. | |
| 82 idb_helper_ = idb_runner_ | |
| 83 ? new IDBSequenceHelper(ipc_process_id_, | |
| 84 std::move(request_context_getter), | |
| 85 indexed_db_context_) | |
| 86 : nullptr; | |
| 87 DCHECK(indexed_db_context_.get()); | 83 DCHECK(indexed_db_context_.get()); |
| 88 } | 84 } |
| 89 | 85 |
| 90 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { | 86 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { |
| 91 if (idb_helper_) | 87 IDBTaskRunner()->DeleteSoon(FROM_HERE, idb_helper_); |
| 92 idb_runner_->DeleteSoon(FROM_HERE, idb_helper_); | |
| 93 } | 88 } |
| 94 | 89 |
| 95 void IndexedDBDispatcherHost::AddBinding( | 90 void IndexedDBDispatcherHost::AddBinding( |
| 96 ::indexed_db::mojom::FactoryAssociatedRequest request) { | 91 ::indexed_db::mojom::FactoryAssociatedRequest request) { |
| 97 bindings_.AddBinding(this, std::move(request)); | 92 bindings_.AddBinding(this, std::move(request)); |
| 98 } | 93 } |
| 99 | 94 |
| 100 void IndexedDBDispatcherHost::AddDatabaseBinding( | 95 void IndexedDBDispatcherHost::AddDatabaseBinding( |
| 101 std::unique_ptr<::indexed_db::mojom::Database> database, | 96 std::unique_ptr<::indexed_db::mojom::Database> database, |
| 102 ::indexed_db::mojom::DatabaseAssociatedRequest request) { | 97 ::indexed_db::mojom::DatabaseAssociatedRequest request) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 161 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 167 const url::Origin& origin) { | 162 const url::Origin& origin) { |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 169 | 164 |
| 170 if (!IsValidOrigin(origin)) { | 165 if (!IsValidOrigin(origin)) { |
| 171 mojo::ReportBadMessage(kInvalidOrigin); | 166 mojo::ReportBadMessage(kInvalidOrigin); |
| 172 return; | 167 return; |
| 173 } | 168 } |
| 174 | 169 |
| 175 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 170 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 176 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 171 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 177 idb_runner_->PostTask( | 172 IDBTaskRunner()->PostTask( |
| 178 FROM_HERE, base::BindOnce(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, | 173 FROM_HERE, base::BindOnce(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, |
| 179 base::Unretained(idb_helper_), | 174 base::Unretained(idb_helper_), |
| 180 base::Passed(&callbacks), origin)); | 175 base::Passed(&callbacks), origin)); |
| 181 } | 176 } |
| 182 | 177 |
| 183 void IndexedDBDispatcherHost::Open( | 178 void IndexedDBDispatcherHost::Open( |
| 184 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 179 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 185 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo | 180 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo |
| 186 database_callbacks_info, | 181 database_callbacks_info, |
| 187 const url::Origin& origin, | 182 const url::Origin& origin, |
| 188 const base::string16& name, | 183 const base::string16& name, |
| 189 int64_t version, | 184 int64_t version, |
| 190 int64_t transaction_id) { | 185 int64_t transaction_id) { |
| 191 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 186 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 192 | 187 |
| 193 if (!IsValidOrigin(origin)) { | 188 if (!IsValidOrigin(origin)) { |
| 194 mojo::ReportBadMessage(kInvalidOrigin); | 189 mojo::ReportBadMessage(kInvalidOrigin); |
| 195 return; | 190 return; |
| 196 } | 191 } |
| 197 | 192 |
| 198 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 193 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 199 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 194 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 200 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( | 195 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( |
| 201 new IndexedDBDatabaseCallbacks(indexed_db_context_, | 196 new IndexedDBDatabaseCallbacks(indexed_db_context_, |
| 202 std::move(database_callbacks_info))); | 197 std::move(database_callbacks_info))); |
| 203 idb_runner_->PostTask( | 198 IDBTaskRunner()->PostTask( |
| 204 FROM_HERE, | 199 FROM_HERE, |
| 205 base::BindOnce(&IDBSequenceHelper::OpenOnIDBThread, | 200 base::BindOnce(&IDBSequenceHelper::OpenOnIDBThread, |
| 206 base::Unretained(idb_helper_), base::Passed(&callbacks), | 201 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 207 base::Passed(&database_callbacks), origin, name, version, | 202 base::Passed(&database_callbacks), origin, name, version, |
| 208 transaction_id)); | 203 transaction_id)); |
| 209 } | 204 } |
| 210 | 205 |
| 211 void IndexedDBDispatcherHost::DeleteDatabase( | 206 void IndexedDBDispatcherHost::DeleteDatabase( |
| 212 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 207 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 213 const url::Origin& origin, | 208 const url::Origin& origin, |
| 214 const base::string16& name, | 209 const base::string16& name, |
| 215 bool force_close) { | 210 bool force_close) { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 211 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 217 | 212 |
| 218 if (!IsValidOrigin(origin)) { | 213 if (!IsValidOrigin(origin)) { |
| 219 mojo::ReportBadMessage(kInvalidOrigin); | 214 mojo::ReportBadMessage(kInvalidOrigin); |
| 220 return; | 215 return; |
| 221 } | 216 } |
| 222 | 217 |
| 223 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 218 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 224 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 219 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 225 idb_runner_->PostTask( | 220 IDBTaskRunner()->PostTask( |
| 226 FROM_HERE, | 221 FROM_HERE, |
| 227 base::BindOnce(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, | 222 base::BindOnce(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, |
| 228 base::Unretained(idb_helper_), base::Passed(&callbacks), | 223 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 229 origin, name, force_close)); | 224 origin, name, force_close)); |
| 230 } | 225 } |
| 231 | 226 |
| 232 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { | 227 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { |
| 233 weak_factory_.InvalidateWeakPtrs(); | 228 weak_factory_.InvalidateWeakPtrs(); |
| 234 cursor_bindings_.CloseAllBindings(); | 229 cursor_bindings_.CloseAllBindings(); |
| 235 database_bindings_.CloseAllBindings(); | 230 database_bindings_.CloseAllBindings(); |
| 236 } | 231 } |
| 237 | 232 |
| 233 base::SequencedTaskRunner* IndexedDBDispatcherHost::IDBTaskRunner() const { |
| 234 return indexed_db_context_->TaskRunner(); |
| 235 } |
| 236 |
| 238 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( | 237 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( |
| 239 scoped_refptr<IndexedDBCallbacks> callbacks, | 238 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 240 const url::Origin& origin) { | 239 const url::Origin& origin) { |
| 241 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 240 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 242 | 241 |
| 243 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 242 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 244 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( | 243 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( |
| 245 callbacks, origin, indexed_db_path, request_context_getter_); | 244 callbacks, origin, indexed_db_path, request_context_getter_); |
| 246 } | 245 } |
| 247 | 246 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 278 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 279 | 278 |
| 280 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 279 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 281 DCHECK(request_context_getter_); | 280 DCHECK(request_context_getter_); |
| 282 indexed_db_context_->GetIDBFactory()->DeleteDatabase( | 281 indexed_db_context_->GetIDBFactory()->DeleteDatabase( |
| 283 name, request_context_getter_, callbacks, origin, indexed_db_path, | 282 name, request_context_getter_, callbacks, origin, indexed_db_path, |
| 284 force_close); | 283 force_close); |
| 285 } | 284 } |
| 286 | 285 |
| 287 } // namespace content | 286 } // namespace content |
| OLD | NEW |