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