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

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

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: comments Created 4 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
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/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/indexed_db/indexed_db_transaction.h" 8 #include "content/browser/indexed_db/indexed_db_transaction.h"
9 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 9 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 IndexedDBTransactionCoordinator::IndexedDBTransactionCoordinator() {} 13 IndexedDBTransactionCoordinator::IndexedDBTransactionCoordinator() {}
14 14
15 IndexedDBTransactionCoordinator::~IndexedDBTransactionCoordinator() { 15 IndexedDBTransactionCoordinator::~IndexedDBTransactionCoordinator() {
16 DCHECK(queued_transactions_.empty()); 16 DCHECK(queued_transactions_.empty());
17 DCHECK(started_transactions_.empty()); 17 DCHECK(started_transactions_.empty());
18 } 18 }
19 19
20 void IndexedDBTransactionCoordinator::DidCreateTransaction( 20 void IndexedDBTransactionCoordinator::DidCreateTransaction(
21 scoped_refptr<IndexedDBTransaction> transaction) { 21 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 IndexedDBTransaction* transaction) { 31 IndexedDBTransaction* transaction) {
(...skipping 26 matching lines...) Expand all
58 DCHECK(!found); 58 DCHECK(!found);
59 found = true; 59 found = true;
60 } 60 }
61 return found; 61 return found;
62 } 62 }
63 #endif 63 #endif
64 64
65 std::vector<const IndexedDBTransaction*> 65 std::vector<const IndexedDBTransaction*>
66 IndexedDBTransactionCoordinator::GetTransactions() const { 66 IndexedDBTransactionCoordinator::GetTransactions() const {
67 std::vector<const IndexedDBTransaction*> result; 67 std::vector<const IndexedDBTransaction*> result;
68 68 result.reserve(started_transactions_.size() + queued_transactions_.size());
69 for (const auto& transaction : started_transactions_) 69 result.insert(result.end(), started_transactions_.begin(),
sof 2016/12/05 20:00:20 Somewhat odd, but I'm running into compilation bre
jsbell 2016/12/06 00:00:47 Weird - I haven't heard any other reports. list_
70 result.push_back(transaction.get()); 70 started_transactions_.end());
71 for (const auto& transaction : queued_transactions_) 71 result.insert(result.end(), queued_transactions_.begin(),
72 result.push_back(transaction.get()); 72 queued_transactions_.end());
73
74 return result; 73 return result;
75 } 74 }
76 75
77 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { 76 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() {
78 if (queued_transactions_.empty()) 77 if (queued_transactions_.empty())
79 return; 78 return;
80 79
81 DCHECK(!IsRunningVersionChangeTransaction()); 80 DCHECK(!IsRunningVersionChangeTransaction());
82 81
83 // The locked_scope set accumulates the ids of object stores in the scope of 82 // The locked_scope set accumulates the ids of object stores in the scope of
84 // running read/write transactions. Other read-write transactions with 83 // running read/write transactions. Other read-write transactions with
85 // stores in this set may not be started. Read-only transactions may start, 84 // stores in this set may not be started. Read-only transactions may start,
86 // taking a snapshot of the database, which does not include uncommitted 85 // taking a snapshot of the database, which does not include uncommitted
87 // data. ("Version change" transactions are exclusive, but handled by the 86 // data. ("Version change" transactions are exclusive, but handled by the
88 // connection sequencing in IndexedDBDatabase.) 87 // connection sequencing in IndexedDBDatabase.)
89 std::set<int64_t> locked_scope; 88 std::set<int64_t> locked_scope;
90 for (const auto& transaction : started_transactions_) { 89 for (const auto& transaction : started_transactions_) {
91 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { 90 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) {
92 // Started read/write transactions have exclusive access to the object 91 // Started read/write transactions have exclusive access to the object
93 // stores within their scopes. 92 // stores within their scopes.
94 locked_scope.insert(transaction->scope().begin(), 93 locked_scope.insert(transaction->scope().begin(),
95 transaction->scope().end()); 94 transaction->scope().end());
96 } 95 }
97 } 96 }
98 97
99 auto it = queued_transactions_.begin(); 98 auto it = queued_transactions_.begin();
100 while (it != queued_transactions_.end()) { 99 while (it != queued_transactions_.end()) {
101 scoped_refptr<IndexedDBTransaction> transaction = *it; 100 IndexedDBTransaction* transaction = *it;
102 ++it; 101 ++it;
103 if (CanStartTransaction(transaction.get(), locked_scope)) { 102 if (CanStartTransaction(transaction, locked_scope)) {
104 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); 103 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state());
105 queued_transactions_.erase(transaction); 104 queued_transactions_.erase(transaction);
106 started_transactions_.insert(transaction); 105 started_transactions_.insert(transaction);
107 transaction->Start(); 106 transaction->Start();
108 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); 107 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state());
109 } 108 }
110 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { 109 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) {
111 // Either the transaction started, so it has exclusive access to the 110 // Either the transaction started, so it has exclusive access to the
112 // stores in its scope, or per the spec the transaction which was 111 // stores in its scope, or per the spec the transaction which was
113 // created first must get access first, so the stores are also locked. 112 // created first must get access first, so the stores are also locked.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 145
147 case blink::WebIDBTransactionModeReadOnly: 146 case blink::WebIDBTransactionModeReadOnly:
148 case blink::WebIDBTransactionModeReadWrite: 147 case blink::WebIDBTransactionModeReadWrite:
149 return !DoSetsIntersect(transaction->scope(), locked_scope); 148 return !DoSetsIntersect(transaction->scope(), locked_scope);
150 } 149 }
151 NOTREACHED(); 150 NOTREACHED();
152 return false; 151 return false;
153 } 152 }
154 153
155 } // namespace content 154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698