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 <queue> | 8 #include <queue> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <stack> | 10 #include <stack> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 15 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database.h" | 16 #include "content/browser/indexed_db/indexed_db_database.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database_error.h" | 17 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class BlobWriteCallbackImpl; | |
| 21 class IndexedDBCursor; | 22 class IndexedDBCursor; |
| 22 class IndexedDBDatabaseCallbacks; | 23 class IndexedDBDatabaseCallbacks; |
| 23 | 24 |
| 24 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> { | 25 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> { |
| 25 public: | 26 public: |
| 26 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 27 typedef base::Callback<void(IndexedDBTransaction*)> Operation; |
| 27 | 28 |
| 28 IndexedDBTransaction(int64 id, | 29 IndexedDBTransaction(int64 id, |
| 29 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 30 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
| 30 const std::set<int64>& object_store_ids, | 31 const std::set<int64>& object_store_ids, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 58 | 59 |
| 59 IndexedDBDatabase* database() const { return database_; } | 60 IndexedDBDatabase* database() const { return database_; } |
| 60 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } | 61 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } |
| 61 bool IsRunning() const { return state_ == RUNNING; } | 62 bool IsRunning() const { return state_ == RUNNING; } |
| 62 | 63 |
| 63 protected: | 64 protected: |
| 64 virtual ~IndexedDBTransaction(); | 65 virtual ~IndexedDBTransaction(); |
| 65 friend class base::RefCounted<IndexedDBTransaction>; | 66 friend class base::RefCounted<IndexedDBTransaction>; |
| 66 | 67 |
| 67 private: | 68 private: |
| 69 friend class BlobWriteCallbackImpl; | |
| 70 | |
| 68 enum State { | 71 enum State { |
| 69 UNUSED, // Created, but no tasks yet. | 72 UNUSED, // Created, but no tasks yet. |
| 70 START_PENDING, // Enqueued tasks, but backing store transaction not yet | 73 START_PENDING, // Enqueued tasks, but backing store transaction not yet |
| 71 // started. | 74 // started. |
| 72 RUNNING, // Backing store transaction started but not yet finished. | 75 RUNNING, // Backing store transaction started but not yet finished. |
| 76 COMMITTING, // In the process of committing, possibly waiting for blobs | |
|
jsbell
2013/09/13 00:12:21
Happy fun state transition diagram.
ericu
2013/11/20 23:05:39
Yup. At least it's still pretty non-branchy.
jsbell
2013/11/21 22:54:32
FYI, I just learned we have a bug here. The UNUSED
| |
| 77 // to be written. | |
| 73 FINISHED, // Either aborted or committed. | 78 FINISHED, // Either aborted or committed. |
| 74 }; | 79 }; |
| 80 enum TransactionUseState { WAS_USED, WAS_NOT_USED }; | |
| 81 enum ShouldSkipCommit { DO_COMMIT, SKIP_COMMIT }; | |
|
jsbell
2013/09/13 00:12:21
Seems like we should be able to combine WAS_NOT_US
ericu
2013/11/20 23:05:39
They could be sliced differently, but we do need t
| |
| 82 | |
| 83 bool IsStatePastRunning() const { | |
|
jsbell
2013/09/13 00:12:21
We'll want context to call into this, to report it
ericu
2013/11/20 23:05:39
Added a TODO.
| |
| 84 return state_ == COMMITTING || state_ == FINISHED; | |
| 85 } | |
| 75 | 86 |
| 76 void EnsureTasksRunning(); | 87 void EnsureTasksRunning(); |
| 77 void Start(); | 88 void Start(); |
| 78 | 89 |
| 79 bool IsTaskQueueEmpty() const; | 90 bool IsTaskQueueEmpty() const; |
| 80 bool HasPendingTasks() const; | 91 bool HasPendingTasks() const; |
| 81 | 92 |
| 93 void BlobWriteComplete(bool success); | |
| 82 void ProcessTaskQueue(); | 94 void ProcessTaskQueue(); |
| 83 void CloseOpenCursors(); | 95 void CloseOpenCursors(); |
| 96 void CommitPhaseTwo(TransactionUseState use_state, | |
| 97 ShouldSkipCommit skip_commit); | |
| 84 | 98 |
| 85 const int64 id_; | 99 const int64 id_; |
| 86 const std::set<int64> object_store_ids_; | 100 const std::set<int64> object_store_ids_; |
| 87 const indexed_db::TransactionMode mode_; | 101 const indexed_db::TransactionMode mode_; |
| 88 | 102 |
| 89 State state_; | 103 State state_; |
| 90 bool commit_pending_; | 104 bool commit_pending_; |
| 105 bool blob_write_success_; | |
| 91 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 106 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| 92 scoped_refptr<IndexedDBDatabase> database_; | 107 scoped_refptr<IndexedDBDatabase> database_; |
| 93 | 108 |
| 94 class TaskQueue { | 109 class TaskQueue { |
| 95 public: | 110 public: |
| 96 TaskQueue(); | 111 TaskQueue(); |
| 97 ~TaskQueue(); | 112 ~TaskQueue(); |
| 98 bool empty() const { return queue_.empty(); } | 113 bool empty() const { return queue_.empty(); } |
| 99 void push(Operation task) { queue_.push(task); } | 114 void push(Operation task) { queue_.push(task); } |
| 100 Operation pop(); | 115 Operation pop(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 125 | 140 |
| 126 bool should_process_queue_; | 141 bool should_process_queue_; |
| 127 int pending_preemptive_events_; | 142 int pending_preemptive_events_; |
| 128 | 143 |
| 129 std::set<IndexedDBCursor*> open_cursors_; | 144 std::set<IndexedDBCursor*> open_cursors_; |
| 130 }; | 145 }; |
| 131 | 146 |
| 132 } // namespace content | 147 } // namespace content |
| 133 | 148 |
| 134 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 149 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
| OLD | NEW |