| 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 #include <vector> |
| 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" |
| 14 #include "base/memory/scoped_vector.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 15 #include "content/browser/indexed_db/indexed_db_connection.h" | 18 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_cursor.h" | 19 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_factory.h" | 20 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 18 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 21 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
| 19 #include "content/browser/indexed_db/indexed_db_tracing.h" | 22 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 20 #include "content/browser/indexed_db/indexed_db_transaction.h" | 23 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 24 #include "content/browser/indexed_db/indexed_db_value.h" |
| 21 #include "content/common/indexed_db/indexed_db_key_path.h" | 25 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 22 #include "content/common/indexed_db/indexed_db_key_range.h" | 26 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 23 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 28 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 29 #include "webkit/browser/blob/blob_data_handle.h" |
| 25 | 30 |
| 26 using base::Int64ToString16; | 31 using base::Int64ToString16; |
| 27 using blink::WebIDBKeyTypeNumber; | 32 using blink::WebIDBKeyTypeNumber; |
| 28 | 33 |
| 29 namespace content { | 34 namespace content { |
| 30 | 35 |
| 31 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it | 36 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it |
| 32 // isn't a connection yet. | 37 // isn't a connection yet. |
| 33 class IndexedDBDatabase::PendingOpenCall { | 38 class IndexedDBDatabase::PendingOpenCall { |
| 34 public: | 39 public: |
| 35 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 40 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 36 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 41 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 42 int child_process_id, |
| 37 int64 transaction_id, | 43 int64 transaction_id, |
| 38 int64 version) | 44 int64 version) |
| 39 : callbacks_(callbacks), | 45 : callbacks_(callbacks), |
| 40 database_callbacks_(database_callbacks), | 46 database_callbacks_(database_callbacks), |
| 47 child_process_id_(child_process_id), |
| 41 version_(version), | 48 version_(version), |
| 42 transaction_id_(transaction_id) {} | 49 transaction_id_(transaction_id) {} |
| 43 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 50 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } |
| 44 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() { | 51 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() { |
| 45 return database_callbacks_; | 52 return database_callbacks_; |
| 46 } | 53 } |
| 54 int ChildProcessId() { return child_process_id_; } |
| 47 int64 Version() { return version_; } | 55 int64 Version() { return version_; } |
| 48 int64 TransactionId() const { return transaction_id_; } | 56 int64 TransactionId() const { return transaction_id_; } |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 scoped_refptr<IndexedDBCallbacks> callbacks_; | 59 scoped_refptr<IndexedDBCallbacks> callbacks_; |
| 52 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; | 60 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; |
| 61 int child_process_id_; |
| 53 int64 version_; | 62 int64 version_; |
| 54 const int64 transaction_id_; | 63 const int64 transaction_id_; |
| 55 }; | 64 }; |
| 56 | 65 |
| 57 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the | 66 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the |
| 58 // in-progress connection. | 67 // in-progress connection. |
| 59 class IndexedDBDatabase::PendingUpgradeCall { | 68 class IndexedDBDatabase::PendingUpgradeCall { |
| 60 public: | 69 public: |
| 61 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, | 70 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 62 scoped_ptr<IndexedDBConnection> connection, | 71 scoped_ptr<IndexedDBConnection> connection, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return backing_store_->CreateIDBDatabaseMetaData( | 214 return backing_store_->CreateIDBDatabaseMetaData( |
| 206 metadata_.name, metadata_.version, metadata_.int_version, &metadata_.id); | 215 metadata_.name, metadata_.version, metadata_.int_version, &metadata_.id); |
| 207 } | 216 } |
| 208 | 217 |
| 209 IndexedDBDatabase::~IndexedDBDatabase() { | 218 IndexedDBDatabase::~IndexedDBDatabase() { |
| 210 DCHECK(transactions_.empty()); | 219 DCHECK(transactions_.empty()); |
| 211 DCHECK(pending_open_calls_.empty()); | 220 DCHECK(pending_open_calls_.empty()); |
| 212 DCHECK(pending_delete_calls_.empty()); | 221 DCHECK(pending_delete_calls_.empty()); |
| 213 } | 222 } |
| 214 | 223 |
| 224 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( |
| 225 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 226 int child_process_id) { |
| 227 scoped_ptr<IndexedDBConnection> connection( |
| 228 new IndexedDBConnection(this, database_callbacks)); |
| 229 connections_.insert(connection.get()); |
| 230 backing_store_->GrantChildProcessPermissions(child_process_id); |
| 231 return connection.Pass(); |
| 232 } |
| 233 |
| 215 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( | 234 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |
| 216 int64 transaction_id) const { | 235 int64 transaction_id) const { |
| 217 TransactionMap::const_iterator trans_iterator = | 236 TransactionMap::const_iterator trans_iterator = |
| 218 transactions_.find(transaction_id); | 237 transactions_.find(transaction_id); |
| 219 if (trans_iterator == transactions_.end()) | 238 if (trans_iterator == transactions_.end()) |
| 220 return NULL; | 239 return NULL; |
| 221 return trans_iterator->second; | 240 return trans_iterator->second; |
| 222 } | 241 } |
| 223 | 242 |
| 224 bool IndexedDBDatabase::ValidateObjectStoreId(int64 object_store_id) const { | 243 bool IndexedDBDatabase::ValidateObjectStoreId(int64 object_store_id) const { |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 return; | 586 return; |
| 568 } | 587 } |
| 569 | 588 |
| 570 key = &backing_store_cursor->key(); | 589 key = &backing_store_cursor->key(); |
| 571 } | 590 } |
| 572 | 591 |
| 573 scoped_ptr<IndexedDBKey> primary_key; | 592 scoped_ptr<IndexedDBKey> primary_key; |
| 574 bool ok; | 593 bool ok; |
| 575 if (index_id == IndexedDBIndexMetadata::kInvalidId) { | 594 if (index_id == IndexedDBIndexMetadata::kInvalidId) { |
| 576 // Object Store Retrieval Operation | 595 // Object Store Retrieval Operation |
| 577 std::string value; | 596 IndexedDBValue value; |
| 578 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 597 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
| 579 id(), | 598 id(), |
| 580 object_store_id, | 599 object_store_id, |
| 581 *key, | 600 *key, |
| 582 &value); | 601 &value); |
| 583 if (!ok) { | 602 if (!ok) { |
| 584 callbacks->OnError( | 603 callbacks->OnError( |
| 585 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 604 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 586 "Internal error in GetRecord.")); | 605 "Internal error in GetRecord.")); |
| 587 return; | 606 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 callbacks->OnSuccess(); | 639 callbacks->OnSuccess(); |
| 621 return; | 640 return; |
| 622 } | 641 } |
| 623 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 642 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
| 624 // Index Value Retrieval Operation | 643 // Index Value Retrieval Operation |
| 625 callbacks->OnSuccess(*primary_key); | 644 callbacks->OnSuccess(*primary_key); |
| 626 return; | 645 return; |
| 627 } | 646 } |
| 628 | 647 |
| 629 // Index Referenced Value Retrieval Operation | 648 // Index Referenced Value Retrieval Operation |
| 630 std::string value; | 649 IndexedDBValue value; |
| 631 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 650 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
| 632 id(), | 651 id(), |
| 633 object_store_id, | 652 object_store_id, |
| 634 *primary_key, | 653 *primary_key, |
| 635 &value); | 654 &value); |
| 636 if (!ok) { | 655 if (!ok) { |
| 637 callbacks->OnError( | 656 callbacks->OnError( |
| 638 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 657 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 639 "Internal error in GetRecord.")); | 658 "Internal error in GetRecord.")); |
| 640 return; | 659 return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 transaction->BackingStoreTransaction(), | 706 transaction->BackingStoreTransaction(), |
| 688 database_id, | 707 database_id, |
| 689 object_store_id, | 708 object_store_id, |
| 690 static_cast<int64>(floor(key.number())) + 1, | 709 static_cast<int64>(floor(key.number())) + 1, |
| 691 check_current); | 710 check_current); |
| 692 } | 711 } |
| 693 | 712 |
| 694 struct IndexedDBDatabase::PutOperationParams { | 713 struct IndexedDBDatabase::PutOperationParams { |
| 695 PutOperationParams() {} | 714 PutOperationParams() {} |
| 696 int64 object_store_id; | 715 int64 object_store_id; |
| 697 std::string value; | 716 IndexedDBValue value; |
| 717 ScopedVector<webkit_blob::BlobDataHandle> handles; |
| 698 scoped_ptr<IndexedDBKey> key; | 718 scoped_ptr<IndexedDBKey> key; |
| 699 IndexedDBDatabase::PutMode put_mode; | 719 IndexedDBDatabase::PutMode put_mode; |
| 700 scoped_refptr<IndexedDBCallbacks> callbacks; | 720 scoped_refptr<IndexedDBCallbacks> callbacks; |
| 701 std::vector<int64> index_ids; | 721 std::vector<int64> index_ids; |
| 702 std::vector<IndexKeys> index_keys; | 722 std::vector<IndexKeys> index_keys; |
| 703 | 723 |
| 704 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 724 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
| 705 }; | 725 }; |
| 706 | 726 |
| 707 void IndexedDBDatabase::Put(int64 transaction_id, | 727 void IndexedDBDatabase::Put(int64 transaction_id, |
| 708 int64 object_store_id, | 728 int64 object_store_id, |
| 709 std::string* value, | 729 IndexedDBValue* value, |
| 730 ScopedVector<webkit_blob::BlobDataHandle>* handles, |
| 710 scoped_ptr<IndexedDBKey> key, | 731 scoped_ptr<IndexedDBKey> key, |
| 711 PutMode put_mode, | 732 PutMode put_mode, |
| 712 scoped_refptr<IndexedDBCallbacks> callbacks, | 733 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 713 const std::vector<int64>& index_ids, | 734 const std::vector<int64>& index_ids, |
| 714 const std::vector<IndexKeys>& index_keys) { | 735 const std::vector<IndexKeys>& index_keys) { |
| 715 IDB_TRACE("IndexedDBDatabase::Put"); | 736 IDB_TRACE("IndexedDBDatabase::Put"); |
| 716 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 737 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 717 if (!transaction) | 738 if (!transaction) |
| 718 return; | 739 return; |
| 719 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 740 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
| 720 | 741 |
| 721 if (!ValidateObjectStoreId(object_store_id)) | 742 if (!ValidateObjectStoreId(object_store_id)) |
| 722 return; | 743 return; |
| 723 | 744 |
| 724 DCHECK(key); | 745 DCHECK(key); |
| 746 DCHECK(value); |
| 725 scoped_ptr<PutOperationParams> params(new PutOperationParams()); | 747 scoped_ptr<PutOperationParams> params(new PutOperationParams()); |
| 726 params->object_store_id = object_store_id; | 748 params->object_store_id = object_store_id; |
| 727 params->value.swap(*value); | 749 params->value.swap(*value); |
| 750 params->handles.swap(*handles); |
| 728 params->key = key.Pass(); | 751 params->key = key.Pass(); |
| 729 params->put_mode = put_mode; | 752 params->put_mode = put_mode; |
| 730 params->callbacks = callbacks; | 753 params->callbacks = callbacks; |
| 731 params->index_ids = index_ids; | 754 params->index_ids = index_ids; |
| 732 params->index_keys = index_keys; | 755 params->index_keys = index_keys; |
| 733 transaction->ScheduleTask(base::Bind( | 756 transaction->ScheduleTask(base::Bind( |
| 734 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); | 757 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); |
| 735 } | 758 } |
| 736 | 759 |
| 737 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, | 760 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 } | 840 } |
| 818 | 841 |
| 819 // Before this point, don't do any mutation. After this point, rollback the | 842 // Before this point, don't do any mutation. After this point, rollback the |
| 820 // transaction in case of error. | 843 // transaction in case of error. |
| 821 backing_store_success = | 844 backing_store_success = |
| 822 backing_store_->PutRecord(transaction->BackingStoreTransaction(), | 845 backing_store_->PutRecord(transaction->BackingStoreTransaction(), |
| 823 id(), | 846 id(), |
| 824 params->object_store_id, | 847 params->object_store_id, |
| 825 *key, | 848 *key, |
| 826 params->value, | 849 params->value, |
| 850 ¶ms->handles, |
| 827 &record_identifier); | 851 &record_identifier); |
| 828 if (!backing_store_success) { | 852 if (!backing_store_success) { |
| 829 params->callbacks->OnError(IndexedDBDatabaseError( | 853 params->callbacks->OnError(IndexedDBDatabaseError( |
| 830 blink::WebIDBDatabaseExceptionUnknownError, | 854 blink::WebIDBDatabaseExceptionUnknownError, |
| 831 "Internal error: backing store error performing put/add.")); | 855 "Internal error: backing store error performing put/add.")); |
| 832 return; | 856 return; |
| 833 } | 857 } |
| 834 | 858 |
| 835 for (size_t i = 0; i < index_writers.size(); ++i) { | 859 for (size_t i = 0; i < index_writers.size(); ++i) { |
| 836 IndexWriter* index_writer = index_writers[i]; | 860 IndexWriter* index_writer = index_writers[i]; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 transaction->BackingStoreTransaction(), | 1072 transaction->BackingStoreTransaction(), |
| 1049 id(), | 1073 id(), |
| 1050 params->object_store_id, | 1074 params->object_store_id, |
| 1051 params->index_id, | 1075 params->index_id, |
| 1052 *params->key_range, | 1076 *params->key_range, |
| 1053 params->direction); | 1077 params->direction); |
| 1054 } | 1078 } |
| 1055 } | 1079 } |
| 1056 | 1080 |
| 1057 if (!backing_store_cursor) { | 1081 if (!backing_store_cursor) { |
| 1058 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); | 1082 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 1059 return; | 1083 return; |
| 1060 } | 1084 } |
| 1061 | 1085 |
| 1062 scoped_refptr<IndexedDBCursor> cursor = | 1086 scoped_refptr<IndexedDBCursor> cursor = |
| 1063 new IndexedDBCursor(backing_store_cursor.Pass(), | 1087 new IndexedDBCursor(backing_store_cursor.Pass(), |
| 1064 params->cursor_type, | 1088 params->cursor_type, |
| 1065 params->task_type, | 1089 params->task_type, |
| 1066 transaction); | 1090 transaction); |
| 1067 params->callbacks->OnSuccess( | 1091 params->callbacks->OnSuccess( |
| 1068 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1092 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 base::Passed(&key_range), | 1171 base::Passed(&key_range), |
| 1148 callbacks)); | 1172 callbacks)); |
| 1149 } | 1173 } |
| 1150 | 1174 |
| 1151 void IndexedDBDatabase::DeleteRangeOperation( | 1175 void IndexedDBDatabase::DeleteRangeOperation( |
| 1152 int64 object_store_id, | 1176 int64 object_store_id, |
| 1153 scoped_ptr<IndexedDBKeyRange> key_range, | 1177 scoped_ptr<IndexedDBKeyRange> key_range, |
| 1154 scoped_refptr<IndexedDBCallbacks> callbacks, | 1178 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1155 IndexedDBTransaction* transaction) { | 1179 IndexedDBTransaction* transaction) { |
| 1156 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation"); | 1180 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation"); |
| 1157 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor = | 1181 if (!backing_store_->DeleteRange(transaction->BackingStoreTransaction(), |
| 1158 backing_store_->OpenObjectStoreCursor( | 1182 id(), |
| 1159 transaction->BackingStoreTransaction(), | 1183 object_store_id, |
| 1160 id(), | 1184 *key_range)) { |
| 1161 object_store_id, | 1185 callbacks->OnError( |
| 1162 *key_range, | 1186 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 1163 indexed_db::CURSOR_NEXT); | 1187 "Internal error deleting data in range")); |
| 1164 if (backing_store_cursor) { | 1188 return; |
| 1165 do { | |
| 1166 if (!backing_store_->DeleteRecord( | |
| 1167 transaction->BackingStoreTransaction(), | |
| 1168 id(), | |
| 1169 object_store_id, | |
| 1170 backing_store_cursor->record_identifier())) { | |
| 1171 callbacks->OnError( | |
| 1172 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | |
| 1173 "Internal error deleting data in range")); | |
| 1174 return; | |
| 1175 } | |
| 1176 } while (backing_store_cursor->Continue()); | |
| 1177 } | 1189 } |
| 1178 | |
| 1179 callbacks->OnSuccess(); | 1190 callbacks->OnSuccess(); |
| 1180 } | 1191 } |
| 1181 | 1192 |
| 1182 void IndexedDBDatabase::Clear(int64 transaction_id, | 1193 void IndexedDBDatabase::Clear(int64 transaction_id, |
| 1183 int64 object_store_id, | 1194 int64 object_store_id, |
| 1184 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1195 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1185 IDB_TRACE("IndexedDBDatabase::Clear"); | 1196 IDB_TRACE("IndexedDBDatabase::Clear"); |
| 1186 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1197 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 1187 if (!transaction) | 1198 if (!transaction) |
| 1188 return; | 1199 return; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 } | 1382 } |
| 1372 | 1383 |
| 1373 if (!IsOpenConnectionBlocked()) { | 1384 if (!IsOpenConnectionBlocked()) { |
| 1374 PendingOpenCallList pending_open_calls; | 1385 PendingOpenCallList pending_open_calls; |
| 1375 pending_open_calls_.swap(pending_open_calls); | 1386 pending_open_calls_.swap(pending_open_calls); |
| 1376 while (!pending_open_calls.empty()) { | 1387 while (!pending_open_calls.empty()) { |
| 1377 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); | 1388 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); |
| 1378 pending_open_calls.pop_front(); | 1389 pending_open_calls.pop_front(); |
| 1379 OpenConnection(pending_open_call->Callbacks(), | 1390 OpenConnection(pending_open_call->Callbacks(), |
| 1380 pending_open_call->DatabaseCallbacks(), | 1391 pending_open_call->DatabaseCallbacks(), |
| 1392 pending_open_call->ChildProcessId(), |
| 1381 pending_open_call->TransactionId(), | 1393 pending_open_call->TransactionId(), |
| 1382 pending_open_call->Version()); | 1394 pending_open_call->Version()); |
| 1383 } | 1395 } |
| 1384 } | 1396 } |
| 1385 } | 1397 } |
| 1386 | 1398 |
| 1387 void IndexedDBDatabase::CreateTransaction( | 1399 void IndexedDBDatabase::CreateTransaction( |
| 1388 int64 transaction_id, | 1400 int64 transaction_id, |
| 1389 IndexedDBConnection* connection, | 1401 IndexedDBConnection* connection, |
| 1390 const std::vector<int64>& object_store_ids, | 1402 const std::vector<int64>& object_store_ids, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1406 | 1418 |
| 1407 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { | 1419 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
| 1408 return !pending_delete_calls_.empty() || | 1420 return !pending_delete_calls_.empty() || |
| 1409 running_version_change_transaction_ || | 1421 running_version_change_transaction_ || |
| 1410 pending_run_version_change_transaction_call_; | 1422 pending_run_version_change_transaction_call_; |
| 1411 } | 1423 } |
| 1412 | 1424 |
| 1413 void IndexedDBDatabase::OpenConnection( | 1425 void IndexedDBDatabase::OpenConnection( |
| 1414 scoped_refptr<IndexedDBCallbacks> callbacks, | 1426 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1415 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 1427 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 1428 int child_process_id, |
| 1416 int64 transaction_id, | 1429 int64 transaction_id, |
| 1417 int64 version) { | 1430 int64 version) { |
| 1418 const blink::WebIDBDataLoss kDataLoss = | 1431 const blink::WebIDBDataLoss kDataLoss = |
| 1419 blink::WebIDBDataLossNone; | 1432 blink::WebIDBDataLossNone; |
| 1420 OpenConnection( | 1433 OpenConnection(callbacks, |
| 1421 callbacks, database_callbacks, transaction_id, version, kDataLoss, ""); | 1434 database_callbacks, |
| 1435 child_process_id, |
| 1436 transaction_id, |
| 1437 version, |
| 1438 kDataLoss, |
| 1439 ""); |
| 1422 } | 1440 } |
| 1423 | 1441 |
| 1424 void IndexedDBDatabase::OpenConnection( | 1442 void IndexedDBDatabase::OpenConnection( |
| 1425 scoped_refptr<IndexedDBCallbacks> callbacks, | 1443 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1426 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 1444 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 1445 int child_process_id, |
| 1427 int64 transaction_id, | 1446 int64 transaction_id, |
| 1428 int64 version, | 1447 int64 version, |
| 1429 blink::WebIDBDataLoss data_loss, | 1448 blink::WebIDBDataLoss data_loss, |
| 1430 std::string data_loss_message) { | 1449 std::string data_loss_message) { |
| 1431 DCHECK(backing_store_); | 1450 DCHECK(backing_store_); |
| 1432 | 1451 |
| 1433 // TODO(jsbell): Should have a priority queue so that higher version | 1452 // TODO(jsbell): Should have a priority queue so that higher version |
| 1434 // requests are processed first. http://crbug.com/225850 | 1453 // requests are processed first. http://crbug.com/225850 |
| 1435 if (IsOpenConnectionBlocked()) { | 1454 if (IsOpenConnectionBlocked()) { |
| 1436 // The backing store only detects data loss when it is first opened. The | 1455 // The backing store only detects data loss when it is first opened. The |
| 1437 // presence of existing connections means we didn't even check for data loss | 1456 // presence of existing connections means we didn't even check for data loss |
| 1438 // so there'd better not be any. | 1457 // so there'd better not be any. |
| 1439 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss); | 1458 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss); |
| 1440 pending_open_calls_.push_back(new PendingOpenCall( | 1459 pending_open_calls_.push_back(new PendingOpenCall(callbacks, |
| 1441 callbacks, database_callbacks, transaction_id, version)); | 1460 database_callbacks, |
| 1461 child_process_id, |
| 1462 transaction_id, |
| 1463 version)); |
| 1442 return; | 1464 return; |
| 1443 } | 1465 } |
| 1444 | 1466 |
| 1445 if (metadata_.id == kInvalidId) { | 1467 if (metadata_.id == kInvalidId) { |
| 1446 // The database was deleted then immediately re-opened; OpenInternal() | 1468 // The database was deleted then immediately re-opened; OpenInternal() |
| 1447 // recreates it in the backing store. | 1469 // recreates it in the backing store. |
| 1448 if (OpenInternal()) { | 1470 if (OpenInternal()) { |
| 1449 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, | 1471 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, |
| 1450 metadata_.int_version); | 1472 metadata_.int_version); |
| 1451 } else { | 1473 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1462 return; | 1484 return; |
| 1463 } | 1485 } |
| 1464 } | 1486 } |
| 1465 | 1487 |
| 1466 // We infer that the database didn't exist from its lack of either type of | 1488 // We infer that the database didn't exist from its lack of either type of |
| 1467 // version. | 1489 // version. |
| 1468 bool is_new_database = | 1490 bool is_new_database = |
| 1469 metadata_.version == kNoStringVersion && | 1491 metadata_.version == kNoStringVersion && |
| 1470 metadata_.int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION; | 1492 metadata_.int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION; |
| 1471 | 1493 |
| 1472 scoped_ptr<IndexedDBConnection> connection( | |
| 1473 new IndexedDBConnection(this, database_callbacks)); | |
| 1474 | |
| 1475 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { | 1494 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { |
| 1476 // For unit tests only - skip upgrade steps. Calling from script with | 1495 // For unit tests only - skip upgrade steps. Calling from script with |
| 1477 // DEFAULT_INT_VERSION throws exception. | 1496 // DEFAULT_INT_VERSION throws exception. |
| 1478 // TODO(jsbell): DCHECK that not in unit tests. | 1497 // TODO(jsbell): DCHECK that not in unit tests. |
| 1479 DCHECK(is_new_database); | 1498 DCHECK(is_new_database); |
| 1480 connections_.insert(connection.get()); | 1499 callbacks->OnSuccess( |
| 1481 callbacks->OnSuccess(connection.Pass(), this->metadata()); | 1500 CreateConnection(database_callbacks, child_process_id), |
| 1501 this->metadata()); |
| 1482 return; | 1502 return; |
| 1483 } | 1503 } |
| 1484 | 1504 |
| 1485 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { | 1505 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { |
| 1486 if (!is_new_database) { | 1506 if (!is_new_database) { |
| 1487 connections_.insert(connection.get()); | 1507 callbacks->OnSuccess( |
| 1488 callbacks->OnSuccess(connection.Pass(), this->metadata()); | 1508 CreateConnection(database_callbacks, child_process_id), |
| 1509 this->metadata()); |
| 1489 return; | 1510 return; |
| 1490 } | 1511 } |
| 1491 // Spec says: If no version is specified and no database exists, set | 1512 // Spec says: If no version is specified and no database exists, set |
| 1492 // database version to 1. | 1513 // database version to 1. |
| 1493 version = 1; | 1514 version = 1; |
| 1494 } | 1515 } |
| 1495 | 1516 |
| 1496 if (version > metadata_.int_version) { | 1517 if (version > metadata_.int_version) { |
| 1497 connections_.insert(connection.get()); | 1518 RunVersionChangeTransaction( |
| 1498 RunVersionChangeTransaction(callbacks, | 1519 callbacks, |
| 1499 connection.Pass(), | 1520 CreateConnection(database_callbacks, child_process_id), |
| 1500 transaction_id, | 1521 transaction_id, |
| 1501 version, | 1522 version, |
| 1502 data_loss, | 1523 data_loss, |
| 1503 data_loss_message); | 1524 data_loss_message); |
| 1504 return; | 1525 return; |
| 1505 } | 1526 } |
| 1506 if (version < metadata_.int_version) { | 1527 if (version < metadata_.int_version) { |
| 1507 callbacks->OnError(IndexedDBDatabaseError( | 1528 callbacks->OnError(IndexedDBDatabaseError( |
| 1508 blink::WebIDBDatabaseExceptionVersionError, | 1529 blink::WebIDBDatabaseExceptionVersionError, |
| 1509 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + | 1530 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + |
| 1510 ASCIIToUTF16(") is less than the existing version (") + | 1531 ASCIIToUTF16(") is less than the existing version (") + |
| 1511 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); | 1532 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); |
| 1512 return; | 1533 return; |
| 1513 } | 1534 } |
| 1514 DCHECK_EQ(version, metadata_.int_version); | 1535 DCHECK_EQ(version, metadata_.int_version); |
| 1515 connections_.insert(connection.get()); | 1536 callbacks->OnSuccess( |
| 1516 callbacks->OnSuccess(connection.Pass(), this->metadata()); | 1537 CreateConnection(database_callbacks, child_process_id), |
| 1538 this->metadata()); |
| 1517 } | 1539 } |
| 1518 | 1540 |
| 1519 void IndexedDBDatabase::RunVersionChangeTransaction( | 1541 void IndexedDBDatabase::RunVersionChangeTransaction( |
| 1520 scoped_refptr<IndexedDBCallbacks> callbacks, | 1542 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1521 scoped_ptr<IndexedDBConnection> connection, | 1543 scoped_ptr<IndexedDBConnection> connection, |
| 1522 int64 transaction_id, | 1544 int64 transaction_id, |
| 1523 int64 requested_version, | 1545 int64 requested_version, |
| 1524 blink::WebIDBDataLoss data_loss, | 1546 blink::WebIDBDataLoss data_loss, |
| 1525 std::string data_loss_message) { | 1547 std::string data_loss_message) { |
| 1526 | 1548 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 const string16& previous_version, | 1739 const string16& previous_version, |
| 1718 int64 previous_int_version, | 1740 int64 previous_int_version, |
| 1719 IndexedDBTransaction* transaction) { | 1741 IndexedDBTransaction* transaction) { |
| 1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1742 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1721 DCHECK(!transaction); | 1743 DCHECK(!transaction); |
| 1722 metadata_.version = previous_version; | 1744 metadata_.version = previous_version; |
| 1723 metadata_.int_version = previous_int_version; | 1745 metadata_.int_version = previous_int_version; |
| 1724 } | 1746 } |
| 1725 | 1747 |
| 1726 } // namespace content | 1748 } // namespace content |
| OLD | NEW |