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 <limits> | |
| 8 #include <set> | 9 #include <set> |
| 9 | 10 |
| 10 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 18 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 void IndexedDBDatabase::Abort(int64 transaction_id, | 484 void IndexedDBDatabase::Abort(int64 transaction_id, |
| 484 const IndexedDBDatabaseError& error) { | 485 const IndexedDBDatabaseError& error) { |
| 485 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); | 486 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); |
| 486 // If the transaction is unknown, then it has already been aborted by the | 487 // If the transaction is unknown, then it has already been aborted by the |
| 487 // backend before this call so it is safe to ignore it. | 488 // backend before this call so it is safe to ignore it. |
| 488 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 489 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 489 if (transaction) | 490 if (transaction) |
| 490 transaction->Abort(error); | 491 transaction->Abort(error); |
| 491 } | 492 } |
| 492 | 493 |
| 494 void IndexedDBDatabase::GetAll(int64 transaction_id, | |
| 495 int64 object_store_id, | |
| 496 scoped_ptr<IndexedDBKeyRange> key_range, | |
| 497 int64 max_count, | |
| 498 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 499 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); | |
| 500 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | |
| 501 if (!transaction) | |
| 502 return; | |
| 503 | |
| 504 if (!ValidateObjectStoreId(object_store_id)) | |
| 505 return; | |
| 506 | |
| 507 transaction->ScheduleTask( | |
| 508 base::Bind(&IndexedDBDatabase::GetAllOperation, this, object_store_id, | |
| 509 Passed(&key_range), max_count, callbacks)); | |
| 510 } | |
| 511 | |
| 493 void IndexedDBDatabase::Get(int64 transaction_id, | 512 void IndexedDBDatabase::Get(int64 transaction_id, |
| 494 int64 object_store_id, | 513 int64 object_store_id, |
| 495 int64 index_id, | 514 int64 index_id, |
| 496 scoped_ptr<IndexedDBKeyRange> key_range, | 515 scoped_ptr<IndexedDBKeyRange> key_range, |
| 497 bool key_only, | 516 bool key_only, |
| 498 scoped_refptr<IndexedDBCallbacks> callbacks) { | 517 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 499 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); | 518 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction_id); |
| 500 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 519 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 501 if (!transaction) | 520 if (!transaction) |
| 502 return; | 521 return; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 return; | 688 return; |
| 670 } | 689 } |
| 671 if (object_store_metadata.auto_increment && | 690 if (object_store_metadata.auto_increment && |
| 672 !object_store_metadata.key_path.IsNull()) { | 691 !object_store_metadata.key_path.IsNull()) { |
| 673 callbacks->OnSuccess(&value, *primary_key, object_store_metadata.key_path); | 692 callbacks->OnSuccess(&value, *primary_key, object_store_metadata.key_path); |
| 674 return; | 693 return; |
| 675 } | 694 } |
| 676 callbacks->OnSuccess(&value); | 695 callbacks->OnSuccess(&value); |
| 677 } | 696 } |
| 678 | 697 |
| 698 void IndexedDBDatabase::GetAllOperation( | |
| 699 int64 object_store_id, | |
| 700 scoped_ptr<IndexedDBKeyRange> key_range, | |
| 701 int64 max_count, | |
| 702 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 703 IndexedDBTransaction* transaction) { | |
| 704 IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id()); | |
| 705 | |
| 706 DCHECK_GE(max_count, 0); | |
| 707 if (!max_count) | |
| 708 max_count = std::numeric_limits<decltype(max_count)>::max(); | |
| 709 | |
| 710 DCHECK(metadata_.object_stores.find(object_store_id) != | |
| 711 metadata_.object_stores.end()); | |
| 712 | |
| 713 leveldb::Status s; | |
| 714 | |
| 715 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; | |
| 716 if (key_range->IsEmpty()) { | |
| 717 backing_store_cursor = backing_store_->OpenObjectStoreCursor( | |
| 718 transaction->BackingStoreTransaction(), id(), object_store_id, | |
| 719 *key_range, blink::WebIDBCursorDirectionNext, &s); | |
| 720 } else { | |
| 721 backing_store_cursor = backing_store_->OpenObjectStoreCursor( | |
| 722 transaction->BackingStoreTransaction(), id(), object_store_id, | |
| 723 *key_range, blink::WebIDBCursorDirectionNext, &s); | |
| 724 } | |
| 725 | |
| 726 if (!s.ok()) { | |
| 727 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); | |
| 728 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | |
| 729 "Internal error deleting data in range"); | |
| 730 if (s.IsCorruption()) { | |
| 731 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | |
| 732 error); | |
| 733 } | |
| 734 } | |
| 735 | |
| 736 std::vector<IndexedDBValue> found_values; | |
| 737 if (!backing_store_cursor) { | |
| 738 callbacks->OnSuccessArray(&found_values); | |
| 739 return; | |
| 740 } | |
| 741 | |
| 742 bool did_first_seek = false; | |
| 743 do { | |
| 744 bool cursor_valid; | |
| 745 if (did_first_seek) { | |
| 746 cursor_valid = backing_store_cursor->Continue(&s); | |
| 747 } else { | |
| 748 cursor_valid = backing_store_cursor->FirstSeek(&s); | |
| 749 did_first_seek = true; | |
| 750 } | |
| 751 if (!s.ok()) { | |
| 752 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | |
| 753 "Internal error in GetRecord."); | |
| 754 callbacks->OnError(error); | |
| 755 | |
| 756 if (s.IsCorruption()) | |
| 757 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | |
| 758 error); | |
| 759 return; | |
| 760 } | |
| 761 | |
| 762 if (!cursor_valid) | |
| 763 break; | |
| 764 | |
| 765 IndexedDBValue value; | |
| 766 value.swap(*backing_store_cursor->value()); | |
| 767 found_values.push_back(value); | |
| 768 } while (found_values.size() < static_cast<size_t>(max_count)); | |
|
jsbell
2015/04/08 18:23:52
What's our behavior if the result size is > max IP
cmumford
2015/04/17 23:01:14
I added the size check & TODO for the next patch,
| |
| 769 | |
| 770 callbacks->OnSuccessArray(&found_values); | |
| 771 } | |
| 772 | |
| 679 static scoped_ptr<IndexedDBKey> GenerateKey( | 773 static scoped_ptr<IndexedDBKey> GenerateKey( |
| 680 IndexedDBBackingStore* backing_store, | 774 IndexedDBBackingStore* backing_store, |
| 681 IndexedDBTransaction* transaction, | 775 IndexedDBTransaction* transaction, |
| 682 int64 database_id, | 776 int64 database_id, |
| 683 int64 object_store_id) { | 777 int64 object_store_id) { |
| 684 const int64 max_generator_value = | 778 const int64 max_generator_value = |
| 685 9007199254740992LL; // Maximum integer storable as ECMAScript number. | 779 9007199254740992LL; // Maximum integer storable as ECMAScript number. |
| 686 int64 current_number; | 780 int64 current_number; |
| 687 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( | 781 leveldb::Status s = backing_store->GetKeyGeneratorCurrentNumber( |
| 688 transaction->BackingStoreTransaction(), | 782 transaction->BackingStoreTransaction(), |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 IndexedDBTransaction* transaction) { | 1866 IndexedDBTransaction* transaction) { |
| 1773 DCHECK(!transaction); | 1867 DCHECK(!transaction); |
| 1774 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", | 1868 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", |
| 1775 "txn.id", | 1869 "txn.id", |
| 1776 transaction->id()); | 1870 transaction->id()); |
| 1777 metadata_.version = previous_version; | 1871 metadata_.version = previous_version; |
| 1778 metadata_.int_version = previous_int_version; | 1872 metadata_.int_version = previous_int_version; |
| 1779 } | 1873 } |
| 1780 | 1874 |
| 1781 } // namespace content | 1875 } // namespace content |
| OLD | NEW |