Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(890)

Side by Side Diff: content/browser/indexed_db/indexed_db_transaction.h

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Post dmurph review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/time/time.h" 18 #include "base/time/time.h"
19 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
20 #include "content/browser/indexed_db/indexed_db_backing_store.h" 20 #include "content/browser/indexed_db/indexed_db_backing_store.h"
21 #include "content/browser/indexed_db/indexed_db_connection.h"
21 #include "content/browser/indexed_db/indexed_db_database.h" 22 #include "content/browser/indexed_db/indexed_db_database.h"
22 #include "content/browser/indexed_db/indexed_db_database_error.h" 23 #include "content/browser/indexed_db/indexed_db_database_error.h"
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
24 25
25 namespace content { 26 namespace content {
26 27
27 class BlobWriteCallbackImpl; 28 class BlobWriteCallbackImpl;
28 class IndexedDBCursor; 29 class IndexedDBCursor;
29 class IndexedDBDatabaseCallbacks; 30 class IndexedDBDatabaseCallbacks;
31 class IndexedDBObserver;
30 32
31 class CONTENT_EXPORT IndexedDBTransaction 33 class CONTENT_EXPORT IndexedDBTransaction
32 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { 34 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) {
33 public: 35 public:
34 typedef base::Callback<void(IndexedDBTransaction*)> Operation; 36 typedef base::Callback<void(IndexedDBTransaction*)> Operation;
35 37
36 enum State { 38 enum State {
37 CREATED, // Created, but not yet started by coordinator. 39 CREATED, // Created, but not yet started by coordinator.
38 STARTED, // Started by the coordinator. 40 STARTED, // Started by the coordinator.
39 COMMITTING, // In the process of committing, possibly waiting for blobs 41 COMMITTING, // In the process of committing, possibly waiting for blobs
(...skipping 16 matching lines...) Expand all
56 } 58 }
57 void ScheduleTask(blink::WebIDBTaskType, Operation task); 59 void ScheduleTask(blink::WebIDBTaskType, Operation task);
58 void ScheduleAbortTask(Operation abort_task); 60 void ScheduleAbortTask(Operation abort_task);
59 void RegisterOpenCursor(IndexedDBCursor* cursor); 61 void RegisterOpenCursor(IndexedDBCursor* cursor);
60 void UnregisterOpenCursor(IndexedDBCursor* cursor); 62 void UnregisterOpenCursor(IndexedDBCursor* cursor);
61 void AddPreemptiveEvent() { pending_preemptive_events_++; } 63 void AddPreemptiveEvent() { pending_preemptive_events_++; }
62 void DidCompletePreemptiveEvent() { 64 void DidCompletePreemptiveEvent() {
63 pending_preemptive_events_--; 65 pending_preemptive_events_--;
64 DCHECK_GE(pending_preemptive_events_, 0); 66 DCHECK_GE(pending_preemptive_events_, 0);
65 } 67 }
68 void AddPendingObserver(int32_t observer_id);
69
66 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { 70 IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
67 return transaction_.get(); 71 return transaction_.get();
68 } 72 }
69 int64_t id() const { return id_; } 73 int64_t id() const { return id_; }
70 74
71 IndexedDBDatabase* database() const { return database_.get(); } 75 IndexedDBDatabase* database() const { return database_.get(); }
72 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); } 76 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); }
77 IndexedDBConnection* getConnection() const { return connection_.get(); }
Marijn Kruisselbrink 2016/06/24 00:48:09 getConnection should be GetConnection (or connecti
palakj1 2016/06/27 20:19:23 Changed.
73 78
74 State state() const { return state_; } 79 State state() const { return state_; }
75 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } 80 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); }
76 81
77 struct Diagnostics { 82 struct Diagnostics {
78 base::Time creation_time; 83 base::Time creation_time;
79 base::Time start_time; 84 base::Time start_time;
80 int tasks_scheduled; 85 int tasks_scheduled;
81 int tasks_completed; 86 int tasks_completed;
82 }; 87 };
83 88
84 const Diagnostics& diagnostics() const { return diagnostics_; } 89 const Diagnostics& diagnostics() const { return diagnostics_; }
90 void RemovePendingObservers(const std::vector<int32_t>& pending_observer_ids);
85 91
86 protected: 92 protected:
87 // Test classes may derive, but most creation should be done via 93 // Test classes may derive, but most creation should be done via
88 // IndexedDBClassFactory. 94 // IndexedDBClassFactory.
89 IndexedDBTransaction( 95 IndexedDBTransaction(
90 int64_t id, 96 int64_t id,
97 base::WeakPtr<IndexedDBConnection> connection,
91 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, 98 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks,
92 const std::set<int64_t>& object_store_ids, 99 const std::set<int64_t>& object_store_ids,
93 blink::WebIDBTransactionMode mode, 100 blink::WebIDBTransactionMode mode,
94 IndexedDBDatabase* db, 101 IndexedDBDatabase* db,
95 IndexedDBBackingStore::Transaction* backing_store_transaction); 102 IndexedDBBackingStore::Transaction* backing_store_transaction);
96 virtual ~IndexedDBTransaction(); 103 virtual ~IndexedDBTransaction();
97 104
98 // May be overridden in tests. 105 // May be overridden in tests.
99 virtual base::TimeDelta GetInactivityTimeout() const; 106 virtual base::TimeDelta GetInactivityTimeout() const;
100 107
(...skipping 22 matching lines...) Expand all
123 leveldb::Status CommitPhaseTwo(); 130 leveldb::Status CommitPhaseTwo();
124 void Timeout(); 131 void Timeout();
125 132
126 const int64_t id_; 133 const int64_t id_;
127 const std::set<int64_t> object_store_ids_; 134 const std::set<int64_t> object_store_ids_;
128 const blink::WebIDBTransactionMode mode_; 135 const blink::WebIDBTransactionMode mode_;
129 136
130 bool used_; 137 bool used_;
131 State state_; 138 State state_;
132 bool commit_pending_; 139 bool commit_pending_;
140 base::WeakPtr<IndexedDBConnection> connection_;
133 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 141 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
134 scoped_refptr<IndexedDBDatabase> database_; 142 scoped_refptr<IndexedDBDatabase> database_;
135 143
144 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_;
145
136 class TaskQueue { 146 class TaskQueue {
137 public: 147 public:
138 TaskQueue(); 148 TaskQueue();
139 ~TaskQueue(); 149 ~TaskQueue();
140 bool empty() const { return queue_.empty(); } 150 bool empty() const { return queue_.empty(); }
141 void push(Operation task) { queue_.push(task); } 151 void push(Operation task) { queue_.push(task); }
142 Operation pop(); 152 Operation pop();
143 void clear(); 153 void clear();
144 154
145 private: 155 private:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // requests are processed before the timer fires, assume the script is 189 // requests are processed before the timer fires, assume the script is
180 // unresponsive and abort to unblock the transaction queue. 190 // unresponsive and abort to unblock the transaction queue.
181 base::OneShotTimer timeout_timer_; 191 base::OneShotTimer timeout_timer_;
182 192
183 Diagnostics diagnostics_; 193 Diagnostics diagnostics_;
184 }; 194 };
185 195
186 } // namespace content 196 } // namespace content
187 197
188 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 198 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698