Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
|
jsbell
2014/06/09 16:38:27
need to include WebIDBTypes.h
Pritam Nikam
2014/06/11 14:05:16
Done.
| |
| 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_.size()); | 16 DCHECK(!queued_transactions_.size()); |
| 17 DCHECK(!started_transactions_.size()); | 17 DCHECK(!started_transactions_.size()); |
| 18 } | 18 } |
| 19 | 19 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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() | 43 bool IndexedDBTransactionCoordinator::IsRunningVersionChangeTransaction() |
| 44 const { | 44 const { |
| 45 return !started_transactions_.empty() && | 45 return !started_transactions_.empty() && |
| 46 (*started_transactions_.begin())->mode() == | 46 (*started_transactions_.begin())->mode() == |
| 47 indexed_db::TRANSACTION_VERSION_CHANGE; | 47 blink::TransactionVersionChange; |
| 48 } | 48 } |
| 49 | 49 |
| 50 #ifndef NDEBUG | 50 #ifndef NDEBUG |
| 51 // Verifies internal consistency while returning whether anything is found. | 51 // Verifies internal consistency while returning whether anything is found. |
| 52 bool IndexedDBTransactionCoordinator::IsActive( | 52 bool IndexedDBTransactionCoordinator::IsActive( |
| 53 IndexedDBTransaction* transaction) { | 53 IndexedDBTransaction* transaction) { |
| 54 bool found = false; | 54 bool found = false; |
| 55 if (queued_transactions_.count(transaction)) | 55 if (queued_transactions_.count(transaction)) |
| 56 found = true; | 56 found = true; |
| 57 if (started_transactions_.count(transaction)) { | 57 if (started_transactions_.count(transaction)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 // running read/write transactions. Other read-write transactions with | 90 // running read/write transactions. Other read-write transactions with |
| 91 // 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, |
| 92 // taking a snapshot of the database, which does not include uncommitted | 92 // taking a snapshot of the database, which does not include uncommitted |
| 93 // data. ("Version change" transactions are exclusive, but handled by the | 93 // data. ("Version change" transactions are exclusive, but handled by the |
| 94 // connection sequencing in IndexedDBDatabase.) | 94 // connection sequencing in IndexedDBDatabase.) |
| 95 std::set<int64> locked_scope; | 95 std::set<int64> locked_scope; |
| 96 for (TransactionSet::const_iterator it = started_transactions_.begin(); | 96 for (TransactionSet::const_iterator it = started_transactions_.begin(); |
| 97 it != started_transactions_.end(); | 97 it != started_transactions_.end(); |
| 98 ++it) { | 98 ++it) { |
| 99 IndexedDBTransaction* transaction = *it; | 99 IndexedDBTransaction* transaction = *it; |
| 100 if (transaction->mode() == indexed_db::TRANSACTION_READ_WRITE) { | 100 if (transaction->mode() == blink::TransactionReadWrite) { |
| 101 // Started read/write transactions have exclusive access to the object | 101 // Started read/write transactions have exclusive access to the object |
| 102 // stores within their scopes. | 102 // stores within their scopes. |
| 103 locked_scope.insert(transaction->scope().begin(), | 103 locked_scope.insert(transaction->scope().begin(), |
| 104 transaction->scope().end()); | 104 transaction->scope().end()); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 TransactionSet::const_iterator it = queued_transactions_.begin(); | 108 TransactionSet::const_iterator it = queued_transactions_.begin(); |
| 109 while (it != queued_transactions_.end()) { | 109 while (it != queued_transactions_.end()) { |
| 110 scoped_refptr<IndexedDBTransaction> transaction = *it; | 110 scoped_refptr<IndexedDBTransaction> transaction = *it; |
| 111 ++it; | 111 ++it; |
| 112 if (CanStartTransaction(transaction, locked_scope)) { | 112 if (CanStartTransaction(transaction, locked_scope)) { |
| 113 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); | 113 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); |
| 114 queued_transactions_.erase(transaction); | 114 queued_transactions_.erase(transaction); |
| 115 started_transactions_.insert(transaction); | 115 started_transactions_.insert(transaction); |
| 116 transaction->Start(); | 116 transaction->Start(); |
| 117 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 117 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 118 } | 118 } |
| 119 if (transaction->mode() == indexed_db::TRANSACTION_READ_WRITE) { | 119 if (transaction->mode() == blink::TransactionReadWrite) { |
| 120 // Either the transaction started, so it has exclusive access to the | 120 // Either the transaction started, so it has exclusive access to the |
| 121 // stores in its scope, or per the spec the transaction which was | 121 // stores in its scope, or per the spec the transaction which was |
| 122 // created first must get access first, so the stores are also locked. | 122 // created first must get access first, so the stores are also locked. |
| 123 locked_scope.insert(transaction->scope().begin(), | 123 locked_scope.insert(transaction->scope().begin(), |
| 124 transaction->scope().end()); | 124 transaction->scope().end()); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 template<typename T> | 129 template<typename T> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool IndexedDBTransactionCoordinator::CanStartTransaction( | 145 bool IndexedDBTransactionCoordinator::CanStartTransaction( |
| 146 IndexedDBTransaction* const transaction, | 146 IndexedDBTransaction* const transaction, |
| 147 const std::set<int64>& locked_scope) const { | 147 const std::set<int64>& locked_scope) const { |
| 148 DCHECK(queued_transactions_.count(transaction)); | 148 DCHECK(queued_transactions_.count(transaction)); |
| 149 switch (transaction->mode()) { | 149 switch (transaction->mode()) { |
| 150 case indexed_db::TRANSACTION_VERSION_CHANGE: | 150 case blink::TransactionVersionChange: |
| 151 DCHECK_EQ(1u, queued_transactions_.size()); | 151 DCHECK_EQ(1u, queued_transactions_.size()); |
| 152 DCHECK(started_transactions_.empty()); | 152 DCHECK(started_transactions_.empty()); |
| 153 DCHECK(locked_scope.empty()); | 153 DCHECK(locked_scope.empty()); |
| 154 return true; | 154 return true; |
| 155 | 155 |
| 156 case indexed_db::TRANSACTION_READ_ONLY: | 156 case blink::TransactionReadOnly: |
| 157 return true; | 157 return true; |
| 158 | 158 |
| 159 case indexed_db::TRANSACTION_READ_WRITE: | 159 case blink::TransactionReadWrite: |
| 160 return !DoSetsIntersect(transaction->scope(), locked_scope); | 160 return !DoSetsIntersect(transaction->scope(), locked_scope); |
| 161 } | 161 } |
| 162 NOTREACHED(); | 162 NOTREACHED(); |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace content | 166 } // namespace content |
| OLD | NEW |