OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/indexed_db/indexed_db_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | |
8 | 9 |
9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 15 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
15 #include "content/browser/indexed_db/indexed_db_connection.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" |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 class IndexedDBDatabase::PendingDeleteCall { | 446 class IndexedDBDatabase::PendingDeleteCall { |
446 public: | 447 public: |
447 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) | 448 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) |
448 : callbacks_(callbacks) {} | 449 : callbacks_(callbacks) {} |
449 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } | 450 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } |
450 | 451 |
451 private: | 452 private: |
452 scoped_refptr<IndexedDBCallbacks> callbacks_; | 453 scoped_refptr<IndexedDBCallbacks> callbacks_; |
453 }; | 454 }; |
454 | 455 |
455 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( | 456 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( |
jsbell
2013/07/13 00:18:32
I did not touch this Create() static method becaus
| |
456 const string16& name, | 457 const string16& name, |
457 IndexedDBBackingStore* database, | 458 IndexedDBBackingStore* database, |
458 IndexedDBFactory* factory, | 459 IndexedDBFactory* factory, |
459 const string16& unique_identifier) { | 460 const string16& unique_identifier) { |
460 scoped_refptr<IndexedDBDatabase> backend = | 461 scoped_refptr<IndexedDBDatabase> backend = |
461 new IndexedDBDatabase(name, database, factory, unique_identifier); | 462 new IndexedDBDatabase(name, database, factory, unique_identifier); |
462 if (!backend->OpenInternal()) | 463 if (!backend->OpenInternal()) |
jsbell
2013/07/13 00:18:32
... of this test which, which causes the Create()
| |
463 return 0; | 464 return 0; |
464 return backend; | 465 return backend; |
465 } | 466 } |
466 | 467 |
467 namespace { | 468 namespace { |
468 const base::string16::value_type kNoStringVersion[] = {0}; | 469 const base::string16::value_type kNoStringVersion[] = {0}; |
469 | 470 |
470 template <typename T, typename U> | 471 template <typename T, typename U> |
471 bool Contains(const T& container, const U& item) { | 472 bool Contains(const T& container, const U& item) { |
472 return container.find(item) != container.end(); | 473 return container.find(item) != container.end(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 return true; | 580 return true; |
580 } | 581 } |
581 | 582 |
582 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId(int64 object_store_id, | 583 bool IndexedDBDatabase::ValidateObjectStoreIdAndIndexId(int64 object_store_id, |
583 int64 index_id) const { | 584 int64 index_id) const { |
584 if (!ValidateObjectStoreId(object_store_id)) | 585 if (!ValidateObjectStoreId(object_store_id)) |
585 return false; | 586 return false; |
586 const IndexedDBObjectStoreMetadata& object_store_metadata = | 587 const IndexedDBObjectStoreMetadata& object_store_metadata = |
587 metadata_.object_stores.find(object_store_id)->second; | 588 metadata_.object_stores.find(object_store_id)->second; |
588 if (!Contains(object_store_metadata.indexes, index_id)) { | 589 if (!Contains(object_store_metadata.indexes, index_id)) { |
589 DLOG(ERROR) << "Invalid index_id"; | 590 DLOG(ERROR) << "Invalid index_id"; |
590 return false; | 591 return false; |
591 } | 592 } |
592 return true; | 593 return true; |
593 } | 594 } |
594 | 595 |
595 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( | 596 bool IndexedDBDatabase::ValidateObjectStoreIdAndOptionalIndexId( |
596 int64 object_store_id, | 597 int64 object_store_id, |
597 int64 index_id) const { | 598 int64 index_id) const { |
598 if (!ValidateObjectStoreId(object_store_id)) | 599 if (!ValidateObjectStoreId(object_store_id)) |
599 return false; | 600 return false; |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1315 *key_range_, | 1316 *key_range_, |
1316 direction_); | 1317 direction_); |
1317 } | 1318 } |
1318 } | 1319 } |
1319 | 1320 |
1320 if (!backing_store_cursor) { | 1321 if (!backing_store_cursor) { |
1321 callbacks_->OnSuccess(static_cast<std::string*>(NULL)); | 1322 callbacks_->OnSuccess(static_cast<std::string*>(NULL)); |
1322 return; | 1323 return; |
1323 } | 1324 } |
1324 | 1325 |
1325 IndexedDBDatabase::TaskType task_type( | 1326 scoped_refptr<IndexedDBCursor> cursor = new IndexedDBCursor( |
1326 static_cast<IndexedDBDatabase::TaskType>(task_type_)); | 1327 backing_store_cursor.Pass(), cursor_type_, task_type_, transaction); |
1327 scoped_refptr<IndexedDBCursor> cursor = IndexedDBCursor::Create( | |
1328 backing_store_cursor.Pass(), cursor_type_, task_type, transaction); | |
1329 callbacks_->OnSuccess( | 1328 callbacks_->OnSuccess( |
1330 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1329 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
1331 } | 1330 } |
1332 | 1331 |
1333 void IndexedDBDatabase::Count(int64 transaction_id, | 1332 void IndexedDBDatabase::Count(int64 transaction_id, |
1334 int64 object_store_id, | 1333 int64 object_store_id, |
1335 int64 index_id, | 1334 int64 index_id, |
1336 scoped_ptr<IndexedDBKeyRange> key_range, | 1335 scoped_ptr<IndexedDBKeyRange> key_range, |
1337 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1336 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1338 IDB_TRACE("IndexedDBDatabase::Count"); | 1337 IDB_TRACE("IndexedDBDatabase::Count"); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1479 int64 database_id = database_->id(); | 1478 int64 database_id = database_->id(); |
1480 int64 old_version = database_->metadata_.int_version; | 1479 int64 old_version = database_->metadata_.int_version; |
1481 DCHECK_GT(version_, old_version); | 1480 DCHECK_GT(version_, old_version); |
1482 database_->metadata_.int_version = version_; | 1481 database_->metadata_.int_version = version_; |
1483 if (!database_->backing_store_->UpdateIDBDatabaseIntVersion( | 1482 if (!database_->backing_store_->UpdateIDBDatabaseIntVersion( |
1484 transaction->BackingStoreTransaction(), | 1483 transaction->BackingStoreTransaction(), |
1485 database_id, | 1484 database_id, |
1486 database_->metadata_.int_version)) { | 1485 database_->metadata_.int_version)) { |
1487 IndexedDBDatabaseError error( | 1486 IndexedDBDatabaseError error( |
1488 WebKit::WebIDBDatabaseExceptionUnknownError, | 1487 WebKit::WebIDBDatabaseExceptionUnknownError, |
1489 ASCIIToUTF16("Internal error writing data to stable storage when " | 1488 ASCIIToUTF16( |
1490 "updating version.")); | 1489 "Internal error writing data to stable storage when " |
1490 "updating version.")); | |
1491 callbacks_->OnError(error); | 1491 callbacks_->OnError(error); |
1492 transaction->Abort(error); | 1492 transaction->Abort(error); |
1493 return; | 1493 return; |
1494 } | 1494 } |
1495 DCHECK(!database_->pending_second_half_open_); | 1495 DCHECK(!database_->pending_second_half_open_); |
1496 | 1496 |
1497 database_->pending_second_half_open_.reset(new PendingSuccessCall( | 1497 database_->pending_second_half_open_.reset(new PendingSuccessCall( |
1498 callbacks_, connection_.get(), transaction_id_, version_)); | 1498 callbacks_, connection_.get(), transaction_id_, version_)); |
1499 callbacks_->OnUpgradeNeeded( | 1499 callbacks_->OnUpgradeNeeded( |
1500 old_version, connection_.Pass(), database_->metadata(), data_loss_); | 1500 old_version, connection_.Pass(), database_->metadata(), data_loss_); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1607 } | 1607 } |
1608 | 1608 |
1609 void IndexedDBDatabase::CreateTransaction( | 1609 void IndexedDBDatabase::CreateTransaction( |
1610 int64 transaction_id, | 1610 int64 transaction_id, |
1611 IndexedDBConnection* connection, | 1611 IndexedDBConnection* connection, |
1612 const std::vector<int64>& object_store_ids, | 1612 const std::vector<int64>& object_store_ids, |
1613 uint16 mode) { | 1613 uint16 mode) { |
1614 | 1614 |
1615 DCHECK(connections_.has(connection)); | 1615 DCHECK(connections_.has(connection)); |
1616 | 1616 |
1617 scoped_refptr<IndexedDBTransaction> transaction = | 1617 scoped_refptr<IndexedDBTransaction> transaction = new IndexedDBTransaction( |
1618 IndexedDBTransaction::Create( | 1618 transaction_id, |
1619 transaction_id, | 1619 connection->callbacks(), |
1620 connection->callbacks(), | 1620 std::set<int64>(object_store_ids.begin(), object_store_ids.end()), |
1621 object_store_ids, | 1621 static_cast<indexed_db::TransactionMode>(mode), |
1622 static_cast<indexed_db::TransactionMode>(mode), | 1622 this); |
1623 this); | |
1624 DCHECK(transactions_.find(transaction_id) == transactions_.end()); | 1623 DCHECK(transactions_.find(transaction_id) == transactions_.end()); |
1625 transactions_[transaction_id] = transaction; | 1624 transactions_[transaction_id] = transaction; |
1626 } | 1625 } |
1627 | 1626 |
1628 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { | 1627 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
1629 return !pending_delete_calls_.empty() || | 1628 return !pending_delete_calls_.empty() || |
1630 running_version_change_transaction_ || | 1629 running_version_change_transaction_ || |
1631 pending_run_version_change_transaction_call_; | 1630 pending_run_version_change_transaction_call_; |
1632 } | 1631 } |
1633 | 1632 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1926 | 1925 |
1927 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( | 1926 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( |
1928 IndexedDBTransaction* transaction) { | 1927 IndexedDBTransaction* transaction) { |
1929 IDB_TRACE("VersionChangeAbortOperation"); | 1928 IDB_TRACE("VersionChangeAbortOperation"); |
1930 DCHECK(!transaction); | 1929 DCHECK(!transaction); |
1931 database_->metadata_.version = previous_version_; | 1930 database_->metadata_.version = previous_version_; |
1932 database_->metadata_.int_version = previous_int_version_; | 1931 database_->metadata_.int_version = previous_int_version_; |
1933 } | 1932 } |
1934 | 1933 |
1935 } // namespace content | 1934 } // namespace content |
OLD | NEW |