Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Unified Diff: content/browser/indexed_db/indexed_db_transaction.h

Issue 15564008: Migrate the IndexedDB backend from Blink to Chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Accessor naming, use LevelDBSlice ctor explicitly Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_transaction.h
diff --git a/content/browser/indexed_db/indexed_db_transaction.h b/content/browser/indexed_db/indexed_db_transaction.h
new file mode 100644
index 0000000000000000000000000000000000000000..0a080c54bc743f1ceb8cff27a5a935a70122e162
--- /dev/null
+++ b/content/browser/indexed_db/indexed_db_transaction.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
+#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
+
+#include <queue>
+#include <set>
+#include <stack>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/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"
+
+namespace content {
+
+class IndexedDBDatabaseImpl;
+class IndexedDBCursorImpl;
+class IndexedDBDatabaseCallbacksWrapper;
+
+class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
+ public:
+ static scoped_refptr<IndexedDBTransaction> Create(
+ int64_t transaction_id,
+ scoped_refptr<IndexedDBDatabaseCallbacksWrapper>,
+ const std::vector<int64_t>&,
+ IndexedDB::TransactionMode,
+ IndexedDBDatabaseImpl*);
+
+ virtual void Abort();
+ void Commit();
+
+ class Operation {
+ public:
+ Operation() {}
+ virtual ~Operation() {}
+ virtual void Perform(IndexedDBTransaction*) = 0;
+ };
+
+ void Abort(scoped_refptr<IndexedDBDatabaseError>);
+ void Run();
+ IndexedDB::TransactionMode mode() const { return mode_; }
+ const std::set<int64_t>& scope() const { return object_store_ids_; }
+ void ScheduleTask(Operation* task, Operation* abort_task = NULL) {
+ ScheduleTask(IndexedDBDatabase::NormalTask, task, abort_task);
+ }
+ void ScheduleTask(IndexedDBDatabase::TaskType,
+ Operation* task,
+ Operation* abort_task = NULL);
+ void RegisterOpenCursor(IndexedDBCursorImpl*);
+ void UnregisterOpenCursor(IndexedDBCursorImpl*);
+ void AddPreemptiveEvent() { pending_preemptive_events_++; }
+ void DidCompletePreemptiveEvent() {
+ pending_preemptive_events_--;
+ DCHECK(pending_preemptive_events_ >= 0);
+ }
+ IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
+ return &transaction_;
+ }
+ int64_t id() const { return id_; }
+
+ IndexedDBDatabaseImpl* database() const { return database_.get(); }
+ IndexedDBDatabaseCallbacksWrapper* connection() const {
+ return callbacks_.get();
+ }
+
+ protected:
+ virtual ~IndexedDBTransaction();
+ friend class base::RefCounted<IndexedDBTransaction>;
+
+ private:
+ IndexedDBTransaction(int64_t id,
+ scoped_refptr<IndexedDBDatabaseCallbacksWrapper>,
+ const std::set<int64_t>& object_store_ids,
+ IndexedDB::TransactionMode,
+ IndexedDBDatabaseImpl*);
+
+ enum State {
+ Unused, // Created, but no tasks yet.
+ StartPending, // Enqueued tasks, but backing store transaction not yet
+ // started.
+ Running, // Backing store transaction started but not yet finished.
+ Finished, // Either aborted or committed.
+ };
+
+ void Start();
+
+ bool IsTaskQueueEmpty() const;
+ bool HasPendingTasks() const;
+
+ void TaskTimerFired();
+ void CloseOpenCursors();
+
+ const int64_t id_;
+ const std::set<int64_t> object_store_ids_;
+ const IndexedDB::TransactionMode mode_;
+
+ State state_;
+ bool commit_pending_;
+ scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_;
+ scoped_refptr<IndexedDBDatabaseImpl> database_;
+
+ class TaskQueue {
+ public:
+ TaskQueue();
+ ~TaskQueue();
+ bool empty() const { return queue_.empty(); }
+ void push(Operation* task) { queue_.push(task); }
+ scoped_ptr<Operation> pop();
+ void clear();
+
+ private:
+ std::queue<Operation*> queue_;
+ };
+
+ class TaskStack {
+ public:
+ TaskStack();
+ ~TaskStack();
+ bool empty() const { return stack_.empty(); }
+ void push(Operation* task) { stack_.push(task); }
+ scoped_ptr<Operation> pop();
+ void clear();
+
+ private:
+ std::stack<Operation*> stack_;
+ };
+
+ TaskQueue task_queue_;
+ TaskQueue preemptive_task_queue_;
+ TaskStack abort_task_stack_;
+
+ IndexedDBBackingStore::Transaction transaction_;
+
+ base::OneShotTimer<IndexedDBTransaction> task_timer_;
+ int pending_preemptive_events_;
+
+ std::set<IndexedDBCursorImpl*> open_cursors_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_

Powered by Google App Engine
This is Rietveld 408576698