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

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: Settle on one name for the live blob journal. 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"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "content/browser/indexed_db/indexed_db_blob_info.h"
15 #include "content/browser/indexed_db/indexed_db_connection.h" 17 #include "content/browser/indexed_db/indexed_db_connection.h"
16 #include "content/browser/indexed_db/indexed_db_cursor.h" 18 #include "content/browser/indexed_db/indexed_db_cursor.h"
17 #include "content/browser/indexed_db/indexed_db_factory.h" 19 #include "content/browser/indexed_db/indexed_db_factory.h"
18 #include "content/browser/indexed_db/indexed_db_index_writer.h" 20 #include "content/browser/indexed_db/indexed_db_index_writer.h"
19 #include "content/browser/indexed_db/indexed_db_tracing.h" 21 #include "content/browser/indexed_db/indexed_db_tracing.h"
20 #include "content/browser/indexed_db/indexed_db_transaction.h" 22 #include "content/browser/indexed_db/indexed_db_transaction.h"
23 #include "content/browser/indexed_db/indexed_db_value.h"
21 #include "content/common/indexed_db/indexed_db_key_path.h" 24 #include "content/common/indexed_db/indexed_db_key_path.h"
22 #include "content/common/indexed_db/indexed_db_key_range.h" 25 #include "content/common/indexed_db/indexed_db_key_range.h"
23 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 27 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
25 28
26 using base::Int64ToString16; 29 using base::Int64ToString16;
27 using blink::WebIDBKeyTypeNumber; 30 using blink::WebIDBKeyTypeNumber;
28 31
29 namespace content { 32 namespace content {
30 33
31 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it 34 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it
32 // isn't a connection yet. 35 // isn't a connection yet.
33 class IndexedDBDatabase::PendingOpenCall { 36 class IndexedDBDatabase::PendingOpenCall {
34 public: 37 public:
35 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, 38 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks,
36 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 39 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
40 int child_process_id,
37 int64 transaction_id, 41 int64 transaction_id,
38 int64 version) 42 int64 version)
39 : callbacks_(callbacks), 43 : callbacks_(callbacks),
40 database_callbacks_(database_callbacks), 44 database_callbacks_(database_callbacks),
45 child_process_id_(child_process_id),
41 version_(version), 46 version_(version),
42 transaction_id_(transaction_id) {} 47 transaction_id_(transaction_id) {}
43 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } 48 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
44 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() { 49 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() {
45 return database_callbacks_; 50 return database_callbacks_;
46 } 51 }
52 int ChildProcessId() { return child_process_id_; }
47 int64 Version() { return version_; } 53 int64 Version() { return version_; }
48 int64 TransactionId() const { return transaction_id_; } 54 int64 TransactionId() const { return transaction_id_; }
49 55
50 private: 56 private:
51 scoped_refptr<IndexedDBCallbacks> callbacks_; 57 scoped_refptr<IndexedDBCallbacks> callbacks_;
52 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; 58 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
59 int child_process_id_;
53 int64 version_; 60 int64 version_;
54 const int64 transaction_id_; 61 const int64 transaction_id_;
55 }; 62 };
56 63
57 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the 64 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the
58 // in-progress connection. 65 // in-progress connection.
59 class IndexedDBDatabase::PendingUpgradeCall { 66 class IndexedDBDatabase::PendingUpgradeCall {
60 public: 67 public:
61 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, 68 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks,
62 scoped_ptr<IndexedDBConnection> connection, 69 scoped_ptr<IndexedDBConnection> connection,
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return; 574 return;
568 } 575 }
569 576
570 key = &backing_store_cursor->key(); 577 key = &backing_store_cursor->key();
571 } 578 }
572 579
573 scoped_ptr<IndexedDBKey> primary_key; 580 scoped_ptr<IndexedDBKey> primary_key;
574 bool ok; 581 bool ok;
575 if (index_id == IndexedDBIndexMetadata::kInvalidId) { 582 if (index_id == IndexedDBIndexMetadata::kInvalidId) {
576 // Object Store Retrieval Operation 583 // Object Store Retrieval Operation
577 std::string value; 584 IndexedDBValue value;
578 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 585 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
579 id(), 586 id(),
580 object_store_id, 587 object_store_id,
581 *key, 588 *key,
582 &value); 589 &value);
583 if (!ok) { 590 if (!ok) {
584 callbacks->OnError( 591 callbacks->OnError(
585 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 592 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
586 "Internal error in GetRecord.")); 593 "Internal error in GetRecord."));
587 return; 594 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 callbacks->OnSuccess(); 627 callbacks->OnSuccess();
621 return; 628 return;
622 } 629 }
623 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 630 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
624 // Index Value Retrieval Operation 631 // Index Value Retrieval Operation
625 callbacks->OnSuccess(*primary_key); 632 callbacks->OnSuccess(*primary_key);
626 return; 633 return;
627 } 634 }
628 635
629 // Index Referenced Value Retrieval Operation 636 // Index Referenced Value Retrieval Operation
630 std::string value; 637 IndexedDBValue value;
631 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 638 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
632 id(), 639 id(),
633 object_store_id, 640 object_store_id,
634 *primary_key, 641 *primary_key,
635 &value); 642 &value);
636 if (!ok) { 643 if (!ok) {
637 callbacks->OnError( 644 callbacks->OnError(
638 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 645 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
639 "Internal error in GetRecord.")); 646 "Internal error in GetRecord."));
640 return; 647 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( 693 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber(
687 transaction->BackingStoreTransaction(), 694 transaction->BackingStoreTransaction(),
688 database_id, 695 database_id,
689 object_store_id, 696 object_store_id,
690 static_cast<int64>(floor(key.number())) + 1, 697 static_cast<int64>(floor(key.number())) + 1,
691 check_current); 698 check_current);
692 } 699 }
693 700
694 struct IndexedDBDatabase::PutOperationParams { 701 struct IndexedDBDatabase::PutOperationParams {
695 PutOperationParams() {} 702 PutOperationParams() {}
703 ~PutOperationParams() {
704 std::vector<webkit_blob::BlobDataHandle*>::iterator iter;
705 for (iter = handles.begin(); iter != handles.end(); ++iter)
706 delete *iter;
707 handles.clear();
708 }
696 int64 object_store_id; 709 int64 object_store_id;
697 std::string value; 710 IndexedDBValue value;
711 std::vector<webkit_blob::BlobDataHandle*> handles;
698 scoped_ptr<IndexedDBKey> key; 712 scoped_ptr<IndexedDBKey> key;
699 IndexedDBDatabase::PutMode put_mode; 713 IndexedDBDatabase::PutMode put_mode;
700 scoped_refptr<IndexedDBCallbacks> callbacks; 714 scoped_refptr<IndexedDBCallbacks> callbacks;
701 std::vector<int64> index_ids; 715 std::vector<int64> index_ids;
702 std::vector<IndexKeys> index_keys; 716 std::vector<IndexKeys> index_keys;
703 717
704 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); 718 DISALLOW_COPY_AND_ASSIGN(PutOperationParams);
705 }; 719 };
706 720
707 void IndexedDBDatabase::Put(int64 transaction_id, 721 void IndexedDBDatabase::Put(int64 transaction_id,
708 int64 object_store_id, 722 int64 object_store_id,
709 std::string* value, 723 IndexedDBValue* value,
724 std::vector<webkit_blob::BlobDataHandle*>* handles,
710 scoped_ptr<IndexedDBKey> key, 725 scoped_ptr<IndexedDBKey> key,
711 PutMode put_mode, 726 PutMode put_mode,
712 scoped_refptr<IndexedDBCallbacks> callbacks, 727 scoped_refptr<IndexedDBCallbacks> callbacks,
713 const std::vector<int64>& index_ids, 728 const std::vector<int64>& index_ids,
714 const std::vector<IndexKeys>& index_keys) { 729 const std::vector<IndexKeys>& index_keys) {
715 IDB_TRACE("IndexedDBDatabase::Put"); 730 IDB_TRACE("IndexedDBDatabase::Put");
716 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 731 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
717 if (!transaction) 732 if (!transaction)
718 return; 733 return;
719 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); 734 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY);
720 735
721 if (!ValidateObjectStoreId(object_store_id)) 736 if (!ValidateObjectStoreId(object_store_id))
722 return; 737 return;
723 738
724 DCHECK(key); 739 DCHECK(key);
740 DCHECK(value);
725 scoped_ptr<PutOperationParams> params(new PutOperationParams()); 741 scoped_ptr<PutOperationParams> params(new PutOperationParams());
726 params->object_store_id = object_store_id; 742 params->object_store_id = object_store_id;
727 params->value.swap(*value); 743 params->value.swap(*value);
744 params->handles.swap(*handles);
728 params->key = key.Pass(); 745 params->key = key.Pass();
729 params->put_mode = put_mode; 746 params->put_mode = put_mode;
730 params->callbacks = callbacks; 747 params->callbacks = callbacks;
731 params->index_ids = index_ids; 748 params->index_ids = index_ids;
732 params->index_keys = index_keys; 749 params->index_keys = index_keys;
733 transaction->ScheduleTask(base::Bind( 750 transaction->ScheduleTask(base::Bind(
734 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 751 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
735 } 752 }
736 753
737 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, 754 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 834 }
818 835
819 // Before this point, don't do any mutation. After this point, rollback the 836 // Before this point, don't do any mutation. After this point, rollback the
820 // transaction in case of error. 837 // transaction in case of error.
821 backing_store_success = 838 backing_store_success =
822 backing_store_->PutRecord(transaction->BackingStoreTransaction(), 839 backing_store_->PutRecord(transaction->BackingStoreTransaction(),
823 id(), 840 id(),
824 params->object_store_id, 841 params->object_store_id,
825 *key, 842 *key,
826 params->value, 843 params->value,
844 &params->handles,
827 &record_identifier); 845 &record_identifier);
828 if (!backing_store_success) { 846 if (!backing_store_success) {
829 params->callbacks->OnError(IndexedDBDatabaseError( 847 params->callbacks->OnError(IndexedDBDatabaseError(
830 blink::WebIDBDatabaseExceptionUnknownError, 848 blink::WebIDBDatabaseExceptionUnknownError,
831 "Internal error: backing store error performing put/add.")); 849 "Internal error: backing store error performing put/add."));
832 return; 850 return;
833 } 851 }
834 852
835 for (size_t i = 0; i < index_writers.size(); ++i) { 853 for (size_t i = 0; i < index_writers.size(); ++i) {
836 IndexWriter* index_writer = index_writers[i]; 854 IndexWriter* index_writer = index_writers[i];
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 transaction->BackingStoreTransaction(), 1066 transaction->BackingStoreTransaction(),
1049 id(), 1067 id(),
1050 params->object_store_id, 1068 params->object_store_id,
1051 params->index_id, 1069 params->index_id,
1052 *params->key_range, 1070 *params->key_range,
1053 params->direction); 1071 params->direction);
1054 } 1072 }
1055 } 1073 }
1056 1074
1057 if (!backing_store_cursor) { 1075 if (!backing_store_cursor) {
1058 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); 1076 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
1059 return; 1077 return;
1060 } 1078 }
1061 1079
1062 scoped_refptr<IndexedDBCursor> cursor = 1080 scoped_refptr<IndexedDBCursor> cursor =
1063 new IndexedDBCursor(backing_store_cursor.Pass(), 1081 new IndexedDBCursor(backing_store_cursor.Pass(),
1064 params->cursor_type, 1082 params->cursor_type,
1065 params->task_type, 1083 params->task_type,
1066 transaction); 1084 transaction);
1067 params->callbacks->OnSuccess( 1085 params->callbacks->OnSuccess(
1068 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); 1086 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), 1165 base::Passed(&key_range),
1148 callbacks)); 1166 callbacks));
1149 } 1167 }
1150 1168
1151 void IndexedDBDatabase::DeleteRangeOperation( 1169 void IndexedDBDatabase::DeleteRangeOperation(
1152 int64 object_store_id, 1170 int64 object_store_id,
1153 scoped_ptr<IndexedDBKeyRange> key_range, 1171 scoped_ptr<IndexedDBKeyRange> key_range,
1154 scoped_refptr<IndexedDBCallbacks> callbacks, 1172 scoped_refptr<IndexedDBCallbacks> callbacks,
1155 IndexedDBTransaction* transaction) { 1173 IndexedDBTransaction* transaction) {
1156 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation"); 1174 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation");
1157 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor = 1175 if (!backing_store_->DeleteRange(transaction->BackingStoreTransaction(),
1158 backing_store_->OpenObjectStoreCursor( 1176 id(), object_store_id, *key_range)) {
1159 transaction->BackingStoreTransaction(), 1177 callbacks->OnError(
1160 id(), 1178 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
1161 object_store_id, 1179 "Internal error deleting data in range"));
1162 *key_range, 1180 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 } 1181 }
1178
1179 callbacks->OnSuccess(); 1182 callbacks->OnSuccess();
1180 } 1183 }
1181 1184
1182 void IndexedDBDatabase::Clear(int64 transaction_id, 1185 void IndexedDBDatabase::Clear(int64 transaction_id,
1183 int64 object_store_id, 1186 int64 object_store_id,
1184 scoped_refptr<IndexedDBCallbacks> callbacks) { 1187 scoped_refptr<IndexedDBCallbacks> callbacks) {
1185 IDB_TRACE("IndexedDBDatabase::Clear"); 1188 IDB_TRACE("IndexedDBDatabase::Clear");
1186 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1189 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1187 if (!transaction) 1190 if (!transaction)
1188 return; 1191 return;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1374 }
1372 1375
1373 if (!IsOpenConnectionBlocked()) { 1376 if (!IsOpenConnectionBlocked()) {
1374 PendingOpenCallList pending_open_calls; 1377 PendingOpenCallList pending_open_calls;
1375 pending_open_calls_.swap(pending_open_calls); 1378 pending_open_calls_.swap(pending_open_calls);
1376 while (!pending_open_calls.empty()) { 1379 while (!pending_open_calls.empty()) {
1377 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); 1380 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front());
1378 pending_open_calls.pop_front(); 1381 pending_open_calls.pop_front();
1379 OpenConnection(pending_open_call->Callbacks(), 1382 OpenConnection(pending_open_call->Callbacks(),
1380 pending_open_call->DatabaseCallbacks(), 1383 pending_open_call->DatabaseCallbacks(),
1384 pending_open_call->ChildProcessId(),
1381 pending_open_call->TransactionId(), 1385 pending_open_call->TransactionId(),
1382 pending_open_call->Version()); 1386 pending_open_call->Version());
1383 } 1387 }
1384 } 1388 }
1385 } 1389 }
1386 1390
1387 void IndexedDBDatabase::CreateTransaction( 1391 void IndexedDBDatabase::CreateTransaction(
1388 int64 transaction_id, 1392 int64 transaction_id,
1389 IndexedDBConnection* connection, 1393 IndexedDBConnection* connection,
1390 const std::vector<int64>& object_store_ids, 1394 const std::vector<int64>& object_store_ids,
(...skipping 15 matching lines...) Expand all
1406 1410
1407 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { 1411 bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
1408 return !pending_delete_calls_.empty() || 1412 return !pending_delete_calls_.empty() ||
1409 running_version_change_transaction_ || 1413 running_version_change_transaction_ ||
1410 pending_run_version_change_transaction_call_; 1414 pending_run_version_change_transaction_call_;
1411 } 1415 }
1412 1416
1413 void IndexedDBDatabase::OpenConnection( 1417 void IndexedDBDatabase::OpenConnection(
1414 scoped_refptr<IndexedDBCallbacks> callbacks, 1418 scoped_refptr<IndexedDBCallbacks> callbacks,
1415 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1419 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1420 int child_process_id,
1416 int64 transaction_id, 1421 int64 transaction_id,
1417 int64 version) { 1422 int64 version) {
1418 const blink::WebIDBDataLoss kDataLoss = 1423 const blink::WebIDBDataLoss kDataLoss =
1419 blink::WebIDBDataLossNone; 1424 blink::WebIDBDataLossNone;
1420 OpenConnection( 1425 OpenConnection(
1421 callbacks, database_callbacks, transaction_id, version, kDataLoss, ""); 1426 callbacks, database_callbacks, child_process_id, transaction_id, version,
1427 kDataLoss, "");
1422 } 1428 }
1423 1429
1424 void IndexedDBDatabase::OpenConnection( 1430 void IndexedDBDatabase::OpenConnection(
1425 scoped_refptr<IndexedDBCallbacks> callbacks, 1431 scoped_refptr<IndexedDBCallbacks> callbacks,
1426 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1432 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1433 int child_process_id,
1427 int64 transaction_id, 1434 int64 transaction_id,
1428 int64 version, 1435 int64 version,
1429 blink::WebIDBDataLoss data_loss, 1436 blink::WebIDBDataLoss data_loss,
1430 std::string data_loss_message) { 1437 std::string data_loss_message) {
1431 DCHECK(backing_store_); 1438 DCHECK(backing_store_);
1432 1439
1433 // TODO(jsbell): Should have a priority queue so that higher version 1440 // TODO(jsbell): Should have a priority queue so that higher version
1434 // requests are processed first. http://crbug.com/225850 1441 // requests are processed first. http://crbug.com/225850
1435 if (IsOpenConnectionBlocked()) { 1442 if (IsOpenConnectionBlocked()) {
1436 // The backing store only detects data loss when it is first opened. The 1443 // 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 1444 // presence of existing connections means we didn't even check for data loss
1438 // so there'd better not be any. 1445 // so there'd better not be any.
1439 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss); 1446 DCHECK_NE(blink::WebIDBDataLossTotal, data_loss);
1440 pending_open_calls_.push_back(new PendingOpenCall( 1447 pending_open_calls_.push_back(new PendingOpenCall(
1441 callbacks, database_callbacks, transaction_id, version)); 1448 callbacks, database_callbacks, child_process_id, transaction_id,
1449 version));
1442 return; 1450 return;
1443 } 1451 }
1444 1452
1445 if (metadata_.id == kInvalidId) { 1453 if (metadata_.id == kInvalidId) {
1446 // The database was deleted then immediately re-opened; OpenInternal() 1454 // The database was deleted then immediately re-opened; OpenInternal()
1447 // recreates it in the backing store. 1455 // recreates it in the backing store.
1448 if (OpenInternal()) { 1456 if (OpenInternal()) {
1449 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, 1457 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION,
1450 metadata_.int_version); 1458 metadata_.int_version);
1451 } else { 1459 } else {
(...skipping 19 matching lines...) Expand all
1471 1479
1472 scoped_ptr<IndexedDBConnection> connection( 1480 scoped_ptr<IndexedDBConnection> connection(
1473 new IndexedDBConnection(this, database_callbacks)); 1481 new IndexedDBConnection(this, database_callbacks));
1474 1482
1475 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { 1483 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) {
1476 // For unit tests only - skip upgrade steps. Calling from script with 1484 // For unit tests only - skip upgrade steps. Calling from script with
1477 // DEFAULT_INT_VERSION throws exception. 1485 // DEFAULT_INT_VERSION throws exception.
1478 // TODO(jsbell): DCHECK that not in unit tests. 1486 // TODO(jsbell): DCHECK that not in unit tests.
1479 DCHECK(is_new_database); 1487 DCHECK(is_new_database);
1480 connections_.insert(connection.get()); 1488 connections_.insert(connection.get());
1489 backing_store_->GrantChildProcessPermissions(child_process_id);
1481 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1490 callbacks->OnSuccess(connection.Pass(), this->metadata());
1482 return; 1491 return;
1483 } 1492 }
1484 1493
1485 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { 1494 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) {
1486 if (!is_new_database) { 1495 if (!is_new_database) {
1487 connections_.insert(connection.get()); 1496 connections_.insert(connection.get());
1497 backing_store_->GrantChildProcessPermissions(child_process_id);
1488 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1498 callbacks->OnSuccess(connection.Pass(), this->metadata());
1489 return; 1499 return;
1490 } 1500 }
1491 // Spec says: If no version is specified and no database exists, set 1501 // Spec says: If no version is specified and no database exists, set
1492 // database version to 1. 1502 // database version to 1.
1493 version = 1; 1503 version = 1;
1494 } 1504 }
1495 1505
1496 if (version > metadata_.int_version) { 1506 if (version > metadata_.int_version) {
1497 connections_.insert(connection.get()); 1507 connections_.insert(connection.get());
1508 backing_store_->GrantChildProcessPermissions(child_process_id);
1498 RunVersionChangeTransaction(callbacks, 1509 RunVersionChangeTransaction(callbacks,
1499 connection.Pass(), 1510 connection.Pass(),
1500 transaction_id, 1511 transaction_id,
1501 version, 1512 version,
1502 data_loss, 1513 data_loss,
1503 data_loss_message); 1514 data_loss_message);
1504 return; 1515 return;
1505 } 1516 }
1506 if (version < metadata_.int_version) { 1517 if (version < metadata_.int_version) {
1507 callbacks->OnError(IndexedDBDatabaseError( 1518 callbacks->OnError(IndexedDBDatabaseError(
1508 blink::WebIDBDatabaseExceptionVersionError, 1519 blink::WebIDBDatabaseExceptionVersionError,
1509 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + 1520 ASCIIToUTF16("The requested version (") + Int64ToString16(version) +
1510 ASCIIToUTF16(") is less than the existing version (") + 1521 ASCIIToUTF16(") is less than the existing version (") +
1511 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); 1522 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(").")));
1512 return; 1523 return;
1513 } 1524 }
1514 DCHECK_EQ(version, metadata_.int_version); 1525 DCHECK_EQ(version, metadata_.int_version);
1515 connections_.insert(connection.get()); 1526 connections_.insert(connection.get());
1527 backing_store_->GrantChildProcessPermissions(child_process_id);
1516 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1528 callbacks->OnSuccess(connection.Pass(), this->metadata());
1517 } 1529 }
1518 1530
1519 void IndexedDBDatabase::RunVersionChangeTransaction( 1531 void IndexedDBDatabase::RunVersionChangeTransaction(
1520 scoped_refptr<IndexedDBCallbacks> callbacks, 1532 scoped_refptr<IndexedDBCallbacks> callbacks,
1521 scoped_ptr<IndexedDBConnection> connection, 1533 scoped_ptr<IndexedDBConnection> connection,
1522 int64 transaction_id, 1534 int64 transaction_id,
1523 int64 requested_version, 1535 int64 requested_version,
1524 blink::WebIDBDataLoss data_loss, 1536 blink::WebIDBDataLoss data_loss,
1525 std::string data_loss_message) { 1537 std::string data_loss_message) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 const string16& previous_version, 1729 const string16& previous_version,
1718 int64 previous_int_version, 1730 int64 previous_int_version,
1719 IndexedDBTransaction* transaction) { 1731 IndexedDBTransaction* transaction) {
1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1732 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1721 DCHECK(!transaction); 1733 DCHECK(!transaction);
1722 metadata_.version = previous_version; 1734 metadata_.version = previous_version;
1723 metadata_.int_version = previous_int_version; 1735 metadata_.int_version = previous_int_version;
1724 } 1736 }
1725 1737
1726 } // namespace content 1738 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698