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/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 14 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 14 #include "content/browser/indexed_db/indexed_db_cursor.h" | 15 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 15 #include "content/browser/indexed_db/indexed_db_database.h" | 16 #include "content/browser/indexed_db/indexed_db_database.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 18 #include "content/browser/indexed_db/indexed_db_observer.h" | |
| 17 #include "content/browser/indexed_db/indexed_db_tracing.h" | 19 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 20 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" |
| 20 #include "third_party/leveldatabase/env_chromium.h" | 22 #include "third_party/leveldatabase/env_chromium.h" |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 const int64_t kInactivityTimeoutPeriodSeconds = 60; | 28 const int64_t kInactivityTimeoutPeriodSeconds = 60; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 61 |
| 60 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() { | 62 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() { |
| 61 DCHECK(!stack_.empty()); | 63 DCHECK(!stack_.empty()); |
| 62 Operation task(stack_.top()); | 64 Operation task(stack_.top()); |
| 63 stack_.pop(); | 65 stack_.pop(); |
| 64 return task; | 66 return task; |
| 65 } | 67 } |
| 66 | 68 |
| 67 IndexedDBTransaction::IndexedDBTransaction( | 69 IndexedDBTransaction::IndexedDBTransaction( |
| 68 int64_t id, | 70 int64_t id, |
| 71 base::WeakPtr<IndexedDBConnection> connection, | |
| 69 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 72 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
| 70 const std::set<int64_t>& object_store_ids, | 73 const std::set<int64_t>& object_store_ids, |
| 71 blink::WebIDBTransactionMode mode, | 74 blink::WebIDBTransactionMode mode, |
| 72 IndexedDBDatabase* database, | 75 IndexedDBDatabase* database, |
| 73 IndexedDBBackingStore::Transaction* backing_store_transaction) | 76 IndexedDBBackingStore::Transaction* backing_store_transaction) |
| 74 : id_(id), | 77 : id_(id), |
| 75 object_store_ids_(object_store_ids), | 78 object_store_ids_(object_store_ids), |
| 76 mode_(mode), | 79 mode_(mode), |
| 77 used_(false), | 80 used_(false), |
| 78 state_(CREATED), | 81 state_(CREATED), |
| 79 commit_pending_(false), | 82 commit_pending_(false), |
| 83 connection_(std::move(connection)), | |
| 80 callbacks_(callbacks), | 84 callbacks_(callbacks), |
| 81 database_(database), | 85 database_(database), |
| 82 transaction_(backing_store_transaction), | 86 transaction_(backing_store_transaction), |
| 83 backing_store_transaction_begun_(false), | 87 backing_store_transaction_begun_(false), |
| 84 should_process_queue_(false), | 88 should_process_queue_(false), |
| 85 pending_preemptive_events_(0) { | 89 pending_preemptive_events_(0) { |
| 86 database_->transaction_coordinator().DidCreateTransaction(this); | 90 database_->transaction_coordinator().DidCreateTransaction(this); |
| 87 | 91 |
| 88 diagnostics_.tasks_scheduled = 0; | 92 diagnostics_.tasks_scheduled = 0; |
| 89 diagnostics_.tasks_completed = 0; | 93 diagnostics_.tasks_completed = 0; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 #ifndef NDEBUG | 188 #ifndef NDEBUG |
| 185 DCHECK(!database_->transaction_coordinator().IsActive(this)); | 189 DCHECK(!database_->transaction_coordinator().IsActive(this)); |
| 186 #endif | 190 #endif |
| 187 | 191 |
| 188 if (callbacks_.get()) | 192 if (callbacks_.get()) |
| 189 callbacks_->OnAbort(id_, error); | 193 callbacks_->OnAbort(id_, error); |
| 190 | 194 |
| 191 database_->TransactionFinished(this, false); | 195 database_->TransactionFinished(this, false); |
| 192 | 196 |
| 193 database_ = NULL; | 197 database_ = NULL; |
| 198 connection_ = nullptr; | |
| 194 } | 199 } |
| 195 | 200 |
| 196 bool IndexedDBTransaction::IsTaskQueueEmpty() const { | 201 bool IndexedDBTransaction::IsTaskQueueEmpty() const { |
| 197 return preemptive_task_queue_.empty() && task_queue_.empty(); | 202 return preemptive_task_queue_.empty() && task_queue_.empty(); |
| 198 } | 203 } |
| 199 | 204 |
| 200 bool IndexedDBTransaction::HasPendingTasks() const { | 205 bool IndexedDBTransaction::HasPendingTasks() const { |
| 201 return pending_preemptive_events_ || !IsTaskQueueEmpty(); | 206 return pending_preemptive_events_ || !IsTaskQueueEmpty(); |
| 202 } | 207 } |
| 203 | 208 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 // released, and order is critical. | 337 // released, and order is critical. |
| 333 CloseOpenCursors(); | 338 CloseOpenCursors(); |
| 334 transaction_->Reset(); | 339 transaction_->Reset(); |
| 335 | 340 |
| 336 // Transactions must also be marked as completed before the | 341 // Transactions must also be marked as completed before the |
| 337 // front-end is notified, as the transaction completion unblocks | 342 // front-end is notified, as the transaction completion unblocks |
| 338 // operations like closing connections. | 343 // operations like closing connections. |
| 339 database_->transaction_coordinator().DidFinishTransaction(this); | 344 database_->transaction_coordinator().DidFinishTransaction(this); |
| 340 | 345 |
| 341 if (committed) { | 346 if (committed) { |
| 347 // TODO (palakj) : Send Observations to observers | |
| 348 if (!pending_observers_.empty()) | |
|
dmurph
2016/06/23 21:53:04
Do a check that the connection is around as well.
palakj1
2016/06/24 00:03:00
Done.
| |
| 349 connection_->ActivatePendingObservers(&pending_observers_); | |
| 342 abort_task_stack_.clear(); | 350 abort_task_stack_.clear(); |
| 343 { | 351 { |
| 344 IDB_TRACE1( | 352 IDB_TRACE1( |
| 345 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", | 353 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", |
| 346 "txn.id", id()); | 354 "txn.id", id()); |
| 347 callbacks_->OnComplete(id_); | 355 callbacks_->OnComplete(id_); |
| 348 } | 356 } |
| 349 database_->TransactionFinished(this, true); | 357 database_->TransactionFinished(this, true); |
| 350 } else { | 358 } else { |
| 351 while (!abort_task_stack_.empty()) | 359 while (!abort_task_stack_.empty()) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); | 446 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); |
| 439 } | 447 } |
| 440 | 448 |
| 441 void IndexedDBTransaction::CloseOpenCursors() { | 449 void IndexedDBTransaction::CloseOpenCursors() { |
| 442 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); | 450 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); |
| 443 for (auto* cursor : open_cursors_) | 451 for (auto* cursor : open_cursors_) |
| 444 cursor->Close(); | 452 cursor->Close(); |
| 445 open_cursors_.clear(); | 453 open_cursors_.clear(); |
| 446 } | 454 } |
| 447 | 455 |
| 456 void IndexedDBTransaction::AddPendingObserver(int32_t observer_id) { | |
| 457 pending_observers_.push_back( | |
| 458 base::WrapUnique(new IndexedDBObserver(observer_id))); | |
| 459 } | |
| 460 | |
| 461 void IndexedDBTransaction::RemovePendingObservers( | |
| 462 const std::vector<int32_t>& pending_observer_ids) { | |
| 463 // TODO(palakj): Change from vector to set or create a tmp vector instead of | |
| 464 // erase. | |
| 465 for (uint32_t i = 0; i < pending_observer_ids.size(); i++) { | |
| 466 for (uint32_t j = 0; j < pending_observers_.size(); j++) { | |
| 467 if (pending_observers_[j]->id() == pending_observer_ids[i]) { | |
| 468 pending_observers_.erase(pending_observers_.begin() + j); | |
|
dmurph
2016/06/23 21:53:04
Same issue here. You have to either use iterator i
palakj1
2016/06/24 00:03:00
Same reason here.
| |
| 469 break; | |
| 470 } | |
| 471 } | |
| 472 } | |
| 473 } | |
| 474 | |
| 448 } // namespace content | 475 } // namespace content |
| OLD | NEW |