| 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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/browser/indexed_db/indexed_db_connection.h" | 16 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_cursor.h" | 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_factory.h" | 18 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 18 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 19 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
| 19 #include "content/browser/indexed_db/indexed_db_tracing.h" | 20 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 20 #include "content/browser/indexed_db/indexed_db_transaction.h" | 21 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 21 #include "content/common/indexed_db/indexed_db_key_path.h" | 22 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 22 #include "content/common/indexed_db/indexed_db_key_range.h" | 23 #include "content/common/indexed_db/indexed_db_key_range.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 class IndexedDBDatabase::PendingOpenCall { | 34 class IndexedDBDatabase::PendingOpenCall { |
| 34 public: | 35 public: |
| 35 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 36 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 36 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 37 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 37 int64 transaction_id, | 38 int64 transaction_id, |
| 38 int64 version) | 39 int64 version) |
| 39 : callbacks_(callbacks), | 40 : callbacks_(callbacks), |
| 40 database_callbacks_(database_callbacks), | 41 database_callbacks_(database_callbacks), |
| 41 version_(version), | 42 version_(version), |
| 42 transaction_id_(transaction_id) {} | 43 transaction_id_(transaction_id) {} |
| 43 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 44 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
| 44 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() { | 45 scoped_refptr<IndexedDBDatabaseCallbacks> const database_callbacks() { |
| 45 return database_callbacks_; | 46 return database_callbacks_; |
| 46 } | 47 } |
| 47 int64 Version() { return version_; } | 48 int64 version() const { return version_; } |
| 48 int64 TransactionId() const { return transaction_id_; } | 49 int64 transaction_id() const { return transaction_id_; } |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 scoped_refptr<IndexedDBCallbacks> callbacks_; | 52 scoped_refptr<IndexedDBCallbacks> callbacks_; |
| 52 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; | 53 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; |
| 53 int64 version_; | 54 int64 version_; |
| 54 const int64 transaction_id_; | 55 const int64 transaction_id_; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the | 58 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the |
| 58 // in-progress connection. | 59 // in-progress connection. |
| 59 class IndexedDBDatabase::PendingUpgradeCall { | 60 class IndexedDBDatabase::PendingUpgradeCall { |
| 60 public: | 61 public: |
| 61 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 62 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 62 scoped_ptr<IndexedDBConnection> connection, | 63 scoped_ptr<IndexedDBConnection> connection, |
| 63 int64 transaction_id, | 64 int64 transaction_id, |
| 64 int64 version) | 65 int64 version) |
| 65 : callbacks_(callbacks), | 66 : callbacks_(callbacks), |
| 66 connection_(connection.Pass()), | 67 connection_(connection.Pass()), |
| 67 version_(version), | 68 version_(version), |
| 68 transaction_id_(transaction_id) {} | 69 transaction_id_(transaction_id) {} |
| 69 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 70 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
| 70 scoped_ptr<IndexedDBConnection> Connection() { return connection_.Pass(); } | 71 // Takes ownership of the connection object. |
| 71 int64 Version() { return version_; } | 72 scoped_ptr<IndexedDBConnection> ReleaseConnection() WARN_UNUSED_RESULT { |
| 72 int64 TransactionId() const { return transaction_id_; } | 73 return connection_.Pass(); |
| 74 } |
| 75 int64 version() const { return version_; } |
| 76 int64 transaction_id() const { return transaction_id_; } |
| 73 | 77 |
| 74 private: | 78 private: |
| 75 scoped_refptr<IndexedDBCallbacks> callbacks_; | 79 scoped_refptr<IndexedDBCallbacks> callbacks_; |
| 76 scoped_ptr<IndexedDBConnection> connection_; | 80 scoped_ptr<IndexedDBConnection> connection_; |
| 77 int64 version_; | 81 int64 version_; |
| 78 const int64 transaction_id_; | 82 const int64 transaction_id_; |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 // PendingSuccessCall has a IndexedDBConnection* because the connection is now | 85 // PendingSuccessCall has a IndexedDBConnection* because the connection is now |
| 82 // owned elsewhere, but we need to cancel the success call if that connection | 86 // owned elsewhere, but we need to cancel the success call if that connection |
| 83 // closes before it is sent. | 87 // closes before it is sent. |
| 84 class IndexedDBDatabase::PendingSuccessCall { | 88 class IndexedDBDatabase::PendingSuccessCall { |
| 85 public: | 89 public: |
| 86 PendingSuccessCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 90 PendingSuccessCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 87 IndexedDBConnection* connection, | 91 IndexedDBConnection* connection, |
| 88 int64 version) | 92 int64 version) |
| 89 : callbacks_(callbacks), connection_(connection), version_(version) {} | 93 : callbacks_(callbacks), connection_(connection), version_(version) {} |
| 90 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 94 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
| 91 IndexedDBConnection* Connection() { return connection_; } | 95 IndexedDBConnection* connection() const { return connection_; } |
| 92 int64 Version() { return version_; } | 96 int64 version() const { return version_; } |
| 93 | 97 |
| 94 private: | 98 private: |
| 95 scoped_refptr<IndexedDBCallbacks> callbacks_; | 99 scoped_refptr<IndexedDBCallbacks> callbacks_; |
| 96 IndexedDBConnection* connection_; | 100 IndexedDBConnection* connection_; |
| 97 int64 version_; | 101 int64 version_; |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 class IndexedDBDatabase::PendingDeleteCall { | 104 class IndexedDBDatabase::PendingDeleteCall { |
| 101 public: | 105 public: |
| 102 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) | 106 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) |
| 103 : callbacks_(callbacks) {} | 107 : callbacks_(callbacks) {} |
| 104 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 108 scoped_refptr<IndexedDBCallbacks> callbacks() const { return callbacks_; } |
| 105 | 109 |
| 106 private: | 110 private: |
| 107 scoped_refptr<IndexedDBCallbacks> callbacks_; | 111 scoped_refptr<IndexedDBCallbacks> callbacks_; |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( | 114 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( |
| 111 const base::string16& name, | 115 const base::string16& name, |
| 112 IndexedDBBackingStore* backing_store, | 116 IndexedDBBackingStore* backing_store, |
| 113 IndexedDBFactory* factory, | 117 IndexedDBFactory* factory, |
| 114 const Identifier& unique_identifier) { | 118 const Identifier& unique_identifier) { |
| 115 scoped_refptr<IndexedDBDatabase> database = | 119 scoped_refptr<IndexedDBDatabase> database = |
| 116 new IndexedDBDatabase(name, backing_store, factory, unique_identifier); | 120 new IndexedDBDatabase(name, backing_store, factory, unique_identifier); |
| 117 if (!database->OpenInternal()) | 121 if (!database->OpenInternal()) |
| 118 return 0; | 122 return 0; |
| 119 return database; | 123 return database; |
| 120 } | 124 } |
| 121 | 125 |
| 122 namespace { | 126 namespace { |
| 123 const base::string16::value_type kNoStringVersion[] = {0}; | 127 const base::string16::value_type kNoStringVersion[] = {0}; |
| 124 | |
| 125 template <typename T, typename U> | |
| 126 bool Contains(const T& container, const U& item) { | |
| 127 return container.find(item) != container.end(); | |
| 128 } | |
| 129 } | 128 } |
| 130 | 129 |
| 131 IndexedDBDatabase::IndexedDBDatabase(const base::string16& name, | 130 IndexedDBDatabase::IndexedDBDatabase(const base::string16& name, |
| 132 IndexedDBBackingStore* backing_store, | 131 IndexedDBBackingStore* backing_store, |
| 133 IndexedDBFactory* factory, | 132 IndexedDBFactory* factory, |
| 134 const Identifier& unique_identifier) | 133 const Identifier& unique_identifier) |
| 135 : backing_store_(backing_store), | 134 : backing_store_(backing_store), |
| 136 metadata_(name, | 135 metadata_(name, |
| 137 kInvalidId, | 136 kInvalidId, |
| 138 kNoStringVersion, | 137 kNoStringVersion, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( | 214 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |
| 216 int64 transaction_id) const { | 215 int64 transaction_id) const { |
| 217 TransactionMap::const_iterator trans_iterator = | 216 TransactionMap::const_iterator trans_iterator = |
| 218 transactions_.find(transaction_id); | 217 transactions_.find(transaction_id); |
| 219 if (trans_iterator == transactions_.end()) | 218 if (trans_iterator == transactions_.end()) |
| 220 return NULL; | 219 return NULL; |
| 221 return trans_iterator->second; | 220 return trans_iterator->second; |
| 222 } | 221 } |
| 223 | 222 |
| 224 bool IndexedDBDatabase::ValidateObjectStoreId(int64 object_store_id) const { | 223 bool IndexedDBDatabase::ValidateObjectStoreId(int64 object_store_id) const { |
| 225 if (!Contains(metadata_.object_stores, object_store_id)) { | 224 if (!ContainsKey(metadata_.object_stores, object_store_id)) { |
| 226 DLOG(ERROR) << "Invalid object_store_id"; | 225 DLOG(ERROR) << "Invalid object_store_id"; |
| 227 return false; | 226 return false; |
| 228 } | 227 } |
| 229 return true; | 228 return true; |
| 230 } | 229 } |
| 231 | 230 |
| 232 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId(int64 object_store_id, | 231 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId(int64 object_store_id, |
| 233 int64 index_id) const { | 232 int64 index_id) const { |
| 234 if (!ValidateObjectStoreId(object_store_id)) | 233 if (!ValidateObjectStoreId(object_store_id)) |
| 235 return false; | 234 return false; |
| 236 const IndexedDBObjectStoreMetadata& object_store_metadata = | 235 const IndexedDBObjectStoreMetadata& object_store_metadata = |
| 237 metadata_.object_stores.find(object_store_id)->second; | 236 metadata_.object_stores.find(object_store_id)->second; |
| 238 if (!Contains(object_store_metadata.indexes, index_id)) { | 237 if (!ContainsKey(object_store_metadata.indexes, index_id)) { |
| 239 DLOG(ERROR) << "Invalid index_id"; | 238 DLOG(ERROR) << "Invalid index_id"; |
| 240 return false; | 239 return false; |
| 241 } | 240 } |
| 242 return true; | 241 return true; |
| 243 } | 242 } |
| 244 | 243 |
| 245 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( | 244 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( |
| 246 int64 object_store_id, | 245 int64 object_store_id, |
| 247 int64 index_id) const { | 246 int64 index_id) const { |
| 248 if (!ValidateObjectStoreId(object_store_id)) | 247 if (!ValidateObjectStoreId(object_store_id)) |
| 249 return false; | 248 return false; |
| 250 const IndexedDBObjectStoreMetadata& object_store_metadata = | 249 const IndexedDBObjectStoreMetadata& object_store_metadata = |
| 251 metadata_.object_stores.find(object_store_id)->second; | 250 metadata_.object_stores.find(object_store_id)->second; |
| 252 if (index_id != IndexedDBIndexMetadata::kInvalidId && | 251 if (index_id != IndexedDBIndexMetadata::kInvalidId && |
| 253 !Contains(object_store_metadata.indexes, index_id)) { | 252 !ContainsKey(object_store_metadata.indexes, index_id)) { |
| 254 DLOG(ERROR) << "Invalid index_id"; | 253 DLOG(ERROR) << "Invalid index_id"; |
| 255 return false; | 254 return false; |
| 256 } | 255 } |
| 257 return true; | 256 return true; |
| 258 } | 257 } |
| 259 | 258 |
| 260 bool IndexedDBDatabase::ValidateObjectStoreIdAndNewIndexId( | 259 bool IndexedDBDatabase::ValidateObjectStoreIdAndNewIndexId( |
| 261 int64 object_store_id, | 260 int64 object_store_id, |
| 262 int64 index_id) const { | 261 int64 index_id) const { |
| 263 if (!ValidateObjectStoreId(object_store_id)) | 262 if (!ValidateObjectStoreId(object_store_id)) |
| 264 return false; | 263 return false; |
| 265 const IndexedDBObjectStoreMetadata& object_store_metadata = | 264 const IndexedDBObjectStoreMetadata& object_store_metadata = |
| 266 metadata_.object_stores.find(object_store_id)->second; | 265 metadata_.object_stores.find(object_store_id)->second; |
| 267 if (Contains(object_store_metadata.indexes, index_id)) { | 266 if (ContainsKey(object_store_metadata.indexes, index_id)) { |
| 268 DLOG(ERROR) << "Invalid index_id"; | 267 DLOG(ERROR) << "Invalid index_id"; |
| 269 return false; | 268 return false; |
| 270 } | 269 } |
| 271 return true; | 270 return true; |
| 272 } | 271 } |
| 273 | 272 |
| 274 void IndexedDBDatabase::CreateObjectStore(int64 transaction_id, | 273 void IndexedDBDatabase::CreateObjectStore(int64 transaction_id, |
| 275 int64 object_store_id, | 274 int64 object_store_id, |
| 276 const base::string16& name, | 275 const base::string16& name, |
| 277 const IndexedDBKeyPath& key_path, | 276 const IndexedDBKeyPath& key_path, |
| 278 bool auto_increment) { | 277 bool auto_increment) { |
| 279 IDB_TRACE("IndexedDBDatabase::CreateObjectStore"); | 278 IDB_TRACE("IndexedDBDatabase::CreateObjectStore"); |
| 280 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 279 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 281 if (!transaction) | 280 if (!transaction) |
| 282 return; | 281 return; |
| 283 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); | 282 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); |
| 284 | 283 |
| 285 if (Contains(metadata_.object_stores, object_store_id)) { | 284 if (ContainsKey(metadata_.object_stores, object_store_id)) { |
| 286 DLOG(ERROR) << "Invalid object_store_id"; | 285 DLOG(ERROR) << "Invalid object_store_id"; |
| 287 return; | 286 return; |
| 288 } | 287 } |
| 289 | 288 |
| 290 IndexedDBObjectStoreMetadata object_store_metadata( | 289 IndexedDBObjectStoreMetadata object_store_metadata( |
| 291 name, | 290 name, |
| 292 object_store_id, | 291 object_store_id, |
| 293 key_path, | 292 key_path, |
| 294 auto_increment, | 293 auto_increment, |
| 295 IndexedDBDatabase::kMinimumIndexId); | 294 IndexedDBDatabase::kMinimumIndexId); |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 DCHECK(transactions_.find(transaction->id()) != transactions_.end()); | 1271 DCHECK(transactions_.find(transaction->id()) != transactions_.end()); |
| 1273 DCHECK_EQ(transactions_[transaction->id()], transaction); | 1272 DCHECK_EQ(transactions_[transaction->id()], transaction); |
| 1274 transactions_.erase(transaction->id()); | 1273 transactions_.erase(transaction->id()); |
| 1275 | 1274 |
| 1276 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { | 1275 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { |
| 1277 DCHECK_EQ(transaction, running_version_change_transaction_); | 1276 DCHECK_EQ(transaction, running_version_change_transaction_); |
| 1278 running_version_change_transaction_ = NULL; | 1277 running_version_change_transaction_ = NULL; |
| 1279 | 1278 |
| 1280 if (pending_second_half_open_) { | 1279 if (pending_second_half_open_) { |
| 1281 if (committed) { | 1280 if (committed) { |
| 1282 DCHECK_EQ(pending_second_half_open_->Version(), metadata_.int_version); | 1281 DCHECK_EQ(pending_second_half_open_->version(), metadata_.int_version); |
| 1283 DCHECK(metadata_.id != kInvalidId); | 1282 DCHECK(metadata_.id != kInvalidId); |
| 1284 | 1283 |
| 1285 // Connection was already minted for OnUpgradeNeeded callback. | 1284 // Connection was already minted for OnUpgradeNeeded callback. |
| 1286 scoped_ptr<IndexedDBConnection> connection; | 1285 scoped_ptr<IndexedDBConnection> connection; |
| 1287 pending_second_half_open_->Callbacks()->OnSuccess(connection.Pass(), | 1286 pending_second_half_open_->callbacks()->OnSuccess(connection.Pass(), |
| 1288 this->metadata()); | 1287 this->metadata()); |
| 1289 } else { | 1288 } else { |
| 1290 pending_second_half_open_->Callbacks()->OnError( | 1289 pending_second_half_open_->callbacks()->OnError( |
| 1291 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, | 1290 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, |
| 1292 "Version change transaction was aborted in " | 1291 "Version change transaction was aborted in " |
| 1293 "upgradeneeded event handler.")); | 1292 "upgradeneeded event handler.")); |
| 1294 } | 1293 } |
| 1295 pending_second_half_open_.reset(); | 1294 pending_second_half_open_.reset(); |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 // Connection queue is now unblocked. | 1297 // Connection queue is now unblocked. |
| 1299 ProcessPendingCalls(); | 1298 ProcessPendingCalls(); |
| 1300 } | 1299 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1324 size_t IndexedDBDatabase::RunningUpgradeCount() const { | 1323 size_t IndexedDBDatabase::RunningUpgradeCount() const { |
| 1325 return pending_second_half_open_ ? 1 : 0; | 1324 return pending_second_half_open_ ? 1 : 0; |
| 1326 } | 1325 } |
| 1327 | 1326 |
| 1328 size_t IndexedDBDatabase::PendingDeleteCount() const { | 1327 size_t IndexedDBDatabase::PendingDeleteCount() const { |
| 1329 return pending_delete_calls_.size(); | 1328 return pending_delete_calls_.size(); |
| 1330 } | 1329 } |
| 1331 | 1330 |
| 1332 void IndexedDBDatabase::ProcessPendingCalls() { | 1331 void IndexedDBDatabase::ProcessPendingCalls() { |
| 1333 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) { | 1332 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) { |
| 1334 DCHECK(pending_run_version_change_transaction_call_->Version() > | 1333 DCHECK(pending_run_version_change_transaction_call_->version() > |
| 1335 metadata_.int_version); | 1334 metadata_.int_version); |
| 1336 scoped_ptr<PendingUpgradeCall> pending_call = | 1335 scoped_ptr<PendingUpgradeCall> pending_call = |
| 1337 pending_run_version_change_transaction_call_.Pass(); | 1336 pending_run_version_change_transaction_call_.Pass(); |
| 1338 RunVersionChangeTransactionFinal(pending_call->Callbacks(), | 1337 RunVersionChangeTransactionFinal(pending_call->callbacks(), |
| 1339 pending_call->Connection(), | 1338 pending_call->ReleaseConnection(), |
| 1340 pending_call->TransactionId(), | 1339 pending_call->transaction_id(), |
| 1341 pending_call->Version()); | 1340 pending_call->version()); |
| 1342 DCHECK_EQ(static_cast<size_t>(1), ConnectionCount()); | 1341 DCHECK_EQ(static_cast<size_t>(1), ConnectionCount()); |
| 1343 // Fall through would be a no-op, since transaction must complete | 1342 // Fall through would be a no-op, since transaction must complete |
| 1344 // asynchronously. | 1343 // asynchronously. |
| 1345 DCHECK(IsDeleteDatabaseBlocked()); | 1344 DCHECK(IsDeleteDatabaseBlocked()); |
| 1346 DCHECK(IsOpenConnectionBlocked()); | 1345 DCHECK(IsOpenConnectionBlocked()); |
| 1347 return; | 1346 return; |
| 1348 } | 1347 } |
| 1349 | 1348 |
| 1350 if (!IsDeleteDatabaseBlocked()) { | 1349 if (!IsDeleteDatabaseBlocked()) { |
| 1351 PendingDeleteCallList pending_delete_calls; | 1350 PendingDeleteCallList pending_delete_calls; |
| 1352 pending_delete_calls_.swap(pending_delete_calls); | 1351 pending_delete_calls_.swap(pending_delete_calls); |
| 1353 while (!pending_delete_calls.empty()) { | 1352 while (!pending_delete_calls.empty()) { |
| 1354 // Only the first delete call will delete the database, but each must fire | 1353 // Only the first delete call will delete the database, but each must fire |
| 1355 // callbacks. | 1354 // callbacks. |
| 1356 scoped_ptr<PendingDeleteCall> pending_delete_call( | 1355 scoped_ptr<PendingDeleteCall> pending_delete_call( |
| 1357 pending_delete_calls.front()); | 1356 pending_delete_calls.front()); |
| 1358 pending_delete_calls.pop_front(); | 1357 pending_delete_calls.pop_front(); |
| 1359 DeleteDatabaseFinal(pending_delete_call->Callbacks()); | 1358 DeleteDatabaseFinal(pending_delete_call->callbacks()); |
| 1360 } | 1359 } |
| 1361 // delete_database_final should never re-queue calls. | 1360 // delete_database_final should never re-queue calls. |
| 1362 DCHECK(pending_delete_calls_.empty()); | 1361 DCHECK(pending_delete_calls_.empty()); |
| 1363 // Fall through when complete, as pending opens may be unblocked. | 1362 // Fall through when complete, as pending opens may be unblocked. |
| 1364 } | 1363 } |
| 1365 | 1364 |
| 1366 if (!IsOpenConnectionBlocked()) { | 1365 if (!IsOpenConnectionBlocked()) { |
| 1367 PendingOpenCallList pending_open_calls; | 1366 PendingOpenCallList pending_open_calls; |
| 1368 pending_open_calls_.swap(pending_open_calls); | 1367 pending_open_calls_.swap(pending_open_calls); |
| 1369 while (!pending_open_calls.empty()) { | 1368 while (!pending_open_calls.empty()) { |
| 1370 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); | 1369 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); |
| 1371 pending_open_calls.pop_front(); | 1370 pending_open_calls.pop_front(); |
| 1372 OpenConnection(pending_open_call->Callbacks(), | 1371 OpenConnection(pending_open_call->callbacks(), |
| 1373 pending_open_call->DatabaseCallbacks(), | 1372 pending_open_call->database_callbacks(), |
| 1374 pending_open_call->TransactionId(), | 1373 pending_open_call->transaction_id(), |
| 1375 pending_open_call->Version()); | 1374 pending_open_call->version()); |
| 1376 } | 1375 } |
| 1377 } | 1376 } |
| 1378 } | 1377 } |
| 1379 | 1378 |
| 1380 void IndexedDBDatabase::CreateTransaction( | 1379 void IndexedDBDatabase::CreateTransaction( |
| 1381 int64 transaction_id, | 1380 int64 transaction_id, |
| 1382 IndexedDBConnection* connection, | 1381 IndexedDBConnection* connection, |
| 1383 const std::vector<int64>& object_store_ids, | 1382 const std::vector<int64>& object_store_ids, |
| 1384 uint16 mode) { | 1383 uint16 mode) { |
| 1385 | 1384 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 ++it) { | 1662 ++it) { |
| 1664 if (it->second->connection() == connection->callbacks()) | 1663 if (it->second->connection() == connection->callbacks()) |
| 1665 it->second->Abort( | 1664 it->second->Abort( |
| 1666 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 1665 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 1667 "Connection is closing.")); | 1666 "Connection is closing.")); |
| 1668 } | 1667 } |
| 1669 } | 1668 } |
| 1670 | 1669 |
| 1671 connections_.erase(connection); | 1670 connections_.erase(connection); |
| 1672 if (pending_second_half_open_ && | 1671 if (pending_second_half_open_ && |
| 1673 pending_second_half_open_->Connection() == connection) { | 1672 pending_second_half_open_->connection() == connection) { |
| 1674 pending_second_half_open_->Callbacks()->OnError( | 1673 pending_second_half_open_->callbacks()->OnError( |
| 1675 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, | 1674 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, |
| 1676 "The connection was closed.")); | 1675 "The connection was closed.")); |
| 1677 pending_second_half_open_.reset(); | 1676 pending_second_half_open_.reset(); |
| 1678 } | 1677 } |
| 1679 | 1678 |
| 1680 ProcessPendingCalls(); | 1679 ProcessPendingCalls(); |
| 1681 | 1680 |
| 1682 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. | 1681 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. |
| 1683 if (!ConnectionCount() && !pending_open_calls_.size() && | 1682 if (!ConnectionCount() && !pending_open_calls_.size() && |
| 1684 !pending_delete_calls_.size()) { | 1683 !pending_delete_calls_.size()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 const base::string16& previous_version, | 1716 const base::string16& previous_version, |
| 1718 int64 previous_int_version, | 1717 int64 previous_int_version, |
| 1719 IndexedDBTransaction* transaction) { | 1718 IndexedDBTransaction* transaction) { |
| 1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1719 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1721 DCHECK(!transaction); | 1720 DCHECK(!transaction); |
| 1722 metadata_.version = previous_version; | 1721 metadata_.version = previous_version; |
| 1723 metadata_.int_version = previous_int_version; | 1722 metadata_.int_version = previous_int_version; |
| 1724 } | 1723 } |
| 1725 | 1724 |
| 1726 } // namespace content | 1725 } // namespace content |
| OLD | NEW |