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/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 Loading... | |
| 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 result.reserve(started_transactions_.size() + queued_transactions_.size()); | |
| 68 | 69 |
| 69 for (const auto& transaction : started_transactions_) | 70 for (const auto& transaction : started_transactions_) |
| 70 result.push_back(transaction.get()); | 71 result.push_back(transaction); |
|
jsbell
2016/11/04 17:48:19
Now that both types are raw pointers can this be r
dmurph
2016/11/04 22:52:25
Done.
| |
| 71 for (const auto& transaction : queued_transactions_) | 72 for (const auto& transaction : queued_transactions_) |
| 72 result.push_back(transaction.get()); | 73 result.push_back(transaction); |
| 73 | 74 |
| 74 return result; | 75 return result; |
| 75 } | 76 } |
| 76 | 77 |
| 77 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { | 78 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { |
| 78 if (queued_transactions_.empty()) | 79 if (queued_transactions_.empty()) |
| 79 return; | 80 return; |
| 80 | 81 |
| 81 DCHECK(!IsRunningVersionChangeTransaction()); | 82 DCHECK(!IsRunningVersionChangeTransaction()); |
| 82 | 83 |
| 83 // The locked_scope set accumulates the ids of object stores in the scope of | 84 // The locked_scope set accumulates the ids of object stores in the scope of |
| 84 // running read/write transactions. Other read-write transactions with | 85 // running read/write transactions. Other read-write transactions with |
| 85 // stores in this set may not be started. Read-only transactions may start, | 86 // 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 | 87 // taking a snapshot of the database, which does not include uncommitted |
| 87 // data. ("Version change" transactions are exclusive, but handled by the | 88 // data. ("Version change" transactions are exclusive, but handled by the |
| 88 // connection sequencing in IndexedDBDatabase.) | 89 // connection sequencing in IndexedDBDatabase.) |
| 89 std::set<int64_t> locked_scope; | 90 std::set<int64_t> locked_scope; |
| 90 for (const auto& transaction : started_transactions_) { | 91 for (const auto& transaction : started_transactions_) { |
| 91 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { | 92 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { |
| 92 // Started read/write transactions have exclusive access to the object | 93 // Started read/write transactions have exclusive access to the object |
| 93 // stores within their scopes. | 94 // stores within their scopes. |
| 94 locked_scope.insert(transaction->scope().begin(), | 95 locked_scope.insert(transaction->scope().begin(), |
| 95 transaction->scope().end()); | 96 transaction->scope().end()); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 auto it = queued_transactions_.begin(); | 100 auto it = queued_transactions_.begin(); |
| 100 while (it != queued_transactions_.end()) { | 101 while (it != queued_transactions_.end()) { |
| 101 scoped_refptr<IndexedDBTransaction> transaction = *it; | 102 IndexedDBTransaction* transaction = *it; |
| 102 ++it; | 103 ++it; |
| 103 if (CanStartTransaction(transaction.get(), locked_scope)) { | 104 if (CanStartTransaction(transaction, locked_scope)) { |
| 104 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); | 105 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); |
| 105 queued_transactions_.erase(transaction); | 106 queued_transactions_.erase(transaction); |
| 106 started_transactions_.insert(transaction); | 107 started_transactions_.insert(transaction); |
| 107 transaction->Start(); | 108 transaction->Start(); |
| 108 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 109 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 109 } | 110 } |
| 110 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { | 111 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { |
| 111 // Either the transaction started, so it has exclusive access to the | 112 // Either the transaction started, so it has exclusive access to the |
| 112 // stores in its scope, or per the spec the transaction which was | 113 // 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. | 114 // created first must get access first, so the stores are also locked. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 147 |
| 147 case blink::WebIDBTransactionModeReadOnly: | 148 case blink::WebIDBTransactionModeReadOnly: |
| 148 case blink::WebIDBTransactionModeReadWrite: | 149 case blink::WebIDBTransactionModeReadWrite: |
| 149 return !DoSetsIntersect(transaction->scope(), locked_scope); | 150 return !DoSetsIntersect(transaction->scope(), locked_scope); |
| 150 } | 151 } |
| 151 NOTREACHED(); | 152 NOTREACHED(); |
| 152 return false; | 153 return false; |
| 153 } | 154 } |
| 154 | 155 |
| 155 } // namespace content | 156 } // namespace content |
| OLD | NEW |