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> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <stack> | 13 #include <stack> |
| 14 | 14 |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 20 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 21 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 21 #include "content/browser/indexed_db/indexed_db_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 22 #include "content/browser/indexed_db/indexed_db_database.h" | 23 #include "content/browser/indexed_db/indexed_db_database.h" |
| 23 #include "content/browser/indexed_db/indexed_db_database_error.h" | 24 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 24 #include "content/browser/indexed_db/indexed_db_observer.h" | 25 #include "content/browser/indexed_db/indexed_db_observer.h" |
| 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
| 27 #include "url/origin.h" | |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 class BlobWriteCallbackImpl; | 31 class BlobWriteCallbackImpl; |
| 30 class IndexedDBCursor; | 32 class IndexedDBCursor; |
| 31 class IndexedDBDatabaseCallbacks; | 33 class IndexedDBDatabaseCallbacks; |
| 32 class IndexedDBObservation; | 34 class IndexedDBObservation; |
| 33 class IndexedDBObserverChanges; | 35 class IndexedDBObserverChanges; |
| 34 | 36 |
| 35 class CONTENT_EXPORT IndexedDBTransaction | 37 class CONTENT_EXPORT IndexedDBTransaction { |
| 36 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { | |
| 37 public: | 38 public: |
| 38 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 39 typedef base::Callback<void(IndexedDBTransaction*)> Operation; |
| 39 | 40 |
| 40 enum State { | 41 enum State { |
| 41 CREATED, // Created, but not yet started by coordinator. | 42 CREATED, // Created, but not yet started by coordinator. |
| 42 STARTED, // Started by the coordinator. | 43 STARTED, // Started by the coordinator. |
| 43 COMMITTING, // In the process of committing, possibly waiting for blobs | 44 COMMITTING, // In the process of committing, possibly waiting for blobs |
| 44 // to be written. | 45 // to be written. |
| 45 FINISHED, // Either aborted or committed. | 46 FINISHED, // Either aborted or committed. |
| 46 }; | 47 }; |
| 47 | 48 |
| 49 IndexedDBTransaction( | |
|
cmumford
2016/11/04 23:33:13
The only reason this is public is so that base::Wr
dmurph
2016/11/07 20:05:23
Done.
| |
| 50 int64_t id, | |
| 51 IndexedDBConnection* connection, | |
| 52 const std::set<int64_t>& object_store_ids, | |
| 53 blink::WebIDBTransactionMode mode, | |
| 54 IndexedDBBackingStore::Transaction* backing_store_transaction); | |
| 55 virtual ~IndexedDBTransaction(); | |
| 56 | |
| 48 virtual void Abort(); | 57 virtual void Abort(); |
| 49 leveldb::Status Commit(); | 58 leveldb::Status Commit(); |
| 50 void Abort(const IndexedDBDatabaseError& error); | 59 void Abort(const IndexedDBDatabaseError& error); |
| 51 | 60 |
| 52 // Called by the transaction coordinator when this transaction is unblocked. | 61 // Called by the transaction coordinator when this transaction is unblocked. |
| 53 void Start(); | 62 void Start(); |
| 54 | 63 |
| 55 blink::WebIDBTransactionMode mode() const { return mode_; } | 64 blink::WebIDBTransactionMode mode() const { return mode_; } |
| 56 const std::set<int64_t>& scope() const { return object_store_ids_; } | 65 const std::set<int64_t>& scope() const { return object_store_ids_; } |
| 57 | 66 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 80 void RecordObserverForLastObservation(int32_t connection_id, | 89 void RecordObserverForLastObservation(int32_t connection_id, |
| 81 int32_t observer_id); | 90 int32_t observer_id); |
| 82 | 91 |
| 83 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 92 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
| 84 return transaction_.get(); | 93 return transaction_.get(); |
| 85 } | 94 } |
| 86 int64_t id() const { return id_; } | 95 int64_t id() const { return id_; } |
| 87 | 96 |
| 88 IndexedDBDatabase* database() const { return database_.get(); } | 97 IndexedDBDatabase* database() const { return database_.get(); } |
| 89 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 98 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } |
| 90 IndexedDBConnection* connection() const { return connection_.get(); } | 99 IndexedDBConnection* connection() const { return connection_; } |
| 91 | 100 |
| 92 State state() const { return state_; } | 101 State state() const { return state_; } |
| 93 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } | 102 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } |
| 94 | 103 |
| 95 struct Diagnostics { | 104 struct Diagnostics { |
| 96 base::Time creation_time; | 105 base::Time creation_time; |
| 97 base::Time start_time; | 106 base::Time start_time; |
| 98 int tasks_scheduled; | 107 int tasks_scheduled; |
| 99 int tasks_completed; | 108 int tasks_completed; |
| 100 }; | 109 }; |
| 101 | 110 |
| 102 const Diagnostics& diagnostics() const { return diagnostics_; } | 111 const Diagnostics& diagnostics() const { return diagnostics_; } |
| 103 | 112 |
| 113 void set_size(uint64_t size) { size_ = size; } | |
| 114 uint64_t size() const { return size_; } | |
| 115 | |
| 116 void set_origin(url::Origin origin) { origin_ = std::move(origin); } | |
| 117 const url::Origin& origin() const { return origin_; } | |
| 118 | |
| 104 protected: | 119 protected: |
| 105 // Test classes may derive, but most creation should be done via | |
| 106 // IndexedDBClassFactory. | |
| 107 IndexedDBTransaction( | |
| 108 int64_t id, | |
| 109 base::WeakPtr<IndexedDBConnection> connection, | |
| 110 const std::set<int64_t>& object_store_ids, | |
| 111 blink::WebIDBTransactionMode mode, | |
| 112 IndexedDBBackingStore::Transaction* backing_store_transaction); | |
| 113 virtual ~IndexedDBTransaction(); | |
| 114 | |
| 115 // May be overridden in tests. | 120 // May be overridden in tests. |
| 116 virtual base::TimeDelta GetInactivityTimeout() const; | 121 virtual base::TimeDelta GetInactivityTimeout() const; |
| 117 | 122 |
| 118 private: | 123 private: |
| 119 friend class BlobWriteCallbackImpl; | 124 friend class BlobWriteCallbackImpl; |
| 120 friend class IndexedDBClassFactory; | 125 friend class IndexedDBClassFactory; |
| 126 friend class IndexedDBConnection; | |
| 121 friend class base::RefCounted<IndexedDBTransaction>; | 127 friend class base::RefCounted<IndexedDBTransaction>; |
| 122 | 128 |
| 123 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); | 129 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); |
| 124 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks); | 130 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks); |
| 125 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly); | 131 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly); |
| 126 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, | 132 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, |
| 127 SchedulePreemptiveTask); | 133 SchedulePreemptiveTask); |
| 128 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, | 134 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, |
| 129 ScheduleNormalTask); | 135 ScheduleNormalTask); |
| 130 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); | 136 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 141 leveldb::Status CommitPhaseTwo(); | 147 leveldb::Status CommitPhaseTwo(); |
| 142 void Timeout(); | 148 void Timeout(); |
| 143 | 149 |
| 144 const int64_t id_; | 150 const int64_t id_; |
| 145 const std::set<int64_t> object_store_ids_; | 151 const std::set<int64_t> object_store_ids_; |
| 146 const blink::WebIDBTransactionMode mode_; | 152 const blink::WebIDBTransactionMode mode_; |
| 147 | 153 |
| 148 bool used_; | 154 bool used_; |
| 149 State state_; | 155 State state_; |
| 150 bool commit_pending_; | 156 bool commit_pending_; |
| 151 base::WeakPtr<IndexedDBConnection> connection_; | 157 // We are owned by the connection object. |
| 158 IndexedDBConnection* connection_; | |
| 152 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 159 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| 153 scoped_refptr<IndexedDBDatabase> database_; | 160 scoped_refptr<IndexedDBDatabase> database_; |
| 154 | 161 |
| 155 // Observers in pending queue do not listen to changes until activated. | 162 // Observers in pending queue do not listen to changes until activated. |
| 156 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; | 163 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; |
| 157 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> | 164 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> |
| 158 connection_changes_map_; | 165 connection_changes_map_; |
| 159 | 166 |
| 167 // Metrics for quota. | |
| 168 uint64_t size_; | |
| 169 url::Origin origin_; | |
|
jsbell
2016/11/04 17:48:19
Can we replace origin_ with connection_->origin()
dmurph
2016/11/04 22:52:25
Done.
| |
| 170 | |
| 160 class TaskQueue { | 171 class TaskQueue { |
| 161 public: | 172 public: |
| 162 TaskQueue(); | 173 TaskQueue(); |
| 163 ~TaskQueue(); | 174 ~TaskQueue(); |
| 164 bool empty() const { return queue_.empty(); } | 175 bool empty() const { return queue_.empty(); } |
| 165 void push(Operation task) { queue_.push(task); } | 176 void push(Operation task) { queue_.push(task); } |
| 166 Operation pop(); | 177 Operation pop(); |
| 167 void clear(); | 178 void clear(); |
| 168 | 179 |
| 169 private: | 180 private: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 198 int pending_preemptive_events_; | 209 int pending_preemptive_events_; |
| 199 | 210 |
| 200 std::set<IndexedDBCursor*> open_cursors_; | 211 std::set<IndexedDBCursor*> open_cursors_; |
| 201 | 212 |
| 202 // This timer is started after requests have been processed. If no subsequent | 213 // This timer is started after requests have been processed. If no subsequent |
| 203 // requests are processed before the timer fires, assume the script is | 214 // requests are processed before the timer fires, assume the script is |
| 204 // unresponsive and abort to unblock the transaction queue. | 215 // unresponsive and abort to unblock the transaction queue. |
| 205 base::OneShotTimer timeout_timer_; | 216 base::OneShotTimer timeout_timer_; |
| 206 | 217 |
| 207 Diagnostics diagnostics_; | 218 Diagnostics diagnostics_; |
| 219 | |
| 220 base::WeakPtrFactory<IndexedDBTransaction> ptr_factory_; | |
| 208 }; | 221 }; |
| 209 | 222 |
| 210 } // namespace content | 223 } // namespace content |
| 211 | 224 |
| 212 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 225 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
| OLD | NEW |