Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: content/browser/indexed_db/indexed_db_database.cc

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use ScopedVector and stl_utils for BlobDataHandles. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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),
jsbell 2013/12/18 23:04:40 We could potentially introduce a IndexedDBPendingC
ericu 2013/12/19 05:19:11 I put a TODO in my notes; I'll look into it.
ericu 2014/03/05 23:30:40 I just put this change in.
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_; }
jsbell 2013/12/18 23:04:40 FYI, I think I have a patch in flight somewhere th
ericu 2013/12/19 05:19:11 Yep--that'll be fun.
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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return; 576 return;
568 } 577 }
569 578
570 key = &backing_store_cursor->key(); 579 key = &backing_store_cursor->key();
571 } 580 }
572 581
573 scoped_ptr<IndexedDBKey> primary_key; 582 scoped_ptr<IndexedDBKey> primary_key;
574 bool ok; 583 bool ok;
575 if (index_id == IndexedDBIndexMetadata::kInvalidId) { 584 if (index_id == IndexedDBIndexMetadata::kInvalidId) {
576 // Object Store Retrieval Operation 585 // Object Store Retrieval Operation
577 std::string value; 586 IndexedDBValue value;
578 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 587 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
579 id(), 588 id(),
580 object_store_id, 589 object_store_id,
581 *key, 590 *key,
582 &value); 591 &value);
583 if (!ok) { 592 if (!ok) {
584 callbacks->OnError( 593 callbacks->OnError(
585 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 594 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
586 "Internal error in GetRecord.")); 595 "Internal error in GetRecord."));
587 return; 596 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 callbacks->OnSuccess(); 629 callbacks->OnSuccess();
621 return; 630 return;
622 } 631 }
623 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 632 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
624 // Index Value Retrieval Operation 633 // Index Value Retrieval Operation
625 callbacks->OnSuccess(*primary_key); 634 callbacks->OnSuccess(*primary_key);
626 return; 635 return;
627 } 636 }
628 637
629 // Index Referenced Value Retrieval Operation 638 // Index Referenced Value Retrieval Operation
630 std::string value; 639 IndexedDBValue value;
631 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 640 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
632 id(), 641 id(),
633 object_store_id, 642 object_store_id,
634 *primary_key, 643 *primary_key,
635 &value); 644 &value);
636 if (!ok) { 645 if (!ok) {
637 callbacks->OnError( 646 callbacks->OnError(
638 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 647 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
639 "Internal error in GetRecord.")); 648 "Internal error in GetRecord."));
640 return; 649 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 transaction->BackingStoreTransaction(), 696 transaction->BackingStoreTransaction(),
688 database_id, 697 database_id,
689 object_store_id, 698 object_store_id,
690 static_cast<int64>(floor(key.number())) + 1, 699 static_cast<int64>(floor(key.number())) + 1,
691 check_current); 700 check_current);
692 } 701 }
693 702
694 struct IndexedDBDatabase::PutOperationParams { 703 struct IndexedDBDatabase::PutOperationParams {
695 PutOperationParams() {} 704 PutOperationParams() {}
696 int64 object_store_id; 705 int64 object_store_id;
697 std::string value; 706 IndexedDBValue value;
707 ScopedVector<webkit_blob::BlobDataHandle> handles;
jsbell 2013/12/18 23:04:40 Would it make sense to add the vector to IndexedDB
ericu 2013/12/19 05:19:11 It's not a clear win to me. We'd use it here, but
698 scoped_ptr<IndexedDBKey> key; 708 scoped_ptr<IndexedDBKey> key;
699 IndexedDBDatabase::PutMode put_mode; 709 IndexedDBDatabase::PutMode put_mode;
700 scoped_refptr<IndexedDBCallbacks> callbacks; 710 scoped_refptr<IndexedDBCallbacks> callbacks;
701 std::vector<int64> index_ids; 711 std::vector<int64> index_ids;
702 std::vector<IndexKeys> index_keys; 712 std::vector<IndexKeys> index_keys;
703 713
704 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); 714 DISALLOW_COPY_AND_ASSIGN(PutOperationParams);
705 }; 715 };
706 716
707 void IndexedDBDatabase::Put(int64 transaction_id, 717 void IndexedDBDatabase::Put(int64 transaction_id,
708 int64 object_store_id, 718 int64 object_store_id,
709 std::string* value, 719 IndexedDBValue* value,
720 ScopedVector<webkit_blob::BlobDataHandle>* handles,
710 scoped_ptr<IndexedDBKey> key, 721 scoped_ptr<IndexedDBKey> key,
711 PutMode put_mode, 722 PutMode put_mode,
712 scoped_refptr<IndexedDBCallbacks> callbacks, 723 scoped_refptr<IndexedDBCallbacks> callbacks,
713 const std::vector<int64>& index_ids, 724 const std::vector<int64>& index_ids,
714 const std::vector<IndexKeys>& index_keys) { 725 const std::vector<IndexKeys>& index_keys) {
715 IDB_TRACE("IndexedDBDatabase::Put"); 726 IDB_TRACE("IndexedDBDatabase::Put");
716 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 727 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
717 if (!transaction) 728 if (!transaction)
718 return; 729 return;
719 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); 730 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY);
720 731
721 if (!ValidateObjectStoreId(object_store_id)) 732 if (!ValidateObjectStoreId(object_store_id))
722 return; 733 return;
723 734
724 DCHECK(key); 735 DCHECK(key);
736 DCHECK(value);
725 scoped_ptr<PutOperationParams> params(new PutOperationParams()); 737 scoped_ptr<PutOperationParams> params(new PutOperationParams());
726 params->object_store_id = object_store_id; 738 params->object_store_id = object_store_id;
727 params->value.swap(*value); 739 params->value.swap(*value);
740 params->handles.swap(*handles);
728 params->key = key.Pass(); 741 params->key = key.Pass();
729 params->put_mode = put_mode; 742 params->put_mode = put_mode;
730 params->callbacks = callbacks; 743 params->callbacks = callbacks;
731 params->index_ids = index_ids; 744 params->index_ids = index_ids;
732 params->index_keys = index_keys; 745 params->index_keys = index_keys;
733 transaction->ScheduleTask(base::Bind( 746 transaction->ScheduleTask(base::Bind(
734 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 747 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
735 } 748 }
736 749
737 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, 750 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 830 }
818 831
819 // Before this point, don't do any mutation. After this point, rollback the 832 // Before this point, don't do any mutation. After this point, rollback the
820 // transaction in case of error. 833 // transaction in case of error.
821 backing_store_success = 834 backing_store_success =
822 backing_store_->PutRecord(transaction->BackingStoreTransaction(), 835 backing_store_->PutRecord(transaction->BackingStoreTransaction(),
823 id(), 836 id(),
824 params->object_store_id, 837 params->object_store_id,
825 *key, 838 *key,
826 params->value, 839 params->value,
840 &params->handles,
827 &record_identifier); 841 &record_identifier);
828 if (!backing_store_success) { 842 if (!backing_store_success) {
829 params->callbacks->OnError(IndexedDBDatabaseError( 843 params->callbacks->OnError(IndexedDBDatabaseError(
830 blink::WebIDBDatabaseExceptionUnknownError, 844 blink::WebIDBDatabaseExceptionUnknownError,
831 "Internal error: backing store error performing put/add.")); 845 "Internal error: backing store error performing put/add."));
832 return; 846 return;
833 } 847 }
834 848
835 for (size_t i = 0; i < index_writers.size(); ++i) { 849 for (size_t i = 0; i < index_writers.size(); ++i) {
836 IndexWriter* index_writer = index_writers[i]; 850 IndexWriter* index_writer = index_writers[i];
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 transaction->BackingStoreTransaction(), 1062 transaction->BackingStoreTransaction(),
1049 id(), 1063 id(),
1050 params->object_store_id, 1064 params->object_store_id,
1051 params->index_id, 1065 params->index_id,
1052 *params->key_range, 1066 *params->key_range,
1053 params->direction); 1067 params->direction);
1054 } 1068 }
1055 } 1069 }
1056 1070
1057 if (!backing_store_cursor) { 1071 if (!backing_store_cursor) {
1058 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); 1072 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
1059 return; 1073 return;
1060 } 1074 }
1061 1075
1062 scoped_refptr<IndexedDBCursor> cursor = 1076 scoped_refptr<IndexedDBCursor> cursor =
1063 new IndexedDBCursor(backing_store_cursor.Pass(), 1077 new IndexedDBCursor(backing_store_cursor.Pass(),
1064 params->cursor_type, 1078 params->cursor_type,
1065 params->task_type, 1079 params->task_type,
1066 transaction); 1080 transaction);
1067 params->callbacks->OnSuccess( 1081 params->callbacks->OnSuccess(
1068 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); 1082 cursor, cursor->key(), cursor->primary_key(), cursor->Value());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 base::Passed(&key_range), 1161 base::Passed(&key_range),
1148 callbacks)); 1162 callbacks));
1149 } 1163 }
1150 1164
1151 void IndexedDBDatabase::DeleteRangeOperation( 1165 void IndexedDBDatabase::DeleteRangeOperation(
1152 int64 object_store_id, 1166 int64 object_store_id,
1153 scoped_ptr<IndexedDBKeyRange> key_range, 1167 scoped_ptr<IndexedDBKeyRange> key_range,
1154 scoped_refptr<IndexedDBCallbacks> callbacks, 1168 scoped_refptr<IndexedDBCallbacks> callbacks,
1155 IndexedDBTransaction* transaction) { 1169 IndexedDBTransaction* transaction) {
1156 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation"); 1170 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation");
1157 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor = 1171 if (!backing_store_->DeleteRange(transaction->BackingStoreTransaction(),
jsbell 2013/12/18 23:04:40 This could be landed early, along with IndexedDBBa
ericu 2013/12/19 05:19:11 ...or just dropped for now, as it doesn't gain any
1158 backing_store_->OpenObjectStoreCursor( 1172 id(), object_store_id, *key_range)) {
1159 transaction->BackingStoreTransaction(), 1173 callbacks->OnError(
1160 id(), 1174 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
1161 object_store_id, 1175 "Internal error deleting data in range"));
1162 *key_range, 1176 return;
1163 indexed_db::CURSOR_NEXT);
1164 if (backing_store_cursor) {
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 } 1177 }
1178
1179 callbacks->OnSuccess(); 1178 callbacks->OnSuccess();
1180 } 1179 }
1181 1180
1182 void IndexedDBDatabase::Clear(int64 transaction_id, 1181 void IndexedDBDatabase::Clear(int64 transaction_id,
1183 int64 object_store_id, 1182 int64 object_store_id,
1184 scoped_refptr<IndexedDBCallbacks> callbacks) { 1183 scoped_refptr<IndexedDBCallbacks> callbacks) {
1185 IDB_TRACE("IndexedDBDatabase::Clear"); 1184 IDB_TRACE("IndexedDBDatabase::Clear");
1186 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1185 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1187 if (!transaction) 1186 if (!transaction)
1188 return; 1187 return;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1370 }
1372 1371
1373 if (!IsOpenConnectionBlocked()) { 1372 if (!IsOpenConnectionBlocked()) {
1374 PendingOpenCallList pending_open_calls; 1373 PendingOpenCallList pending_open_calls;
1375 pending_open_calls_.swap(pending_open_calls); 1374 pending_open_calls_.swap(pending_open_calls);
1376 while (!pending_open_calls.empty()) { 1375 while (!pending_open_calls.empty()) {
1377 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); 1376 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front());
1378 pending_open_calls.pop_front(); 1377 pending_open_calls.pop_front();
1379 OpenConnection(pending_open_call->Callbacks(), 1378 OpenConnection(pending_open_call->Callbacks(),
1380 pending_open_call->DatabaseCallbacks(), 1379 pending_open_call->DatabaseCallbacks(),
1380 pending_open_call->ChildProcessId(),
1381 pending_open_call->TransactionId(), 1381 pending_open_call->TransactionId(),
1382 pending_open_call->Version()); 1382 pending_open_call->Version());
1383 } 1383 }
1384 } 1384 }
1385 } 1385 }
1386 1386
1387 void IndexedDBDatabase::CreateTransaction( 1387 void IndexedDBDatabase::CreateTransaction(
1388 int64 transaction_id, 1388 int64 transaction_id,
1389 IndexedDBConnection* connection, 1389 IndexedDBConnection* connection,
1390 const std::vector<int64>& object_store_ids, 1390 const std::vector<int64>& object_store_ids,
(...skipping 15 matching lines...) Expand all
1406 1406
1407 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { 1407 bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
1408 return !pending_delete_calls_.empty() || 1408 return !pending_delete_calls_.empty() ||
1409 running_version_change_transaction_ || 1409 running_version_change_transaction_ ||
1410 pending_run_version_change_transaction_call_; 1410 pending_run_version_change_transaction_call_;
1411 } 1411 }
1412 1412
1413 void IndexedDBDatabase::OpenConnection( 1413 void IndexedDBDatabase::OpenConnection(
1414 scoped_refptr<IndexedDBCallbacks> callbacks, 1414 scoped_refptr<IndexedDBCallbacks> callbacks,
1415 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1415 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1416 int child_process_id,
1416 int64 transaction_id, 1417 int64 transaction_id,
1417 int64 version) { 1418 int64 version) {
1418 const blink::WebIDBDataLoss kDataLoss = 1419 const blink::WebIDBDataLoss kDataLoss =
1419 blink::WebIDBDataLossNone; 1420 blink::WebIDBDataLossNone;
1420 OpenConnection( 1421 OpenConnection(
1421 callbacks, database_callbacks, transaction_id, version, kDataLoss, ""); 1422 callbacks, database_callbacks, child_process_id, transaction_id, version,
1423 kDataLoss, "");
1422 } 1424 }
1423 1425
1424 void IndexedDBDatabase::OpenConnection( 1426 void IndexedDBDatabase::OpenConnection(
1425 scoped_refptr<IndexedDBCallbacks> callbacks, 1427 scoped_refptr<IndexedDBCallbacks> callbacks,
1426 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1428 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1429 int child_process_id,
1427 int64 transaction_id, 1430 int64 transaction_id,
1428 int64 version, 1431 int64 version,
1429 blink::WebIDBDataLoss data_loss, 1432 blink::WebIDBDataLoss data_loss,
1430 std::string data_loss_message) { 1433 std::string data_loss_message) {
1431 DCHECK(backing_store_); 1434 DCHECK(backing_store_);
1432 1435
1433 // TODO(jsbell): Should have a priority queue so that higher version 1436 // TODO(jsbell): Should have a priority queue so that higher version
1434 // requests are processed first. http://crbug.com/225850 1437 // requests are processed first. http://crbug.com/225850
1435 if (IsOpenConnectionBlocked()) { 1438 if (IsOpenConnectionBlocked()) {
1436 // The backing store only detects data loss when it is first opened. The 1439 // 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 1440 // presence of existing connections means we didn't even check for data loss
1438 // so there'd better not be any. 1441 // so there'd better not be any.
1439 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss); 1442 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss);
1440 pending_open_calls_.push_back(new PendingOpenCall( 1443 pending_open_calls_.push_back(new PendingOpenCall(
1441 callbacks, database_callbacks, transaction_id, version)); 1444 callbacks, database_callbacks, child_process_id, transaction_id,
1445 version));
1442 return; 1446 return;
1443 } 1447 }
1444 1448
1445 if (metadata_.id == kInvalidId) { 1449 if (metadata_.id == kInvalidId) {
1446 // The database was deleted then immediately re-opened; OpenInternal() 1450 // The database was deleted then immediately re-opened; OpenInternal()
1447 // recreates it in the backing store. 1451 // recreates it in the backing store.
1448 if (OpenInternal()) { 1452 if (OpenInternal()) {
1449 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, 1453 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION,
1450 metadata_.int_version); 1454 metadata_.int_version);
1451 } else { 1455 } else {
(...skipping 19 matching lines...) Expand all
1471 1475
1472 scoped_ptr<IndexedDBConnection> connection( 1476 scoped_ptr<IndexedDBConnection> connection(
1473 new IndexedDBConnection(this, database_callbacks)); 1477 new IndexedDBConnection(this, database_callbacks));
1474 1478
1475 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { 1479 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) {
1476 // For unit tests only - skip upgrade steps. Calling from script with 1480 // For unit tests only - skip upgrade steps. Calling from script with
1477 // DEFAULT_INT_VERSION throws exception. 1481 // DEFAULT_INT_VERSION throws exception.
1478 // TODO(jsbell): DCHECK that not in unit tests. 1482 // TODO(jsbell): DCHECK that not in unit tests.
1479 DCHECK(is_new_database); 1483 DCHECK(is_new_database);
1480 connections_.insert(connection.get()); 1484 connections_.insert(connection.get());
1485 backing_store_->GrantChildProcessPermissions(child_process_id);
jsbell 2013/12/18 23:04:40 DRY; can we wrap the connection insertion and gran
ericu 2013/12/19 05:19:11 Done.
1481 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1486 callbacks->OnSuccess(connection.Pass(), this->metadata());
1482 return; 1487 return;
1483 } 1488 }
1484 1489
1485 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { 1490 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) {
1486 if (!is_new_database) { 1491 if (!is_new_database) {
1487 connections_.insert(connection.get()); 1492 connections_.insert(connection.get());
1493 backing_store_->GrantChildProcessPermissions(child_process_id);
1488 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1494 callbacks->OnSuccess(connection.Pass(), this->metadata());
1489 return; 1495 return;
1490 } 1496 }
1491 // Spec says: If no version is specified and no database exists, set 1497 // Spec says: If no version is specified and no database exists, set
1492 // database version to 1. 1498 // database version to 1.
1493 version = 1; 1499 version = 1;
1494 } 1500 }
1495 1501
1496 if (version > metadata_.int_version) { 1502 if (version > metadata_.int_version) {
1497 connections_.insert(connection.get()); 1503 connections_.insert(connection.get());
1504 backing_store_->GrantChildProcessPermissions(child_process_id);
1498 RunVersionChangeTransaction(callbacks, 1505 RunVersionChangeTransaction(callbacks,
1499 connection.Pass(), 1506 connection.Pass(),
1500 transaction_id, 1507 transaction_id,
1501 version, 1508 version,
1502 data_loss, 1509 data_loss,
1503 data_loss_message); 1510 data_loss_message);
1504 return; 1511 return;
1505 } 1512 }
1506 if (version < metadata_.int_version) { 1513 if (version < metadata_.int_version) {
1507 callbacks->OnError(IndexedDBDatabaseError( 1514 callbacks->OnError(IndexedDBDatabaseError(
1508 blink::WebIDBDatabaseExceptionVersionError, 1515 blink::WebIDBDatabaseExceptionVersionError,
1509 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + 1516 ASCIIToUTF16("The requested version (") + Int64ToString16(version) +
1510 ASCIIToUTF16(") is less than the existing version (") + 1517 ASCIIToUTF16(") is less than the existing version (") +
1511 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); 1518 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(").")));
1512 return; 1519 return;
1513 } 1520 }
1514 DCHECK_EQ(version, metadata_.int_version); 1521 DCHECK_EQ(version, metadata_.int_version);
1515 connections_.insert(connection.get()); 1522 connections_.insert(connection.get());
1523 backing_store_->GrantChildProcessPermissions(child_process_id);
1516 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1524 callbacks->OnSuccess(connection.Pass(), this->metadata());
1517 } 1525 }
1518 1526
1519 void IndexedDBDatabase::RunVersionChangeTransaction( 1527 void IndexedDBDatabase::RunVersionChangeTransaction(
1520 scoped_refptr<IndexedDBCallbacks> callbacks, 1528 scoped_refptr<IndexedDBCallbacks> callbacks,
1521 scoped_ptr<IndexedDBConnection> connection, 1529 scoped_ptr<IndexedDBConnection> connection,
1522 int64 transaction_id, 1530 int64 transaction_id,
1523 int64 requested_version, 1531 int64 requested_version,
1524 blink::WebIDBDataLoss data_loss, 1532 blink::WebIDBDataLoss data_loss,
1525 std::string data_loss_message) { 1533 std::string data_loss_message) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 const string16& previous_version, 1725 const string16& previous_version,
1718 int64 previous_int_version, 1726 int64 previous_int_version,
1719 IndexedDBTransaction* transaction) { 1727 IndexedDBTransaction* transaction) {
1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1728 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1721 DCHECK(!transaction); 1729 DCHECK(!transaction);
1722 metadata_.version = previous_version; 1730 metadata_.version = previous_version;
1723 metadata_.int_version = previous_int_version; 1731 metadata_.int_version = previous_int_version;
1724 } 1732 }
1725 1733
1726 } // namespace content 1734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698