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