Chromium Code Reviews| 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_transaction.h" | 5 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.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_cursor.h" | 16 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database.h" | 17 #include "content/browser/indexed_db/indexed_db_database.h" |
| 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 19 #include "content/browser/indexed_db/indexed_db_observer.h" | 19 #include "content/browser/indexed_db/indexed_db_observation.h" |
| 20 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | |
| 20 #include "content/browser/indexed_db/indexed_db_tracing.h" | 21 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 21 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 22 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" |
| 23 #include "third_party/leveldatabase/env_chromium.h" | 24 #include "third_party/leveldatabase/env_chromium.h" |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const int64_t kInactivityTimeoutPeriodSeconds = 60; | 30 const int64_t kInactivityTimeoutPeriodSeconds = 60; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 // released, and order is critical. | 340 // released, and order is critical. |
| 340 CloseOpenCursors(); | 341 CloseOpenCursors(); |
| 341 transaction_->Reset(); | 342 transaction_->Reset(); |
| 342 | 343 |
| 343 // Transactions must also be marked as completed before the | 344 // Transactions must also be marked as completed before the |
| 344 // front-end is notified, as the transaction completion unblocks | 345 // front-end is notified, as the transaction completion unblocks |
| 345 // operations like closing connections. | 346 // operations like closing connections. |
| 346 database_->transaction_coordinator().DidFinishTransaction(this); | 347 database_->transaction_coordinator().DidFinishTransaction(this); |
| 347 | 348 |
| 348 if (committed) { | 349 if (committed) { |
| 349 // TODO (palakj) : Send Observations to observers | |
| 350 if (!pending_observers_.empty() && connection_) | |
| 351 connection_->ActivatePendingObservers(std::move(pending_observers_)); | |
| 352 abort_task_stack_.clear(); | 350 abort_task_stack_.clear(); |
| 351 | |
| 352 // SendObservations must be called before OnComplete to ensure consistency | |
| 353 // of callbacks at renderer. | |
| 354 if (!connection_changes_map_.empty()) { | |
| 355 database_->SendObservations(std::move(connection_changes_map_)); | |
| 356 connection_changes_map_.clear(); | |
|
cmumford
2016/07/19 16:00:16
connection_changes_map_ was moved above and is alr
Marijn Kruisselbrink
2016/07/19 17:16:28
The c++ standard gives no such guarantees. std::un
| |
| 357 } | |
| 353 { | 358 { |
| 354 IDB_TRACE1( | 359 IDB_TRACE1( |
| 355 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", | 360 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", |
| 356 "txn.id", id()); | 361 "txn.id", id()); |
| 357 callbacks_->OnComplete(id_); | 362 callbacks_->OnComplete(id_); |
| 358 } | 363 } |
| 364 if (!pending_observers_.empty() && connection_) { | |
| 365 connection_->ActivatePendingObservers(std::move(pending_observers_)); | |
| 366 pending_observers_.clear(); | |
|
cmumford
2016/07/19 16:00:16
Also, no need to clear pending_observers_.
Marijn Kruisselbrink
2016/07/19 17:16:28
Same here, no guarantees what moving from does to
| |
| 367 } | |
| 368 | |
| 359 database_->TransactionFinished(this, true); | 369 database_->TransactionFinished(this, true); |
| 360 } else { | 370 } else { |
| 361 while (!abort_task_stack_.empty()) | 371 while (!abort_task_stack_.empty()) |
| 362 abort_task_stack_.pop().Run(NULL); | 372 abort_task_stack_.pop().Run(NULL); |
| 363 | 373 |
| 364 IndexedDBDatabaseError error; | 374 IndexedDBDatabaseError error; |
| 365 if (leveldb_env::IndicatesDiskFull(s)) { | 375 if (leveldb_env::IndicatesDiskFull(s)) { |
| 366 error = IndexedDBDatabaseError( | 376 error = IndexedDBDatabaseError( |
| 367 blink::WebIDBDatabaseExceptionQuotaError, | 377 blink::WebIDBDatabaseExceptionQuotaError, |
| 368 "Encountered disk full while committing transaction."); | 378 "Encountered disk full while committing transaction."); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); | 458 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); |
| 449 } | 459 } |
| 450 | 460 |
| 451 void IndexedDBTransaction::CloseOpenCursors() { | 461 void IndexedDBTransaction::CloseOpenCursors() { |
| 452 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); | 462 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); |
| 453 for (auto* cursor : open_cursors_) | 463 for (auto* cursor : open_cursors_) |
| 454 cursor->Close(); | 464 cursor->Close(); |
| 455 open_cursors_.clear(); | 465 open_cursors_.clear(); |
| 456 } | 466 } |
| 457 | 467 |
| 458 void IndexedDBTransaction::AddPendingObserver(int32_t observer_id) { | 468 void IndexedDBTransaction::AddPendingObserver( |
| 459 pending_observers_.push_back( | 469 int32_t observer_id, |
| 460 base::WrapUnique(new IndexedDBObserver(observer_id))); | 470 IndexedDBObserver::Options options) { |
|
cmumford
2016/07/19 16:00:16
const IndexedDBObserver::Options& options
palakj1
2016/07/19 18:04:14
done
| |
| 471 pending_observers_.push_back(base::WrapUnique( | |
| 472 new IndexedDBObserver(observer_id, object_store_ids_, options))); | |
| 461 } | 473 } |
| 462 | 474 |
| 463 void IndexedDBTransaction::RemovePendingObservers( | 475 void IndexedDBTransaction::RemovePendingObservers( |
| 464 const std::vector<int32_t>& pending_observer_ids) { | 476 const std::vector<int32_t>& pending_observer_ids) { |
| 465 const auto& it = std::remove_if( | 477 const auto& it = std::remove_if( |
| 466 pending_observers_.begin(), pending_observers_.end(), | 478 pending_observers_.begin(), pending_observers_.end(), |
| 467 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { | 479 [&pending_observer_ids](const std::unique_ptr<IndexedDBObserver>& o) { |
| 468 return ContainsValue(pending_observer_ids, o->id()); | 480 return ContainsValue(pending_observer_ids, o->id()); |
| 469 }); | 481 }); |
| 470 if (it != pending_observers_.end()) | 482 if (it != pending_observers_.end()) |
| 471 pending_observers_.erase(it, pending_observers_.end()); | 483 pending_observers_.erase(it, pending_observers_.end()); |
| 472 } | 484 } |
| 473 | 485 |
| 486 void IndexedDBTransaction::AddObservation( | |
| 487 int32_t connection_id, | |
| 488 std::unique_ptr<IndexedDBObservation> observation) { | |
| 489 auto it = connection_changes_map_.find(connection_id); | |
| 490 if (it == connection_changes_map_.end()) { | |
| 491 it = connection_changes_map_ | |
| 492 .insert(std::make_pair( | |
| 493 connection_id, | |
| 494 base::WrapUnique(new IndexedDBObserverChanges()))) | |
| 495 .first; | |
| 496 } | |
| 497 it->second->AddObservation(std::move(observation)); | |
| 498 } | |
| 499 | |
| 500 void IndexedDBTransaction::RecordObserverForLastObservation( | |
| 501 int32_t connection_id, | |
| 502 int32_t observer_id) { | |
| 503 auto it = connection_changes_map_.find(connection_id); | |
| 504 DCHECK(it != connection_changes_map_.end()); | |
| 505 it->second->RecordObserverForLastObservation(observer_id); | |
| 506 } | |
| 507 | |
| 474 } // namespace content | 508 } // namespace content |
| OLD | NEW |