| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 160 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 166 const url::Origin& origin) { | 161 const url::Origin& origin) { |
| 167 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 168 | 163 |
| 169 if (!IsValidOrigin(origin)) { | 164 if (!IsValidOrigin(origin)) { |
| 170 mojo::ReportBadMessage(kInvalidOrigin); | 165 mojo::ReportBadMessage(kInvalidOrigin); |
| 171 return; | 166 return; |
| 172 } | 167 } |
| 173 | 168 |
| 174 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 169 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 175 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 170 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 176 idb_runner_->PostTask( | 171 IDBTaskRunner()->PostTask( |
| 177 FROM_HERE, base::Bind(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, | 172 FROM_HERE, base::Bind(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, |
| 178 base::Unretained(idb_helper_), | 173 base::Unretained(idb_helper_), |
| 179 base::Passed(&callbacks), origin)); | 174 base::Passed(&callbacks), origin)); |
| 180 } | 175 } |
| 181 | 176 |
| 182 void IndexedDBDispatcherHost::Open( | 177 void IndexedDBDispatcherHost::Open( |
| 183 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 178 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 184 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo | 179 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo |
| 185 database_callbacks_info, | 180 database_callbacks_info, |
| 186 const url::Origin& origin, | 181 const url::Origin& origin, |
| 187 const base::string16& name, | 182 const base::string16& name, |
| 188 int64_t version, | 183 int64_t version, |
| 189 int64_t transaction_id) { | 184 int64_t transaction_id) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 185 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 191 | 186 |
| 192 if (!IsValidOrigin(origin)) { | 187 if (!IsValidOrigin(origin)) { |
| 193 mojo::ReportBadMessage(kInvalidOrigin); | 188 mojo::ReportBadMessage(kInvalidOrigin); |
| 194 return; | 189 return; |
| 195 } | 190 } |
| 196 | 191 |
| 197 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 192 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 198 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 193 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 199 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( | 194 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( |
| 200 new IndexedDBDatabaseCallbacks(indexed_db_context_, | 195 new IndexedDBDatabaseCallbacks(indexed_db_context_, |
| 201 std::move(database_callbacks_info))); | 196 std::move(database_callbacks_info))); |
| 202 idb_runner_->PostTask( | 197 IDBTaskRunner()->PostTask( |
| 203 FROM_HERE, | 198 FROM_HERE, |
| 204 base::Bind(&IDBSequenceHelper::OpenOnIDBThread, | 199 base::Bind(&IDBSequenceHelper::OpenOnIDBThread, |
| 205 base::Unretained(idb_helper_), base::Passed(&callbacks), | 200 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 206 base::Passed(&database_callbacks), origin, name, version, | 201 base::Passed(&database_callbacks), origin, name, version, |
| 207 transaction_id)); | 202 transaction_id)); |
| 208 } | 203 } |
| 209 | 204 |
| 210 void IndexedDBDispatcherHost::DeleteDatabase( | 205 void IndexedDBDispatcherHost::DeleteDatabase( |
| 211 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 206 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 212 const url::Origin& origin, | 207 const url::Origin& origin, |
| 213 const base::string16& name, | 208 const base::string16& name, |
| 214 bool force_close) { | 209 bool force_close) { |
| 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 210 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 216 | 211 |
| 217 if (!IsValidOrigin(origin)) { | 212 if (!IsValidOrigin(origin)) { |
| 218 mojo::ReportBadMessage(kInvalidOrigin); | 213 mojo::ReportBadMessage(kInvalidOrigin); |
| 219 return; | 214 return; |
| 220 } | 215 } |
| 221 | 216 |
| 222 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 217 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 223 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); | 218 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner())); |
| 224 idb_runner_->PostTask( | 219 IDBTaskRunner()->PostTask( |
| 225 FROM_HERE, | 220 FROM_HERE, |
| 226 base::Bind(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, | 221 base::Bind(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, |
| 227 base::Unretained(idb_helper_), base::Passed(&callbacks), | 222 base::Unretained(idb_helper_), base::Passed(&callbacks), |
| 228 origin, name, force_close)); | 223 origin, name, force_close)); |
| 229 } | 224 } |
| 230 | 225 |
| 231 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { | 226 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { |
| 232 weak_factory_.InvalidateWeakPtrs(); | 227 weak_factory_.InvalidateWeakPtrs(); |
| 233 cursor_bindings_.CloseAllBindings(); | 228 cursor_bindings_.CloseAllBindings(); |
| 234 database_bindings_.CloseAllBindings(); | 229 database_bindings_.CloseAllBindings(); |
| 235 } | 230 } |
| 236 | 231 |
| 232 base::SequencedTaskRunner* IndexedDBDispatcherHost::IDBTaskRunner() const { |
| 233 return indexed_db_context_->TaskRunner(); |
| 234 } |
| 235 |
| 237 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( | 236 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( |
| 238 scoped_refptr<IndexedDBCallbacks> callbacks, | 237 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 239 const url::Origin& origin) { | 238 const url::Origin& origin) { |
| 240 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 239 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 241 | 240 |
| 242 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 241 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 243 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( | 242 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( |
| 244 callbacks, origin, indexed_db_path, request_context_getter_); | 243 callbacks, origin, indexed_db_path, request_context_getter_); |
| 245 } | 244 } |
| 246 | 245 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 277 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); | 276 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); |
| 278 | 277 |
| 279 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 278 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 280 DCHECK(request_context_getter_); | 279 DCHECK(request_context_getter_); |
| 281 indexed_db_context_->GetIDBFactory()->DeleteDatabase( | 280 indexed_db_context_->GetIDBFactory()->DeleteDatabase( |
| 282 name, request_context_getter_, callbacks, origin, indexed_db_path, | 281 name, request_context_getter_, callbacks, origin, indexed_db_path, |
| 283 force_close); | 282 force_close); |
| 284 } | 283 } |
| 285 | 284 |
| 286 } // namespace content | 285 } // namespace content |
| OLD | NEW |