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

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: Expected test results changed Created 4 years, 5 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 // Removes |pending_observer_ids| from |pending_observers_| if it is present.
cmumford 2016/07/01 18:35:01 Nit: I think the comment is a little odd because p
palakj1 2016/07/02 00:48:14 Done.
70 void RemovePendingObservers(const std::vector<int32_t>& pending_observer_ids);
71
66 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { 72 IndexedDBBackingStore::Transaction* BackingStoreTransaction() {
67 return transaction_.get(); 73 return transaction_.get();
68 } 74 }
69 int64_t id() const { return id_; } 75 int64_t id() const { return id_; }
70 76
71 IndexedDBDatabase* database() const { return database_.get(); } 77 IndexedDBDatabase* database() const { return database_.get(); }
72 IndexedDBDatabaseCallbacks* connection() const { return callbacks_.get(); } 78 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
cmumford 2016/07/01 18:35:01 Thanks for fixing this incorrect name.
79 IndexedDBConnection* connection() const { return connection_.get(); }
73 80
74 State state() const { return state_; } 81 State state() const { return state_; }
75 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); } 82 bool IsTimeoutTimerRunning() const { return timeout_timer_.IsRunning(); }
76 83
77 struct Diagnostics { 84 struct Diagnostics {
78 base::Time creation_time; 85 base::Time creation_time;
79 base::Time start_time; 86 base::Time start_time;
80 int tasks_scheduled; 87 int tasks_scheduled;
81 int tasks_completed; 88 int tasks_completed;
82 }; 89 };
83 90
84 const Diagnostics& diagnostics() const { return diagnostics_; } 91 const Diagnostics& diagnostics() const { return diagnostics_; }
85 92
86 protected: 93 protected:
87 // Test classes may derive, but most creation should be done via 94 // Test classes may derive, but most creation should be done via
88 // IndexedDBClassFactory. 95 // IndexedDBClassFactory.
89 IndexedDBTransaction( 96 IndexedDBTransaction(
90 int64_t id, 97 int64_t id,
91 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks, 98 base::WeakPtr<IndexedDBConnection> connection,
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,
95 IndexedDBBackingStore::Transaction* backing_store_transaction); 101 IndexedDBBackingStore::Transaction* backing_store_transaction);
96 virtual ~IndexedDBTransaction(); 102 virtual ~IndexedDBTransaction();
97 103
98 // May be overridden in tests. 104 // May be overridden in tests.
99 virtual base::TimeDelta GetInactivityTimeout() const; 105 virtual base::TimeDelta GetInactivityTimeout() const;
100 106
101 private: 107 private:
102 friend class BlobWriteCallbackImpl; 108 friend class BlobWriteCallbackImpl;
103 friend class IndexedDBClassFactory; 109 friend class IndexedDBClassFactory;
104 friend class base::RefCounted<IndexedDBTransaction>; 110 friend class base::RefCounted<IndexedDBTransaction>;
105 111
106 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive); 112 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortPreemptive);
107 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks); 113 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, AbortTasks);
108 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly); 114 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, NoTimeoutReadOnly);
109 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, 115 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest,
110 SchedulePreemptiveTask); 116 SchedulePreemptiveTask);
111 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode, 117 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTestMode,
112 ScheduleNormalTask); 118 ScheduleNormalTask);
113 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout); 119 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, Timeout);
120 FRIEND_TEST_ALL_PREFIXES(IndexedDBTransactionTest, IndexedDBObserver);
114 121
115 void RunTasksIfStarted(); 122 void RunTasksIfStarted();
116 123
117 bool IsTaskQueueEmpty() const; 124 bool IsTaskQueueEmpty() const;
118 bool HasPendingTasks() const; 125 bool HasPendingTasks() const;
119 126
120 void BlobWriteComplete(bool success); 127 void BlobWriteComplete(bool success);
121 void ProcessTaskQueue(); 128 void ProcessTaskQueue();
122 void CloseOpenCursors(); 129 void CloseOpenCursors();
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_;
141 // TODO(palakj): Eliminate callbacks_ and database_ as we already have
cmumford 2016/07/01 18:35:01 Same on this TODO - it'd be great to consolidate t
palakj1 2016/07/02 00:48:14 I am not sure if I can eliminate these. callbacks_
142 // connection_.
133 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 143 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
134 scoped_refptr<IndexedDBDatabase> database_; 144 scoped_refptr<IndexedDBDatabase> database_;
135 145
146 // These observers do not listen to changes until they are activated.
cmumford 2016/07/01 18:35:01 Nit: delete "They" and "they are".
palakj1 2016/07/02 00:48:14 Done.
147 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_;
148
136 class TaskQueue { 149 class TaskQueue {
137 public: 150 public:
138 TaskQueue(); 151 TaskQueue();
139 ~TaskQueue(); 152 ~TaskQueue();
140 bool empty() const { return queue_.empty(); } 153 bool empty() const { return queue_.empty(); }
141 void push(Operation task) { queue_.push(task); } 154 void push(Operation task) { queue_.push(task); }
142 Operation pop(); 155 Operation pop();
143 void clear(); 156 void clear();
144 157
145 private: 158 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 192 // requests are processed before the timer fires, assume the script is
180 // unresponsive and abort to unblock the transaction queue. 193 // unresponsive and abort to unblock the transaction queue.
181 base::OneShotTimer timeout_timer_; 194 base::OneShotTimer timeout_timer_;
182 195
183 Diagnostics diagnostics_; 196 Diagnostics diagnostics_;
184 }; 197 };
185 198
186 } // namespace content 199 } // namespace content
187 200
188 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ 201 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698