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 #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/timer.h" | 16 #include "base/timer/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 IndexedDBDatabase; | 23 class IndexedDBDatabase; |
24 class IndexedDBCursor; | 24 class IndexedDBCursor; |
25 class IndexedDBDatabaseCallbacksWrapper; | 25 class IndexedDBDatabaseCallbacks; |
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<IndexedDBDatabaseCallbacks> callbacks, |
32 const std::vector<int64>& scope, | 32 const std::vector<int64>& scope, |
33 indexed_db::TransactionMode, | 33 indexed_db::TransactionMode, |
34 IndexedDBDatabase* 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() {} |
(...skipping 23 matching lines...) Expand all Loading... |
65 void DidCompletePreemptiveEvent() { | 65 void DidCompletePreemptiveEvent() { |
66 pending_preemptive_events_--; | 66 pending_preemptive_events_--; |
67 DCHECK_GE(pending_preemptive_events_, 0); | 67 DCHECK_GE(pending_preemptive_events_, 0); |
68 } | 68 } |
69 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 69 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
70 return &transaction_; | 70 return &transaction_; |
71 } | 71 } |
72 int64 id() const { return id_; } | 72 int64 id() const { return id_; } |
73 | 73 |
74 IndexedDBDatabase* database() const { return database_.get(); } | 74 IndexedDBDatabase* database() const { return database_.get(); } |
75 IndexedDBDatabaseCallbacksWrapper* connection() const { | 75 IndexedDBDatabaseCallbacks* connection() const { |
76 return callbacks_.get(); | 76 return callbacks_.get(); |
77 } | 77 } |
78 | 78 |
79 protected: | 79 protected: |
80 virtual ~IndexedDBTransaction(); | 80 virtual ~IndexedDBTransaction(); |
81 friend class base::RefCounted<IndexedDBTransaction>; | 81 friend class base::RefCounted<IndexedDBTransaction>; |
82 | 82 |
83 private: | 83 private: |
84 IndexedDBTransaction( | 84 IndexedDBTransaction( |
85 int64 id, | 85 int64 id, |
86 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks, | 86 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
87 const std::set<int64>& object_store_ids, | 87 const std::set<int64>& object_store_ids, |
88 indexed_db::TransactionMode, | 88 indexed_db::TransactionMode, |
89 IndexedDBDatabase* db); | 89 IndexedDBDatabase* db); |
90 | 90 |
91 enum State { | 91 enum State { |
92 UNUSED, // Created, but no tasks yet. | 92 UNUSED, // Created, but no tasks yet. |
93 START_PENDING, // Enqueued tasks, but backing store transaction not yet | 93 START_PENDING, // Enqueued tasks, but backing store transaction not yet |
94 // started. | 94 // started. |
95 RUNNING, // Backing store transaction started but not yet finished. | 95 RUNNING, // Backing store transaction started but not yet finished. |
96 FINISHED, // Either aborted or committed. | 96 FINISHED, // Either aborted or committed. |
97 }; | 97 }; |
98 | 98 |
99 void Start(); | 99 void Start(); |
100 | 100 |
101 bool IsTaskQueueEmpty() const; | 101 bool IsTaskQueueEmpty() const; |
102 bool HasPendingTasks() const; | 102 bool HasPendingTasks() const; |
103 | 103 |
104 void TaskTimerFired(); | 104 void TaskTimerFired(); |
105 void CloseOpenCursors(); | 105 void CloseOpenCursors(); |
106 | 106 |
107 const int64 id_; | 107 const int64 id_; |
108 const std::set<int64> object_store_ids_; | 108 const std::set<int64> object_store_ids_; |
109 const indexed_db::TransactionMode mode_; | 109 const indexed_db::TransactionMode mode_; |
110 | 110 |
111 State state_; | 111 State state_; |
112 bool commit_pending_; | 112 bool commit_pending_; |
113 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> callbacks_; | 113 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
114 scoped_refptr<IndexedDBDatabase> database_; | 114 scoped_refptr<IndexedDBDatabase> database_; |
115 | 115 |
116 class TaskQueue { | 116 class TaskQueue { |
117 public: | 117 public: |
118 TaskQueue(); | 118 TaskQueue(); |
119 ~TaskQueue(); | 119 ~TaskQueue(); |
120 bool empty() const { return queue_.empty(); } | 120 bool empty() const { return queue_.empty(); } |
121 void push(Operation* task) { queue_.push(task); } | 121 void push(Operation* task) { queue_.push(task); } |
122 scoped_ptr<Operation> pop(); | 122 scoped_ptr<Operation> pop(); |
123 void clear(); | 123 void clear(); |
(...skipping 23 matching lines...) Expand all Loading... |
147 | 147 |
148 base::OneShotTimer<IndexedDBTransaction> task_timer_; | 148 base::OneShotTimer<IndexedDBTransaction> task_timer_; |
149 int pending_preemptive_events_; | 149 int pending_preemptive_events_; |
150 | 150 |
151 std::set<IndexedDBCursor*> open_cursors_; | 151 std::set<IndexedDBCursor*> open_cursors_; |
152 }; | 152 }; |
153 | 153 |
154 } // namespace content | 154 } // namespace content |
155 | 155 |
156 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 156 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
OLD | NEW |