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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.cc

Issue 2930183002: Let IndexedDBContextImpl create its own task runner (Closed)
Patch Set: rebased Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper); 125 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper);
126 }; 126 };
127 127
128 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 128 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
129 int ipc_process_id, 129 int ipc_process_id,
130 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 130 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
131 scoped_refptr<IndexedDBContextImpl> indexed_db_context, 131 scoped_refptr<IndexedDBContextImpl> indexed_db_context,
132 scoped_refptr<ChromeBlobStorageContext> blob_storage_context) 132 scoped_refptr<ChromeBlobStorageContext> blob_storage_context)
133 : indexed_db_context_(std::move(indexed_db_context)), 133 : indexed_db_context_(std::move(indexed_db_context)),
134 blob_storage_context_(std::move(blob_storage_context)), 134 blob_storage_context_(std::move(blob_storage_context)),
135 idb_runner_(indexed_db_context_->TaskRunner()),
136 ipc_process_id_(ipc_process_id), 135 ipc_process_id_(ipc_process_id),
136 idb_helper_(new IDBSequenceHelper(ipc_process_id_,
137 std::move(request_context_getter),
138 indexed_db_context_)),
137 weak_factory_(this) { 139 weak_factory_(this) {
138 // Can be null in unittests.
139 idb_helper_ = idb_runner_
140 ? new IDBSequenceHelper(ipc_process_id_,
141 std::move(request_context_getter),
142 indexed_db_context_)
143 : nullptr;
144 DCHECK(indexed_db_context_.get()); 140 DCHECK(indexed_db_context_.get());
145 } 141 }
146 142
147 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { 143 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {
148 if (idb_helper_) 144 IDBTaskRunner()->DeleteSoon(FROM_HERE, idb_helper_);
149 idb_runner_->DeleteSoon(FROM_HERE, idb_helper_);
150 } 145 }
151 146
152 void IndexedDBDispatcherHost::AddBinding( 147 void IndexedDBDispatcherHost::AddBinding(
153 ::indexed_db::mojom::FactoryAssociatedRequest request) { 148 ::indexed_db::mojom::FactoryAssociatedRequest request) {
154 bindings_.AddBinding(this, std::move(request)); 149 bindings_.AddBinding(this, std::move(request));
155 } 150 }
156 151
157 void IndexedDBDispatcherHost::AddDatabaseBinding( 152 void IndexedDBDispatcherHost::AddDatabaseBinding(
158 std::unique_ptr<::indexed_db::mojom::Database> database, 153 std::unique_ptr<::indexed_db::mojom::Database> database,
159 ::indexed_db::mojom::DatabaseAssociatedRequest request) { 154 ::indexed_db::mojom::DatabaseAssociatedRequest request) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 218 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
224 const url::Origin& origin) { 219 const url::Origin& origin) {
225 DCHECK_CURRENTLY_ON(BrowserThread::IO); 220 DCHECK_CURRENTLY_ON(BrowserThread::IO);
226 221
227 if (!IsValidOrigin(origin)) { 222 if (!IsValidOrigin(origin)) {
228 mojo::ReportBadMessage(kInvalidOrigin); 223 mojo::ReportBadMessage(kInvalidOrigin);
229 return; 224 return;
230 } 225 }
231 226
232 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 227 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
233 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); 228 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner()));
234 idb_runner_->PostTask( 229 IDBTaskRunner()->PostTask(
235 FROM_HERE, base::BindOnce(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread, 230 FROM_HERE, base::BindOnce(&IDBSequenceHelper::GetDatabaseNamesOnIDBThread,
236 base::Unretained(idb_helper_), 231 base::Unretained(idb_helper_),
237 base::Passed(&callbacks), origin)); 232 base::Passed(&callbacks), origin));
238 } 233 }
239 234
240 void IndexedDBDispatcherHost::Open( 235 void IndexedDBDispatcherHost::Open(
241 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 236 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
242 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo 237 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo
243 database_callbacks_info, 238 database_callbacks_info,
244 const url::Origin& origin, 239 const url::Origin& origin,
245 const base::string16& name, 240 const base::string16& name,
246 int64_t version, 241 int64_t version,
247 int64_t transaction_id) { 242 int64_t transaction_id) {
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); 243 DCHECK_CURRENTLY_ON(BrowserThread::IO);
249 244
250 if (!IsValidOrigin(origin)) { 245 if (!IsValidOrigin(origin)) {
251 mojo::ReportBadMessage(kInvalidOrigin); 246 mojo::ReportBadMessage(kInvalidOrigin);
252 return; 247 return;
253 } 248 }
254 249
255 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 250 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
256 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); 251 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner()));
257 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks( 252 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks(
258 new IndexedDBDatabaseCallbacks(indexed_db_context_, 253 new IndexedDBDatabaseCallbacks(indexed_db_context_,
259 std::move(database_callbacks_info))); 254 std::move(database_callbacks_info)));
260 idb_runner_->PostTask( 255 IDBTaskRunner()->PostTask(
261 FROM_HERE, 256 FROM_HERE,
262 base::BindOnce(&IDBSequenceHelper::OpenOnIDBThread, 257 base::BindOnce(&IDBSequenceHelper::OpenOnIDBThread,
263 base::Unretained(idb_helper_), base::Passed(&callbacks), 258 base::Unretained(idb_helper_), base::Passed(&callbacks),
264 base::Passed(&database_callbacks), origin, name, version, 259 base::Passed(&database_callbacks), origin, name, version,
265 transaction_id)); 260 transaction_id));
266 } 261 }
267 262
268 void IndexedDBDispatcherHost::DeleteDatabase( 263 void IndexedDBDispatcherHost::DeleteDatabase(
269 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 264 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
270 const url::Origin& origin, 265 const url::Origin& origin,
271 const base::string16& name, 266 const base::string16& name,
272 bool force_close) { 267 bool force_close) {
273 DCHECK_CURRENTLY_ON(BrowserThread::IO); 268 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274 269
275 if (!IsValidOrigin(origin)) { 270 if (!IsValidOrigin(origin)) {
276 mojo::ReportBadMessage(kInvalidOrigin); 271 mojo::ReportBadMessage(kInvalidOrigin);
277 return; 272 return;
278 } 273 }
279 274
280 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 275 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
281 this->AsWeakPtr(), origin, std::move(callbacks_info), idb_runner_)); 276 this->AsWeakPtr(), origin, std::move(callbacks_info), IDBTaskRunner()));
282 idb_runner_->PostTask( 277 IDBTaskRunner()->PostTask(
283 FROM_HERE, 278 FROM_HERE,
284 base::BindOnce(&IDBSequenceHelper::DeleteDatabaseOnIDBThread, 279 base::BindOnce(&IDBSequenceHelper::DeleteDatabaseOnIDBThread,
285 base::Unretained(idb_helper_), base::Passed(&callbacks), 280 base::Unretained(idb_helper_), base::Passed(&callbacks),
286 origin, name, force_close)); 281 origin, name, force_close));
287 } 282 }
288 283
289 void IndexedDBDispatcherHost::AbortTransactionsAndCompactDatabase( 284 void IndexedDBDispatcherHost::AbortTransactionsAndCompactDatabase(
290 const url::Origin& origin, 285 const url::Origin& origin,
291 AbortTransactionsAndCompactDatabaseCallback mojo_callback) { 286 AbortTransactionsAndCompactDatabaseCallback mojo_callback) {
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); 287 DCHECK_CURRENTLY_ON(BrowserThread::IO);
293 288
294 if (!IsValidOrigin(origin)) { 289 if (!IsValidOrigin(origin)) {
295 mojo::ReportBadMessage(kInvalidOrigin); 290 mojo::ReportBadMessage(kInvalidOrigin);
296 return; 291 return;
297 } 292 }
298 293
299 base::OnceCallback<void(leveldb::Status)> callback_on_io = base::BindOnce( 294 base::OnceCallback<void(leveldb::Status)> callback_on_io = base::BindOnce(
300 &CallCompactionStatusCallbackOnIOThread, 295 &CallCompactionStatusCallbackOnIOThread,
301 base::ThreadTaskRunnerHandle::Get(), std::move(mojo_callback)); 296 base::ThreadTaskRunnerHandle::Get(), std::move(mojo_callback));
302 idb_runner_->PostTask( 297 IDBTaskRunner()->PostTask(
303 FROM_HERE, 298 FROM_HERE,
304 base::BindOnce( 299 base::BindOnce(
305 &IDBSequenceHelper::AbortTransactionsAndCompactDatabaseOnIDBThread, 300 &IDBSequenceHelper::AbortTransactionsAndCompactDatabaseOnIDBThread,
306 base::Unretained(idb_helper_), base::Passed(&callback_on_io), 301 base::Unretained(idb_helper_), base::Passed(&callback_on_io),
307 origin)); 302 origin));
308 } 303 }
309 304
310 void IndexedDBDispatcherHost::AbortTransactionsForDatabase( 305 void IndexedDBDispatcherHost::AbortTransactionsForDatabase(
311 const url::Origin& origin, 306 const url::Origin& origin,
312 AbortTransactionsForDatabaseCallback mojo_callback) { 307 AbortTransactionsForDatabaseCallback mojo_callback) {
313 DCHECK_CURRENTLY_ON(BrowserThread::IO); 308 DCHECK_CURRENTLY_ON(BrowserThread::IO);
314 309
315 if (!IsValidOrigin(origin)) { 310 if (!IsValidOrigin(origin)) {
316 mojo::ReportBadMessage(kInvalidOrigin); 311 mojo::ReportBadMessage(kInvalidOrigin);
317 return; 312 return;
318 } 313 }
319 314
320 base::OnceCallback<void(leveldb::Status)> callback_on_io = base::BindOnce( 315 base::OnceCallback<void(leveldb::Status)> callback_on_io = base::BindOnce(
321 &CallAbortStatusCallbackOnIOThread, base::ThreadTaskRunnerHandle::Get(), 316 &CallAbortStatusCallbackOnIOThread, base::ThreadTaskRunnerHandle::Get(),
322 std::move(mojo_callback)); 317 std::move(mojo_callback));
323 idb_runner_->PostTask( 318 IDBTaskRunner()->PostTask(
324 FROM_HERE, 319 FROM_HERE,
325 base::BindOnce( 320 base::BindOnce(
326 &IDBSequenceHelper::AbortTransactionsForDatabaseOnIDBThread, 321 &IDBSequenceHelper::AbortTransactionsForDatabaseOnIDBThread,
327 base::Unretained(idb_helper_), base::Passed(&callback_on_io), 322 base::Unretained(idb_helper_), base::Passed(&callback_on_io),
328 origin)); 323 origin));
329 } 324 }
330 325
331 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() { 326 void IndexedDBDispatcherHost::InvalidateWeakPtrsAndClearBindings() {
332 weak_factory_.InvalidateWeakPtrs(); 327 weak_factory_.InvalidateWeakPtrs();
333 cursor_bindings_.CloseAllBindings(); 328 cursor_bindings_.CloseAllBindings();
334 database_bindings_.CloseAllBindings(); 329 database_bindings_.CloseAllBindings();
335 } 330 }
336 331
332 base::SequencedTaskRunner* IndexedDBDispatcherHost::IDBTaskRunner() const {
333 return indexed_db_context_->TaskRunner();
334 }
335
337 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread( 336 void IndexedDBDispatcherHost::IDBSequenceHelper::GetDatabaseNamesOnIDBThread(
338 scoped_refptr<IndexedDBCallbacks> callbacks, 337 scoped_refptr<IndexedDBCallbacks> callbacks,
339 const url::Origin& origin) { 338 const url::Origin& origin) {
340 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); 339 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence());
341 340
342 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 341 base::FilePath indexed_db_path = indexed_db_context_->data_path();
343 indexed_db_context_->GetIDBFactory()->GetDatabaseNames( 342 indexed_db_context_->GetIDBFactory()->GetDatabaseNames(
344 callbacks, origin, indexed_db_path, request_context_getter_); 343 callbacks, origin, indexed_db_path, request_context_getter_);
345 } 344 }
346 345
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 AbortTransactionsForDatabaseOnIDBThread( 396 AbortTransactionsForDatabaseOnIDBThread(
398 base::OnceCallback<void(leveldb::Status)> callback, 397 base::OnceCallback<void(leveldb::Status)> callback,
399 const url::Origin& origin) { 398 const url::Origin& origin) {
400 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence()); 399 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksInCurrentSequence());
401 400
402 indexed_db_context_->GetIDBFactory()->AbortTransactionsForDatabase( 401 indexed_db_context_->GetIDBFactory()->AbortTransactionsForDatabase(
403 std::move(callback), origin); 402 std::move(callback), origin);
404 } 403 }
405 404
406 } // namespace content 405 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698