| 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 | 8 | 
| 9 #include <limits> | 9 #include <limits> | 
| 10 #include <set> | 10 #include <set> | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 90 | 90 | 
| 91   // Called if a front-end signals that it is ignoring a "versionchange" | 91   // Called if a front-end signals that it is ignoring a "versionchange" | 
| 92   // event. This should result in firing a "blocked" event at the request. | 92   // event. This should result in firing a "blocked" event at the request. | 
| 93   virtual void OnVersionChangeIgnored() const = 0; | 93   virtual void OnVersionChangeIgnored() const = 0; | 
| 94 | 94 | 
| 95   // Called when a connection is closed; if it corresponds to this connection, | 95   // Called when a connection is closed; if it corresponds to this connection, | 
| 96   // need to do cleanup. Otherwise, it may unblock further steps. | 96   // need to do cleanup. Otherwise, it may unblock further steps. | 
| 97   virtual void OnConnectionClosed(IndexedDBConnection* connection) = 0; | 97   virtual void OnConnectionClosed(IndexedDBConnection* connection) = 0; | 
| 98 | 98 | 
| 99   // Called when the upgrade transaction has started executing. | 99   // Called when the upgrade transaction has started executing. | 
| 100   virtual void UpgradeTransactionStarted(int64_t old_version) = 0; | 100   virtual void UpgradeTransactionStarted(int64_t old_version, | 
|  | 101                                          IndexedDBTransaction* transaction) = 0; | 
| 101 | 102 | 
| 102   // Called when the upgrade transaction has finished. | 103   // Called when the upgrade transaction has finished. | 
| 103   virtual void UpgradeTransactionFinished(bool committed) = 0; | 104   virtual void UpgradeTransactionFinished(bool committed) = 0; | 
| 104 | 105 | 
| 105  protected: | 106  protected: | 
| 106   scoped_refptr<IndexedDBDatabase> db_; | 107   scoped_refptr<IndexedDBDatabase> db_; | 
| 107 | 108 | 
| 108  private: | 109  private: | 
| 109   DISALLOW_COPY_AND_ASSIGN(ConnectionRequest); | 110   DISALLOW_COPY_AND_ASSIGN(ConnectionRequest); | 
| 110 }; | 111 }; | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 244         pending_->transaction_id, connection_.get(), object_store_ids, | 245         pending_->transaction_id, connection_.get(), object_store_ids, | 
| 245         blink::WebIDBTransactionModeVersionChange); | 246         blink::WebIDBTransactionModeVersionChange); | 
| 246 | 247 | 
| 247     DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction()); | 248     DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction()); | 
| 248     transaction->ScheduleTask( | 249     transaction->ScheduleTask( | 
| 249         base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_, | 250         base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_, | 
| 250                    pending_->version, pending_->callbacks)); | 251                    pending_->version, pending_->callbacks)); | 
| 251   } | 252   } | 
| 252 | 253 | 
| 253   // Called when the upgrade transaction has started executing. | 254   // Called when the upgrade transaction has started executing. | 
| 254   void UpgradeTransactionStarted(int64_t old_version) override { | 255   void UpgradeTransactionStarted(int64_t old_version, | 
|  | 256                                  IndexedDBTransaction* transaction) override { | 
| 255     DCHECK(connection_); | 257     DCHECK(connection_); | 
| 256     pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_), | 258     pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_), | 
| 257                                          db_->metadata_, | 259                                          transaction, db_->metadata_, | 
| 258                                          pending_->data_loss_info); | 260                                          pending_->data_loss_info); | 
| 259   } | 261   } | 
| 260 | 262 | 
| 261   void UpgradeTransactionFinished(bool committed) override { | 263   void UpgradeTransactionFinished(bool committed) override { | 
| 262     // Ownership of connection was already passed along in OnUpgradeNeeded. | 264     // Ownership of connection was already passed along in OnUpgradeNeeded. | 
| 263     DCHECK(!connection_); | 265     DCHECK(!connection_); | 
| 264 | 266 | 
| 265     if (committed) { | 267     if (committed) { | 
| 266       DCHECK_EQ(pending_->version, db_->metadata_.version); | 268       DCHECK_EQ(pending_->version, db_->metadata_.version); | 
| 267       pending_->callbacks->OnSuccess(std::unique_ptr<IndexedDBConnection>(), | 269       pending_->callbacks->OnSuccess(std::unique_ptr<IndexedDBConnection>(), | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 339     db_->metadata_.id = kInvalidId; | 341     db_->metadata_.id = kInvalidId; | 
| 340     db_->metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION; | 342     db_->metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION; | 
| 341     db_->metadata_.max_object_store_id = kInvalidId; | 343     db_->metadata_.max_object_store_id = kInvalidId; | 
| 342     db_->metadata_.object_stores.clear(); | 344     db_->metadata_.object_stores.clear(); | 
| 343     callbacks_->OnSuccess(old_version); | 345     callbacks_->OnSuccess(old_version); | 
| 344     db_->factory_->DatabaseDeleted(db_->identifier_); | 346     db_->factory_->DatabaseDeleted(db_->identifier_); | 
| 345 | 347 | 
| 346     db_->RequestComplete(this); | 348     db_->RequestComplete(this); | 
| 347   } | 349   } | 
| 348 | 350 | 
| 349   void UpgradeTransactionStarted(int64_t old_version) override { NOTREACHED(); } | 351   void UpgradeTransactionStarted(int64_t old_version, | 
|  | 352                                  IndexedDBTransaction* transaction) override { | 
|  | 353     NOTREACHED(); | 
|  | 354   } | 
| 350 | 355 | 
| 351   void UpgradeTransactionFinished(bool committed) override { NOTREACHED(); } | 356   void UpgradeTransactionFinished(bool committed) override { NOTREACHED(); } | 
| 352 | 357 | 
| 353  private: | 358  private: | 
| 354   scoped_refptr<IndexedDBCallbacks> callbacks_; | 359   scoped_refptr<IndexedDBCallbacks> callbacks_; | 
| 355 | 360 | 
| 356   DISALLOW_COPY_AND_ASSIGN(DeleteRequest); | 361   DISALLOW_COPY_AND_ASSIGN(DeleteRequest); | 
| 357 }; | 362 }; | 
| 358 | 363 | 
| 359 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( | 364 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 461     return s; | 466     return s; | 
| 462   if (success) | 467   if (success) | 
| 463     return backing_store_->GetObjectStores(metadata_.id, | 468     return backing_store_->GetObjectStores(metadata_.id, | 
| 464                                            &metadata_.object_stores); | 469                                            &metadata_.object_stores); | 
| 465 | 470 | 
| 466   return backing_store_->CreateIDBDatabaseMetaData( | 471   return backing_store_->CreateIDBDatabaseMetaData( | 
| 467       metadata_.name, metadata_.version, &metadata_.id); | 472       metadata_.name, metadata_.version, &metadata_.id); | 
| 468 } | 473 } | 
| 469 | 474 | 
| 470 IndexedDBDatabase::~IndexedDBDatabase() { | 475 IndexedDBDatabase::~IndexedDBDatabase() { | 
| 471   DCHECK(transactions_.empty()); |  | 
| 472   DCHECK(!active_request_); | 476   DCHECK(!active_request_); | 
| 473   DCHECK(pending_requests_.empty()); | 477   DCHECK(pending_requests_.empty()); | 
| 474 } | 478 } | 
| 475 | 479 | 
| 476 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const { | 480 size_t IndexedDBDatabase::GetMaxMessageSizeInBytes() const { | 
| 477   return kMaxIDBMessageSizeInBytes; | 481   return kMaxIDBMessageSizeInBytes; | 
| 478 } | 482 } | 
| 479 | 483 | 
| 480 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( | 484 std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( | 
| 481     scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 485     scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 
| 482     int child_process_id) { | 486     int child_process_id) { | 
| 483   std::unique_ptr<IndexedDBConnection> connection( | 487   std::unique_ptr<IndexedDBConnection> connection( | 
| 484       base::MakeUnique<IndexedDBConnection>(this, database_callbacks)); | 488       base::MakeUnique<IndexedDBConnection>(child_process_id, this, | 
|  | 489                                             database_callbacks)); | 
| 485   connections_.insert(connection.get()); | 490   connections_.insert(connection.get()); | 
| 486   backing_store_->GrantChildProcessPermissions(child_process_id); | 491   backing_store_->GrantChildProcessPermissions(child_process_id); | 
| 487   return connection; | 492   return connection; | 
| 488 } | 493 } | 
| 489 | 494 | 
| 490 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |  | 
| 491     int64_t transaction_id) const { |  | 
| 492   const auto& trans_iterator = transactions_.find(transaction_id); |  | 
| 493   if (trans_iterator == transactions_.end()) |  | 
| 494     return NULL; |  | 
| 495   return trans_iterator->second; |  | 
| 496 } |  | 
| 497 |  | 
| 498 bool IndexedDBDatabase::ValidateObjectStoreId(int64_t object_store_id) const { | 495 bool IndexedDBDatabase::ValidateObjectStoreId(int64_t object_store_id) const { | 
| 499   if (!base::ContainsKey(metadata_.object_stores, object_store_id)) { | 496   if (!base::ContainsKey(metadata_.object_stores, object_store_id)) { | 
| 500     DLOG(ERROR) << "Invalid object_store_id"; | 497     DLOG(ERROR) << "Invalid object_store_id"; | 
| 501     return false; | 498     return false; | 
| 502   } | 499   } | 
| 503   return true; | 500   return true; | 
| 504 } | 501 } | 
| 505 | 502 | 
| 506 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId( | 503 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId( | 
| 507     int64_t object_store_id, | 504     int64_t object_store_id, | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 539     return false; | 536     return false; | 
| 540   const IndexedDBObjectStoreMetadata& object_store_metadata = | 537   const IndexedDBObjectStoreMetadata& object_store_metadata = | 
| 541       metadata_.object_stores.find(object_store_id)->second; | 538       metadata_.object_stores.find(object_store_id)->second; | 
| 542   if (base::ContainsKey(object_store_metadata.indexes, index_id)) { | 539   if (base::ContainsKey(object_store_metadata.indexes, index_id)) { | 
| 543     DLOG(ERROR) << "Invalid index_id"; | 540     DLOG(ERROR) << "Invalid index_id"; | 
| 544     return false; | 541     return false; | 
| 545   } | 542   } | 
| 546   return true; | 543   return true; | 
| 547 } | 544 } | 
| 548 | 545 | 
| 549 void IndexedDBDatabase::CreateObjectStore(int64_t transaction_id, | 546 void IndexedDBDatabase::CreateObjectStore(IndexedDBTransaction* transaction, | 
| 550                                           int64_t object_store_id, | 547                                           int64_t object_store_id, | 
| 551                                           const base::string16& name, | 548                                           const base::string16& name, | 
| 552                                           const IndexedDBKeyPath& key_path, | 549                                           const IndexedDBKeyPath& key_path, | 
| 553                                           bool auto_increment) { | 550                                           bool auto_increment) { | 
| 554   IDB_TRACE1("IndexedDBDatabase::CreateObjectStore", "txn.id", transaction_id); |  | 
| 555   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 556   if (!transaction) | 551   if (!transaction) | 
| 557     return; | 552     return; | 
|  | 553   IDB_TRACE1("IndexedDBDatabase::CreateObjectStore", "txn.id", | 
|  | 554              transaction->id()); | 
| 558   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 555   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 559 | 556 | 
| 560   if (base::ContainsKey(metadata_.object_stores, object_store_id)) { | 557   if (base::ContainsKey(metadata_.object_stores, object_store_id)) { | 
| 561     DLOG(ERROR) << "Invalid object_store_id"; | 558     DLOG(ERROR) << "Invalid object_store_id"; | 
| 562     return; | 559     return; | 
| 563   } | 560   } | 
| 564 | 561 | 
| 565   UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Schema.ObjectStore.KeyPathType", | 562   UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Schema.ObjectStore.KeyPathType", | 
| 566                             HistogramKeyPathType(key_path), KEY_PATH_TYPE_MAX); | 563                             HistogramKeyPathType(key_path), KEY_PATH_TYPE_MAX); | 
| 567   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.ObjectStore.AutoIncrement", | 564   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.ObjectStore.AutoIncrement", | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 595     return; | 592     return; | 
| 596   } | 593   } | 
| 597 | 594 | 
| 598   AddObjectStore(object_store_metadata, object_store_id); | 595   AddObjectStore(object_store_metadata, object_store_id); | 
| 599   transaction->ScheduleAbortTask( | 596   transaction->ScheduleAbortTask( | 
| 600       base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, | 597       base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, | 
| 601                  this, | 598                  this, | 
| 602                  object_store_id)); | 599                  object_store_id)); | 
| 603 } | 600 } | 
| 604 | 601 | 
| 605 void IndexedDBDatabase::DeleteObjectStore(int64_t transaction_id, | 602 void IndexedDBDatabase::DeleteObjectStore(IndexedDBTransaction* transaction, | 
| 606                                           int64_t object_store_id) { | 603                                           int64_t object_store_id) { | 
| 607   IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", transaction_id); |  | 
| 608   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 609   if (!transaction) | 604   if (!transaction) | 
| 610     return; | 605     return; | 
|  | 606   IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", | 
|  | 607              transaction->id()); | 
| 611   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 608   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 612 | 609 | 
| 613   if (!ValidateObjectStoreId(object_store_id)) | 610   if (!ValidateObjectStoreId(object_store_id)) | 
| 614     return; | 611     return; | 
| 615 | 612 | 
| 616   transaction->ScheduleTask( | 613   transaction->ScheduleTask( | 
| 617       base::Bind(&IndexedDBDatabase::DeleteObjectStoreOperation, | 614       base::Bind(&IndexedDBDatabase::DeleteObjectStoreOperation, | 
| 618                  this, | 615                  this, | 
| 619                  object_store_id)); | 616                  object_store_id)); | 
| 620 } | 617 } | 
| 621 | 618 | 
| 622 void IndexedDBDatabase::RenameObjectStore(int64_t transaction_id, | 619 void IndexedDBDatabase::RenameObjectStore(IndexedDBTransaction* transaction, | 
| 623                                           int64_t object_store_id, | 620                                           int64_t object_store_id, | 
| 624                                           const base::string16& new_name) { | 621                                           const base::string16& new_name) { | 
| 625   IDB_TRACE1("IndexedDBDatabase::RenameObjectStore", "txn.id", transaction_id); |  | 
| 626   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 627   if (!transaction) | 622   if (!transaction) | 
| 628     return; | 623     return; | 
|  | 624   IDB_TRACE1("IndexedDBDatabase::RenameObjectStore", "txn.id", | 
|  | 625              transaction->id()); | 
| 629   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 626   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 630 | 627 | 
| 631   if (!ValidateObjectStoreId(object_store_id)) | 628   if (!ValidateObjectStoreId(object_store_id)) | 
| 632     return; | 629     return; | 
| 633 | 630 | 
| 634   // Store renaming is done synchronously, as it may be followed by | 631   // Store renaming is done synchronously, as it may be followed by | 
| 635   // index creation (also sync) since preemptive OpenCursor/SetIndexKeys | 632   // index creation (also sync) since preemptive OpenCursor/SetIndexKeys | 
| 636   // may follow. | 633   // may follow. | 
| 637   const IndexedDBObjectStoreMetadata object_store_metadata = | 634   const IndexedDBObjectStoreMetadata object_store_metadata = | 
| 638       metadata_.object_stores[object_store_id]; | 635       metadata_.object_stores[object_store_id]; | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 654   } | 651   } | 
| 655 | 652 | 
| 656   transaction->ScheduleAbortTask( | 653   transaction->ScheduleAbortTask( | 
| 657       base::Bind(&IndexedDBDatabase::RenameObjectStoreAbortOperation, | 654       base::Bind(&IndexedDBDatabase::RenameObjectStoreAbortOperation, | 
| 658                  this, | 655                  this, | 
| 659                  object_store_id, | 656                  object_store_id, | 
| 660                  object_store_metadata.name)); | 657                  object_store_metadata.name)); | 
| 661   SetObjectStoreName(object_store_id, new_name); | 658   SetObjectStoreName(object_store_id, new_name); | 
| 662 } | 659 } | 
| 663 | 660 | 
| 664 void IndexedDBDatabase::CreateIndex(int64_t transaction_id, | 661 void IndexedDBDatabase::CreateIndex(IndexedDBTransaction* transaction, | 
| 665                                     int64_t object_store_id, | 662                                     int64_t object_store_id, | 
| 666                                     int64_t index_id, | 663                                     int64_t index_id, | 
| 667                                     const base::string16& name, | 664                                     const base::string16& name, | 
| 668                                     const IndexedDBKeyPath& key_path, | 665                                     const IndexedDBKeyPath& key_path, | 
| 669                                     bool unique, | 666                                     bool unique, | 
| 670                                     bool multi_entry) { | 667                                     bool multi_entry) { | 
| 671   IDB_TRACE1("IndexedDBDatabase::CreateIndex", "txn.id", transaction_id); |  | 
| 672   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 673   if (!transaction) | 668   if (!transaction) | 
| 674     return; | 669     return; | 
|  | 670   IDB_TRACE1("IndexedDBDatabase::CreateIndex", "txn.id", transaction->id()); | 
| 675   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 671   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 676 | 672 | 
| 677   if (!ValidateObjectStoreIdAndNewIndexId(object_store_id, index_id)) | 673   if (!ValidateObjectStoreIdAndNewIndexId(object_store_id, index_id)) | 
| 678     return; | 674     return; | 
| 679 | 675 | 
| 680   UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Schema.Index.KeyPathType", | 676   UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Schema.Index.KeyPathType", | 
| 681                             HistogramKeyPathType(key_path), KEY_PATH_TYPE_MAX); | 677                             HistogramKeyPathType(key_path), KEY_PATH_TYPE_MAX); | 
| 682   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.Index.Unique", unique); | 678   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.Index.Unique", unique); | 
| 683   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.Index.MultiEntry", | 679   UMA_HISTOGRAM_BOOLEAN("WebCore.IndexedDB.Schema.Index.MultiEntry", | 
| 684                         multi_entry); | 680                         multi_entry); | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 714 | 710 | 
| 715 void IndexedDBDatabase::CreateIndexAbortOperation( | 711 void IndexedDBDatabase::CreateIndexAbortOperation( | 
| 716     int64_t object_store_id, | 712     int64_t object_store_id, | 
| 717     int64_t index_id, | 713     int64_t index_id, | 
| 718     IndexedDBTransaction* transaction) { | 714     IndexedDBTransaction* transaction) { | 
| 719   DCHECK(!transaction); | 715   DCHECK(!transaction); | 
| 720   IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); | 716   IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); | 
| 721   RemoveIndex(object_store_id, index_id); | 717   RemoveIndex(object_store_id, index_id); | 
| 722 } | 718 } | 
| 723 | 719 | 
| 724 void IndexedDBDatabase::DeleteIndex(int64_t transaction_id, | 720 void IndexedDBDatabase::DeleteIndex(IndexedDBTransaction* transaction, | 
| 725                                     int64_t object_store_id, | 721                                     int64_t object_store_id, | 
| 726                                     int64_t index_id) { | 722                                     int64_t index_id) { | 
| 727   IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction_id); |  | 
| 728   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 729   if (!transaction) | 723   if (!transaction) | 
| 730     return; | 724     return; | 
|  | 725   IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction->id()); | 
| 731   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 726   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 732 | 727 | 
| 733   if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 728   if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 
| 734     return; | 729     return; | 
| 735 | 730 | 
| 736   transaction->ScheduleTask( | 731   transaction->ScheduleTask( | 
| 737       base::Bind(&IndexedDBDatabase::DeleteIndexOperation, | 732       base::Bind(&IndexedDBDatabase::DeleteIndexOperation, | 
| 738                  this, | 733                  this, | 
| 739                  object_store_id, | 734                  object_store_id, | 
| 740                  index_id)); | 735                  index_id)); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 777 | 772 | 
| 778 void IndexedDBDatabase::DeleteIndexAbortOperation( | 773 void IndexedDBDatabase::DeleteIndexAbortOperation( | 
| 779     int64_t object_store_id, | 774     int64_t object_store_id, | 
| 780     const IndexedDBIndexMetadata& index_metadata, | 775     const IndexedDBIndexMetadata& index_metadata, | 
| 781     IndexedDBTransaction* transaction) { | 776     IndexedDBTransaction* transaction) { | 
| 782   DCHECK(!transaction); | 777   DCHECK(!transaction); | 
| 783   IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); | 778   IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); | 
| 784   AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); | 779   AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); | 
| 785 } | 780 } | 
| 786 | 781 | 
| 787 void IndexedDBDatabase::RenameIndex(int64_t transaction_id, | 782 void IndexedDBDatabase::RenameIndex(IndexedDBTransaction* transaction, | 
| 788                                     int64_t object_store_id, | 783                                     int64_t object_store_id, | 
| 789                                     int64_t index_id, | 784                                     int64_t index_id, | 
| 790                                     const base::string16& new_name) { | 785                                     const base::string16& new_name) { | 
| 791   IDB_TRACE1("IndexedDBDatabase::RenameIndex", "txn.id", transaction_id); |  | 
| 792   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 793   if (!transaction) | 786   if (!transaction) | 
| 794     return; | 787     return; | 
|  | 788   IDB_TRACE1("IndexedDBDatabase::RenameIndex", "txn.id", transaction->id()); | 
| 795   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 789   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 796 | 790 | 
| 797   if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 791   if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 
| 798     return; | 792     return; | 
| 799 | 793 | 
| 800   // Index renaming is done synchronously since preemptive | 794   // Index renaming is done synchronously since preemptive | 
| 801   // OpenCursor/SetIndexKeys may follow. | 795   // OpenCursor/SetIndexKeys may follow. | 
| 802 | 796 | 
| 803   const IndexedDBIndexMetadata index_metadata = | 797   const IndexedDBIndexMetadata index_metadata = | 
| 804       metadata_.object_stores[object_store_id].indexes[index_id]; | 798       metadata_.object_stores[object_store_id].indexes[index_id]; | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 831 void IndexedDBDatabase::RenameIndexAbortOperation( | 825 void IndexedDBDatabase::RenameIndexAbortOperation( | 
| 832     int64_t object_store_id, | 826     int64_t object_store_id, | 
| 833     int64_t index_id, | 827     int64_t index_id, | 
| 834     const base::string16& old_name, | 828     const base::string16& old_name, | 
| 835     IndexedDBTransaction* transaction) { | 829     IndexedDBTransaction* transaction) { | 
| 836   DCHECK(!transaction); | 830   DCHECK(!transaction); | 
| 837   IDB_TRACE("IndexedDBDatabase::RenameIndexAbortOperation"); | 831   IDB_TRACE("IndexedDBDatabase::RenameIndexAbortOperation"); | 
| 838   SetIndexName(object_store_id, index_id, old_name); | 832   SetIndexName(object_store_id, index_id, old_name); | 
| 839 } | 833 } | 
| 840 | 834 | 
| 841 void IndexedDBDatabase::Commit(int64_t transaction_id) { | 835 void IndexedDBDatabase::Commit(IndexedDBTransaction* transaction) { | 
| 842   // The frontend suggests that we commit, but we may have previously initiated | 836   // The frontend suggests that we commit, but we may have previously initiated | 
| 843   // an abort, and so have disposed of the transaction. on_abort has already | 837   // an abort, and so have disposed of the transaction. on_abort has already | 
| 844   // been dispatched to the frontend, so it will find out about that | 838   // been dispatched to the frontend, so it will find out about that | 
| 845   // asynchronously. | 839   // asynchronously. | 
| 846   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 847   if (transaction) { | 840   if (transaction) { | 
| 848     scoped_refptr<IndexedDBFactory> factory = factory_; | 841     scoped_refptr<IndexedDBFactory> factory = factory_; | 
| 849     leveldb::Status s = transaction->Commit(); | 842     leveldb::Status s = transaction->Commit(); | 
| 850     if (s.IsCorruption()) { | 843     if (s.IsCorruption()) { | 
| 851       IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 844       IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 
| 852                                    "Internal error committing transaction."); | 845                                    "Internal error committing transaction."); | 
| 853       factory->HandleBackingStoreCorruption(identifier_.first, error); | 846       factory->HandleBackingStoreCorruption(identifier_.first, error); | 
| 854     } | 847     } | 
| 855   } | 848   } | 
| 856 } | 849 } | 
| 857 | 850 | 
| 858 void IndexedDBDatabase::Abort(int64_t transaction_id) { | 851 void IndexedDBDatabase::Abort(IndexedDBTransaction* transaction) { | 
| 859   // If the transaction is unknown, then it has already been aborted by the | 852   // If the transaction is unknown, then it has already been aborted by the | 
| 860   // backend before this call so it is safe to ignore it. | 853   // backend before this call so it is safe to ignore it. | 
| 861   IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction_id); | 854   IDB_TRACE1("IndexedDBDatabase::Abort", "txn.id", transaction->id()); | 
| 862   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 863   if (transaction) | 855   if (transaction) | 
| 864     transaction->Abort(); | 856     transaction->Abort(); | 
| 865 } | 857 } | 
| 866 | 858 | 
| 867 void IndexedDBDatabase::Abort(int64_t transaction_id, | 859 void IndexedDBDatabase::Abort(IndexedDBTransaction* transaction, | 
| 868                               const IndexedDBDatabaseError& error) { | 860                               const IndexedDBDatabaseError& error) { | 
| 869   IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); | 861   IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction->id()); | 
| 870   // If the transaction is unknown, then it has already been aborted by the | 862   // If the transaction is unknown, then it has already been aborted by the | 
| 871   // backend before this call so it is safe to ignore it. | 863   // backend before this call so it is safe to ignore it. | 
| 872   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 873   if (transaction) | 864   if (transaction) | 
| 874     transaction->Abort(error); | 865     transaction->Abort(error); | 
| 875 } | 866 } | 
| 876 | 867 | 
| 877 void IndexedDBDatabase::AddPendingObserver( | 868 void IndexedDBDatabase::AddPendingObserver( | 
| 878     int64_t transaction_id, | 869     IndexedDBTransaction* transaction, | 
| 879     int32_t observer_id, | 870     int32_t observer_id, | 
| 880     const IndexedDBObserver::Options& options) { | 871     const IndexedDBObserver::Options& options) { | 
| 881   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 882   if (!transaction) | 872   if (!transaction) | 
| 883     return; | 873     return; | 
| 884   transaction->AddPendingObserver(observer_id, options); | 874   transaction->AddPendingObserver(observer_id, options); | 
| 885 } | 875 } | 
| 886 | 876 | 
| 887 void IndexedDBDatabase::RemovePendingObservers( |  | 
| 888     IndexedDBConnection* connection, |  | 
| 889     const std::vector<int32_t>& pending_observer_ids) { |  | 
| 890   for (const auto& it : transactions_) { |  | 
| 891     // Avoid call to RemovePendingObservers for transactions on other |  | 
| 892     // connections. |  | 
| 893     if (it.second->connection() == connection) |  | 
| 894       it.second->RemovePendingObservers(pending_observer_ids); |  | 
| 895   } |  | 
| 896 } |  | 
| 897 |  | 
| 898 // TODO(palakj): Augment the function with IDBValue later. Issue | 877 // TODO(palakj): Augment the function with IDBValue later. Issue | 
| 899 // crbug.com/609934. | 878 // crbug.com/609934. | 
| 900 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, | 879 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, | 
| 901                                           int64_t object_store_id, | 880                                           int64_t object_store_id, | 
| 902                                           blink::WebIDBOperationType type, | 881                                           blink::WebIDBOperationType type, | 
| 903                                           const IndexedDBKeyRange& key_range) { | 882                                           const IndexedDBKeyRange& key_range) { | 
| 904   for (auto* connection : connections_) { | 883   for (auto* connection : connections_) { | 
| 905     bool recorded = false; | 884     bool recorded = false; | 
| 906     for (const auto& observer : connection->active_observers()) { | 885     for (const auto& observer : connection->active_observers()) { | 
| 907       if (!observer->IsRecordingType(type) || | 886       if (!observer->IsRecordingType(type) || | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 927 | 906 | 
| 928 void IndexedDBDatabase::SendObservations( | 907 void IndexedDBDatabase::SendObservations( | 
| 929     std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) { | 908     std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) { | 
| 930   for (auto* conn : connections_) { | 909   for (auto* conn : connections_) { | 
| 931     auto it = changes_map.find(conn->id()); | 910     auto it = changes_map.find(conn->id()); | 
| 932     if (it != changes_map.end()) | 911     if (it != changes_map.end()) | 
| 933       conn->callbacks()->OnDatabaseChange(std::move(it->second)); | 912       conn->callbacks()->OnDatabaseChange(std::move(it->second)); | 
| 934   } | 913   } | 
| 935 } | 914 } | 
| 936 | 915 | 
| 937 void IndexedDBDatabase::GetAll(int64_t transaction_id, | 916 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction, | 
| 938                                int64_t object_store_id, | 917                                int64_t object_store_id, | 
| 939                                int64_t index_id, | 918                                int64_t index_id, | 
| 940                                std::unique_ptr<IndexedDBKeyRange> key_range, | 919                                std::unique_ptr<IndexedDBKeyRange> key_range, | 
| 941                                bool key_only, | 920                                bool key_only, | 
| 942                                int64_t max_count, | 921                                int64_t max_count, | 
| 943                                scoped_refptr<IndexedDBCallbacks> callbacks) { | 922                                scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 944   IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |  | 
| 945   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 946   if (!transaction) | 923   if (!transaction) | 
| 947     return; | 924     return; | 
|  | 925   IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction->id()); | 
| 948 | 926 | 
| 949   if (!ValidateObjectStoreId(object_store_id)) | 927   if (!ValidateObjectStoreId(object_store_id)) | 
| 950     return; | 928     return; | 
| 951 | 929 | 
| 952   transaction->ScheduleTask(base::Bind( | 930   transaction->ScheduleTask(base::Bind( | 
| 953       &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, | 931       &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, | 
| 954       base::Passed(&key_range), | 932       base::Passed(&key_range), | 
| 955       key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 933       key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 
| 956       max_count, callbacks)); | 934       max_count, callbacks)); | 
| 957 } | 935 } | 
| 958 | 936 | 
| 959 void IndexedDBDatabase::Get(int64_t transaction_id, | 937 void IndexedDBDatabase::Get(IndexedDBTransaction* transaction, | 
| 960                             int64_t object_store_id, | 938                             int64_t object_store_id, | 
| 961                             int64_t index_id, | 939                             int64_t index_id, | 
| 962                             std::unique_ptr<IndexedDBKeyRange> key_range, | 940                             std::unique_ptr<IndexedDBKeyRange> key_range, | 
| 963                             bool key_only, | 941                             bool key_only, | 
| 964                             scoped_refptr<IndexedDBCallbacks> callbacks) { | 942                             scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 965   IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); |  | 
| 966   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 967   if (!transaction) | 943   if (!transaction) | 
| 968     return; | 944     return; | 
|  | 945   IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction->id()); | 
| 969 | 946 | 
| 970   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 947   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 
| 971     return; | 948     return; | 
| 972 | 949 | 
| 973   transaction->ScheduleTask(base::Bind( | 950   transaction->ScheduleTask(base::Bind( | 
| 974       &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, | 951       &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, | 
| 975       base::Passed(&key_range), | 952       base::Passed(&key_range), | 
| 976       key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 953       key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 
| 977       callbacks)); | 954       callbacks)); | 
| 978 } | 955 } | 
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1319   std::unique_ptr<IndexedDBKey> key; | 1296   std::unique_ptr<IndexedDBKey> key; | 
| 1320   blink::WebIDBPutMode put_mode; | 1297   blink::WebIDBPutMode put_mode; | 
| 1321   scoped_refptr<IndexedDBCallbacks> callbacks; | 1298   scoped_refptr<IndexedDBCallbacks> callbacks; | 
| 1322   std::vector<IndexKeys> index_keys; | 1299   std::vector<IndexKeys> index_keys; | 
| 1323 | 1300 | 
| 1324  private: | 1301  private: | 
| 1325   DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 1302   DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 
| 1326 }; | 1303 }; | 
| 1327 | 1304 | 
| 1328 void IndexedDBDatabase::Put( | 1305 void IndexedDBDatabase::Put( | 
| 1329     int64_t transaction_id, | 1306     IndexedDBTransaction* transaction, | 
| 1330     int64_t object_store_id, | 1307     int64_t object_store_id, | 
| 1331     IndexedDBValue* value, | 1308     IndexedDBValue* value, | 
| 1332     std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, | 1309     std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, | 
| 1333     std::unique_ptr<IndexedDBKey> key, | 1310     std::unique_ptr<IndexedDBKey> key, | 
| 1334     blink::WebIDBPutMode put_mode, | 1311     blink::WebIDBPutMode put_mode, | 
| 1335     scoped_refptr<IndexedDBCallbacks> callbacks, | 1312     scoped_refptr<IndexedDBCallbacks> callbacks, | 
| 1336     const std::vector<IndexKeys>& index_keys) { | 1313     const std::vector<IndexKeys>& index_keys) { | 
| 1337   IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction_id); |  | 
| 1338   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1339   if (!transaction) | 1314   if (!transaction) | 
| 1340     return; | 1315     return; | 
|  | 1316   IDB_TRACE1("IndexedDBDatabase::Put", "txn.id", transaction->id()); | 
| 1341   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1317   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 
| 1342 | 1318 | 
| 1343   if (!ValidateObjectStoreId(object_store_id)) | 1319   if (!ValidateObjectStoreId(object_store_id)) | 
| 1344     return; | 1320     return; | 
| 1345 | 1321 | 
| 1346   DCHECK(key); | 1322   DCHECK(key); | 
| 1347   DCHECK(value); | 1323   DCHECK(value); | 
| 1348   std::unique_ptr<PutOperationParams> params( | 1324   std::unique_ptr<PutOperationParams> params( | 
| 1349       base::MakeUnique<PutOperationParams>()); | 1325       base::MakeUnique<PutOperationParams>()); | 
| 1350   params->object_store_id = object_store_id; | 1326   params->object_store_id = object_store_id; | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1494                transaction->id()); | 1470                transaction->id()); | 
| 1495     params->callbacks->OnSuccess(*key); | 1471     params->callbacks->OnSuccess(*key); | 
| 1496   } | 1472   } | 
| 1497   FilterObservation(transaction, params->object_store_id, | 1473   FilterObservation(transaction, params->object_store_id, | 
| 1498                     params->put_mode == blink::WebIDBPutModeAddOnly | 1474                     params->put_mode == blink::WebIDBPutModeAddOnly | 
| 1499                         ? blink::WebIDBAdd | 1475                         ? blink::WebIDBAdd | 
| 1500                         : blink::WebIDBPut, | 1476                         : blink::WebIDBPut, | 
| 1501                     IndexedDBKeyRange(*key)); | 1477                     IndexedDBKeyRange(*key)); | 
| 1502 } | 1478 } | 
| 1503 | 1479 | 
| 1504 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, | 1480 void IndexedDBDatabase::SetIndexKeys(IndexedDBTransaction* transaction, | 
| 1505                                      int64_t object_store_id, | 1481                                      int64_t object_store_id, | 
| 1506                                      std::unique_ptr<IndexedDBKey> primary_key, | 1482                                      std::unique_ptr<IndexedDBKey> primary_key, | 
| 1507                                      const std::vector<IndexKeys>& index_keys) { | 1483                                      const std::vector<IndexKeys>& index_keys) { | 
| 1508   IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); |  | 
| 1509   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1510   if (!transaction) | 1484   if (!transaction) | 
| 1511     return; | 1485     return; | 
|  | 1486   IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id()); | 
| 1512   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 1487   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 1513 | 1488 | 
| 1514   // TODO(alecflett): This method could be asynchronous, but we need to | 1489   // TODO(alecflett): This method could be asynchronous, but we need to | 
| 1515   // evaluate if it's worth the extra complexity. | 1490   // evaluate if it's worth the extra complexity. | 
| 1516   IndexedDBBackingStore::RecordIdentifier record_identifier; | 1491   IndexedDBBackingStore::RecordIdentifier record_identifier; | 
| 1517   bool found = false; | 1492   bool found = false; | 
| 1518   leveldb::Status s = backing_store_->KeyExistsInObjectStore( | 1493   leveldb::Status s = backing_store_->KeyExistsInObjectStore( | 
| 1519       transaction->BackingStoreTransaction(), | 1494       transaction->BackingStoreTransaction(), | 
| 1520       metadata_.id, | 1495       metadata_.id, | 
| 1521       object_store_id, | 1496       object_store_id, | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1566     return; | 1541     return; | 
| 1567   } | 1542   } | 
| 1568 | 1543 | 
| 1569   for (const auto& writer : index_writers) { | 1544   for (const auto& writer : index_writers) { | 
| 1570     writer->WriteIndexKeys(record_identifier, backing_store_.get(), | 1545     writer->WriteIndexKeys(record_identifier, backing_store_.get(), | 
| 1571                            transaction->BackingStoreTransaction(), id(), | 1546                            transaction->BackingStoreTransaction(), id(), | 
| 1572                            object_store_id); | 1547                            object_store_id); | 
| 1573   } | 1548   } | 
| 1574 } | 1549 } | 
| 1575 | 1550 | 
| 1576 void IndexedDBDatabase::SetIndexesReady(int64_t transaction_id, | 1551 void IndexedDBDatabase::SetIndexesReady(IndexedDBTransaction* transaction, | 
| 1577                                         int64_t, | 1552                                         int64_t, | 
| 1578                                         const std::vector<int64_t>& index_ids) { | 1553                                         const std::vector<int64_t>& index_ids) { | 
| 1579   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1580   if (!transaction) | 1554   if (!transaction) | 
| 1581     return; | 1555     return; | 
| 1582   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 1556   DCHECK_EQ(transaction->mode(), blink::WebIDBTransactionModeVersionChange); | 
| 1583 | 1557 | 
| 1584   transaction->ScheduleTask( | 1558   transaction->ScheduleTask( | 
| 1585       blink::WebIDBTaskTypePreemptive, | 1559       blink::WebIDBTaskTypePreemptive, | 
| 1586       base::Bind(&IndexedDBDatabase::SetIndexesReadyOperation, | 1560       base::Bind(&IndexedDBDatabase::SetIndexesReadyOperation, | 
| 1587                  this, | 1561                  this, | 
| 1588                  index_ids.size())); | 1562                  index_ids.size())); | 
| 1589 } | 1563 } | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 1603   blink::WebIDBCursorDirection direction; | 1577   blink::WebIDBCursorDirection direction; | 
| 1604   indexed_db::CursorType cursor_type; | 1578   indexed_db::CursorType cursor_type; | 
| 1605   blink::WebIDBTaskType task_type; | 1579   blink::WebIDBTaskType task_type; | 
| 1606   scoped_refptr<IndexedDBCallbacks> callbacks; | 1580   scoped_refptr<IndexedDBCallbacks> callbacks; | 
| 1607 | 1581 | 
| 1608  private: | 1582  private: | 
| 1609   DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); | 1583   DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); | 
| 1610 }; | 1584 }; | 
| 1611 | 1585 | 
| 1612 void IndexedDBDatabase::OpenCursor( | 1586 void IndexedDBDatabase::OpenCursor( | 
| 1613     int64_t transaction_id, | 1587     IndexedDBTransaction* transaction, | 
| 1614     int64_t object_store_id, | 1588     int64_t object_store_id, | 
| 1615     int64_t index_id, | 1589     int64_t index_id, | 
| 1616     std::unique_ptr<IndexedDBKeyRange> key_range, | 1590     std::unique_ptr<IndexedDBKeyRange> key_range, | 
| 1617     blink::WebIDBCursorDirection direction, | 1591     blink::WebIDBCursorDirection direction, | 
| 1618     bool key_only, | 1592     bool key_only, | 
| 1619     blink::WebIDBTaskType task_type, | 1593     blink::WebIDBTaskType task_type, | 
| 1620     scoped_refptr<IndexedDBCallbacks> callbacks) { | 1594     scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 1621   IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction_id); |  | 
| 1622   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1623   if (!transaction) | 1595   if (!transaction) | 
| 1624     return; | 1596     return; | 
|  | 1597   IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction->id()); | 
| 1625 | 1598 | 
| 1626   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 1599   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 
| 1627     return; | 1600     return; | 
| 1628 | 1601 | 
| 1629   std::unique_ptr<OpenCursorOperationParams> params( | 1602   std::unique_ptr<OpenCursorOperationParams> params( | 
| 1630       base::MakeUnique<OpenCursorOperationParams>()); | 1603       base::MakeUnique<OpenCursorOperationParams>()); | 
| 1631   params->object_store_id = object_store_id; | 1604   params->object_store_id = object_store_id; | 
| 1632   params->index_id = index_id; | 1605   params->index_id = index_id; | 
| 1633   params->key_range = std::move(key_range); | 1606   params->key_range = std::move(key_range); | 
| 1634   params->direction = direction; | 1607   params->direction = direction; | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1705       factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1678       factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 
| 1706     } | 1679     } | 
| 1707   } | 1680   } | 
| 1708 | 1681 | 
| 1709   if (!backing_store_cursor) { | 1682   if (!backing_store_cursor) { | 
| 1710     // Why is Success being called? | 1683     // Why is Success being called? | 
| 1711     params->callbacks->OnSuccess(nullptr); | 1684     params->callbacks->OnSuccess(nullptr); | 
| 1712     return; | 1685     return; | 
| 1713   } | 1686   } | 
| 1714 | 1687 | 
| 1715   scoped_refptr<IndexedDBCursor> cursor = | 1688   std::unique_ptr<IndexedDBCursor> cursor = base::MakeUnique<IndexedDBCursor>( | 
| 1716       new IndexedDBCursor(std::move(backing_store_cursor), params->cursor_type, | 1689       std::move(backing_store_cursor), params->cursor_type, params->task_type, | 
| 1717                           params->task_type, transaction); | 1690       transaction); | 
| 1718   params->callbacks->OnSuccess( | 1691   IndexedDBCursor* cursor_ptr = cursor.get(); | 
| 1719       cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1692   transaction->RegisterOpenCursor(cursor_ptr); | 
|  | 1693   params->callbacks->OnSuccess(std::move(cursor), cursor_ptr->key(), | 
|  | 1694                                cursor_ptr->primary_key(), cursor_ptr->Value()); | 
| 1720 } | 1695 } | 
| 1721 | 1696 | 
| 1722 void IndexedDBDatabase::Count(int64_t transaction_id, | 1697 void IndexedDBDatabase::Count(IndexedDBTransaction* transaction, | 
| 1723                               int64_t object_store_id, | 1698                               int64_t object_store_id, | 
| 1724                               int64_t index_id, | 1699                               int64_t index_id, | 
| 1725                               std::unique_ptr<IndexedDBKeyRange> key_range, | 1700                               std::unique_ptr<IndexedDBKeyRange> key_range, | 
| 1726                               scoped_refptr<IndexedDBCallbacks> callbacks) { | 1701                               scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 1727   IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction_id); |  | 
| 1728   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1729   if (!transaction) | 1702   if (!transaction) | 
| 1730     return; | 1703     return; | 
|  | 1704   IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction->id()); | 
| 1731 | 1705 | 
| 1732   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 1706   if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 
| 1733     return; | 1707     return; | 
| 1734 | 1708 | 
| 1735   transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, | 1709   transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, | 
| 1736                                        this, | 1710                                        this, | 
| 1737                                        object_store_id, | 1711                                        object_store_id, | 
| 1738                                        index_id, | 1712                                        index_id, | 
| 1739                                        base::Passed(&key_range), | 1713                                        base::Passed(&key_range), | 
| 1740                                        callbacks)); | 1714                                        callbacks)); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1785   do { | 1759   do { | 
| 1786     ++count; | 1760     ++count; | 
| 1787   } while (backing_store_cursor->Continue(&s)); | 1761   } while (backing_store_cursor->Continue(&s)); | 
| 1788 | 1762 | 
| 1789   // TODO(cmumford): Check for database corruption. | 1763   // TODO(cmumford): Check for database corruption. | 
| 1790 | 1764 | 
| 1791   callbacks->OnSuccess(count); | 1765   callbacks->OnSuccess(count); | 
| 1792 } | 1766 } | 
| 1793 | 1767 | 
| 1794 void IndexedDBDatabase::DeleteRange( | 1768 void IndexedDBDatabase::DeleteRange( | 
| 1795     int64_t transaction_id, | 1769     IndexedDBTransaction* transaction, | 
| 1796     int64_t object_store_id, | 1770     int64_t object_store_id, | 
| 1797     std::unique_ptr<IndexedDBKeyRange> key_range, | 1771     std::unique_ptr<IndexedDBKeyRange> key_range, | 
| 1798     scoped_refptr<IndexedDBCallbacks> callbacks) { | 1772     scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 1799   IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction_id); |  | 
| 1800   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1801   if (!transaction) | 1773   if (!transaction) | 
| 1802     return; | 1774     return; | 
|  | 1775   IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction->id()); | 
| 1803   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1776   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 
| 1804 | 1777 | 
| 1805   if (!ValidateObjectStoreId(object_store_id)) | 1778   if (!ValidateObjectStoreId(object_store_id)) | 
| 1806     return; | 1779     return; | 
| 1807 | 1780 | 
| 1808   transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, | 1781   transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, | 
| 1809                                        this, | 1782                                        this, | 
| 1810                                        object_store_id, | 1783                                        object_store_id, | 
| 1811                                        base::Passed(&key_range), | 1784                                        base::Passed(&key_range), | 
| 1812                                        callbacks)); | 1785                                        callbacks)); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 1832     if (s.IsCorruption()) { | 1805     if (s.IsCorruption()) { | 
| 1833       factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1806       factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 
| 1834     } | 1807     } | 
| 1835     return; | 1808     return; | 
| 1836   } | 1809   } | 
| 1837   callbacks->OnSuccess(); | 1810   callbacks->OnSuccess(); | 
| 1838   FilterObservation(transaction, object_store_id, blink::WebIDBDelete, | 1811   FilterObservation(transaction, object_store_id, blink::WebIDBDelete, | 
| 1839                     *key_range); | 1812                     *key_range); | 
| 1840 } | 1813 } | 
| 1841 | 1814 | 
| 1842 void IndexedDBDatabase::Clear(int64_t transaction_id, | 1815 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, | 
| 1843                               int64_t object_store_id, | 1816                               int64_t object_store_id, | 
| 1844                               scoped_refptr<IndexedDBCallbacks> callbacks) { | 1817                               scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 1845   IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |  | 
| 1846   IndexedDBTransaction* transaction = GetTransaction(transaction_id); |  | 
| 1847   if (!transaction) | 1818   if (!transaction) | 
| 1848     return; | 1819     return; | 
|  | 1820   IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); | 
| 1849   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1821   DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 
| 1850 | 1822 | 
| 1851   if (!ValidateObjectStoreId(object_store_id)) | 1823   if (!ValidateObjectStoreId(object_store_id)) | 
| 1852     return; | 1824     return; | 
| 1853 | 1825 | 
| 1854   transaction->ScheduleTask(base::Bind( | 1826   transaction->ScheduleTask(base::Bind( | 
| 1855       &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); | 1827       &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); | 
| 1856 } | 1828 } | 
| 1857 | 1829 | 
| 1858 void IndexedDBDatabase::ClearOperation( | 1830 void IndexedDBDatabase::ClearOperation( | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1928     callbacks->OnError(error); | 1900     callbacks->OnError(error); | 
| 1929     transaction->Abort(error); | 1901     transaction->Abort(error); | 
| 1930     return; | 1902     return; | 
| 1931   } | 1903   } | 
| 1932 | 1904 | 
| 1933   transaction->ScheduleAbortTask( | 1905   transaction->ScheduleAbortTask( | 
| 1934       base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this, | 1906       base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this, | 
| 1935                  metadata_.version)); | 1907                  metadata_.version)); | 
| 1936   metadata_.version = version; | 1908   metadata_.version = version; | 
| 1937 | 1909 | 
| 1938   active_request_->UpgradeTransactionStarted(old_version); | 1910   active_request_->UpgradeTransactionStarted(old_version, transaction); | 
| 1939 } | 1911 } | 
| 1940 | 1912 | 
| 1941 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, | 1913 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, | 
| 1942                                             bool committed) { | 1914                                             bool committed) { | 
| 1943   IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", id()); | 1915   IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", | 
| 1944   DCHECK(transactions_.find(transaction->id()) != transactions_.end()); | 1916              transaction->id()); | 
| 1945   DCHECK_EQ(transactions_[transaction->id()], transaction); | 1917   --transaction_count_; | 
| 1946   transactions_.erase(transaction->id()); | 1918   DCHECK_LE(0, transaction_count_); | 
| 1947 | 1919 | 
| 1948   // This may be an unrelated transaction finishing while waiting for | 1920   // This may be an unrelated transaction finishing while waiting for | 
| 1949   // connections to close, or the actual upgrade transaction from an active | 1921   // connections to close, or the actual upgrade transaction from an active | 
| 1950   // request. Notify the active request if it's the latter. | 1922   // request. Notify the active request if it's the latter. | 
| 1951   if (active_request_ && | 1923   if (active_request_ && | 
| 1952       transaction->mode() == blink::WebIDBTransactionModeVersionChange) { | 1924       transaction->mode() == blink::WebIDBTransactionModeVersionChange) { | 
| 1953     active_request_->UpgradeTransactionFinished(committed); | 1925     active_request_->UpgradeTransactionFinished(committed); | 
| 1954   } | 1926   } | 
| 1955 } | 1927 } | 
| 1956 | 1928 | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1999   } while (!active_request_ && !pending_requests_.empty()); | 1971   } while (!active_request_ && !pending_requests_.empty()); | 
| 2000 } | 1972 } | 
| 2001 | 1973 | 
| 2002 IndexedDBTransaction* IndexedDBDatabase::CreateTransaction( | 1974 IndexedDBTransaction* IndexedDBDatabase::CreateTransaction( | 
| 2003     int64_t transaction_id, | 1975     int64_t transaction_id, | 
| 2004     IndexedDBConnection* connection, | 1976     IndexedDBConnection* connection, | 
| 2005     const std::vector<int64_t>& object_store_ids, | 1977     const std::vector<int64_t>& object_store_ids, | 
| 2006     blink::WebIDBTransactionMode mode) { | 1978     blink::WebIDBTransactionMode mode) { | 
| 2007   IDB_TRACE1("IndexedDBDatabase::CreateTransaction", "txn.id", transaction_id); | 1979   IDB_TRACE1("IndexedDBDatabase::CreateTransaction", "txn.id", transaction_id); | 
| 2008   DCHECK(connections_.count(connection)); | 1980   DCHECK(connections_.count(connection)); | 
| 2009   DCHECK(transactions_.find(transaction_id) == transactions_.end()); |  | 
| 2010   if (transactions_.find(transaction_id) != transactions_.end()) |  | 
| 2011     return nullptr; |  | 
| 2012 | 1981 | 
| 2013   UMA_HISTOGRAM_COUNTS_1000( | 1982   UMA_HISTOGRAM_COUNTS_1000( | 
| 2014       "WebCore.IndexedDB.Database.OutstandingTransactionCount", | 1983       "WebCore.IndexedDB.Database.OutstandingTransactionCount", | 
| 2015       transactions_.size()); | 1984       transaction_count_); | 
| 2016 | 1985 | 
| 2017   // The transaction will add itself to this database's coordinator, which | 1986   IndexedDBTransaction* transaction = connection->CreateTransaction( | 
| 2018   // manages the lifetime of the object. | 1987       transaction_id, | 
| 2019   IndexedDBTransaction* transaction = | 1988       std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode, | 
| 2020       IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( | 1989       new IndexedDBBackingStore::Transaction(backing_store_.get())); | 
| 2021           transaction_id, connection->GetWeakPtr(), |  | 
| 2022           std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), |  | 
| 2023           mode, new IndexedDBBackingStore::Transaction(backing_store_.get())); |  | 
| 2024   TransactionCreated(transaction); | 1990   TransactionCreated(transaction); | 
| 2025   return transaction; | 1991   return transaction; | 
| 2026 } | 1992 } | 
| 2027 | 1993 | 
| 2028 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { | 1994 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { | 
| 2029   transactions_[transaction->id()] = transaction; | 1995   transaction_count_++; | 
|  | 1996   transaction_coordinator_.DidCreateTransaction(transaction); | 
| 2030 } | 1997 } | 
| 2031 | 1998 | 
| 2032 void IndexedDBDatabase::OpenConnection( | 1999 void IndexedDBDatabase::OpenConnection( | 
| 2033     std::unique_ptr<IndexedDBPendingConnection> connection) { | 2000     std::unique_ptr<IndexedDBPendingConnection> connection) { | 
| 2034   AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection))); | 2001   AppendRequest(base::MakeUnique<OpenRequest>(this, std::move(connection))); | 
| 2035 } | 2002 } | 
| 2036 | 2003 | 
| 2037 void IndexedDBDatabase::DeleteDatabase( | 2004 void IndexedDBDatabase::DeleteDatabase( | 
| 2038     scoped_refptr<IndexedDBCallbacks> callbacks) { | 2005     scoped_refptr<IndexedDBCallbacks> callbacks) { | 
| 2039   AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks)); | 2006   AppendRequest(base::MakeUnique<DeleteRequest>(this, callbacks)); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 2059   DCHECK(connections_.count(connection)); | 2026   DCHECK(connections_.count(connection)); | 
| 2060   DCHECK(connection->IsConnected()); | 2027   DCHECK(connection->IsConnected()); | 
| 2061   DCHECK(connection->database() == this); | 2028   DCHECK(connection->database() == this); | 
| 2062 | 2029 | 
| 2063   IDB_TRACE("IndexedDBDatabase::Close"); | 2030   IDB_TRACE("IndexedDBDatabase::Close"); | 
| 2064 | 2031 | 
| 2065   // Abort outstanding transactions from the closing connection. This can not | 2032   // Abort outstanding transactions from the closing connection. This can not | 
| 2066   // happen if the close is requested by the connection itself as the | 2033   // happen if the close is requested by the connection itself as the | 
| 2067   // front-end defers the close until all transactions are complete, but can | 2034   // front-end defers the close until all transactions are complete, but can | 
| 2068   // occur on process termination or forced close. | 2035   // occur on process termination or forced close. | 
| 2069   { | 2036   connection->AbortAllTransactions(IndexedDBDatabaseError( | 
| 2070     auto transactions(transactions_); | 2037       blink::WebIDBDatabaseExceptionUnknownError, "Connection is closing.")); | 
| 2071     for (const auto& it : transactions) { |  | 
| 2072       if (it.second->callbacks() == connection->callbacks()) |  | 
| 2073         it.second->Abort( |  | 
| 2074             IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |  | 
| 2075                                    "Connection is closing.")); |  | 
| 2076     } |  | 
| 2077   } |  | 
| 2078 | 2038 | 
| 2079   // Abort transactions before removing the connection; aborting may complete | 2039   // Abort transactions before removing the connection; aborting may complete | 
| 2080   // an upgrade, and thus allow the next open/delete requests to proceed. The | 2040   // an upgrade, and thus allow the next open/delete requests to proceed. The | 
| 2081   // new active_request_ should see the old connection count until explicitly | 2041   // new active_request_ should see the old connection count until explicitly | 
| 2082   // notified below. | 2042   // notified below. | 
| 2083   connections_.erase(connection); | 2043   connections_.erase(connection); | 
| 2084 | 2044 | 
| 2085   // Notify the active request, which may need to do cleanup or proceed with | 2045   // Notify the active request, which may need to do cleanup or proceed with | 
| 2086   // the operation. This may trigger other work, such as more connections or | 2046   // the operation. This may trigger other work, such as more connections or | 
| 2087   // deletions, so |active_request_| itself may change. | 2047   // deletions, so |active_request_| itself may change. | 
| 2088   if (active_request_) | 2048   if (active_request_) | 
| 2089     active_request_->OnConnectionClosed(connection); | 2049     active_request_->OnConnectionClosed(connection); | 
| 2090 | 2050 | 
| 2091   // If there are no more connections (current, active, or pending), tell the | 2051   // If there are no more connections (current, active, or pending), tell the | 
| 2092   // factory to clean us up. | 2052   // factory to clean us up. | 
| 2093   if (connections_.empty() && !active_request_ && pending_requests_.empty()) { | 2053   if (connections_.empty() && !active_request_ && pending_requests_.empty()) { | 
| 2094     DCHECK(transactions_.empty()); |  | 
| 2095     backing_store_ = nullptr; | 2054     backing_store_ = nullptr; | 
| 2096     factory_->ReleaseDatabase(identifier_, forced); | 2055     factory_->ReleaseDatabase(identifier_, forced); | 
| 2097   } | 2056   } | 
| 2098 } | 2057 } | 
| 2099 | 2058 | 
| 2100 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 2059 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 
| 2101     int64_t object_store_id, | 2060     int64_t object_store_id, | 
| 2102     IndexedDBTransaction* transaction) { | 2061     IndexedDBTransaction* transaction) { | 
| 2103   DCHECK(!transaction); | 2062   DCHECK(!transaction); | 
| 2104   IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); | 2063   IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 2125 | 2084 | 
| 2126 void IndexedDBDatabase::VersionChangeAbortOperation( | 2085 void IndexedDBDatabase::VersionChangeAbortOperation( | 
| 2127     int64_t previous_version, | 2086     int64_t previous_version, | 
| 2128     IndexedDBTransaction* transaction) { | 2087     IndexedDBTransaction* transaction) { | 
| 2129   DCHECK(!transaction); | 2088   DCHECK(!transaction); | 
| 2130   IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2089   IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 
| 2131   metadata_.version = previous_version; | 2090   metadata_.version = previous_version; | 
| 2132 } | 2091 } | 
| 2133 | 2092 | 
| 2134 }  // namespace content | 2093 }  // namespace content | 
| OLD | NEW | 
|---|