| 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 #include "third_party/WebKit/public/platform/WebIDBTypes.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 std::vector<const IndexedDBTransaction*> | 66 std::vector<const IndexedDBTransaction*> |
| 67 IndexedDBTransactionCoordinator::GetTransactions() const { | 67 IndexedDBTransactionCoordinator::GetTransactions() const { |
| 68 std::vector<const IndexedDBTransaction*> result; | 68 std::vector<const IndexedDBTransaction*> result; |
| 69 | 69 |
| 70 for (TransactionSet::const_iterator it = started_transactions_.begin(); | 70 for (TransactionSet::const_iterator it = started_transactions_.begin(); |
| 71 it != started_transactions_.end(); | 71 it != started_transactions_.end(); |
| 72 ++it) { | 72 ++it) { |
| 73 result.push_back(*it); | 73 result.push_back(it->get()); |
| 74 } | 74 } |
| 75 for (TransactionSet::const_iterator it = queued_transactions_.begin(); | 75 for (TransactionSet::const_iterator it = queued_transactions_.begin(); |
| 76 it != queued_transactions_.end(); | 76 it != queued_transactions_.end(); |
| 77 ++it) { | 77 ++it) { |
| 78 result.push_back(*it); | 78 result.push_back(it->get()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 return result; | 81 return result; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { | 84 void IndexedDBTransactionCoordinator::ProcessQueuedTransactions() { |
| 85 if (queued_transactions_.empty()) | 85 if (queued_transactions_.empty()) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 DCHECK(!IsRunningVersionChangeTransaction()); | 88 DCHECK(!IsRunningVersionChangeTransaction()); |
| 89 | 89 |
| 90 // The locked_scope set accumulates the ids of object stores in the scope of | 90 // The locked_scope set accumulates the ids of object stores in the scope of |
| 91 // running read/write transactions. Other read-write transactions with | 91 // running read/write transactions. Other read-write transactions with |
| 92 // 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, |
| 93 // taking a snapshot of the database, which does not include uncommitted | 93 // taking a snapshot of the database, which does not include uncommitted |
| 94 // data. ("Version change" transactions are exclusive, but handled by the | 94 // data. ("Version change" transactions are exclusive, but handled by the |
| 95 // connection sequencing in IndexedDBDatabase.) | 95 // connection sequencing in IndexedDBDatabase.) |
| 96 std::set<int64> locked_scope; | 96 std::set<int64> locked_scope; |
| 97 for (TransactionSet::const_iterator it = started_transactions_.begin(); | 97 for (TransactionSet::const_iterator it = started_transactions_.begin(); |
| 98 it != started_transactions_.end(); | 98 it != started_transactions_.end(); |
| 99 ++it) { | 99 ++it) { |
| 100 IndexedDBTransaction* transaction = *it; | 100 IndexedDBTransaction* transaction = it->get(); |
| 101 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { | 101 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { |
| 102 // Started read/write transactions have exclusive access to the object | 102 // Started read/write transactions have exclusive access to the object |
| 103 // stores within their scopes. | 103 // stores within their scopes. |
| 104 locked_scope.insert(transaction->scope().begin(), | 104 locked_scope.insert(transaction->scope().begin(), |
| 105 transaction->scope().end()); | 105 transaction->scope().end()); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 TransactionSet::const_iterator it = queued_transactions_.begin(); | 109 TransactionSet::const_iterator it = queued_transactions_.begin(); |
| 110 while (it != queued_transactions_.end()) { | 110 while (it != queued_transactions_.end()) { |
| 111 scoped_refptr<IndexedDBTransaction> transaction = *it; | 111 scoped_refptr<IndexedDBTransaction> transaction = *it; |
| 112 ++it; | 112 ++it; |
| 113 if (CanStartTransaction(transaction, locked_scope)) { | 113 if (CanStartTransaction(transaction.get(), locked_scope)) { |
| 114 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); | 114 DCHECK_EQ(IndexedDBTransaction::CREATED, transaction->state()); |
| 115 queued_transactions_.erase(transaction); | 115 queued_transactions_.erase(transaction); |
| 116 started_transactions_.insert(transaction); | 116 started_transactions_.insert(transaction); |
| 117 transaction->Start(); | 117 transaction->Start(); |
| 118 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); | 118 DCHECK_EQ(IndexedDBTransaction::STARTED, transaction->state()); |
| 119 } | 119 } |
| 120 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { | 120 if (transaction->mode() == blink::WebIDBTransactionModeReadWrite) { |
| 121 // Either the transaction started, so it has exclusive access to the | 121 // Either the transaction started, so it has exclusive access to the |
| 122 // 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 |
| 123 // 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. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 return true; | 158 return true; |
| 159 | 159 |
| 160 case blink::WebIDBTransactionModeReadWrite: | 160 case blink::WebIDBTransactionModeReadWrite: |
| 161 return !DoSetsIntersect(transaction->scope(), locked_scope); | 161 return !DoSetsIntersect(transaction->scope(), locked_scope); |
| 162 } | 162 } |
| 163 NOTREACHED(); | 163 NOTREACHED(); |
| 164 return false; | 164 return false; |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace content | 167 } // namespace content |
| OLD | NEW |