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

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: Merge fixes [builds, untested] Created 7 years, 3 months 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"
15 #include "content/browser/indexed_db/indexed_db_backing_store.h" 16 #include "content/browser/indexed_db/indexed_db_backing_store.h"
17 #include "content/browser/indexed_db/indexed_db_blob_info.h"
16 #include "content/browser/indexed_db/indexed_db_connection.h" 18 #include "content/browser/indexed_db/indexed_db_connection.h"
17 #include "content/browser/indexed_db/indexed_db_cursor.h" 19 #include "content/browser/indexed_db/indexed_db_cursor.h"
18 #include "content/browser/indexed_db/indexed_db_factory.h" 20 #include "content/browser/indexed_db/indexed_db_factory.h"
19 #include "content/browser/indexed_db/indexed_db_index_writer.h" 21 #include "content/browser/indexed_db/indexed_db_index_writer.h"
20 #include "content/browser/indexed_db/indexed_db_tracing.h" 22 #include "content/browser/indexed_db/indexed_db_tracing.h"
21 #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"
22 #include "content/common/indexed_db/indexed_db_key_path.h" 25 #include "content/common/indexed_db/indexed_db_key_path.h"
23 #include "content/common/indexed_db/indexed_db_key_range.h" 26 #include "content/common/indexed_db/indexed_db_key_range.h"
24 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
25 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 28 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
26 29
27 using base::Int64ToString16; 30 using base::Int64ToString16;
28 using WebKit::WebIDBKeyTypeNumber; 31 using WebKit::WebIDBKeyTypeNumber;
29 32
30 namespace content { 33 namespace content {
31 34
32 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it 35 // PendingOpenCall has a scoped_refptr<IndexedDBDatabaseCallbacks> because it
33 // isn't a connection yet. 36 // isn't a connection yet.
34 class IndexedDBDatabase::PendingOpenCall { 37 class IndexedDBDatabase::PendingOpenCall {
35 public: 38 public:
36 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks, 39 PendingOpenCall(scoped_refptr<IndexedDBCallbacks> callbacks,
37 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 40 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
41 int child_process_id,
38 int64 transaction_id, 42 int64 transaction_id,
39 int64 version) 43 int64 version)
40 : callbacks_(callbacks), 44 : callbacks_(callbacks),
41 database_callbacks_(database_callbacks), 45 database_callbacks_(database_callbacks),
46 child_process_id_(child_process_id),
42 version_(version), 47 version_(version),
43 transaction_id_(transaction_id) {} 48 transaction_id_(transaction_id) {}
44 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } 49 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
45 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() { 50 scoped_refptr<IndexedDBDatabaseCallbacks> DatabaseCallbacks() {
46 return database_callbacks_; 51 return database_callbacks_;
47 } 52 }
53 int ChildProcessId() { return child_process_id_; }
48 int64 Version() { return version_; } 54 int64 Version() { return version_; }
49 int64 TransactionId() const { return transaction_id_; } 55 int64 TransactionId() const { return transaction_id_; }
50 56
51 private: 57 private:
52 scoped_refptr<IndexedDBCallbacks> callbacks_; 58 scoped_refptr<IndexedDBCallbacks> callbacks_;
53 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; 59 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
60 int child_process_id_;
54 int64 version_; 61 int64 version_;
55 const int64 transaction_id_; 62 const int64 transaction_id_;
56 }; 63 };
57 64
58 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the 65 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the
59 // in-progress connection. 66 // in-progress connection.
60 class IndexedDBDatabase::PendingUpgradeCall { 67 class IndexedDBDatabase::PendingUpgradeCall {
61 public: 68 public:
62 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks, 69 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks,
63 scoped_ptr<IndexedDBConnection> connection, 70 scoped_ptr<IndexedDBConnection> connection,
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 return; 586 return;
580 } 587 }
581 588
582 key = &backing_store_cursor->key(); 589 key = &backing_store_cursor->key();
583 } 590 }
584 591
585 scoped_ptr<IndexedDBKey> primary_key; 592 scoped_ptr<IndexedDBKey> primary_key;
586 bool ok; 593 bool ok;
587 if (index_id == IndexedDBIndexMetadata::kInvalidId) { 594 if (index_id == IndexedDBIndexMetadata::kInvalidId) {
588 // Object Store Retrieval Operation 595 // Object Store Retrieval Operation
589 std::string value; 596 IndexedDBValue value;
590 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 597 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
591 id(), 598 id(),
592 object_store_id, 599 object_store_id,
593 *key, 600 *key,
594 &value); 601 &value);
595 if (!ok) { 602 if (!ok) {
596 callbacks->OnError( 603 callbacks->OnError(
597 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, 604 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
598 "Internal error in GetRecord.")); 605 "Internal error in GetRecord."));
599 return; 606 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 callbacks->OnSuccess(); 639 callbacks->OnSuccess();
633 return; 640 return;
634 } 641 }
635 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { 642 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) {
636 // Index Value Retrieval Operation 643 // Index Value Retrieval Operation
637 callbacks->OnSuccess(*primary_key); 644 callbacks->OnSuccess(*primary_key);
638 return; 645 return;
639 } 646 }
640 647
641 // Index Referenced Value Retrieval Operation 648 // Index Referenced Value Retrieval Operation
642 std::string value; 649 IndexedDBValue value;
643 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), 650 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(),
644 id(), 651 id(),
645 object_store_id, 652 object_store_id,
646 *primary_key, 653 *primary_key,
647 &value); 654 &value);
648 if (!ok) { 655 if (!ok) {
649 callbacks->OnError( 656 callbacks->OnError(
650 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, 657 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
651 "Internal error in GetRecord.")); 658 "Internal error in GetRecord."));
652 return; 659 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 transaction->BackingStoreTransaction(), 706 transaction->BackingStoreTransaction(),
700 database_id, 707 database_id,
701 object_store_id, 708 object_store_id,
702 static_cast<int64>(floor(key.number())) + 1, 709 static_cast<int64>(floor(key.number())) + 1,
703 check_current); 710 check_current);
704 } 711 }
705 712
706 struct IndexedDBDatabase::PutOperationParams { 713 struct IndexedDBDatabase::PutOperationParams {
707 PutOperationParams() {} 714 PutOperationParams() {}
708 int64 object_store_id; 715 int64 object_store_id;
709 std::string value; 716 IndexedDBValue value;
710 scoped_ptr<IndexedDBKey> key; 717 scoped_ptr<IndexedDBKey> key;
711 IndexedDBDatabase::PutMode put_mode; 718 IndexedDBDatabase::PutMode put_mode;
712 scoped_refptr<IndexedDBCallbacks> callbacks; 719 scoped_refptr<IndexedDBCallbacks> callbacks;
713 std::vector<int64> index_ids; 720 std::vector<int64> index_ids;
714 std::vector<IndexKeys> index_keys; 721 std::vector<IndexKeys> index_keys;
715 722
716 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); 723 DISALLOW_COPY_AND_ASSIGN(PutOperationParams);
717 }; 724 };
718 725
719 void IndexedDBDatabase::Put(int64 transaction_id, 726 void IndexedDBDatabase::Put(int64 transaction_id,
720 int64 object_store_id, 727 int64 object_store_id,
721 std::string* value, 728 IndexedDBValue* value,
722 scoped_ptr<IndexedDBKey> key, 729 scoped_ptr<IndexedDBKey> key,
723 PutMode put_mode, 730 PutMode put_mode,
724 scoped_refptr<IndexedDBCallbacks> callbacks, 731 scoped_refptr<IndexedDBCallbacks> callbacks,
725 const std::vector<int64>& index_ids, 732 const std::vector<int64>& index_ids,
726 const std::vector<IndexKeys>& index_keys) { 733 const std::vector<IndexKeys>& index_keys) {
727 IDB_TRACE("IndexedDBDatabase::Put"); 734 IDB_TRACE("IndexedDBDatabase::Put");
728 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 735 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
729 if (!transaction) 736 if (!transaction)
730 return; 737 return;
731 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); 738 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY);
732 739
733 if (!ValidateObjectStoreId(object_store_id)) 740 if (!ValidateObjectStoreId(object_store_id))
734 return; 741 return;
735 742
736 DCHECK(key); 743 DCHECK(key);
744 DCHECK(value); // TODO(ericu): True?
737 scoped_ptr<PutOperationParams> params(new PutOperationParams()); 745 scoped_ptr<PutOperationParams> params(new PutOperationParams());
738 params->object_store_id = object_store_id; 746 params->object_store_id = object_store_id;
739 params->value.swap(*value); 747 params->value.swap(*value);
740 params->key = key.Pass(); 748 params->key = key.Pass();
741 params->put_mode = put_mode; 749 params->put_mode = put_mode;
742 params->callbacks = callbacks; 750 params->callbacks = callbacks;
743 params->index_ids = index_ids; 751 params->index_ids = index_ids;
744 params->index_keys = index_keys; 752 params->index_keys = index_keys;
745 transaction->ScheduleTask(base::Bind( 753 transaction->ScheduleTask(base::Bind(
746 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 754 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 transaction->BackingStoreTransaction(), 1069 transaction->BackingStoreTransaction(),
1062 id(), 1070 id(),
1063 params->object_store_id, 1071 params->object_store_id,
1064 params->index_id, 1072 params->index_id,
1065 *params->key_range, 1073 *params->key_range,
1066 params->direction); 1074 params->direction);
1067 } 1075 }
1068 } 1076 }
1069 1077
1070 if (!backing_store_cursor) { 1078 if (!backing_store_cursor) {
1071 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); 1079 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
1072 return; 1080 return;
1073 } 1081 }
1074 1082
1075 scoped_refptr<IndexedDBCursor> cursor = 1083 scoped_refptr<IndexedDBCursor> cursor =
1076 new IndexedDBCursor(backing_store_cursor.Pass(), 1084 new IndexedDBCursor(backing_store_cursor.Pass(),
1077 params->cursor_type, 1085 params->cursor_type,
1078 params->task_type, 1086 params->task_type,
1079 transaction); 1087 transaction);
1080 params->callbacks->OnSuccess( 1088 params->callbacks->OnSuccess(
1081 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); 1089 cursor, cursor->key(), cursor->primary_key(), cursor->Value());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 base::Passed(&key_range), 1168 base::Passed(&key_range),
1161 callbacks)); 1169 callbacks));
1162 } 1170 }
1163 1171
1164 void IndexedDBDatabase::DeleteRangeOperation( 1172 void IndexedDBDatabase::DeleteRangeOperation(
1165 int64 object_store_id, 1173 int64 object_store_id,
1166 scoped_ptr<IndexedDBKeyRange> key_range, 1174 scoped_ptr<IndexedDBKeyRange> key_range,
1167 scoped_refptr<IndexedDBCallbacks> callbacks, 1175 scoped_refptr<IndexedDBCallbacks> callbacks,
1168 IndexedDBTransaction* transaction) { 1176 IndexedDBTransaction* transaction) {
1169 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation"); 1177 IDB_TRACE("IndexedDBDatabase::DeleteRangeOperation");
1170 scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor = 1178 if (!backing_store_->DeleteRange(transaction->BackingStoreTransaction(),
1171 backing_store_->OpenObjectStoreCursor( 1179 id(), object_store_id, *key_range)) {
1172 transaction->BackingStoreTransaction(), 1180 callbacks->OnError(
1173 id(), 1181 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
1174 object_store_id, 1182 "Internal error deleting data in range"));
1175 *key_range, 1183 return;
1176 indexed_db::CURSOR_NEXT);
1177 if (backing_store_cursor) {
1178 do {
1179 if (!backing_store_->DeleteRecord(
1180 transaction->BackingStoreTransaction(),
1181 id(),
1182 object_store_id,
1183 backing_store_cursor->record_identifier())) {
1184 callbacks->OnError(
1185 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
1186 "Internal error deleting data in range"));
1187 return;
1188 }
1189 } while (backing_store_cursor->Continue());
1190 } 1184 }
1191
1192 callbacks->OnSuccess(); 1185 callbacks->OnSuccess();
1193 } 1186 }
1194 1187
1195 void IndexedDBDatabase::Clear(int64 transaction_id, 1188 void IndexedDBDatabase::Clear(int64 transaction_id,
1196 int64 object_store_id, 1189 int64 object_store_id,
1197 scoped_refptr<IndexedDBCallbacks> callbacks) { 1190 scoped_refptr<IndexedDBCallbacks> callbacks) {
1198 IDB_TRACE("IndexedDBDatabase::Clear"); 1191 IDB_TRACE("IndexedDBDatabase::Clear");
1199 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1192 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1200 if (!transaction) 1193 if (!transaction)
1201 return; 1194 return;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } 1372 }
1380 1373
1381 if (!IsOpenConnectionBlocked()) { 1374 if (!IsOpenConnectionBlocked()) {
1382 PendingOpenCallList pending_open_calls; 1375 PendingOpenCallList pending_open_calls;
1383 pending_open_calls_.swap(pending_open_calls); 1376 pending_open_calls_.swap(pending_open_calls);
1384 while (!pending_open_calls.empty()) { 1377 while (!pending_open_calls.empty()) {
1385 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front()); 1378 scoped_ptr<PendingOpenCall> pending_open_call(pending_open_calls.front());
1386 pending_open_calls.pop_front(); 1379 pending_open_calls.pop_front();
1387 OpenConnection(pending_open_call->Callbacks(), 1380 OpenConnection(pending_open_call->Callbacks(),
1388 pending_open_call->DatabaseCallbacks(), 1381 pending_open_call->DatabaseCallbacks(),
1382 pending_open_call->ChildProcessId(),
1389 pending_open_call->TransactionId(), 1383 pending_open_call->TransactionId(),
1390 pending_open_call->Version()); 1384 pending_open_call->Version());
1391 } 1385 }
1392 } 1386 }
1393 } 1387 }
1394 1388
1395 void IndexedDBDatabase::CreateTransaction( 1389 void IndexedDBDatabase::CreateTransaction(
1396 int64 transaction_id, 1390 int64 transaction_id,
1397 IndexedDBConnection* connection, 1391 IndexedDBConnection* connection,
1398 const std::vector<int64>& object_store_ids, 1392 const std::vector<int64>& object_store_ids,
(...skipping 13 matching lines...) Expand all
1412 1406
1413 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { 1407 bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
1414 return !pending_delete_calls_.empty() || 1408 return !pending_delete_calls_.empty() ||
1415 running_version_change_transaction_ || 1409 running_version_change_transaction_ ||
1416 pending_run_version_change_transaction_call_; 1410 pending_run_version_change_transaction_call_;
1417 } 1411 }
1418 1412
1419 void IndexedDBDatabase::OpenConnection( 1413 void IndexedDBDatabase::OpenConnection(
1420 scoped_refptr<IndexedDBCallbacks> callbacks, 1414 scoped_refptr<IndexedDBCallbacks> callbacks,
1421 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1415 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1416 int child_process_id,
1422 int64 transaction_id, 1417 int64 transaction_id,
1423 int64 version) { 1418 int64 version) {
1424 const WebKit::WebIDBCallbacks::DataLoss kDataLoss = 1419 const WebKit::WebIDBCallbacks::DataLoss kDataLoss =
1425 WebKit::WebIDBCallbacks::DataLossNone; 1420 WebKit::WebIDBCallbacks::DataLossNone;
1426 OpenConnection( 1421 OpenConnection(
1427 callbacks, database_callbacks, transaction_id, version, kDataLoss); 1422 callbacks, database_callbacks, child_process_id, transaction_id, version,
1423 kDataLoss);
1428 } 1424 }
1429 1425
1430 void IndexedDBDatabase::OpenConnection( 1426 void IndexedDBDatabase::OpenConnection(
1431 scoped_refptr<IndexedDBCallbacks> callbacks, 1427 scoped_refptr<IndexedDBCallbacks> callbacks,
1432 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1428 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
1429 int child_process_id,
1433 int64 transaction_id, 1430 int64 transaction_id,
1434 int64 version, 1431 int64 version,
1435 WebKit::WebIDBCallbacks::DataLoss data_loss) { 1432 WebKit::WebIDBCallbacks::DataLoss data_loss) {
1436 DCHECK(backing_store_); 1433 DCHECK(backing_store_);
1437 1434
1438 // TODO(jsbell): Should have a priority queue so that higher version 1435 // TODO(jsbell): Should have a priority queue so that higher version
1439 // requests are processed first. http://crbug.com/225850 1436 // requests are processed first. http://crbug.com/225850
1440 if (IsOpenConnectionBlocked()) { 1437 if (IsOpenConnectionBlocked()) {
1441 // The backing store only detects data loss when it is first opened. The 1438 // The backing store only detects data loss when it is first opened. The
1442 // presence of existing connections means we didn't even check for data loss 1439 // presence of existing connections means we didn't even check for data loss
1443 // so there'd better not be any. 1440 // so there'd better not be any.
1444 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss); 1441 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss);
1445 pending_open_calls_.push_back(new PendingOpenCall( 1442 pending_open_calls_.push_back(
1446 callbacks, database_callbacks, transaction_id, version)); 1443 new PendingOpenCall(callbacks, database_callbacks, child_process_id,
1444 transaction_id, version));
1447 return; 1445 return;
1448 } 1446 }
1449 1447
1450 if (metadata_.id == kInvalidId) { 1448 if (metadata_.id == kInvalidId) {
1451 // The database was deleted then immediately re-opened; OpenInternal() 1449 // The database was deleted then immediately re-opened; OpenInternal()
1452 // recreates it in the backing store. 1450 // recreates it in the backing store.
1453 if (OpenInternal()) { 1451 if (OpenInternal()) {
1454 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, 1452 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION,
1455 metadata_.int_version); 1453 metadata_.int_version);
1456 } else { 1454 } else {
(...skipping 19 matching lines...) Expand all
1476 1474
1477 scoped_ptr<IndexedDBConnection> connection( 1475 scoped_ptr<IndexedDBConnection> connection(
1478 new IndexedDBConnection(this, database_callbacks)); 1476 new IndexedDBConnection(this, database_callbacks));
1479 1477
1480 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { 1478 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) {
1481 // For unit tests only - skip upgrade steps. Calling from script with 1479 // For unit tests only - skip upgrade steps. Calling from script with
1482 // DEFAULT_INT_VERSION throws exception. 1480 // DEFAULT_INT_VERSION throws exception.
1483 // TODO(jsbell): DCHECK that not in unit tests. 1481 // TODO(jsbell): DCHECK that not in unit tests.
1484 DCHECK(is_new_database); 1482 DCHECK(is_new_database);
1485 connections_.insert(connection.get()); 1483 connections_.insert(connection.get());
1484 backing_store_->GrantChildProcessPermissions(child_process_id);
1486 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1485 callbacks->OnSuccess(connection.Pass(), this->metadata());
1487 return; 1486 return;
1488 } 1487 }
1489 1488
1490 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { 1489 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) {
1491 if (!is_new_database) { 1490 if (!is_new_database) {
1492 connections_.insert(connection.get()); 1491 connections_.insert(connection.get());
1492 backing_store_->GrantChildProcessPermissions(child_process_id);
1493 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1493 callbacks->OnSuccess(connection.Pass(), this->metadata());
1494 return; 1494 return;
1495 } 1495 }
1496 // Spec says: If no version is specified and no database exists, set 1496 // Spec says: If no version is specified and no database exists, set
1497 // database version to 1. 1497 // database version to 1.
1498 version = 1; 1498 version = 1;
1499 } 1499 }
1500 1500
1501 if (version > metadata_.int_version) { 1501 if (version > metadata_.int_version) {
1502 connections_.insert(connection.get()); 1502 connections_.insert(connection.get());
1503 backing_store_->GrantChildProcessPermissions(child_process_id);
1503 RunVersionChangeTransaction( 1504 RunVersionChangeTransaction(
1504 callbacks, connection.Pass(), transaction_id, version, data_loss); 1505 callbacks, connection.Pass(), transaction_id, version, data_loss);
1505 return; 1506 return;
1506 } 1507 }
1507 if (version < metadata_.int_version) { 1508 if (version < metadata_.int_version) {
1508 callbacks->OnError(IndexedDBDatabaseError( 1509 callbacks->OnError(IndexedDBDatabaseError(
1509 WebKit::WebIDBDatabaseExceptionVersionError, 1510 WebKit::WebIDBDatabaseExceptionVersionError,
1510 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + 1511 ASCIIToUTF16("The requested version (") + Int64ToString16(version) +
1511 ASCIIToUTF16(") is less than the existing version (") + 1512 ASCIIToUTF16(") is less than the existing version (") +
1512 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); 1513 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(").")));
1513 return; 1514 return;
1514 } 1515 }
1515 DCHECK_EQ(version, metadata_.int_version); 1516 DCHECK_EQ(version, metadata_.int_version);
1516 connections_.insert(connection.get()); 1517 connections_.insert(connection.get());
1518 backing_store_->GrantChildProcessPermissions(child_process_id);
1517 callbacks->OnSuccess(connection.Pass(), this->metadata()); 1519 callbacks->OnSuccess(connection.Pass(), this->metadata());
1518 } 1520 }
1519 1521
1520 void IndexedDBDatabase::RunVersionChangeTransaction( 1522 void IndexedDBDatabase::RunVersionChangeTransaction(
1521 scoped_refptr<IndexedDBCallbacks> callbacks, 1523 scoped_refptr<IndexedDBCallbacks> callbacks,
1522 scoped_ptr<IndexedDBConnection> connection, 1524 scoped_ptr<IndexedDBConnection> connection,
1523 int64 transaction_id, 1525 int64 transaction_id,
1524 int64 requested_version, 1526 int64 requested_version,
1525 WebKit::WebIDBCallbacks::DataLoss data_loss) { 1527 WebKit::WebIDBCallbacks::DataLoss data_loss) {
1526 1528
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 const string16& previous_version, 1719 const string16& previous_version,
1718 int64 previous_int_version, 1720 int64 previous_int_version,
1719 IndexedDBTransaction* transaction) { 1721 IndexedDBTransaction* transaction) {
1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1722 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1721 DCHECK(!transaction); 1723 DCHECK(!transaction);
1722 metadata_.version = previous_version; 1724 metadata_.version = previous_version;
1723 metadata_.int_version = previous_int_version; 1725 metadata_.int_version = previous_int_version;
1724 } 1726 }
1725 1727
1726 } // namespace content 1728 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698