Chromium Code Reviews| 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> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 class BlobWriteCallbackImpl; | 29 class BlobWriteCallbackImpl; |
| 30 class IndexedDBCursor; | 30 class IndexedDBCursor; |
| 31 class IndexedDBDatabaseCallbacks; | 31 class IndexedDBDatabaseCallbacks; |
| 32 class IndexedDBObservation; | 32 class IndexedDBObservation; |
| 33 class IndexedDBObserverChanges; | 33 class IndexedDBObserverChanges; |
| 34 | 34 |
| 35 class CONTENT_EXPORT IndexedDBTransaction | 35 class CONTENT_EXPORT IndexedDBTransaction |
| 36 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { | 36 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { |
| 37 public: | 37 public: |
| 38 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 38 using OperationResult = leveldb::Status; |
|
cmumford
2016/11/21 18:29:22
I'm not a fan of introducing OperationResult. It o
dmurph
2016/11/22 23:33:11
Done.
| |
| 39 using Operation = base::Callback<OperationResult(IndexedDBTransaction*)>; | |
| 40 using AbortOperation = base::Closure; | |
| 39 | 41 |
| 40 enum State { | 42 enum State { |
| 41 CREATED, // Created, but not yet started by coordinator. | 43 CREATED, // Created, but not yet started by coordinator. |
| 42 STARTED, // Started by the coordinator. | 44 STARTED, // Started by the coordinator. |
| 43 COMMITTING, // In the process of committing, possibly waiting for blobs | 45 COMMITTING, // In the process of committing, possibly waiting for blobs |
| 44 // to be written. | 46 // to be written. |
| 45 FINISHED, // Either aborted or committed. | 47 FINISHED, // Either aborted or committed. |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 virtual void Abort(); | 50 virtual void Abort(); |
| 49 leveldb::Status Commit(); | 51 leveldb::Status Commit(); |
| 50 void Abort(const IndexedDBDatabaseError& error); | 52 void Abort(const IndexedDBDatabaseError& error); |
| 51 | 53 |
| 52 // Called by the transaction coordinator when this transaction is unblocked. | 54 // Called by the transaction coordinator when this transaction is unblocked. |
| 53 void Start(); | 55 void Start(); |
| 54 | 56 |
| 55 blink::WebIDBTransactionMode mode() const { return mode_; } | 57 blink::WebIDBTransactionMode mode() const { return mode_; } |
| 56 const std::set<int64_t>& scope() const { return object_store_ids_; } | 58 const std::set<int64_t>& scope() const { return object_store_ids_; } |
| 57 | 59 |
| 58 void ScheduleTask(Operation task) { | 60 void ScheduleTask(Operation task) { |
| 59 ScheduleTask(blink::WebIDBTaskTypeNormal, task); | 61 ScheduleTask(blink::WebIDBTaskTypeNormal, task); |
| 60 } | 62 } |
| 61 void ScheduleTask(blink::WebIDBTaskType, Operation task); | 63 void ScheduleTask(blink::WebIDBTaskType, Operation task); |
| 62 void ScheduleAbortTask(Operation abort_task); | 64 void ScheduleAbortTask(AbortOperation abort_task); |
| 63 void RegisterOpenCursor(IndexedDBCursor* cursor); | 65 void RegisterOpenCursor(IndexedDBCursor* cursor); |
| 64 void UnregisterOpenCursor(IndexedDBCursor* cursor); | 66 void UnregisterOpenCursor(IndexedDBCursor* cursor); |
| 65 void AddPreemptiveEvent() { pending_preemptive_events_++; } | 67 void AddPreemptiveEvent() { pending_preemptive_events_++; } |
| 66 void DidCompletePreemptiveEvent() { | 68 void DidCompletePreemptiveEvent() { |
| 67 pending_preemptive_events_--; | 69 pending_preemptive_events_--; |
| 68 DCHECK_GE(pending_preemptive_events_, 0); | 70 DCHECK_GE(pending_preemptive_events_, 0); |
| 69 } | 71 } |
| 70 void AddPendingObserver(int32_t observer_id, | 72 void AddPendingObserver(int32_t observer_id, |
| 71 const IndexedDBObserver::Options& options); | 73 const IndexedDBObserver::Options& options); |
| 72 // Delete pending observers with ID's listed in |pending_observer_ids|. | 74 // Delete pending observers with ID's listed in |pending_observer_ids|. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 friend class IndexedDBClassFactory; | 122 friend class IndexedDBClassFactory; |
| 121 friend class base::RefCounted<IndexedDBTransaction>; | 123 friend class base::RefCounted<IndexedDBTransaction>; |
| 122 | 124 |
| 123 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); | 125 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); |
| 124 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks); | 126 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks); |
| 125 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly); | 127 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly); |
| 126 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, | 128 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, |
| 127 SchedulePreemptiveTask); | 129 SchedulePreemptiveTask); |
| 128 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, | 130 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, |
| 129 ScheduleNormalTask); | 131 ScheduleNormalTask); |
| 132 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, TaskFails); | |
| 130 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); | 133 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); |
| 131 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, IndexedDBObserver); | 134 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, IndexedDBObserver); |
| 132 | 135 |
| 133 void RunTasksIfStarted(); | 136 void RunTasksIfStarted(); |
| 134 | 137 |
| 135 bool IsTaskQueueEmpty() const; | 138 bool IsTaskQueueEmpty() const; |
| 136 bool HasPendingTasks() const; | 139 bool HasPendingTasks() const; |
| 137 | 140 |
| 138 void BlobWriteComplete(bool success); | 141 void BlobWriteComplete(bool success); |
| 139 void ProcessTaskQueue(); | 142 void ProcessTaskQueue(); |
| 140 void CloseOpenCursors(); | 143 void CloseOpenCursors(); |
| 141 leveldb::Status CommitPhaseTwo(); | 144 leveldb::Status CommitPhaseTwo(); |
| 142 void Timeout(); | 145 void Timeout(); |
| 143 | 146 |
| 144 const int64_t id_; | 147 const int64_t id_; |
| 145 const std::set<int64_t> object_store_ids_; | 148 const std::set<int64_t> object_store_ids_; |
| 146 const blink::WebIDBTransactionMode mode_; | 149 const blink::WebIDBTransactionMode mode_; |
| 147 | 150 |
| 148 bool used_; | 151 bool used_ = false; |
| 149 State state_; | 152 State state_ = CREATED; |
| 150 bool commit_pending_; | 153 bool commit_pending_ = false; |
| 151 base::WeakPtr<IndexedDBConnection> connection_; | 154 base::WeakPtr<IndexedDBConnection> connection_; |
| 152 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 155 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| 153 scoped_refptr<IndexedDBDatabase> database_; | 156 scoped_refptr<IndexedDBDatabase> database_; |
| 154 | 157 |
| 155 // Observers in pending queue do not listen to changes until activated. | 158 // Observers in pending queue do not listen to changes until activated. |
| 156 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; | 159 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; |
| 157 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> | 160 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> |
| 158 connection_changes_map_; | 161 connection_changes_map_; |
| 159 | 162 |
| 160 class TaskQueue { | 163 class TaskQueue { |
| 161 public: | 164 public: |
| 162 TaskQueue(); | 165 TaskQueue(); |
| 163 ~TaskQueue(); | 166 ~TaskQueue(); |
| 164 bool empty() const { return queue_.empty(); } | 167 bool empty() const { return queue_.empty(); } |
| 165 void push(Operation task) { queue_.push(task); } | 168 void push(Operation task) { queue_.push(std::move(task)); } |
| 166 Operation pop(); | 169 Operation pop(); |
| 167 void clear(); | 170 void clear(); |
| 168 | 171 |
| 169 private: | 172 private: |
| 170 std::queue<Operation> queue_; | 173 std::queue<Operation> queue_; |
| 171 | 174 |
| 172 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 175 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
| 173 }; | 176 }; |
| 174 | 177 |
| 175 class TaskStack { | 178 class TaskStack { |
| 176 public: | 179 public: |
| 177 TaskStack(); | 180 TaskStack(); |
| 178 ~TaskStack(); | 181 ~TaskStack(); |
| 179 bool empty() const { return stack_.empty(); } | 182 bool empty() const { return stack_.empty(); } |
| 180 void push(Operation task) { stack_.push(task); } | 183 void push(AbortOperation task) { stack_.push(std::move(task)); } |
| 181 Operation pop(); | 184 AbortOperation pop(); |
| 182 void clear(); | 185 void clear(); |
| 183 | 186 |
| 184 private: | 187 private: |
| 185 std::stack<Operation> stack_; | 188 std::stack<AbortOperation> stack_; |
| 186 | 189 |
| 187 DISALLOW_COPY_AND_ASSIGN(TaskStack); | 190 DISALLOW_COPY_AND_ASSIGN(TaskStack); |
| 188 }; | 191 }; |
| 189 | 192 |
| 190 TaskQueue task_queue_; | 193 TaskQueue task_queue_; |
| 191 TaskQueue preemptive_task_queue_; | 194 TaskQueue preemptive_task_queue_; |
| 192 TaskStack abort_task_stack_; | 195 TaskStack abort_task_stack_; |
| 193 | 196 |
| 194 std::unique_ptr<IndexedDBBackingStore::Transaction> transaction_; | 197 std::unique_ptr<IndexedDBBackingStore::Transaction> transaction_; |
| 195 bool backing_store_transaction_begun_; | 198 bool backing_store_transaction_begun_ = false; |
| 196 | 199 |
| 197 bool should_process_queue_; | 200 bool should_process_queue_ = false; |
| 198 int pending_preemptive_events_; | 201 int pending_preemptive_events_ = 0; |
| 202 bool processing_event_queue_ = false; | |
| 199 | 203 |
| 200 std::set<IndexedDBCursor*> open_cursors_; | 204 std::set<IndexedDBCursor*> open_cursors_; |
| 201 | 205 |
| 202 // This timer is started after requests have been processed. If no subsequent | 206 // This timer is started after requests have been processed. If no subsequent |
| 203 // requests are processed before the timer fires, assume the script is | 207 // requests are processed before the timer fires, assume the script is |
| 204 // unresponsive and abort to unblock the transaction queue. | 208 // unresponsive and abort to unblock the transaction queue. |
| 205 base::OneShotTimer timeout_timer_; | 209 base::OneShotTimer timeout_timer_; |
| 206 | 210 |
| 207 Diagnostics diagnostics_; | 211 Diagnostics diagnostics_; |
| 208 }; | 212 }; |
| 209 | 213 |
| 210 } // namespace content | 214 } // namespace content |
| 211 | 215 |
| 212 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 216 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
| OLD | NEW |