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 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 IndexedDBTransaction* transaction = *it; | 98 IndexedDBTransaction* transaction = *it; |
99 ++it; | 99 ++it; |
100 if (CanRunTransaction(transaction)) { | 100 if (CanRunTransaction(transaction)) { |
101 queued_transactions_.erase(transaction); | 101 queued_transactions_.erase(transaction); |
102 started_transactions_.insert(transaction); | 102 started_transactions_.insert(transaction); |
103 transaction->Run(); | 103 transaction->Run(); |
104 } | 104 } |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 static bool DoScopesOverlap(const std::set<int64>& scope1, | 108 template<typename T> |
109 const std::set<int64>& scope2) { | 109 static bool DoSetsIntersect(const std::set<T>& set1, |
110 for (std::set<int64>::const_iterator it = scope1.begin(); it != scope1.end(); | 110 const std::set<T>& set2) { |
111 ++it) { | 111 typename std::set<T>::const_iterator it1 = set1.begin(); |
112 if (scope2.find(*it) != scope2.end()) | 112 typename std::set<T>::const_iterator it2 = set2.begin(); |
| 113 while (it1 != set1.end() && it2 != set2.end()) { |
| 114 if (*it1 < *it2) |
| 115 ++it1; |
| 116 else if (*it2 < *it1) |
| 117 ++it2; |
| 118 else |
113 return true; | 119 return true; |
114 } | 120 } |
115 return false; | 121 return false; |
116 } | 122 } |
117 | 123 |
118 bool IndexedDBTransactionCoordinator::CanRunTransaction( | 124 bool IndexedDBTransactionCoordinator::CanRunTransaction( |
119 IndexedDBTransaction* transaction) { | 125 IndexedDBTransaction* transaction) { |
120 DCHECK(queued_transactions_.has(transaction)); | 126 DCHECK(queued_transactions_.has(transaction)); |
121 switch (transaction->mode()) { | 127 switch (transaction->mode()) { |
122 case indexed_db::TRANSACTION_VERSION_CHANGE: | 128 case indexed_db::TRANSACTION_VERSION_CHANGE: |
123 DCHECK_EQ(static_cast<size_t>(1), queued_transactions_.size()); | 129 DCHECK_EQ(static_cast<size_t>(1), queued_transactions_.size()); |
124 DCHECK(started_transactions_.empty()); | 130 DCHECK(started_transactions_.empty()); |
125 return true; | 131 return true; |
126 | 132 |
127 case indexed_db::TRANSACTION_READ_ONLY: | 133 case indexed_db::TRANSACTION_READ_ONLY: |
128 return true; | 134 return true; |
129 | 135 |
130 case indexed_db::TRANSACTION_READ_WRITE: | 136 case indexed_db::TRANSACTION_READ_WRITE: |
131 for (list_set<IndexedDBTransaction*>::const_iterator it = | 137 for (list_set<IndexedDBTransaction*>::const_iterator it = |
132 started_transactions_.begin(); | 138 started_transactions_.begin(); |
133 it != started_transactions_.end(); | 139 it != started_transactions_.end(); |
134 ++it) { | 140 ++it) { |
135 IndexedDBTransaction* other = *it; | 141 IndexedDBTransaction* other = *it; |
136 if (other->mode() == indexed_db::TRANSACTION_READ_WRITE && | 142 if (other->mode() == indexed_db::TRANSACTION_READ_WRITE && |
137 DoScopesOverlap(transaction->scope(), other->scope())) | 143 DoSetsIntersect(transaction->scope(), other->scope())) |
138 return false; | 144 return false; |
139 } | 145 } |
140 for (list_set<IndexedDBTransaction*>::const_iterator it = | 146 for (list_set<IndexedDBTransaction*>::const_iterator it = |
141 queued_transactions_.begin(); | 147 queued_transactions_.begin(); |
142 *it != transaction; | 148 *it != transaction; |
143 ++it) { | 149 ++it) { |
144 DCHECK(it != queued_transactions_.end()); | 150 DCHECK(it != queued_transactions_.end()); |
145 IndexedDBTransaction* other = *it; | 151 IndexedDBTransaction* other = *it; |
146 if (other->mode() == indexed_db::TRANSACTION_READ_WRITE && | 152 if (other->mode() == indexed_db::TRANSACTION_READ_WRITE && |
147 DoScopesOverlap(transaction->scope(), other->scope())) | 153 DoSetsIntersect(transaction->scope(), other->scope())) |
148 return false; | 154 return false; |
149 } | 155 } |
150 return true; | 156 return true; |
151 } | 157 } |
152 NOTREACHED(); | 158 NOTREACHED(); |
153 return false; | 159 return false; |
154 } | 160 } |
155 | 161 |
156 } // namespace content | 162 } // namespace content |
OLD | NEW |