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 <stdint.h> |
| 9 |
8 #include <queue> | 10 #include <queue> |
9 #include <set> | 11 #include <set> |
10 #include <stack> | 12 #include <stack> |
11 | 13 |
12 #include "base/basictypes.h" | |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
18 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 20 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
19 #include "content/browser/indexed_db/indexed_db_database.h" | 21 #include "content/browser/indexed_db/indexed_db_database.h" |
20 #include "content/browser/indexed_db/indexed_db_database_error.h" | 22 #include "content/browser/indexed_db/indexed_db_database_error.h" |
21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
22 | 24 |
23 namespace content { | 25 namespace content { |
(...skipping 16 matching lines...) Expand all Loading... |
40 }; | 42 }; |
41 | 43 |
42 virtual void Abort(); | 44 virtual void Abort(); |
43 leveldb::Status Commit(); | 45 leveldb::Status Commit(); |
44 void Abort(const IndexedDBDatabaseError& error); | 46 void Abort(const IndexedDBDatabaseError& error); |
45 | 47 |
46 // Called by the transaction coordinator when this transaction is unblocked. | 48 // Called by the transaction coordinator when this transaction is unblocked. |
47 void Start(); | 49 void Start(); |
48 | 50 |
49 blink::WebIDBTransactionMode mode() const { return mode_; } | 51 blink::WebIDBTransactionMode mode() const { return mode_; } |
50 const std::set<int64>& scope() const { return object_store_ids_; } | 52 const std::set<int64_t>& scope() const { return object_store_ids_; } |
51 | 53 |
52 void ScheduleTask(Operation task) { | 54 void ScheduleTask(Operation task) { |
53 ScheduleTask(blink::WebIDBTaskTypeNormal, task); | 55 ScheduleTask(blink::WebIDBTaskTypeNormal, task); |
54 } | 56 } |
55 void ScheduleTask(blink::WebIDBTaskType, Operation task); | 57 void ScheduleTask(blink::WebIDBTaskType, Operation task); |
56 void ScheduleAbortTask(Operation abort_task); | 58 void ScheduleAbortTask(Operation abort_task); |
57 void RegisterOpenCursor(IndexedDBCursor* cursor); | 59 void RegisterOpenCursor(IndexedDBCursor* cursor); |
58 void UnregisterOpenCursor(IndexedDBCursor* cursor); | 60 void UnregisterOpenCursor(IndexedDBCursor* cursor); |
59 void AddPreemptiveEvent() { pending_preemptive_events_++; } | 61 void AddPreemptiveEvent() { pending_preemptive_events_++; } |
60 void DidCompletePreemptiveEvent() { | 62 void DidCompletePreemptiveEvent() { |
61 pending_preemptive_events_--; | 63 pending_preemptive_events_--; |
62 DCHECK_GE(pending_preemptive_events_, 0); | 64 DCHECK_GE(pending_preemptive_events_, 0); |
63 } | 65 } |
64 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 66 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
65 return transaction_.get(); | 67 return transaction_.get(); |
66 } | 68 } |
67 int64 id() const { return id_; } | 69 int64_t id() const { return id_; } |
68 | 70 |
69 IndexedDBDatabase* database() const { return database_.get(); } | 71 IndexedDBDatabase* database() const { return database_.get(); } |
70 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); } | 72 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); } |
71 | 73 |
72 State state() const { return state_; } | 74 State state() const { return state_; } |
73 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } | 75 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } |
74 | 76 |
75 struct Diagnostics { | 77 struct Diagnostics { |
76 base::Time creation_time; | 78 base::Time creation_time; |
77 base::Time start_time; | 79 base::Time start_time; |
78 int tasks_scheduled; | 80 int tasks_scheduled; |
79 int tasks_completed; | 81 int tasks_completed; |
80 }; | 82 }; |
81 | 83 |
82 const Diagnostics& diagnostics() const { return diagnostics_; } | 84 const Diagnostics& diagnostics() const { return diagnostics_; } |
83 | 85 |
84 protected: | 86 protected: |
85 // Test classes may derive, but most creation should be done via | 87 // Test classes may derive, but most creation should be done via |
86 // IndexedDBClassFactory. | 88 // IndexedDBClassFactory. |
87 IndexedDBTransaction( | 89 IndexedDBTransaction( |
88 int64 id, | 90 int64_t id, |
89 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 91 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
90 const std::set<int64>& object_store_ids, | 92 const std::set<int64_t>& object_store_ids, |
91 blink::WebIDBTransactionMode mode, | 93 blink::WebIDBTransactionMode mode, |
92 IndexedDBDatabase* db, | 94 IndexedDBDatabase* db, |
93 IndexedDBBackingStore::Transaction* backing_store_transaction); | 95 IndexedDBBackingStore::Transaction* backing_store_transaction); |
94 virtual ~IndexedDBTransaction(); | 96 virtual ~IndexedDBTransaction(); |
95 | 97 |
96 // May be overridden in tests. | 98 // May be overridden in tests. |
97 virtual base::TimeDelta GetInactivityTimeout() const; | 99 virtual base::TimeDelta GetInactivityTimeout() const; |
98 | 100 |
99 private: | 101 private: |
100 friend class BlobWriteCallbackImpl; | 102 friend class BlobWriteCallbackImpl; |
(...skipping 13 matching lines...) Expand all Loading... |
114 | 116 |
115 bool IsTaskQueueEmpty() const; | 117 bool IsTaskQueueEmpty() const; |
116 bool HasPendingTasks() const; | 118 bool HasPendingTasks() const; |
117 | 119 |
118 void BlobWriteComplete(bool success); | 120 void BlobWriteComplete(bool success); |
119 void ProcessTaskQueue(); | 121 void ProcessTaskQueue(); |
120 void CloseOpenCursors(); | 122 void CloseOpenCursors(); |
121 leveldb::Status CommitPhaseTwo(); | 123 leveldb::Status CommitPhaseTwo(); |
122 void Timeout(); | 124 void Timeout(); |
123 | 125 |
124 const int64 id_; | 126 const int64_t id_; |
125 const std::set<int64> object_store_ids_; | 127 const std::set<int64_t> object_store_ids_; |
126 const blink::WebIDBTransactionMode mode_; | 128 const blink::WebIDBTransactionMode mode_; |
127 | 129 |
128 bool used_; | 130 bool used_; |
129 State state_; | 131 State state_; |
130 bool commit_pending_; | 132 bool commit_pending_; |
131 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 133 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
132 scoped_refptr<IndexedDBDatabase> database_; | 134 scoped_refptr<IndexedDBDatabase> database_; |
133 | 135 |
134 class TaskQueue { | 136 class TaskQueue { |
135 public: | 137 public: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // requests are processed before the timer fires, assume the script is | 179 // requests are processed before the timer fires, assume the script is |
178 // unresponsive and abort to unblock the transaction queue. | 180 // unresponsive and abort to unblock the transaction queue. |
179 base::OneShotTimer timeout_timer_; | 181 base::OneShotTimer timeout_timer_; |
180 | 182 |
181 Diagnostics diagnostics_; | 183 Diagnostics diagnostics_; |
182 }; | 184 }; |
183 | 185 |
184 } // namespace content | 186 } // namespace content |
185 | 187 |
186 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 188 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
OLD | NEW |