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 "base/time/time.h" | 15 #include "base/time/time.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 BlobWriteCallbackImpl; | |
| 23 class IndexedDBCursor; | 24 class IndexedDBCursor; |
| 24 class IndexedDBDatabaseCallbacks; | 25 class IndexedDBDatabaseCallbacks; |
| 25 | 26 |
| 26 class CONTENT_EXPORT IndexedDBTransaction | 27 class CONTENT_EXPORT IndexedDBTransaction |
| 27 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { | 28 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { |
| 28 public: | 29 public: |
| 29 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 30 typedef base::Callback<void(IndexedDBTransaction*)> Operation; |
| 30 | 31 |
| 31 IndexedDBTransaction( | 32 IndexedDBTransaction( |
| 32 int64 id, | 33 int64 id, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 60 } | 61 } |
| 61 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 62 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
| 62 return transaction_.get(); | 63 return transaction_.get(); |
| 63 } | 64 } |
| 64 int64 id() const { return id_; } | 65 int64 id() const { return id_; } |
| 65 | 66 |
| 66 IndexedDBDatabase* database() const { return database_; } | 67 IndexedDBDatabase* database() const { return database_; } |
| 67 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } | 68 IndexedDBDatabaseCallbacks* connection() const { return callbacks_; } |
| 68 | 69 |
| 69 enum State { | 70 enum State { |
| 70 CREATED, // Created, but not yet started by coordinator. | 71 CREATED, // Created, but not yet started by coordinator. |
| 71 STARTED, // Started by the coordinator. | 72 STARTED, // Started by the coordinator. |
| 72 FINISHED, // Either aborted or committed. | 73 COMMITTING, // In the process of committing, possibly waiting for blobs |
| 74 // to be written. | |
| 75 FINISHED, // Either aborted or committed. | |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 State state() const { return state_; } | 78 State state() const { return state_; } |
| 76 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } | 79 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } |
| 77 | 80 |
| 78 struct Diagnostics { | 81 struct Diagnostics { |
| 79 base::Time creation_time; | 82 base::Time creation_time; |
| 80 base::Time start_time; | 83 base::Time start_time; |
| 81 int tasks_scheduled; | 84 int tasks_scheduled; |
| 82 int tasks_completed; | 85 int tasks_completed; |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 const Diagnostics& diagnostics() const { return diagnostics_; } | 88 const Diagnostics& diagnostics() const { return diagnostics_; } |
| 86 | 89 |
| 87 private: | 90 private: |
| 91 friend class BlobWriteCallbackImpl; | |
| 92 | |
| 93 // TODO(ericu): Report this on the internals page. | |
|
jsbell
2014/05/28 21:29:15
This is sort-of done. The data is passed to the pa
ericu
2014/05/28 22:50:42
Yup.
| |
| 94 bool IsStatePastStarted() const { | |
|
jsbell
2014/05/28 21:29:15
It's unclear to me that we need this method...
| |
| 95 return state_ == COMMITTING || state_ == FINISHED; | |
| 96 } | |
| 88 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); | 97 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); |
| 89 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); | 98 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); |
| 90 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, | 99 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, |
| 91 SchedulePreemptiveTask); | 100 SchedulePreemptiveTask); |
| 92 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, | 101 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, |
| 93 ScheduleNormalTask); | 102 ScheduleNormalTask); |
| 94 | 103 |
| 95 friend class base::RefCounted<IndexedDBTransaction>; | 104 friend class base::RefCounted<IndexedDBTransaction>; |
| 96 virtual ~IndexedDBTransaction(); | 105 virtual ~IndexedDBTransaction(); |
| 97 | 106 |
| 98 void RunTasksIfStarted(); | 107 void RunTasksIfStarted(); |
| 99 | 108 |
| 100 bool IsTaskQueueEmpty() const; | 109 bool IsTaskQueueEmpty() const; |
| 101 bool HasPendingTasks() const; | 110 bool HasPendingTasks() const; |
| 102 | 111 |
| 112 void BlobWriteComplete(bool success); | |
| 103 void ProcessTaskQueue(); | 113 void ProcessTaskQueue(); |
| 104 void CloseOpenCursors(); | 114 void CloseOpenCursors(); |
| 115 void CommitPhaseTwo(); | |
| 105 void Timeout(); | 116 void Timeout(); |
| 106 | 117 |
| 107 const int64 id_; | 118 const int64 id_; |
| 108 const std::set<int64> object_store_ids_; | 119 const std::set<int64> object_store_ids_; |
| 109 const indexed_db::TransactionMode mode_; | 120 const indexed_db::TransactionMode mode_; |
| 110 | 121 |
| 111 bool used_; | 122 bool used_; |
| 112 State state_; | 123 State state_; |
| 113 bool commit_pending_; | 124 bool commit_pending_; |
| 114 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 125 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 // requests are processed before the timer fires, assume the script is | 167 // requests are processed before the timer fires, assume the script is |
| 157 // unresponsive and abort to unblock the transaction queue. | 168 // unresponsive and abort to unblock the transaction queue. |
| 158 base::OneShotTimer<IndexedDBTransaction> timeout_timer_; | 169 base::OneShotTimer<IndexedDBTransaction> timeout_timer_; |
| 159 | 170 |
| 160 Diagnostics diagnostics_; | 171 Diagnostics diagnostics_; |
| 161 }; | 172 }; |
| 162 | 173 |
| 163 } // namespace content | 174 } // namespace content |
| 164 | 175 |
| 165 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 176 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
| OLD | NEW |