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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
7
8 #include <queue>
9 #include <set>
10 #include <stack>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/timer.h"
15 #include "content/browser/indexed_db/indexed_db_backing_store.h"
16 #include "content/browser/indexed_db/indexed_db_database.h"
17 #include "content/browser/indexed_db/indexed_db_database_error.h"
18
19 namespace content {
20
21 class IndexedDBDatabaseImpl;
22 class IndexedDBCursorImpl;
23 class IndexedDBDatabaseCallbacksWrapper;
24
25 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
26 public:
27 static scoped_refptr<IndexedDBTransaction> Create(
28 int64_t transaction_id,
29 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>,
30 const std::vector<int64_t>&,
31 IndexedDB::TransactionMode,
32 IndexedDBDatabaseImpl*);
33
34 virtual void Abort();
35 void Commit();
36
37 class Operation {
38 public:
39 Operation() {}
40 virtual ~Operation() {}
41 virtual void Perform(IndexedDBTransaction*) = 0;
42 };
43
44 void Abort(scoped_refptr<IndexedDBDatabaseError>);
45 void Run();
46 IndexedDB::TransactionMode mode() const { return mode_; }
47 const std::set<int64_t>& scope() const { return object_store_ids_; }
48 void ScheduleTask(Operation* task, Operation* abort_task = NULL) {
49 ScheduleTask(IndexedDBDatabase::NormalTask, task, abort_task);
50 }
51 void ScheduleTask(IndexedDBDatabase::TaskType,
52 Operation* task,
53 Operation* abort_task = NULL);
54 void RegisterOpenCursor(IndexedDBCursorImpl*);
55 void UnregisterOpenCursor(IndexedDBCursorImpl*);
56 void AddPreemptiveEvent() { pending_preemptive_events_++; }
57 void DidCompletePreemptiveEvent() {
58 pending_preemptive_events_--;
59 DCHECK(pending_preemptive_events_ >= 0);
60 }
61 IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
62 return &transaction_;
63 }
64 int64_t id() const { return id_; }
65
66 IndexedDBDatabaseImpl* database() const { return database_.get(); }
67 IndexedDBDatabaseCallbacksWrapper* connection() const {
68 return callbacks_.get();
69 }
70
71 protected:
72 virtual ~IndexedDBTransaction();
73 friend class base::RefCounted<IndexedDBTransaction>;
74
75 private:
76 IndexedDBTransaction(int64_t id,
77 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>,
78 const std::set<int64_t>& object_store_ids,
79 IndexedDB::TransactionMode,
80 IndexedDBDatabaseImpl*);
81
82 enum State {
83 Unused, // Created, but no tasks yet.
84 StartPending, // Enqueued tasks, but backing store transaction not yet
85 // started.
86 Running, // Backing store transaction started but not yet finished.
87 Finished, // Either aborted or committed.
88 };
89
90 void Start();
91
92 bool IsTaskQueueEmpty() const;
93 bool HasPendingTasks() const;
94
95 void TaskTimerFired();
96 void CloseOpenCursors();
97
98 const int64_t id_;
99 const std::set<int64_t> object_store_ids_;
100 const IndexedDB::TransactionMode mode_;
101
102 State state_;
103 bool commit_pending_;
104 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_;
105 scoped_refptr<IndexedDBDatabaseImpl> database_;
106
107 class TaskQueue {
108 public:
109 TaskQueue();
110 ~TaskQueue();
111 bool empty() const { return queue_.empty(); }
112 void push(Operation* task) { queue_.push(task); }
113 scoped_ptr<Operation> pop();
114 void clear();
115
116 private:
117 std::queue<Operation*> queue_;
118 };
119
120 class TaskStack {
121 public:
122 TaskStack();
123 ~TaskStack();
124 bool empty() const { return stack_.empty(); }
125 void push(Operation* task) { stack_.push(task); }
126 scoped_ptr<Operation> pop();
127 void clear();
128
129 private:
130 std::stack<Operation*> stack_;
131 };
132
133 TaskQueue task_queue_;
134 TaskQueue preemptive_task_queue_;
135 TaskStack abort_task_stack_;
136
137 IndexedDBBackingStore::Transaction transaction_;
138
139 base::OneShotTimer<IndexedDBTransaction> task_timer_;
140 int pending_preemptive_events_;
141
142 std::set<IndexedDBCursorImpl*> open_cursors_;
143 };
144
145 } // namespace content
146
147 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698