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/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 13 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 14 #include "content/browser/indexed_db/indexed_db_cursor.h" | 14 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 15 #include "content/browser/indexed_db/indexed_db_database.h" | 15 #include "content/browser/indexed_db/indexed_db_database.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 17 #include "content/browser/indexed_db/indexed_db_observer.h" | |
| 17 #include "content/browser/indexed_db/indexed_db_tracing.h" | 18 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 19 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" |
| 20 #include "third_party/leveldatabase/env_chromium.h" | 21 #include "third_party/leveldatabase/env_chromium.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 const int64_t kInactivityTimeoutPeriodSeconds = 60; | 25 const int64_t kInactivityTimeoutPeriodSeconds = 60; |
| 25 | 26 |
| 26 IndexedDBTransaction::TaskQueue::TaskQueue() {} | 27 IndexedDBTransaction::TaskQueue::TaskQueue() {} |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 48 | 49 |
| 49 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() { | 50 IndexedDBTransaction::Operation IndexedDBTransaction::TaskStack::pop() { |
| 50 DCHECK(!stack_.empty()); | 51 DCHECK(!stack_.empty()); |
| 51 Operation task(stack_.top()); | 52 Operation task(stack_.top()); |
| 52 stack_.pop(); | 53 stack_.pop(); |
| 53 return task; | 54 return task; |
| 54 } | 55 } |
| 55 | 56 |
| 56 IndexedDBTransaction::IndexedDBTransaction( | 57 IndexedDBTransaction::IndexedDBTransaction( |
| 57 int64_t id, | 58 int64_t id, |
| 59 IndexedDBConnection* connection, | |
| 58 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 60 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
| 59 const std::set<int64_t>& object_store_ids, | 61 const std::set<int64_t>& object_store_ids, |
| 60 blink::WebIDBTransactionMode mode, | 62 blink::WebIDBTransactionMode mode, |
| 61 IndexedDBDatabase* database, | 63 IndexedDBDatabase* database, |
| 62 IndexedDBBackingStore::Transaction* backing_store_transaction) | 64 IndexedDBBackingStore::Transaction* backing_store_transaction) |
| 63 : id_(id), | 65 : id_(id), |
| 64 object_store_ids_(object_store_ids), | 66 object_store_ids_(object_store_ids), |
| 65 mode_(mode), | 67 mode_(mode), |
| 66 used_(false), | 68 used_(false), |
| 67 state_(CREATED), | 69 state_(CREATED), |
| 68 commit_pending_(false), | 70 commit_pending_(false), |
| 71 connection_(connection), | |
| 69 callbacks_(callbacks), | 72 callbacks_(callbacks), |
| 70 database_(database), | 73 database_(database), |
| 71 transaction_(backing_store_transaction), | 74 transaction_(backing_store_transaction), |
| 72 backing_store_transaction_begun_(false), | 75 backing_store_transaction_begun_(false), |
| 73 should_process_queue_(false), | 76 should_process_queue_(false), |
| 74 pending_preemptive_events_(0) { | 77 pending_preemptive_events_(0) { |
| 75 database_->transaction_coordinator().DidCreateTransaction(this); | 78 database_->transaction_coordinator().DidCreateTransaction(this); |
| 76 | 79 |
| 77 diagnostics_.tasks_scheduled = 0; | 80 diagnostics_.tasks_scheduled = 0; |
| 78 diagnostics_.tasks_completed = 0; | 81 diagnostics_.tasks_completed = 0; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 #ifndef NDEBUG | 176 #ifndef NDEBUG |
| 174 DCHECK(!database_->transaction_coordinator().IsActive(this)); | 177 DCHECK(!database_->transaction_coordinator().IsActive(this)); |
| 175 #endif | 178 #endif |
| 176 | 179 |
| 177 if (callbacks_.get()) | 180 if (callbacks_.get()) |
| 178 callbacks_->OnAbort(id_, error); | 181 callbacks_->OnAbort(id_, error); |
| 179 | 182 |
| 180 database_->TransactionFinished(this, false); | 183 database_->TransactionFinished(this, false); |
| 181 | 184 |
| 182 database_ = NULL; | 185 database_ = NULL; |
| 186 connection_ = nullptr; | |
| 183 } | 187 } |
| 184 | 188 |
| 185 bool IndexedDBTransaction::IsTaskQueueEmpty() const { | 189 bool IndexedDBTransaction::IsTaskQueueEmpty() const { |
| 186 return preemptive_task_queue_.empty() && task_queue_.empty(); | 190 return preemptive_task_queue_.empty() && task_queue_.empty(); |
| 187 } | 191 } |
| 188 | 192 |
| 189 bool IndexedDBTransaction::HasPendingTasks() const { | 193 bool IndexedDBTransaction::HasPendingTasks() const { |
| 190 return pending_preemptive_events_ || !IsTaskQueueEmpty(); | 194 return pending_preemptive_events_ || !IsTaskQueueEmpty(); |
| 191 } | 195 } |
| 192 | 196 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 // released, and order is critical. | 311 // released, and order is critical. |
| 308 CloseOpenCursors(); | 312 CloseOpenCursors(); |
| 309 transaction_->Reset(); | 313 transaction_->Reset(); |
| 310 | 314 |
| 311 // Transactions must also be marked as completed before the | 315 // Transactions must also be marked as completed before the |
| 312 // front-end is notified, as the transaction completion unblocks | 316 // front-end is notified, as the transaction completion unblocks |
| 313 // operations like closing connections. | 317 // operations like closing connections. |
| 314 database_->transaction_coordinator().DidFinishTransaction(this); | 318 database_->transaction_coordinator().DidFinishTransaction(this); |
| 315 | 319 |
| 316 if (committed) { | 320 if (committed) { |
| 321 // TODO (palakj) : Send Observations to observers | |
| 322 if (!pending_observers_.empty()) | |
| 323 ActivatePendingObserver(); | |
| 317 abort_task_stack_.clear(); | 324 abort_task_stack_.clear(); |
| 318 { | 325 { |
| 319 IDB_TRACE1( | 326 IDB_TRACE1( |
| 320 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", | 327 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", |
| 321 "txn.id", id()); | 328 "txn.id", id()); |
| 322 callbacks_->OnComplete(id_); | 329 callbacks_->OnComplete(id_); |
| 323 } | 330 } |
| 324 database_->TransactionFinished(this, true); | 331 database_->TransactionFinished(this, true); |
| 325 } else { | 332 } else { |
| 326 while (!abort_task_stack_.empty()) | 333 while (!abort_task_stack_.empty()) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); | 420 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); |
| 414 } | 421 } |
| 415 | 422 |
| 416 void IndexedDBTransaction::CloseOpenCursors() { | 423 void IndexedDBTransaction::CloseOpenCursors() { |
| 417 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); | 424 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); |
| 418 for (auto* cursor : open_cursors_) | 425 for (auto* cursor : open_cursors_) |
| 419 cursor->Close(); | 426 cursor->Close(); |
| 420 open_cursors_.clear(); | 427 open_cursors_.clear(); |
| 421 } | 428 } |
| 422 | 429 |
| 430 void IndexedDBTransaction::AddPendingObserver( | |
| 431 std::unique_ptr<IndexedDBObserver> observer) { | |
| 432 pending_observers_.push_back(std::move(observer)); | |
| 433 } | |
| 434 | |
| 435 void IndexedDBTransaction::ActivatePendingObserver() { | |
| 436 for (uint32_t i = 0; i < pending_observers_.size(); i++) { | |
| 437 connection_->active_observers_.push_back(std::move(pending_observers_[i])); | |
|
dmurph
2016/06/22 01:09:49
Maybe make this a method, so we're not calling int
| |
| 438 ; | |
|
dmurph
2016/06/22 01:09:49
remove extra semicolon
palakj1
2016/06/23 20:56:30
Done
| |
| 439 } | |
| 440 } | |
| 441 | |
| 423 } // namespace content | 442 } // namespace content |
| OLD | NEW |