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

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: Expected test results changed Created 4 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) 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/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
13 #include "content/browser/indexed_db/indexed_db_backing_store.h" 14 #include "content/browser/indexed_db/indexed_db_backing_store.h"
14 #include "content/browser/indexed_db/indexed_db_cursor.h" 15 #include "content/browser/indexed_db/indexed_db_cursor.h"
15 #include "content/browser/indexed_db/indexed_db_database.h" 16 #include "content/browser/indexed_db/indexed_db_database.h"
16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
18 #include "content/browser/indexed_db/indexed_db_observer.h"
17 #include "content/browser/indexed_db/indexed_db_tracing.h" 19 #include "content/browser/indexed_db/indexed_db_tracing.h"
18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" 20 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h"
19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
20 #include "third_party/leveldatabase/env_chromium.h" 22 #include "third_party/leveldatabase/env_chromium.h"
21 23
22 namespace content { 24 namespace content {
23 25
24 namespace { 26 namespace {
25 27
26 const int64_t kInactivityTimeoutPeriodSeconds = 60; 28 const int64_t kInactivityTimeoutPeriodSeconds = 60;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 61
60 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() { 62 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() {
61 DCHECK(!stack_.empty()); 63 DCHECK(!stack_.empty());
62 Operation task(stack_.top()); 64 Operation task(stack_.top());
63 stack_.pop(); 65 stack_.pop();
64 return task; 66 return task;
65 } 67 }
66 68
67 IndexedDBTransaction::IndexedDBTransaction( 69 IndexedDBTransaction::IndexedDBTransaction(
68 int64_t id, 70 int64_t id,
69 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, 71 base::WeakPtr<IndexedDBConnection> connection,
70 const std::set<int64_t>& object_store_ids, 72 const std::set<int64_t>& object_store_ids,
71 blink::WebIDBTransactionMode mode, 73 blink::WebIDBTransactionMode mode,
72 IndexedDBDatabase* database,
73 IndexedDBBackingStore::Transaction* backing_store_transaction) 74 IndexedDBBackingStore::Transaction* backing_store_transaction)
74 : id_(id), 75 : id_(id),
75 object_store_ids_(object_store_ids), 76 object_store_ids_(object_store_ids),
76 mode_(mode), 77 mode_(mode),
77 used_(false), 78 used_(false),
78 state_(CREATED), 79 state_(CREATED),
79 commit_pending_(false), 80 commit_pending_(false),
80 callbacks_(callbacks), 81 connection_(std::move(connection)),
81 database_(database),
82 transaction_(backing_store_transaction), 82 transaction_(backing_store_transaction),
83 backing_store_transaction_begun_(false), 83 backing_store_transaction_begun_(false),
84 should_process_queue_(false), 84 should_process_queue_(false),
85 pending_preemptive_events_(0) { 85 pending_preemptive_events_(0) {
86 callbacks_ = connection_->callbacks();
87 database_ = connection_->database();
88
86 database_->transaction_coordinator().DidCreateTransaction(this); 89 database_->transaction_coordinator().DidCreateTransaction(this);
87 90
88 diagnostics_.tasks_scheduled = 0; 91 diagnostics_.tasks_scheduled = 0;
89 diagnostics_.tasks_completed = 0; 92 diagnostics_.tasks_completed = 0;
90 diagnostics_.creation_time = base::Time::Now(); 93 diagnostics_.creation_time = base::Time::Now();
91 } 94 }
92 95
93 IndexedDBTransaction::~IndexedDBTransaction() { 96 IndexedDBTransaction::~IndexedDBTransaction() {
94 // It shouldn't be possible for this object to get deleted until it's either 97 // It shouldn't be possible for this object to get deleted until it's either
95 // complete or aborted. 98 // complete or aborted.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 #ifndef NDEBUG 187 #ifndef NDEBUG
185 DCHECK(!database_->transaction_coordinator().IsActive(this)); 188 DCHECK(!database_->transaction_coordinator().IsActive(this));
186 #endif 189 #endif
187 190
188 if (callbacks_.get()) 191 if (callbacks_.get())
189 callbacks_->OnAbort(id_, error); 192 callbacks_->OnAbort(id_, error);
190 193
191 database_->TransactionFinished(this, false); 194 database_->TransactionFinished(this, false);
192 195
193 database_ = NULL; 196 database_ = NULL;
197 connection_ = nullptr;
cmumford 2016/07/01 18:35:01 What about also calling: pending_observers_.cle
palakj1 2016/07/02 00:48:14 Done. Also adding a check in transaction destructo
194 } 198 }
195 199
196 bool IndexedDBTransaction::IsTaskQueueEmpty() const { 200 bool IndexedDBTransaction::IsTaskQueueEmpty() const {
197 return preemptive_task_queue_.empty() && task_queue_.empty(); 201 return preemptive_task_queue_.empty() && task_queue_.empty();
198 } 202 }
199 203
200 bool IndexedDBTransaction::HasPendingTasks() const { 204 bool IndexedDBTransaction::HasPendingTasks() const {
201 return pending_preemptive_events_ || !IsTaskQueueEmpty(); 205 return pending_preemptive_events_ || !IsTaskQueueEmpty();
202 } 206 }
203 207
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // released, and order is critical. 336 // released, and order is critical.
333 CloseOpenCursors(); 337 CloseOpenCursors();
334 transaction_->Reset(); 338 transaction_->Reset();
335 339
336 // Transactions must also be marked as completed before the 340 // Transactions must also be marked as completed before the
337 // front-end is notified, as the transaction completion unblocks 341 // front-end is notified, as the transaction completion unblocks
338 // operations like closing connections. 342 // operations like closing connections.
339 database_->transaction_coordinator().DidFinishTransaction(this); 343 database_->transaction_coordinator().DidFinishTransaction(this);
340 344
341 if (committed) { 345 if (committed) {
346 // TODO (palakj) : Send Observations to observers
347 if (!pending_observers_.empty() && connection_)
348 connection_->ActivatePendingObservers(std::move(pending_observers_));
342 abort_task_stack_.clear(); 349 abort_task_stack_.clear();
343 { 350 {
344 IDB_TRACE1( 351 IDB_TRACE1(
345 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", 352 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks",
346 "txn.id", id()); 353 "txn.id", id());
347 callbacks_->OnComplete(id_); 354 callbacks_->OnComplete(id_);
348 } 355 }
349 database_->TransactionFinished(this, true); 356 database_->TransactionFinished(this, true);
350 } else { 357 } else {
351 while (!abort_task_stack_.empty()) 358 while (!abort_task_stack_.empty())
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); 445 base::ASCIIToUTF16("Transaction timed out due to inactivity.")));
439 } 446 }
440 447
441 void IndexedDBTransaction::CloseOpenCursors() { 448 void IndexedDBTransaction::CloseOpenCursors() {
442 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); 449 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id());
443 for (auto* cursor : open_cursors_) 450 for (auto* cursor : open_cursors_)
444 cursor->Close(); 451 cursor->Close();
445 open_cursors_.clear(); 452 open_cursors_.clear();
446 } 453 }
447 454
455 void IndexedDBTransaction::AddPendingObserver(int32_t observer_id) {
456 pending_observers_.push_back(
457 base::WrapUnique(new IndexedDBObserver(observer_id)));
458 }
459
460 void IndexedDBTransaction::RemovePendingObservers(
461 const std::vector<int32_t>& pending_observer_ids) {
462 for (size_t i = 0; i < pending_observer_ids.size(); i++) {
cmumford 2016/07/01 18:35:01 Nit: I don't believe we have a rule on using itera
palakj1 2016/07/02 00:48:14 Changed. Used remove_if function instead to elimin
463 for (size_t j = 0; j < pending_observers_.size(); j++) {
464 if (pending_observers_[j]->id() == pending_observer_ids[i]) {
465 pending_observers_.erase(pending_observers_.begin() + j);
466 break;
467 }
468 }
469 }
470 }
471
448 } // namespace content 472 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698