summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-10 23:37:14 +0000
committerjsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-10 23:37:14 +0000
commitf95bffd7018cd39055dff3e504f6e9d62acc8a80 (patch)
tree763a334ca3035621ad2898edacbde763c19920df /content
parent97670cfb8c588f71dac6e49b30474393cff98cb9 (diff)
downloadchromium_src-f95bffd7018cd39055dff3e504f6e9d62acc8a80.zip
chromium_src-f95bffd7018cd39055dff3e504f6e9d62acc8a80.tar.gz
chromium_src-f95bffd7018cd39055dff3e504f6e9d62acc8a80.tar.bz2
IndexedDB: Remove transaction timer, just post tasks
In the Blink implementation transactions used a timer to keep to schedule asynchronous processing of tasks. This was retained in the Chromium port, but with access to the message loop we can post tasks instead. Note that transactions still maintain an internal list of tasks and all that is posted is a "process the queue" task. Future changes may integrate the transaction task queue and the message loop more tightly. BUG=246629 Review URL: https://chromiumcodereview.appspot.com/18612007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/indexed_db/indexed_db_transaction.cc41
-rw-r--r--content/browser/indexed_db/indexed_db_transaction.h5
2 files changed, 27 insertions, 19 deletions
diff --git a/content/browser/indexed_db/indexed_db_transaction.cc b/content/browser/indexed_db/indexed_db_transaction.cc
index cdfb133..19b2b28 100644
--- a/content/browser/indexed_db/indexed_db_transaction.cc
+++ b/content/browser/indexed_db/indexed_db_transaction.cc
@@ -4,7 +4,9 @@
#include "content/browser/indexed_db/indexed_db_transaction.h"
+#include "base/bind.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/indexed_db/indexed_db_backing_store.h"
#include "content/browser/indexed_db/indexed_db_cursor.h"
@@ -76,6 +78,7 @@ IndexedDBTransaction::IndexedDBTransaction(
callbacks_(callbacks),
database_(database),
transaction_(database->BackingStore().get()),
+ should_process_queue_(false),
pending_preemptive_events_(0) {
database_->transaction_coordinator().DidCreateTransaction(this);
}
@@ -103,13 +106,14 @@ void IndexedDBTransaction::ScheduleTask(IndexedDBDatabase::TaskType type,
if (abort_task)
abort_task_stack_.push(abort_task);
- if (state_ == UNUSED)
+ if (state_ == UNUSED) {
Start();
- else if (state_ == RUNNING && !task_timer_.IsRunning())
- task_timer_.Start(FROM_HERE,
- base::TimeDelta::FromSeconds(0),
- this,
- &IndexedDBTransaction::TaskTimerFired);
+ } else if (state_ == RUNNING && !should_process_queue_) {
+ should_process_queue_ = true;
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&IndexedDBTransaction::ProcessTaskQueue, this));
+ }
}
void IndexedDBTransaction::Abort() {
@@ -130,7 +134,7 @@ void IndexedDBTransaction::Abort(const IndexedDBDatabaseError& error) {
scoped_refptr<IndexedDBTransaction> protect(this);
state_ = FINISHED;
- task_timer_.Stop();
+ should_process_queue_ = false;
if (was_running)
transaction_.Rollback();
@@ -184,15 +188,14 @@ void IndexedDBTransaction::UnregisterOpenCursor(IndexedDBCursor* cursor) {
}
void IndexedDBTransaction::Run() {
- // TransactionCoordinator has started this transaction. Schedule a timer
- // to process the first task.
+ // TransactionCoordinator has started this transaction.
DCHECK(state_ == START_PENDING || state_ == RUNNING);
- DCHECK(!task_timer_.IsRunning());
+ DCHECK(!should_process_queue_);
- task_timer_.Start(FROM_HERE,
- base::TimeDelta::FromSeconds(0),
- this,
- &IndexedDBTransaction::TaskTimerFired);
+ should_process_queue_ = true;
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&IndexedDBTransaction::ProcessTaskQueue, this));
}
void IndexedDBTransaction::Start() {
@@ -261,9 +264,15 @@ void IndexedDBTransaction::Commit() {
database_ = NULL;
}
-void IndexedDBTransaction::TaskTimerFired() {
- IDB_TRACE("IndexedDBTransaction::TaskTimerFired");
+void IndexedDBTransaction::ProcessTaskQueue() {
+ IDB_TRACE("IndexedDBTransaction::ProcessTaskQueue");
+
+ // May have been aborted.
+ if (!should_process_queue_)
+ return;
+
DCHECK(!IsTaskQueueEmpty());
+ should_process_queue_ = false;
if (state_ == START_PENDING) {
transaction_.Begin();
diff --git a/content/browser/indexed_db/indexed_db_transaction.h b/content/browser/indexed_db/indexed_db_transaction.h
index c1a20d5..70160e1 100644
--- a/content/browser/indexed_db/indexed_db_transaction.h
+++ b/content/browser/indexed_db/indexed_db_transaction.h
@@ -13,7 +13,6 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/timer/timer.h"
#include "content/browser/indexed_db/indexed_db_backing_store.h"
#include "content/browser/indexed_db/indexed_db_database.h"
#include "content/browser/indexed_db/indexed_db_database_error.h"
@@ -97,7 +96,7 @@ class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
bool IsTaskQueueEmpty() const;
bool HasPendingTasks() const;
- void TaskTimerFired();
+ void ProcessTaskQueue();
void CloseOpenCursors();
const int64 id_;
@@ -141,7 +140,7 @@ class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
IndexedDBBackingStore::Transaction transaction_;
- base::OneShotTimer<IndexedDBTransaction> task_timer_;
+ bool should_process_queue_;
int pending_preemptive_events_;
std::set<IndexedDBCursor*> open_cursors_;