| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 DCHECK(!stack_.empty()); | 47 DCHECK(!stack_.empty()); |
| 48 Operation task(stack_.top()); | 48 Operation task(stack_.top()); |
| 49 stack_.pop(); | 49 stack_.pop(); |
| 50 return task; | 50 return task; |
| 51 } | 51 } |
| 52 | 52 |
| 53 IndexedDBTransaction::IndexedDBTransaction( | 53 IndexedDBTransaction::IndexedDBTransaction( |
| 54 int64 id, | 54 int64 id, |
| 55 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 55 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
| 56 const std::set<int64>& object_store_ids, | 56 const std::set<int64>& object_store_ids, |
| 57 indexed_db::TransactionMode mode, | 57 blink::WebIDBTransactionMode mode, |
| 58 IndexedDBDatabase* database, | 58 IndexedDBDatabase* database, |
| 59 IndexedDBBackingStore::Transaction* backing_store_transaction) | 59 IndexedDBBackingStore::Transaction* backing_store_transaction) |
| 60 : id_(id), | 60 : id_(id), |
| 61 object_store_ids_(object_store_ids), | 61 object_store_ids_(object_store_ids), |
| 62 mode_(mode), | 62 mode_(mode), |
| 63 used_(false), | 63 used_(false), |
| 64 state_(CREATED), | 64 state_(CREATED), |
| 65 commit_pending_(false), | 65 commit_pending_(false), |
| 66 callbacks_(callbacks), | 66 callbacks_(callbacks), |
| 67 database_(database), | 67 database_(database), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 IndexedDBTransaction::~IndexedDBTransaction() { | 79 IndexedDBTransaction::~IndexedDBTransaction() { |
| 80 // It shouldn't be possible for this object to get deleted until it's either | 80 // It shouldn't be possible for this object to get deleted until it's either |
| 81 // complete or aborted. | 81 // complete or aborted. |
| 82 DCHECK_EQ(state_, FINISHED); | 82 DCHECK_EQ(state_, FINISHED); |
| 83 DCHECK(preemptive_task_queue_.empty()); | 83 DCHECK(preemptive_task_queue_.empty()); |
| 84 DCHECK_EQ(pending_preemptive_events_, 0); | 84 DCHECK_EQ(pending_preemptive_events_, 0); |
| 85 DCHECK(task_queue_.empty()); | 85 DCHECK(task_queue_.empty()); |
| 86 DCHECK(abort_task_stack_.empty()); | 86 DCHECK(abort_task_stack_.empty()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void IndexedDBTransaction::ScheduleTask(IndexedDBDatabase::TaskType type, | 89 void IndexedDBTransaction::ScheduleTask(blink::WebIDBTaskType type, |
| 90 Operation task) { | 90 Operation task) { |
| 91 DCHECK_NE(state_, COMMITTING); | 91 DCHECK_NE(state_, COMMITTING); |
| 92 if (state_ == FINISHED) | 92 if (state_ == FINISHED) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 timeout_timer_.Stop(); | 95 timeout_timer_.Stop(); |
| 96 used_ = true; | 96 used_ = true; |
| 97 if (type == IndexedDBDatabase::NORMAL_TASK) { | 97 if (type == blink::WebIDBTaskTypeNormal) { |
| 98 task_queue_.push(task); | 98 task_queue_.push(task); |
| 99 ++diagnostics_.tasks_scheduled; | 99 ++diagnostics_.tasks_scheduled; |
| 100 } else { | 100 } else { |
| 101 preemptive_task_queue_.push(task); | 101 preemptive_task_queue_.push(task); |
| 102 } | 102 } |
| 103 RunTasksIfStarted(); | 103 RunTasksIfStarted(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void IndexedDBTransaction::ScheduleAbortTask(Operation abort_task) { | 106 void IndexedDBTransaction::ScheduleAbortTask(Operation abort_task) { |
| 107 DCHECK_NE(FINISHED, state_); | 107 DCHECK_NE(FINISHED, state_); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 363 |
| 364 // The transaction may have been aborted while processing tasks. | 364 // The transaction may have been aborted while processing tasks. |
| 365 if (state_ == FINISHED) | 365 if (state_ == FINISHED) |
| 366 return; | 366 return; |
| 367 | 367 |
| 368 DCHECK(state_ == STARTED); | 368 DCHECK(state_ == STARTED); |
| 369 | 369 |
| 370 // Otherwise, start a timer in case the front-end gets wedged and | 370 // Otherwise, start a timer in case the front-end gets wedged and |
| 371 // never requests further activity. Read-only transactions don't | 371 // never requests further activity. Read-only transactions don't |
| 372 // block other transactions, so don't time those out. | 372 // block other transactions, so don't time those out. |
| 373 if (mode_ != indexed_db::TRANSACTION_READ_ONLY) { | 373 if (mode_ != blink::WebIDBTransactionModeReadOnly) { |
| 374 timeout_timer_.Start( | 374 timeout_timer_.Start( |
| 375 FROM_HERE, | 375 FROM_HERE, |
| 376 base::TimeDelta::FromSeconds(kInactivityTimeoutPeriodSeconds), | 376 base::TimeDelta::FromSeconds(kInactivityTimeoutPeriodSeconds), |
| 377 base::Bind(&IndexedDBTransaction::Timeout, this)); | 377 base::Bind(&IndexedDBTransaction::Timeout, this)); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 void IndexedDBTransaction::Timeout() { | 381 void IndexedDBTransaction::Timeout() { |
| 382 Abort(IndexedDBDatabaseError( | 382 Abort(IndexedDBDatabaseError( |
| 383 blink::WebIDBDatabaseExceptionTimeoutError, | 383 blink::WebIDBDatabaseExceptionTimeoutError, |
| 384 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); | 384 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); |
| 385 } | 385 } |
| 386 | 386 |
| 387 void IndexedDBTransaction::CloseOpenCursors() { | 387 void IndexedDBTransaction::CloseOpenCursors() { |
| 388 for (std::set<IndexedDBCursor*>::iterator i = open_cursors_.begin(); | 388 for (std::set<IndexedDBCursor*>::iterator i = open_cursors_.begin(); |
| 389 i != open_cursors_.end(); | 389 i != open_cursors_.end(); |
| 390 ++i) | 390 ++i) |
| 391 (*i)->Close(); | 391 (*i)->Close(); |
| 392 open_cursors_.clear(); | 392 open_cursors_.clear(); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace content | 395 } // namespace content |
| OLD | NEW |