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 "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 16 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
17 #include "content/browser/indexed_db/indexed_db_database.h" | 17 #include "content/browser/indexed_db/indexed_db_database.h" |
18 #include "content/browser/indexed_db/indexed_db_database_error.h" | 18 #include "content/browser/indexed_db/indexed_db_database_error.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
| 22 class BlobWriteCallbackImpl; |
22 class IndexedDBCursor; | 23 class IndexedDBCursor; |
23 class IndexedDBDatabaseCallbacks; | 24 class IndexedDBDatabaseCallbacks; |
24 | 25 |
25 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> { | 26 class IndexedDBTransaction : public base::RefCounted<IndexedDBTransaction> { |
26 public: | 27 public: |
27 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 28 typedef base::Callback<void(IndexedDBTransaction*)> Operation; |
28 | 29 |
29 IndexedDBTransaction(int64 id, | 30 IndexedDBTransaction(int64 id, |
30 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, | 31 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, |
31 const std::set<int64>& object_store_ids, | 32 const std::set<int64>& object_store_ids, |
(...skipping 24 matching lines...) Expand all Loading... |
56 } | 57 } |
57 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 58 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
58 return &transaction_; | 59 return &transaction_; |
59 } | 60 } |
60 int64 id() const { return id_; } | 61 int64 id() const { return id_; } |
61 | 62 |
62 IndexedDBDatabase* database() const { return database_; } | 63 IndexedDBDatabase* database() const { return database_; } |
63 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } | 64 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } |
64 | 65 |
65 enum State { | 66 enum State { |
66 CREATED, // Created, but not yet started by coordinator. | 67 CREATED, // Created, but not yet started by coordinator. |
67 STARTED, // Started by the coordinator. | 68 STARTED, // Started by the coordinator. |
68 FINISHED, // Either aborted or committed. | 69 COMMITTING, // In the process of committing, possibly waiting for blobs |
| 70 // to be written. |
| 71 FINISHED, // Either aborted or committed. |
69 }; | 72 }; |
70 | 73 |
71 State state() const { return state_; } | 74 State state() const { return state_; } |
72 | 75 |
73 struct Diagnostics { | 76 struct Diagnostics { |
74 base::Time creation_time; | 77 base::Time creation_time; |
75 base::Time start_time; | 78 base::Time start_time; |
76 int tasks_scheduled; | 79 int tasks_scheduled; |
77 int tasks_completed; | 80 int tasks_completed; |
78 }; | 81 }; |
79 | 82 |
80 const Diagnostics& diagnostics() const { return diagnostics_; } | 83 const Diagnostics& diagnostics() const { return diagnostics_; } |
81 | 84 |
82 private: | 85 private: |
| 86 friend class BlobWriteCallbackImpl; |
| 87 |
| 88 enum TransactionUseState { WAS_USED, WAS_NOT_USED }; |
| 89 enum ShouldSkipCommit { DO_COMMIT, SKIP_COMMIT }; |
| 90 |
| 91 // TODO(ericu): Report this on the internals page. |
| 92 bool IsStatePastRunning() const { |
| 93 return state_ == COMMITTING || state_ == FINISHED; |
| 94 } |
83 friend class base::RefCounted<IndexedDBTransaction>; | 95 friend class base::RefCounted<IndexedDBTransaction>; |
84 virtual ~IndexedDBTransaction(); | 96 virtual ~IndexedDBTransaction(); |
85 | 97 |
86 void RunTasksIfStarted(); | 98 void RunTasksIfStarted(); |
87 | 99 |
88 bool IsTaskQueueEmpty() const; | 100 bool IsTaskQueueEmpty() const; |
89 bool HasPendingTasks() const; | 101 bool HasPendingTasks() const; |
90 | 102 |
| 103 void BlobWriteComplete(bool success); |
91 void ProcessTaskQueue(); | 104 void ProcessTaskQueue(); |
92 void CloseOpenCursors(); | 105 void CloseOpenCursors(); |
| 106 void CommitPhaseTwo(TransactionUseState use_state, |
| 107 ShouldSkipCommit skip_commit); |
93 | 108 |
94 const int64 id_; | 109 const int64 id_; |
95 const std::set<int64> object_store_ids_; | 110 const std::set<int64> object_store_ids_; |
96 const indexed_db::TransactionMode mode_; | 111 const indexed_db::TransactionMode mode_; |
97 | 112 |
98 bool used_; | 113 bool used_; |
99 State state_; | 114 State state_; |
100 bool commit_pending_; | 115 bool commit_pending_; |
| 116 bool blob_write_success_; |
101 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 117 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
102 scoped_refptr<IndexedDBDatabase> database_; | 118 scoped_refptr<IndexedDBDatabase> database_; |
103 | 119 |
104 class TaskQueue { | 120 class TaskQueue { |
105 public: | 121 public: |
106 TaskQueue(); | 122 TaskQueue(); |
107 ~TaskQueue(); | 123 ~TaskQueue(); |
108 bool empty() const { return queue_.empty(); } | 124 bool empty() const { return queue_.empty(); } |
109 void push(Operation task) { queue_.push(task); } | 125 void push(Operation task) { queue_.push(task); } |
110 Operation pop(); | 126 Operation pop(); |
(...skipping 26 matching lines...) Expand all Loading... |
137 bool should_process_queue_; | 153 bool should_process_queue_; |
138 int pending_preemptive_events_; | 154 int pending_preemptive_events_; |
139 | 155 |
140 std::set<IndexedDBCursor*> open_cursors_; | 156 std::set<IndexedDBCursor*> open_cursors_; |
141 Diagnostics diagnostics_; | 157 Diagnostics diagnostics_; |
142 }; | 158 }; |
143 | 159 |
144 } // namespace content | 160 } // namespace content |
145 | 161 |
146 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 162 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
OLD | NEW |