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

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

Issue 18221003: Convert WebIDBDatabaseImpl to IndexedDBConnection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format Created 7 years, 5 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 <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/browser/indexed_db/indexed_db_backing_store.h" 15 #include "content/browser/indexed_db/indexed_db_backing_store.h"
16 #include "content/browser/indexed_db/indexed_db_connection.h"
16 #include "content/browser/indexed_db/indexed_db_cursor.h" 17 #include "content/browser/indexed_db/indexed_db_cursor.h"
17 #include "content/browser/indexed_db/indexed_db_factory.h" 18 #include "content/browser/indexed_db/indexed_db_factory.h"
18 #include "content/browser/indexed_db/indexed_db_index_writer.h" 19 #include "content/browser/indexed_db/indexed_db_index_writer.h"
19 #include "content/browser/indexed_db/indexed_db_tracing.h" 20 #include "content/browser/indexed_db/indexed_db_tracing.h"
20 #include "content/browser/indexed_db/indexed_db_transaction.h" 21 #include "content/browser/indexed_db/indexed_db_transaction.h"
21 #include "content/common/indexed_db/indexed_db_key_path.h" 22 #include "content/common/indexed_db/indexed_db_key_path.h"
22 #include "content/common/indexed_db/indexed_db_key_range.h" 23 #include "content/common/indexed_db/indexed_db_key_range.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 25 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
25 26
(...skipping 26 matching lines...) Expand all
52 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 53 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
53 54
54 private: 55 private:
55 const scoped_refptr<IndexedDBBackingStore> backing_store_; 56 const scoped_refptr<IndexedDBBackingStore> backing_store_;
56 const IndexedDBObjectStoreMetadata object_store_metadata_; 57 const IndexedDBObjectStoreMetadata object_store_metadata_;
57 }; 58 };
58 59
59 class IndexedDBDatabase::VersionChangeOperation 60 class IndexedDBDatabase::VersionChangeOperation
60 : public IndexedDBTransaction::Operation { 61 : public IndexedDBTransaction::Operation {
61 public: 62 public:
62 VersionChangeOperation( 63 VersionChangeOperation(scoped_refptr<IndexedDBDatabase> database,
63 scoped_refptr<IndexedDBDatabase> database, 64 int64 transaction_id,
64 int64 transaction_id, 65 int64 version,
65 int64 version, 66 scoped_refptr<IndexedDBCallbacks> callbacks,
66 scoped_refptr<IndexedDBCallbacks> callbacks, 67 scoped_ptr<IndexedDBConnection> connection,
67 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 68 WebKit::WebIDBCallbacks::DataLoss data_loss)
68 WebKit::WebIDBCallbacks::DataLoss data_loss)
69 : database_(database), 69 : database_(database),
70 transaction_id_(transaction_id), 70 transaction_id_(transaction_id),
71 version_(version), 71 version_(version),
72 callbacks_(callbacks), 72 callbacks_(callbacks),
73 database_callbacks_(database_callbacks), 73 connection_(connection.Pass()),
74 data_loss_(data_loss) {} 74 data_loss_(data_loss) {}
75 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 75 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
76 76
77 private: 77 private:
78 scoped_refptr<IndexedDBDatabase> database_; 78 scoped_refptr<IndexedDBDatabase> database_;
79 int64 transaction_id_; 79 int64 transaction_id_;
80 int64 version_; 80 int64 version_;
81 scoped_refptr<IndexedDBCallbacks> callbacks_; 81 scoped_refptr<IndexedDBCallbacks> callbacks_;
82 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; 82 scoped_ptr<IndexedDBConnection> connection_;
83 WebKit::WebIDBCallbacks::DataLoss data_loss_; 83 WebKit::WebIDBCallbacks::DataLoss data_loss_;
84 }; 84 };
85 85
86 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation { 86 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation {
87 public: 87 public:
88 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database, 88 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database,
89 int64 object_store_id) 89 int64 object_store_id)
90 : database_(database), object_store_id_(object_store_id) {} 90 : database_(database), object_store_id_(object_store_id) {}
91 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 91 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
92 92
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 int64 Version() { return version_; } 385 int64 Version() { return version_; }
386 int64 TransactionId() const { return transaction_id_; } 386 int64 TransactionId() const { return transaction_id_; }
387 387
388 private: 388 private:
389 scoped_refptr<IndexedDBCallbacks> callbacks_; 389 scoped_refptr<IndexedDBCallbacks> callbacks_;
390 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_; 390 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
391 int64 version_; 391 int64 version_;
392 const int64 transaction_id_; 392 const int64 transaction_id_;
393 }; 393 };
394 394
395 class IndexedDBDatabase::PendingUpgradeCall {
jsbell 2013/07/02 17:38:15 This addition of two new PendingXXXCall types is u
396 public:
397 PendingUpgradeCall(scoped_refptr<IndexedDBCallbacks> callbacks,
398 scoped_ptr<IndexedDBConnection> connection,
399 int64 transaction_id,
400 int64 version)
401 : callbacks_(callbacks),
402 connection_(connection.Pass()),
403 version_(version),
404 transaction_id_(transaction_id) {}
405 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
406 scoped_ptr<IndexedDBConnection> Connection() { return connection_.Pass(); }
407 int64 Version() { return version_; }
408 int64 TransactionId() const { return transaction_id_; }
409
410 private:
411 scoped_refptr<IndexedDBCallbacks> callbacks_;
412 scoped_ptr<IndexedDBConnection> connection_;
413 int64 version_;
414 const int64 transaction_id_;
415 };
416
417 class IndexedDBDatabase::PendingSuccessCall {
418 public:
419 PendingSuccessCall(scoped_refptr<IndexedDBCallbacks> callbacks,
420 IndexedDBConnection* connection,
421 int64 transaction_id,
422 int64 version)
423 : callbacks_(callbacks),
424 connection_(connection),
425 version_(version),
426 transaction_id_(transaction_id) {}
427 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
428 IndexedDBConnection* Connection() { return connection_; }
429 int64 Version() { return version_; }
430 int64 TransactionId() const { return transaction_id_; }
431
432 private:
433 scoped_refptr<IndexedDBCallbacks> callbacks_;
434 IndexedDBConnection* connection_;
435 int64 version_;
436 const int64 transaction_id_;
437 };
438
395 class IndexedDBDatabase::PendingDeleteCall { 439 class IndexedDBDatabase::PendingDeleteCall {
396 public: 440 public:
397 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) 441 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks)
398 : callbacks_(callbacks) {} 442 : callbacks_(callbacks) {}
399 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } 443 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
400 444
401 private: 445 private:
402 scoped_refptr<IndexedDBCallbacks> callbacks_; 446 scoped_refptr<IndexedDBCallbacks> callbacks_;
403 }; 447 };
404 448
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 database_->metadata_.int_version)) { 1426 database_->metadata_.int_version)) {
1383 IndexedDBDatabaseError error( 1427 IndexedDBDatabaseError error(
1384 WebKit::WebIDBDatabaseExceptionUnknownError, 1428 WebKit::WebIDBDatabaseExceptionUnknownError,
1385 ASCIIToUTF16("Internal error writing data to stable storage when " 1429 ASCIIToUTF16("Internal error writing data to stable storage when "
1386 "updating version.")); 1430 "updating version."));
1387 callbacks_->OnError(error); 1431 callbacks_->OnError(error);
1388 transaction->Abort(error); 1432 transaction->Abort(error);
1389 return; 1433 return;
1390 } 1434 }
1391 DCHECK(!database_->pending_second_half_open_); 1435 DCHECK(!database_->pending_second_half_open_);
1392 database_->pending_second_half_open_.reset(new PendingOpenCall( 1436
1393 callbacks_, database_callbacks_, transaction_id_, version_)); 1437 database_->pending_second_half_open_.reset(new PendingSuccessCall(
1438 callbacks_, connection_.get(), transaction_id_, version_));
1394 callbacks_->OnUpgradeNeeded( 1439 callbacks_->OnUpgradeNeeded(
1395 old_version, database_, database_->metadata(), data_loss_); 1440 old_version, connection_.Pass(), database_->metadata(), data_loss_);
1396 } 1441 }
1397 1442
1398 void IndexedDBDatabase::TransactionStarted(IndexedDBTransaction* transaction) { 1443 void IndexedDBDatabase::TransactionStarted(IndexedDBTransaction* transaction) {
1399 1444
1400 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { 1445 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) {
1401 DCHECK(!running_version_change_transaction_); 1446 DCHECK(!running_version_change_transaction_);
1402 running_version_change_transaction_ = transaction; 1447 running_version_change_transaction_ = transaction;
1403 } 1448 }
1404 } 1449 }
1405 1450
(...skipping 22 matching lines...) Expand all
1428 } 1473 }
1429 } 1474 }
1430 1475
1431 void IndexedDBDatabase::TransactionFinishedAndCompleteFired( 1476 void IndexedDBDatabase::TransactionFinishedAndCompleteFired(
1432 IndexedDBTransaction* transaction) { 1477 IndexedDBTransaction* transaction) {
1433 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { 1478 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) {
1434 DCHECK(pending_second_half_open_); 1479 DCHECK(pending_second_half_open_);
1435 if (pending_second_half_open_) { 1480 if (pending_second_half_open_) {
1436 DCHECK_EQ(pending_second_half_open_->Version(), metadata_.int_version); 1481 DCHECK_EQ(pending_second_half_open_->Version(), metadata_.int_version);
1437 DCHECK(metadata_.id != kInvalidId); 1482 DCHECK(metadata_.id != kInvalidId);
1438 pending_second_half_open_->Callbacks()->OnSuccess(this, this->metadata()); 1483
1484 // Connection was already minted for OnUpgradeNeeded callback.
1485 scoped_ptr<IndexedDBConnection> connection;
1486
1487 pending_second_half_open_->Callbacks()->OnSuccess(
1488 connection.Pass(), this->metadata());
1439 pending_second_half_open_.reset(); 1489 pending_second_half_open_.reset();
1440 } 1490 }
1441 ProcessPendingCalls(); 1491 ProcessPendingCalls();
1442 } 1492 }
1443 } 1493 }
1444 1494
1445 size_t IndexedDBDatabase::ConnectionCount() const { 1495 size_t IndexedDBDatabase::ConnectionCount() const {
1446 // This does not include pending open calls, as those should not block version 1496 // This does not include pending open calls, as those should not block version
1447 // changes and deletes. 1497 // changes and deletes.
1448 return database_callbacks_set_.size(); 1498 return connections_.size();
1449 } 1499 }
1450 1500
1451 void IndexedDBDatabase::ProcessPendingCalls() { 1501 void IndexedDBDatabase::ProcessPendingCalls() {
1452 if (pending_second_half_open_) {
1453 DCHECK_EQ(pending_second_half_open_->Version(), metadata_.int_version);
dgrogan 2013/07/02 22:01:58 What happened here? This block was just never ente
jsbell 2013/07/02 22:19:24 Oh yeah, meant to comment on this. Thanks. :) Dur
1454 DCHECK(metadata_.id != kInvalidId);
1455 scoped_ptr<PendingOpenCall> pending_call = pending_second_half_open_.Pass();
1456 pending_call->Callbacks()->OnSuccess(this, this->metadata());
1457 // Fall through when complete, as pending opens may be unblocked.
1458 }
1459
1460 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) { 1502 if (pending_run_version_change_transaction_call_ && ConnectionCount() == 1) {
1461 DCHECK(pending_run_version_change_transaction_call_->Version() > 1503 DCHECK(pending_run_version_change_transaction_call_->Version() >
1462 metadata_.int_version); 1504 metadata_.int_version);
1463 scoped_ptr<PendingOpenCall> pending_call = 1505 scoped_ptr<PendingUpgradeCall> pending_call =
1464 pending_run_version_change_transaction_call_.Pass(); 1506 pending_run_version_change_transaction_call_.Pass();
1465 RunVersionChangeTransactionFinal(pending_call->Callbacks(), 1507 RunVersionChangeTransactionFinal(pending_call->Callbacks(),
1466 pending_call->DatabaseCallbacks(), 1508 pending_call->Connection(),
1467 pending_call->TransactionId(), 1509 pending_call->TransactionId(),
1468 pending_call->Version()); 1510 pending_call->Version());
1469 DCHECK_EQ(static_cast<size_t>(1), ConnectionCount()); 1511 DCHECK_EQ(static_cast<size_t>(1), ConnectionCount());
1470 // Fall through would be a no-op, since transaction must complete 1512 // Fall through would be a no-op, since transaction must complete
1471 // asynchronously. 1513 // asynchronously.
1472 DCHECK(IsDeleteDatabaseBlocked()); 1514 DCHECK(IsDeleteDatabaseBlocked());
1473 DCHECK(IsOpenConnectionBlocked()); 1515 DCHECK(IsOpenConnectionBlocked());
1474 return; 1516 return;
1475 } 1517 }
1476 1518
(...skipping 22 matching lines...) Expand all
1499 OpenConnection(pending_open_call->Callbacks(), 1541 OpenConnection(pending_open_call->Callbacks(),
1500 pending_open_call->DatabaseCallbacks(), 1542 pending_open_call->DatabaseCallbacks(),
1501 pending_open_call->TransactionId(), 1543 pending_open_call->TransactionId(),
1502 pending_open_call->Version()); 1544 pending_open_call->Version());
1503 } 1545 }
1504 } 1546 }
1505 } 1547 }
1506 1548
1507 void IndexedDBDatabase::CreateTransaction( 1549 void IndexedDBDatabase::CreateTransaction(
1508 int64 transaction_id, 1550 int64 transaction_id,
1509 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, 1551 IndexedDBConnection* connection,
1510 const std::vector<int64>& object_store_ids, 1552 const std::vector<int64>& object_store_ids,
1511 uint16 mode) { 1553 uint16 mode) {
1512 1554
1513 DCHECK(database_callbacks_set_.has(callbacks)); 1555 DCHECK(connections_.has(connection));
1514 1556
1515 scoped_refptr<IndexedDBTransaction> transaction = 1557 scoped_refptr<IndexedDBTransaction> transaction =
1516 IndexedDBTransaction::Create( 1558 IndexedDBTransaction::Create(
1517 transaction_id, 1559 transaction_id,
1518 callbacks, 1560 connection->callbacks(),
1519 object_store_ids, 1561 object_store_ids,
1520 static_cast<indexed_db::TransactionMode>(mode), 1562 static_cast<indexed_db::TransactionMode>(mode),
1521 this); 1563 this);
1522 DCHECK(transactions_.find(transaction_id) == transactions_.end()); 1564 DCHECK(transactions_.find(transaction_id) == transactions_.end());
1523 transactions_[transaction_id] = transaction.get(); 1565 transactions_[transaction_id] = transaction.get();
1524 } 1566 }
1525 1567
1526 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { 1568 bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
1527 return !pending_delete_calls_.empty() || 1569 return !pending_delete_calls_.empty() ||
1528 running_version_change_transaction_ || 1570 running_version_change_transaction_ ||
(...skipping 28 matching lines...) Expand all
1557 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss); 1599 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss);
1558 pending_open_calls_.push_back(new PendingOpenCall( 1600 pending_open_calls_.push_back(new PendingOpenCall(
1559 callbacks, database_callbacks, transaction_id, version)); 1601 callbacks, database_callbacks, transaction_id, version));
1560 return; 1602 return;
1561 } 1603 }
1562 1604
1563 if (metadata_.id == kInvalidId) { 1605 if (metadata_.id == kInvalidId) {
1564 // The database was deleted then immediately re-opened; OpenInternal() 1606 // The database was deleted then immediately re-opened; OpenInternal()
1565 // recreates it in the backing store. 1607 // recreates it in the backing store.
1566 if (OpenInternal()) { 1608 if (OpenInternal()) {
1567 DCHECK_EQ(metadata_.int_version, 1609 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION,
1568 IndexedDBDatabaseMetadata::NO_INT_VERSION); 1610 metadata_.int_version);
1569 } else { 1611 } else {
1570 string16 message; 1612 string16 message;
1571 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) 1613 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION)
1572 message = ASCIIToUTF16( 1614 message = ASCIIToUTF16(
1573 "Internal error opening database with no version specified."); 1615 "Internal error opening database with no version specified.");
1574 else 1616 else
1575 message = 1617 message =
1576 ASCIIToUTF16("Internal error opening database with version ") + 1618 ASCIIToUTF16("Internal error opening database with version ") +
1577 Int64ToString16(version); 1619 Int64ToString16(version);
1578 callbacks->OnError(IndexedDBDatabaseError( 1620 callbacks->OnError(IndexedDBDatabaseError(
1579 WebKit::WebIDBDatabaseExceptionUnknownError, message)); 1621 WebKit::WebIDBDatabaseExceptionUnknownError, message));
1580 return; 1622 return;
1581 } 1623 }
1582 } 1624 }
1583 1625
1584 // We infer that the database didn't exist from its lack of either type of 1626 // We infer that the database didn't exist from its lack of either type of
1585 // version. 1627 // version.
1586 bool is_new_database = 1628 bool is_new_database =
1587 metadata_.version == kNoStringVersion && 1629 metadata_.version == kNoStringVersion &&
1588 metadata_.int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION; 1630 metadata_.int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION;
1589 1631
1632 scoped_ptr<IndexedDBConnection> connection(
1633 new IndexedDBConnection(this, database_callbacks));
1634
1590 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) { 1635 if (version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) {
1591 // For unit tests only - skip upgrade steps. Calling from script with 1636 // For unit tests only - skip upgrade steps. Calling from script with
1592 // DEFAULT_INT_VERSION throws exception. 1637 // DEFAULT_INT_VERSION throws exception.
1593 // TODO(jsbell): DCHECK that not in unit tests. 1638 // TODO(jsbell): DCHECK that not in unit tests.
1594 DCHECK(is_new_database); 1639 DCHECK(is_new_database);
1595 database_callbacks_set_.insert(database_callbacks); 1640 connections_.insert(connection.get());
1596 callbacks->OnSuccess(this, this->metadata()); 1641 callbacks->OnSuccess(connection.Pass(), this->metadata());
1597 return; 1642 return;
1598 } 1643 }
1599 1644
1600 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) { 1645 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) {
1601 if (!is_new_database) { 1646 if (!is_new_database) {
1602 database_callbacks_set_.insert(database_callbacks); 1647 connections_.insert(connection.get());
1603 callbacks->OnSuccess(this, this->metadata()); 1648 callbacks->OnSuccess(connection.Pass(), this->metadata());
1604 return; 1649 return;
1605 } 1650 }
1606 // Spec says: If no version is specified and no database exists, set 1651 // Spec says: If no version is specified and no database exists, set
1607 // database version to 1. 1652 // database version to 1.
1608 version = 1; 1653 version = 1;
1609 } 1654 }
1610 1655
1611 if (version > metadata_.int_version) { 1656 if (version > metadata_.int_version) {
1612 database_callbacks_set_.insert(database_callbacks); 1657 connections_.insert(connection.get());
1613 RunVersionChangeTransaction( 1658 RunVersionChangeTransaction(
1614 callbacks, database_callbacks, transaction_id, version, data_loss); 1659 callbacks, connection.Pass(), transaction_id, version, data_loss);
1615 return; 1660 return;
1616 } 1661 }
1617 if (version < metadata_.int_version) { 1662 if (version < metadata_.int_version) {
1618 callbacks->OnError(IndexedDBDatabaseError( 1663 callbacks->OnError(IndexedDBDatabaseError(
1619 WebKit::WebIDBDatabaseExceptionVersionError, 1664 WebKit::WebIDBDatabaseExceptionVersionError,
1620 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + 1665 ASCIIToUTF16("The requested version (") + Int64ToString16(version) +
1621 ASCIIToUTF16(") is less than the existing version (") + 1666 ASCIIToUTF16(") is less than the existing version (") +
1622 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); 1667 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(").")));
1623 return; 1668 return;
1624 } 1669 }
1625 DCHECK_EQ(version, metadata_.int_version); 1670 DCHECK_EQ(version, metadata_.int_version);
1626 database_callbacks_set_.insert(database_callbacks); 1671 connections_.insert(connection.get());
1627 callbacks->OnSuccess(this, this->metadata()); 1672 callbacks->OnSuccess(connection.Pass(), this->metadata());
1628 } 1673 }
1629 1674
1630 void IndexedDBDatabase::RunVersionChangeTransaction( 1675 void IndexedDBDatabase::RunVersionChangeTransaction(
1631 scoped_refptr<IndexedDBCallbacks> callbacks, 1676 scoped_refptr<IndexedDBCallbacks> callbacks,
1632 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1677 scoped_ptr<IndexedDBConnection> connection,
1633 int64 transaction_id, 1678 int64 transaction_id,
1634 int64 requested_version, 1679 int64 requested_version,
1635 WebKit::WebIDBCallbacks::DataLoss data_loss) { 1680 WebKit::WebIDBCallbacks::DataLoss data_loss) {
1636 1681
1637 DCHECK(callbacks.get()); 1682 DCHECK(callbacks.get());
1638 DCHECK(database_callbacks_set_.has(database_callbacks)); 1683 DCHECK(connections_.has(connection.get()));
1639 if (ConnectionCount() > 1) { 1684 if (ConnectionCount() > 1) {
1640 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss); 1685 DCHECK_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss);
1641 // Front end ensures the event is not fired at connections that have 1686 // Front end ensures the event is not fired at connections that have
1642 // close_pending set. 1687 // close_pending set.
1643 for (DatabaseCallbacksSet::const_iterator it = 1688 for (ConnectionSet::const_iterator it = connections_.begin();
1644 database_callbacks_set_.begin(); 1689 it != connections_.end();
1645 it != database_callbacks_set_.end();
1646 ++it) { 1690 ++it) {
1647 if (it->get() != database_callbacks.get()) 1691 if (*it != connection.get()) {
1648 (*it)->OnVersionChange(metadata_.int_version, requested_version); 1692 (*it)->callbacks()->OnVersionChange(
1693 metadata_.int_version, requested_version);
1694 }
1649 } 1695 }
1650 // TODO(jsbell): Remove the call to OnBlocked and instead wait 1696 // TODO(jsbell): Remove the call to OnBlocked and instead wait
1651 // until the frontend tells us that all the "versionchange" events 1697 // until the frontend tells us that all the "versionchange" events
1652 // have been delivered. http://crbug.com/100123 1698 // have been delivered. http://crbug.com/100123
1653 callbacks->OnBlocked(metadata_.int_version); 1699 callbacks->OnBlocked(metadata_.int_version);
1654 1700
1655 DCHECK(!pending_run_version_change_transaction_call_); 1701 DCHECK(!pending_run_version_change_transaction_call_);
1656 pending_run_version_change_transaction_call_.reset(new PendingOpenCall( 1702 pending_run_version_change_transaction_call_.reset(new PendingUpgradeCall(
1657 callbacks, database_callbacks, transaction_id, requested_version)); 1703 callbacks, connection.Pass(), transaction_id, requested_version));
1658 return; 1704 return;
1659 } 1705 }
1660 RunVersionChangeTransactionFinal(callbacks, 1706 RunVersionChangeTransactionFinal(callbacks,
1661 database_callbacks, 1707 connection.Pass(),
1662 transaction_id, 1708 transaction_id,
1663 requested_version, 1709 requested_version,
1664 data_loss); 1710 data_loss);
1665 } 1711 }
1666 1712
1667 void IndexedDBDatabase::RunVersionChangeTransactionFinal( 1713 void IndexedDBDatabase::RunVersionChangeTransactionFinal(
1668 scoped_refptr<IndexedDBCallbacks> callbacks, 1714 scoped_refptr<IndexedDBCallbacks> callbacks,
1669 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1715 scoped_ptr<IndexedDBConnection> connection,
1670 int64 transaction_id, 1716 int64 transaction_id,
1671 int64 requested_version) { 1717 int64 requested_version) {
1672 const WebKit::WebIDBCallbacks::DataLoss kDataLoss = 1718 const WebKit::WebIDBCallbacks::DataLoss kDataLoss =
1673 WebKit::WebIDBCallbacks::DataLossNone; 1719 WebKit::WebIDBCallbacks::DataLossNone;
1674 RunVersionChangeTransactionFinal(callbacks, 1720 RunVersionChangeTransactionFinal(callbacks,
1675 database_callbacks, 1721 connection.Pass(),
1676 transaction_id, 1722 transaction_id,
1677 requested_version, 1723 requested_version,
1678 kDataLoss); 1724 kDataLoss);
1679 } 1725 }
1680 1726
1681 void IndexedDBDatabase::RunVersionChangeTransactionFinal( 1727 void IndexedDBDatabase::RunVersionChangeTransactionFinal(
1682 scoped_refptr<IndexedDBCallbacks> callbacks, 1728 scoped_refptr<IndexedDBCallbacks> callbacks,
1683 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 1729 scoped_ptr<IndexedDBConnection> connection,
1684 int64 transaction_id, 1730 int64 transaction_id,
1685 int64 requested_version, 1731 int64 requested_version,
1686 WebKit::WebIDBCallbacks::DataLoss data_loss) { 1732 WebKit::WebIDBCallbacks::DataLoss data_loss) {
1687 1733
1688 std::vector<int64> object_store_ids; 1734 std::vector<int64> object_store_ids;
1689 CreateTransaction(transaction_id, 1735 CreateTransaction(transaction_id,
1690 database_callbacks, 1736 connection.get(),
1691 object_store_ids, 1737 object_store_ids,
1692 indexed_db::TRANSACTION_VERSION_CHANGE); 1738 indexed_db::TRANSACTION_VERSION_CHANGE);
1693 scoped_refptr<IndexedDBTransaction> transaction = 1739 scoped_refptr<IndexedDBTransaction> transaction =
1694 transactions_[transaction_id]; 1740 transactions_[transaction_id];
1695 1741
1696 transaction->ScheduleTask( 1742 transaction->ScheduleTask(
1697 new VersionChangeOperation(this, 1743 new VersionChangeOperation(this,
1698 transaction_id, 1744 transaction_id,
1699 requested_version, 1745 requested_version,
1700 callbacks, 1746 callbacks,
1701 database_callbacks, 1747 connection.Pass(),
1702 data_loss), 1748 data_loss),
1703 new VersionChangeAbortOperation( 1749 new VersionChangeAbortOperation(
1704 this, metadata_.version, metadata_.int_version)); 1750 this, metadata_.version, metadata_.int_version));
1705 1751
1706 DCHECK(!pending_second_half_open_); 1752 DCHECK(!pending_second_half_open_);
1707 } 1753 }
1708 1754
1709 void IndexedDBDatabase::DeleteDatabase( 1755 void IndexedDBDatabase::DeleteDatabase(
1710 scoped_refptr<IndexedDBCallbacks> callbacks) { 1756 scoped_refptr<IndexedDBCallbacks> callbacks) {
1711 1757
1712 if (IsDeleteDatabaseBlocked()) { 1758 if (IsDeleteDatabaseBlocked()) {
1713 for (DatabaseCallbacksSet::const_iterator it = 1759 for (ConnectionSet::const_iterator it = connections_.begin();
1714 database_callbacks_set_.begin(); 1760 it != connections_.end();
1715 it != database_callbacks_set_.end();
1716 ++it) { 1761 ++it) {
1717 // Front end ensures the event is not fired at connections that have 1762 // Front end ensures the event is not fired at connections that have
1718 // close_pending set. 1763 // close_pending set.
1719 (*it)->OnVersionChange(metadata_.int_version, 1764 (*it)->callbacks()->OnVersionChange(
1720 IndexedDBDatabaseMetadata::NO_INT_VERSION); 1765 metadata_.int_version, IndexedDBDatabaseMetadata::NO_INT_VERSION);
1721 } 1766 }
1722 // TODO(jsbell): Only fire OnBlocked if there are open 1767 // TODO(jsbell): Only fire OnBlocked if there are open
1723 // connections after the VersionChangeEvents are received, not 1768 // connections after the VersionChangeEvents are received, not
1724 // just set up to fire. http://crbug.com/100123 1769 // just set up to fire. http://crbug.com/100123
1725 callbacks->OnBlocked(metadata_.int_version); 1770 callbacks->OnBlocked(metadata_.int_version);
1726 pending_delete_calls_.push_back(new PendingDeleteCall(callbacks)); 1771 pending_delete_calls_.push_back(new PendingDeleteCall(callbacks));
1727 return; 1772 return;
1728 } 1773 }
1729 DeleteDatabaseFinal(callbacks); 1774 DeleteDatabaseFinal(callbacks);
1730 } 1775 }
(...skipping 12 matching lines...) Expand all
1743 "Internal error deleting database.")); 1788 "Internal error deleting database."));
1744 return; 1789 return;
1745 } 1790 }
1746 metadata_.version = kNoStringVersion; 1791 metadata_.version = kNoStringVersion;
1747 metadata_.id = kInvalidId; 1792 metadata_.id = kInvalidId;
1748 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; 1793 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION;
1749 metadata_.object_stores.clear(); 1794 metadata_.object_stores.clear();
1750 callbacks->OnSuccess(); 1795 callbacks->OnSuccess();
1751 } 1796 }
1752 1797
1753 void IndexedDBDatabase::Close( 1798 void IndexedDBDatabase::Close(IndexedDBConnection* connection) {
1754 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) { 1799 DCHECK(connections_.has(connection));
1755 DCHECK(callbacks.get());
1756 DCHECK(database_callbacks_set_.has(callbacks));
1757 1800
1758 // Close outstanding transactions from the closing connection. This 1801 // Close outstanding transactions from the closing connection. This
1759 // can not happen if the close is requested by the connection itself 1802 // can not happen if the close is requested by the connection itself
1760 // as the front-end defers the close until all transactions are 1803 // as the front-end defers the close until all transactions are
1761 // complete, so something unusual has happened e.g. unexpected 1804 // complete, so something unusual has happened e.g. unexpected
1762 // process termination. 1805 // process termination.
1763 { 1806 {
1764 TransactionMap transactions(transactions_); 1807 TransactionMap transactions(transactions_);
1765 for (TransactionMap::const_iterator it = transactions.begin(), 1808 for (TransactionMap::const_iterator it = transactions.begin(),
1766 end = transactions.end(); 1809 end = transactions.end();
1767 it != end; 1810 it != end;
1768 ++it) { 1811 ++it) {
1769 if (it->second->connection() == callbacks.get()) 1812 if (it->second->connection() == connection->callbacks())
1770 it->second->Abort( 1813 it->second->Abort(
1771 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, 1814 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
1772 "Connection is closing.")); 1815 "Connection is closing."));
1773 } 1816 }
1774 } 1817 }
1775 1818
1776 database_callbacks_set_.erase(callbacks); 1819 connections_.erase(connection);
1777 if (pending_second_half_open_ && 1820 if (pending_second_half_open_ &&
1778 pending_second_half_open_->DatabaseCallbacks().get() == callbacks.get()) { 1821 pending_second_half_open_->Connection() == connection) {
1779 pending_second_half_open_->Callbacks()->OnError( 1822 pending_second_half_open_->Callbacks()->OnError(
1780 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionAbortError, 1823 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionAbortError,
1781 "The connection was closed.")); 1824 "The connection was closed."));
1782 pending_second_half_open_.reset(); 1825 pending_second_half_open_.reset();
1783 } 1826 }
1784 1827
1785 // process_pending_calls allows the inspector to process a pending open call 1828 // process_pending_calls allows the inspector to process a pending open call
1786 // and call close, reentering IndexedDBDatabase::close. Then the 1829 // and call close, reentering IndexedDBDatabase::close. Then the
1787 // backend would be removed both by the inspector closing its connection, and 1830 // backend would be removed both by the inspector closing its connection, and
1788 // by the connection that first called close. 1831 // by the connection that first called close.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 1866
1824 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( 1867 void IndexedDBDatabase::VersionChangeAbortOperation::Perform(
1825 IndexedDBTransaction* transaction) { 1868 IndexedDBTransaction* transaction) {
1826 IDB_TRACE("VersionChangeAbortOperation"); 1869 IDB_TRACE("VersionChangeAbortOperation");
1827 DCHECK(!transaction); 1870 DCHECK(!transaction);
1828 database_->metadata_.version = previous_version_; 1871 database_->metadata_.version = previous_version_;
1829 database_->metadata_.int_version = previous_int_version_; 1872 database_->metadata_.int_version = previous_int_version_;
1830 } 1873 }
1831 1874
1832 } // namespace content 1875 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698