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

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

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding Observer Created 4 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_transaction.h" 5 #include "content/browser/indexed_db/indexed_db_transaction.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "content/browser/indexed_db/indexed_db_backing_store.h" 13 #include "content/browser/indexed_db/indexed_db_backing_store.h"
14 #include "content/browser/indexed_db/indexed_db_cursor.h" 14 #include "content/browser/indexed_db/indexed_db_cursor.h"
15 #include "content/browser/indexed_db/indexed_db_database.h" 15 #include "content/browser/indexed_db/indexed_db_database.h"
16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
17 #include "content/browser/indexed_db/indexed_db_observer.h"
17 #include "content/browser/indexed_db/indexed_db_tracing.h" 18 #include "content/browser/indexed_db/indexed_db_tracing.h"
18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" 19 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h"
19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
20 #include "third_party/leveldatabase/env_chromium.h" 21 #include "third_party/leveldatabase/env_chromium.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 const int64_t kInactivityTimeoutPeriodSeconds = 60; 25 const int64_t kInactivityTimeoutPeriodSeconds = 60;
25 26
26 IndexedDBTransaction::TaskQueue::TaskQueue() {} 27 IndexedDBTransaction::TaskQueue::TaskQueue() {}
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // released, and order is critical. 308 // released, and order is critical.
308 CloseOpenCursors(); 309 CloseOpenCursors();
309 transaction_->Reset(); 310 transaction_->Reset();
310 311
311 // Transactions must also be marked as completed before the 312 // Transactions must also be marked as completed before the
312 // front-end is notified, as the transaction completion unblocks 313 // front-end is notified, as the transaction completion unblocks
313 // operations like closing connections. 314 // operations like closing connections.
314 database_->transaction_coordinator().DidFinishTransaction(this); 315 database_->transaction_coordinator().DidFinishTransaction(this);
315 316
316 if (committed) { 317 if (committed) {
318 // TODO (palakj) : Send Observations to observers
319 if (!pending_observers_.empty())
320 AddActiveObserver();
317 abort_task_stack_.clear(); 321 abort_task_stack_.clear();
318 { 322 {
319 IDB_TRACE1( 323 IDB_TRACE1(
320 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", 324 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks",
321 "txn.id", id()); 325 "txn.id", id());
322 callbacks_->OnComplete(id_); 326 callbacks_->OnComplete(id_);
323 } 327 }
324 database_->TransactionFinished(this, true); 328 database_->TransactionFinished(this, true);
325 } else { 329 } else {
326 while (!abort_task_stack_.empty()) 330 while (!abort_task_stack_.empty())
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); 417 base::ASCIIToUTF16("Transaction timed out due to inactivity.")));
414 } 418 }
415 419
416 void IndexedDBTransaction::CloseOpenCursors() { 420 void IndexedDBTransaction::CloseOpenCursors() {
417 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); 421 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id());
418 for (auto* cursor : open_cursors_) 422 for (auto* cursor : open_cursors_)
419 cursor->Close(); 423 cursor->Close();
420 open_cursors_.clear(); 424 open_cursors_.clear();
421 } 425 }
422 426
427 void IndexedDBTransaction::AddPendingObserver(
428 std::unique_ptr<IndexedDBObserver> observer) {
429 pending_observers_.emplace_back(std::move(observer));
Marijn Kruisselbrink 2016/06/15 13:14:57 why emplace_back? You probably just want push_back
palakj1 2016/06/16 07:05:40 Changed. Never knew the difference between emplace
430 }
431
432 void IndexedDBTransaction::AddActiveObserver() {
433 for (size_t i = 0; i < pending_observers_.size(); i++) {
434 database_->active_observers_.emplace_back(std::move(pending_observers_[i]));
Marijn Kruisselbrink 2016/06/15 13:14:57 Same here, this should probably just be push_back
palakj1 2016/06/16 07:05:40 Done
435 }
436 }
437
423 } // namespace content 438 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698