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

Side by Side Diff: content/browser/indexed_db/indexed_db_transaction.h

Issue 16581002: IndexedDB: Eliminate interfaces for IndexedDB{Factory,Database,Cursor} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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
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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 #include <stack> 10 #include <stack>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/timer.h" 16 #include "base/timer.h"
17 #include "content/browser/indexed_db/indexed_db_backing_store.h" 17 #include "content/browser/indexed_db/indexed_db_backing_store.h"
18 #include "content/browser/indexed_db/indexed_db_database.h" 18 #include "content/browser/indexed_db/indexed_db_database.h"
19 #include "content/browser/indexed_db/indexed_db_database_error.h" 19 #include "content/browser/indexed_db/indexed_db_database_error.h"
20 20
21 namespace content { 21 namespace content {
22 22
23 class IndexedDBDatabaseImpl; 23 class IndexedDBDatabase;
24 class IndexedDBCursorImpl; 24 class IndexedDBCursor;
25 class IndexedDBDatabaseCallbacksWrapper; 25 class IndexedDBDatabaseCallbacksWrapper;
26 26
27 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> { 27 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> {
28 public: 28 public:
29 static scoped_refptr<IndexedDBTransaction> Create( 29 static scoped_refptr<IndexedDBTransaction> Create(
30 int64 transaction_id, 30 int64 transaction_id,
31 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks, 31 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks,
32 const std::vector<int64>& scope, 32 const std::vector<int64>& scope,
33 indexed_db::TransactionMode, 33 indexed_db::TransactionMode,
34 IndexedDBDatabaseImpl* db); 34 IndexedDBDatabase* db);
35 35
36 virtual void Abort(); 36 virtual void Abort();
37 void Commit(); 37 void Commit();
38 38
39 class Operation { 39 class Operation {
40 public: 40 public:
41 Operation() {} 41 Operation() {}
42 virtual ~Operation() {} 42 virtual ~Operation() {}
43 virtual void Perform(IndexedDBTransaction* transaction) = 0; 43 virtual void Perform(IndexedDBTransaction* transaction) = 0;
44 }; 44 };
45 45
46 void Abort(const IndexedDBDatabaseError& error); 46 void Abort(const IndexedDBDatabaseError& error);
47 void Run(); 47 void Run();
48 indexed_db::TransactionMode mode() const { return mode_; } 48 indexed_db::TransactionMode mode() const { return mode_; }
49 const std::set<int64>& scope() const { return object_store_ids_; } 49 const std::set<int64>& scope() const { return object_store_ids_; }
50 void ScheduleTask(Operation* task, Operation* abort_task = NULL) { 50 void ScheduleTask(Operation* task, Operation* abort_task = NULL) {
51 ScheduleTask(IndexedDBDatabase::NORMAL_TASK, task, abort_task); 51 ScheduleTask(IndexedDBDatabase::NORMAL_TASK, task, abort_task);
52 } 52 }
53 void ScheduleTask(IndexedDBDatabase::TaskType, 53 void ScheduleTask(IndexedDBDatabase::TaskType,
54 Operation* task, 54 Operation* task,
55 Operation* abort_task = NULL); 55 Operation* abort_task = NULL);
56 void RegisterOpenCursor(IndexedDBCursorImpl* cursor); 56 void RegisterOpenCursor(IndexedDBCursor* cursor);
57 void UnregisterOpenCursor(IndexedDBCursorImpl* cursor); 57 void UnregisterOpenCursor(IndexedDBCursor* cursor);
58 void AddPreemptiveEvent() { pending_preemptive_events_++; } 58 void AddPreemptiveEvent() { pending_preemptive_events_++; }
59 void DidCompletePreemptiveEvent() { 59 void DidCompletePreemptiveEvent() {
60 pending_preemptive_events_--; 60 pending_preemptive_events_--;
61 DCHECK_GE(pending_preemptive_events_, 0); 61 DCHECK_GE(pending_preemptive_events_, 0);
62 } 62 }
63 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { 63 IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
64 return &transaction_; 64 return &transaction_;
65 } 65 }
66 int64 id() const { return id_; } 66 int64 id() const { return id_; }
67 67
68 IndexedDBDatabaseImpl* database() const { return database_.get(); } 68 IndexedDBDatabase* database() const { return database_.get(); }
69 IndexedDBDatabaseCallbacksWrapper* connection() const { 69 IndexedDBDatabaseCallbacksWrapper* connection() const {
70 return callbacks_.get(); 70 return callbacks_.get();
71 } 71 }
72 72
73 protected: 73 protected:
74 virtual ~IndexedDBTransaction(); 74 virtual ~IndexedDBTransaction();
75 friend class base::RefCounted<IndexedDBTransaction>; 75 friend class base::RefCounted<IndexedDBTransaction>;
76 76
77 private: 77 private:
78 IndexedDBTransaction( 78 IndexedDBTransaction(
79 int64 id, 79 int64 id,
80 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks, 80 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks,
81 const std::set<int64>& object_store_ids, 81 const std::set<int64>& object_store_ids,
82 indexed_db::TransactionMode, 82 indexed_db::TransactionMode,
83 IndexedDBDatabaseImpl* db); 83 IndexedDBDatabase* db);
84 84
85 enum State { 85 enum State {
86 UNUSED, // Created, but no tasks yet. 86 UNUSED, // Created, but no tasks yet.
87 START_PENDING, // Enqueued tasks, but backing store transaction not yet 87 START_PENDING, // Enqueued tasks, but backing store transaction not yet
88 // started. 88 // started.
89 RUNNING, // Backing store transaction started but not yet finished. 89 RUNNING, // Backing store transaction started but not yet finished.
90 FINISHED, // Either aborted or committed. 90 FINISHED, // Either aborted or committed.
91 }; 91 };
92 92
93 void Start(); 93 void Start();
94 94
95 bool IsTaskQueueEmpty() const; 95 bool IsTaskQueueEmpty() const;
96 bool HasPendingTasks() const; 96 bool HasPendingTasks() const;
97 97
98 void TaskTimerFired(); 98 void TaskTimerFired();
99 void CloseOpenCursors(); 99 void CloseOpenCursors();
100 100
101 const int64 id_; 101 const int64 id_;
102 const std::set<int64> object_store_ids_; 102 const std::set<int64> object_store_ids_;
103 const indexed_db::TransactionMode mode_; 103 const indexed_db::TransactionMode mode_;
104 104
105 State state_; 105 State state_;
106 bool commit_pending_; 106 bool commit_pending_;
107 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_; 107 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_;
108 scoped_refptr<IndexedDBDatabaseImpl> database_; 108 scoped_refptr<IndexedDBDatabase> database_;
109 109
110 class TaskQueue { 110 class TaskQueue {
111 public: 111 public:
112 TaskQueue(); 112 TaskQueue();
113 ~TaskQueue(); 113 ~TaskQueue();
114 bool empty() const { return queue_.empty(); } 114 bool empty() const { return queue_.empty(); }
115 void push(Operation* task) { queue_.push(task); } 115 void push(Operation* task) { queue_.push(task); }
116 scoped_ptr<Operation> pop(); 116 scoped_ptr<Operation> pop();
117 void clear(); 117 void clear();
118 118
(...skipping 16 matching lines...) Expand all
135 135
136 TaskQueue task_queue_; 136 TaskQueue task_queue_;
137 TaskQueue preemptive_task_queue_; 137 TaskQueue preemptive_task_queue_;
138 TaskStack abort_task_stack_; 138 TaskStack abort_task_stack_;
139 139
140 IndexedDBBackingStore::Transaction transaction_; 140 IndexedDBBackingStore::Transaction transaction_;
141 141
142 base::OneShotTimer<IndexedDBTransaction> task_timer_; 142 base::OneShotTimer<IndexedDBTransaction> task_timer_;
143 int pending_preemptive_events_; 143 int pending_preemptive_events_;
144 144
145 std::set<IndexedDBCursorImpl*> open_cursors_; 145 std::set<IndexedDBCursor*> open_cursors_;
146 }; 146 };
147 147
148 } // namespace content 148 } // namespace content
149 149
150 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 150 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_leveldb_coding.cc ('k') | content/browser/indexed_db/indexed_db_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698