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

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

Issue 110983004: IndexedDB: More database<->transaction relationship simplification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction_coordinator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_coordinator.h" 5 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/indexed_db/indexed_db_transaction.h" 9 #include "content/browser/indexed_db/indexed_db_transaction.h"
10 10
(...skipping 10 matching lines...) Expand all
21 scoped_refptr<IndexedDBTransaction> transaction) { 21 scoped_refptr<IndexedDBTransaction> transaction) {
22 DCHECK(!queued_transactions_.count(transaction)); 22 DCHECK(!queued_transactions_.count(transaction));
23 DCHECK(!started_transactions_.count(transaction)); 23 DCHECK(!started_transactions_.count(transaction));
24 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); 24 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state());
25 25
26 queued_transactions_.insert(transaction); 26 queued_transactions_.insert(transaction);
27 ProcessQueuedTransactions(); 27 ProcessQueuedTransactions();
28 } 28 }
29 29
30 void IndexedDBTransactionCoordinator::DidFinishTransaction( 30 void IndexedDBTransactionCoordinator::DidFinishTransaction(
31 scoped_refptr<IndexedDBTransaction> transaction) { 31 IndexedDBTransaction* transaction) {
32 if (queued_transactions_.count(transaction)) { 32 if (queued_transactions_.count(transaction)) {
33 DCHECK(!started_transactions_.count(transaction)); 33 DCHECK(!started_transactions_.count(transaction));
34 queued_transactions_.erase(transaction); 34 queued_transactions_.erase(transaction);
35 } else { 35 } else {
36 DCHECK(started_transactions_.count(transaction)); 36 DCHECK(started_transactions_.count(transaction));
37 started_transactions_.erase(transaction); 37 started_transactions_.erase(transaction);
38 } 38 }
39 39
40 ProcessQueuedTransactions(); 40 ProcessQueuedTransactions();
41 } 41 }
42 42
43 bool IndexedDBTransactionCoordinator::IsRunningVersionChangeTransaction()
44 const {
45 return !started_transactions_.empty() &&
46 (*started_transactions_.begin())->mode() ==
47 indexed_db::TRANSACTION_VERSION_CHANGE;
48 }
49
43 #ifndef NDEBUG 50 #ifndef NDEBUG
44 // Verifies internal consistency while returning whether anything is found. 51 // Verifies internal consistency while returning whether anything is found.
45 bool IndexedDBTransactionCoordinator::IsActive( 52 bool IndexedDBTransactionCoordinator::IsActive(
46 IndexedDBTransaction* transaction) { 53 IndexedDBTransaction* transaction) {
47 bool found = false; 54 bool found = false;
48 if (queued_transactions_.count(transaction)) 55 if (queued_transactions_.count(transaction))
49 found = true; 56 found = true;
50 if (started_transactions_.count(transaction)) { 57 if (started_transactions_.count(transaction)) {
51 DCHECK(!found); 58 DCHECK(!found);
52 found = true; 59 found = true;
(...skipping 17 matching lines...) Expand all
70 result.push_back(*it); 77 result.push_back(*it);
71 } 78 }
72 79
73 return result; 80 return result;
74 } 81 }
75 82
76 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { 83 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() {
77 if (queued_transactions_.empty()) 84 if (queued_transactions_.empty())
78 return; 85 return;
79 86
80 DCHECK(started_transactions_.empty() || 87 DCHECK(!IsRunningVersionChangeTransaction());
81 (*started_transactions_.begin())->mode() !=
82 indexed_db::TRANSACTION_VERSION_CHANGE);
83 88
84 // The locked_scope set accumulates the ids of object stores in the scope of 89 // The locked_scope set accumulates the ids of object stores in the scope of
85 // running read/write transactions. Other read-write transactions with 90 // running read/write transactions. Other read-write transactions with
86 // stores in this set may not be started. Read-only transactions may start, 91 // stores in this set may not be started. Read-only transactions may start,
87 // taking a snapshot of the database, which does not include uncommitted 92 // taking a snapshot of the database, which does not include uncommitted
88 // data. ("Version change" transactions are exclusive, but handled by the 93 // data. ("Version change" transactions are exclusive, but handled by the
89 // connection sequencing in IndexedDBDatabase.) 94 // connection sequencing in IndexedDBDatabase.)
90 std::set<int64> locked_scope; 95 std::set<int64> locked_scope;
91 for (TransactionSet::const_iterator it = started_transactions_.begin(); 96 for (TransactionSet::const_iterator it = started_transactions_.begin();
92 it != started_transactions_.end(); 97 it != started_transactions_.end();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return true; 157 return true;
153 158
154 case indexed_db::TRANSACTION_READ_WRITE: 159 case indexed_db::TRANSACTION_READ_WRITE:
155 return !DoSetsIntersect(transaction->scope(), locked_scope); 160 return !DoSetsIntersect(transaction->scope(), locked_scope);
156 } 161 }
157 NOTREACHED(); 162 NOTREACHED();
158 return false; 163 return false;
159 } 164 }
160 165
161 } // namespace content 166 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction_coordinator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698