| 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::TransactionMode 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::TaskType type, Operation task) { |
| 90 Operation task) { | |
| 91 DCHECK_NE(state_, COMMITTING); | 90 DCHECK_NE(state_, COMMITTING); |
| 92 if (state_ == FINISHED) | 91 if (state_ == FINISHED) |
| 93 return; | 92 return; |
| 94 | 93 |
| 95 timeout_timer_.Stop(); | 94 timeout_timer_.Stop(); |
| 96 used_ = true; | 95 used_ = true; |
| 97 if (type == IndexedDBDatabase::NORMAL_TASK) { | 96 if (type == blink::NormalTask) { |
| 98 task_queue_.push(task); | 97 task_queue_.push(task); |
| 99 ++diagnostics_.tasks_scheduled; | 98 ++diagnostics_.tasks_scheduled; |
| 100 } else { | 99 } else { |
| 101 preemptive_task_queue_.push(task); | 100 preemptive_task_queue_.push(task); |
| 102 } | 101 } |
| 103 RunTasksIfStarted(); | 102 RunTasksIfStarted(); |
| 104 } | 103 } |
| 105 | 104 |
| 106 void IndexedDBTransaction::ScheduleAbortTask(Operation abort_task) { | 105 void IndexedDBTransaction::ScheduleAbortTask(Operation abort_task) { |
| 107 DCHECK_NE(FINISHED, state_); | 106 DCHECK_NE(FINISHED, state_); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 361 |
| 363 // The transaction may have been aborted while processing tasks. | 362 // The transaction may have been aborted while processing tasks. |
| 364 if (state_ == FINISHED) | 363 if (state_ == FINISHED) |
| 365 return; | 364 return; |
| 366 | 365 |
| 367 DCHECK(state_ == STARTED); | 366 DCHECK(state_ == STARTED); |
| 368 | 367 |
| 369 // Otherwise, start a timer in case the front-end gets wedged and | 368 // Otherwise, start a timer in case the front-end gets wedged and |
| 370 // never requests further activity. Read-only transactions don't | 369 // never requests further activity. Read-only transactions don't |
| 371 // block other transactions, so don't time those out. | 370 // block other transactions, so don't time those out. |
| 372 if (mode_ != indexed_db::TRANSACTION_READ_ONLY) { | 371 if (mode_ != blink::TransactionReadOnly) { |
| 373 timeout_timer_.Start( | 372 timeout_timer_.Start( |
| 374 FROM_HERE, | 373 FROM_HERE, |
| 375 base::TimeDelta::FromSeconds(kInactivityTimeoutPeriodSeconds), | 374 base::TimeDelta::FromSeconds(kInactivityTimeoutPeriodSeconds), |
| 376 base::Bind(&IndexedDBTransaction::Timeout, this)); | 375 base::Bind(&IndexedDBTransaction::Timeout, this)); |
| 377 } | 376 } |
| 378 } | 377 } |
| 379 | 378 |
| 380 void IndexedDBTransaction::Timeout() { | 379 void IndexedDBTransaction::Timeout() { |
| 381 Abort(IndexedDBDatabaseError( | 380 Abort(IndexedDBDatabaseError( |
| 382 blink::WebIDBDatabaseExceptionTimeoutError, | 381 blink::WebIDBDatabaseExceptionTimeoutError, |
| 383 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); | 382 base::ASCIIToUTF16("Transaction timed out due to inactivity."))); |
| 384 } | 383 } |
| 385 | 384 |
| 386 void IndexedDBTransaction::CloseOpenCursors() { | 385 void IndexedDBTransaction::CloseOpenCursors() { |
| 387 for (std::set<IndexedDBCursor*>::iterator i = open_cursors_.begin(); | 386 for (std::set<IndexedDBCursor*>::iterator i = open_cursors_.begin(); |
| 388 i != open_cursors_.end(); | 387 i != open_cursors_.end(); |
| 389 ++i) | 388 ++i) |
| 390 (*i)->Close(); | 389 (*i)->Close(); |
| 391 open_cursors_.clear(); | 390 open_cursors_.clear(); |
| 392 } | 391 } |
| 393 | 392 |
| 394 } // namespace content | 393 } // namespace content |
| OLD | NEW |