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/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_connection.h" |
22 #include "content/browser/indexed_db/indexed_db_database.h" | 22 #include "content/browser/indexed_db/indexed_db_database.h" |
23 #include "content/browser/indexed_db/indexed_db_database_error.h" | 23 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 24 #include "content/browser/indexed_db/indexed_db_observer.h" |
24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 class BlobWriteCallbackImpl; | 29 class BlobWriteCallbackImpl; |
29 class IndexedDBCursor; | 30 class IndexedDBCursor; |
30 class IndexedDBDatabaseCallbacks; | 31 class IndexedDBDatabaseCallbacks; |
31 class IndexedDBObserver; | 32 class IndexedDBObservation; |
| 33 class IndexedDBObserverChanges; |
32 | 34 |
33 class CONTENT_EXPORT IndexedDBTransaction | 35 class CONTENT_EXPORT IndexedDBTransaction |
34 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { | 36 : public NON_EXPORTED_BASE(base::RefCounted<IndexedDBTransaction>) { |
35 public: | 37 public: |
36 typedef base::Callback<void(IndexedDBTransaction*)> Operation; | 38 typedef base::Callback<void(IndexedDBTransaction*)> Operation; |
37 | 39 |
38 enum State { | 40 enum State { |
39 CREATED, // Created, but not yet started by coordinator. | 41 CREATED, // Created, but not yet started by coordinator. |
40 STARTED, // Started by the coordinator. | 42 STARTED, // Started by the coordinator. |
41 COMMITTING, // In the process of committing, possibly waiting for blobs | 43 COMMITTING, // In the process of committing, possibly waiting for blobs |
(...skipping 16 matching lines...) Expand all Loading... |
58 } | 60 } |
59 void ScheduleTask(blink::WebIDBTaskType, Operation task); | 61 void ScheduleTask(blink::WebIDBTaskType, Operation task); |
60 void ScheduleAbortTask(Operation abort_task); | 62 void ScheduleAbortTask(Operation abort_task); |
61 void RegisterOpenCursor(IndexedDBCursor* cursor); | 63 void RegisterOpenCursor(IndexedDBCursor* cursor); |
62 void UnregisterOpenCursor(IndexedDBCursor* cursor); | 64 void UnregisterOpenCursor(IndexedDBCursor* cursor); |
63 void AddPreemptiveEvent() { pending_preemptive_events_++; } | 65 void AddPreemptiveEvent() { pending_preemptive_events_++; } |
64 void DidCompletePreemptiveEvent() { | 66 void DidCompletePreemptiveEvent() { |
65 pending_preemptive_events_--; | 67 pending_preemptive_events_--; |
66 DCHECK_GE(pending_preemptive_events_, 0); | 68 DCHECK_GE(pending_preemptive_events_, 0); |
67 } | 69 } |
68 void AddPendingObserver(int32_t observer_id); | 70 void AddPendingObserver(int32_t observer_id, |
| 71 const IndexedDBObserver::Options& options); |
69 // Delete pending observers with ID's listed in |pending_observer_ids|. | 72 // Delete pending observers with ID's listed in |pending_observer_ids|. |
70 void RemovePendingObservers(const std::vector<int32_t>& pending_observer_ids); | 73 void RemovePendingObservers(const std::vector<int32_t>& pending_observer_ids); |
71 | 74 |
| 75 // Adds observation for the connection. |
| 76 void AddObservation(int32_t connection_id, |
| 77 std::unique_ptr<IndexedDBObservation>); |
| 78 // Adds the last observation index to observer_id's list of recorded |
| 79 // observation indices. |
| 80 void RecordObserverForLastObservation(int32_t connection_id, |
| 81 int32_t observer_id); |
| 82 |
72 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { | 83 IndexedDBBackingStore::Transaction* BackingStoreTransaction() { |
73 return transaction_.get(); | 84 return transaction_.get(); |
74 } | 85 } |
75 int64_t id() const { return id_; } | 86 int64_t id() const { return id_; } |
76 | 87 |
77 IndexedDBDatabase* database() const { return database_.get(); } | 88 IndexedDBDatabase* database() const { return database_.get(); } |
78 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 89 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } |
79 IndexedDBConnection* connection() const { return connection_.get(); } | 90 IndexedDBConnection* connection() const { return connection_.get(); } |
80 | 91 |
81 State state() const { return state_; } | 92 State state() const { return state_; } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 147 |
137 bool used_; | 148 bool used_; |
138 State state_; | 149 State state_; |
139 bool commit_pending_; | 150 bool commit_pending_; |
140 base::WeakPtr<IndexedDBConnection> connection_; | 151 base::WeakPtr<IndexedDBConnection> connection_; |
141 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 152 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
142 scoped_refptr<IndexedDBDatabase> database_; | 153 scoped_refptr<IndexedDBDatabase> database_; |
143 | 154 |
144 // Observers in pending queue do not listen to changes until activated. | 155 // Observers in pending queue do not listen to changes until activated. |
145 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; | 156 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers_; |
| 157 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> |
| 158 connection_changes_map_; |
146 | 159 |
147 class TaskQueue { | 160 class TaskQueue { |
148 public: | 161 public: |
149 TaskQueue(); | 162 TaskQueue(); |
150 ~TaskQueue(); | 163 ~TaskQueue(); |
151 bool empty() const { return queue_.empty(); } | 164 bool empty() const { return queue_.empty(); } |
152 void push(Operation task) { queue_.push(task); } | 165 void push(Operation task) { queue_.push(task); } |
153 Operation pop(); | 166 Operation pop(); |
154 void clear(); | 167 void clear(); |
155 | 168 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // requests are processed before the timer fires, assume the script is | 203 // requests are processed before the timer fires, assume the script is |
191 // unresponsive and abort to unblock the transaction queue. | 204 // unresponsive and abort to unblock the transaction queue. |
192 base::OneShotTimer timeout_timer_; | 205 base::OneShotTimer timeout_timer_; |
193 | 206 |
194 Diagnostics diagnostics_; | 207 Diagnostics diagnostics_; |
195 }; | 208 }; |
196 | 209 |
197 } // namespace content | 210 } // namespace content |
198 | 211 |
199 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ | 212 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_H_ |
OLD | NEW |