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

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: Adding Observer 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_database.h" 21 #include "content/browser/indexed_db/indexed_db_database.h"
22 #include "content/browser/indexed_db/indexed_db_database_error.h" 22 #include "content/browser/indexed_db/indexed_db_database_error.h"
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
24 24
25 namespace content { 25 namespace content {
26 26
27 class BlobWriteCallbackImpl; 27 class BlobWriteCallbackImpl;
28 class IndexedDBCursor; 28 class IndexedDBCursor;
29 class IndexedDBDatabaseCallbacks; 29 class IndexedDBDatabaseCallbacks;
30 class IndexedDBObserver;
30 31
31 class CONTENT_EXPORT IndexedDBTransaction 32 class CONTENT_EXPORT IndexedDBTransaction
32 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { 33 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) {
33 public: 34 public:
34 typedef base::Callback<void(IndexedDBTransaction*)> Operation; 35 typedef base::Callback<void(IndexedDBTransaction*)> Operation;
35 36
36 enum State { 37 enum State {
37 CREATED, // Created, but not yet started by coordinator. 38 CREATED, // Created, but not yet started by coordinator.
38 STARTED, // Started by the coordinator. 39 STARTED, // Started by the coordinator.
39 COMMITTING, // In the process of committing, possibly waiting for blobs 40 COMMITTING, // In the process of committing, possibly waiting for blobs
(...skipping 16 matching lines...) Expand all
56 } 57 }
57 void ScheduleTask(blink::WebIDBTaskType, Operation task); 58 void ScheduleTask(blink::WebIDBTaskType, Operation task);
58 void ScheduleAbortTask(Operation abort_task); 59 void ScheduleAbortTask(Operation abort_task);
59 void RegisterOpenCursor(IndexedDBCursor* cursor); 60 void RegisterOpenCursor(IndexedDBCursor* cursor);
60 void UnregisterOpenCursor(IndexedDBCursor* cursor); 61 void UnregisterOpenCursor(IndexedDBCursor* cursor);
61 void AddPreemptiveEvent() { pending_preemptive_events_++; } 62 void AddPreemptiveEvent() { pending_preemptive_events_++; }
62 void DidCompletePreemptiveEvent() { 63 void DidCompletePreemptiveEvent() {
63 pending_preemptive_events_--; 64 pending_preemptive_events_--;
64 DCHECK_GE(pending_preemptive_events_, 0); 65 DCHECK_GE(pending_preemptive_events_, 0);
65 } 66 }
67 void AddPendingObserver(std::unique_ptr<IndexedDBObserver> observer);
68
66 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { 69 IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
67 return transaction_.get(); 70 return transaction_.get();
68 } 71 }
69 int64_t id() const { return id_; } 72 int64_t id() const { return id_; }
70 73
71 IndexedDBDatabase* database() const { return database_.get(); } 74 IndexedDBDatabase* database() const { return database_.get(); }
72 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); } 75 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); }
73 76
74 State state() const { return state_; } 77 State state() const { return state_; }
75 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } 78 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 119
117 bool IsTaskQueueEmpty() const; 120 bool IsTaskQueueEmpty() const;
118 bool HasPendingTasks() const; 121 bool HasPendingTasks() const;
119 122
120 void BlobWriteComplete(bool success); 123 void BlobWriteComplete(bool success);
121 void ProcessTaskQueue(); 124 void ProcessTaskQueue();
122 void CloseOpenCursors(); 125 void CloseOpenCursors();
123 leveldb::Status CommitPhaseTwo(); 126 leveldb::Status CommitPhaseTwo();
124 void Timeout(); 127 void Timeout();
125 128
129 void AddActiveObserver();
dmurph 2016/06/15 12:49:43 what about 'MaybeActivatePendingObservers()'
palakj1 2016/06/16 07:05:40 yaa, that's a lot more intutive. changed.
130
126 const int64_t id_; 131 const int64_t id_;
127 const std::set<int64_t> object_store_ids_; 132 const std::set<int64_t> object_store_ids_;
128 const blink::WebIDBTransactionMode mode_; 133 const blink::WebIDBTransactionMode mode_;
129 134
130 bool used_; 135 bool used_;
131 State state_; 136 State state_;
132 bool commit_pending_; 137 bool commit_pending_;
133 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 138 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
134 scoped_refptr<IndexedDBDatabase> database_; 139 scoped_refptr<IndexedDBDatabase> database_;
135 140
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 TaskQueue preemptive_task_queue_; 172 TaskQueue preemptive_task_queue_;
168 TaskStack abort_task_stack_; 173 TaskStack abort_task_stack_;
169 174
170 std::unique_ptr<IndexedDBBackingStore::Transaction> transaction_; 175 std::unique_ptr<IndexedDBBackingStore::Transaction> transaction_;
171 bool backing_store_transaction_begun_; 176 bool backing_store_transaction_begun_;
172 177
173 bool should_process_queue_; 178 bool should_process_queue_;
174 int pending_preemptive_events_; 179 int pending_preemptive_events_;
175 180
176 std::set<IndexedDBCursor*> open_cursors_; 181 std::set<IndexedDBCursor*> open_cursors_;
182 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_;
177 183
178 // This timer is started after requests have been processed. If no subsequent 184 // This timer is started after requests have been processed. If no subsequent
179 // requests are processed before the timer fires, assume the script is 185 // requests are processed before the timer fires, assume the script is
180 // unresponsive and abort to unblock the transaction queue. 186 // unresponsive and abort to unblock the transaction queue.
181 base::OneShotTimer timeout_timer_; 187 base::OneShotTimer timeout_timer_;
182 188
183 Diagnostics diagnostics_; 189 Diagnostics diagnostics_;
184 }; 190 };
185 191
186 } // namespace content 192 } // namespace content
187 193
188 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 194 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698