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

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

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: comments Created 4 years 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_DATABASE_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 int64_t new_max_index_id); 75 int64_t new_max_index_id);
76 void RemoveIndex(int64_t object_store_id, int64_t index_id); 76 void RemoveIndex(int64_t object_store_id, int64_t index_id);
77 void SetIndexName(int64_t object_store_id, 77 void SetIndexName(int64_t object_store_id,
78 int64_t index_id, 78 int64_t index_id,
79 const base::string16& name); 79 const base::string16& name);
80 80
81 void OpenConnection(std::unique_ptr<IndexedDBPendingConnection> connection); 81 void OpenConnection(std::unique_ptr<IndexedDBPendingConnection> connection);
82 void DeleteDatabase(scoped_refptr<IndexedDBCallbacks> callbacks); 82 void DeleteDatabase(scoped_refptr<IndexedDBCallbacks> callbacks);
83 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; } 83 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; }
84 84
85 void CreateObjectStore(int64_t transaction_id, 85 void CreateObjectStore(IndexedDBTransaction* transaction,
86 int64_t object_store_id, 86 int64_t object_store_id,
87 const base::string16& name, 87 const base::string16& name,
88 const IndexedDBKeyPath& key_path, 88 const IndexedDBKeyPath& key_path,
89 bool auto_increment); 89 bool auto_increment);
90 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); 90 void DeleteObjectStore(IndexedDBTransaction* transaction,
91 void RenameObjectStore(int64_t transaction_id, 91 int64_t object_store_id);
92 void RenameObjectStore(IndexedDBTransaction* transaction,
92 int64_t object_store_id, 93 int64_t object_store_id,
93 const base::string16& new_name); 94 const base::string16& new_name);
94 95
95 // Returns a pointer to a newly created transaction. The object is owned 96 // Returns a pointer to a newly created transaction. The object is owned
96 // by |transaction_coordinator_|. 97 // by |transaction_coordinator_|.
97 IndexedDBTransaction* CreateTransaction( 98 IndexedDBTransaction* CreateTransaction(
98 int64_t transaction_id, 99 int64_t transaction_id,
99 IndexedDBConnection* connection, 100 IndexedDBConnection* connection,
100 const std::vector<int64_t>& object_store_ids, 101 const std::vector<int64_t>& object_store_ids,
101 blink::WebIDBTransactionMode mode); 102 blink::WebIDBTransactionMode mode);
102 void Close(IndexedDBConnection* connection, bool forced); 103 void Close(IndexedDBConnection* connection, bool forced);
103 void ForceClose(); 104 void ForceClose();
104 105
105 // Ack that one of the connections notified with a "versionchange" event did 106 // Ack that one of the connections notified with a "versionchange" event did
106 // not promptly close. Therefore a "blocked" event should be fired at the 107 // not promptly close. Therefore a "blocked" event should be fired at the
107 // pending connection. 108 // pending connection.
108 void VersionChangeIgnored(); 109 void VersionChangeIgnored();
109 110
110 void Commit(int64_t transaction_id); 111 void Commit(IndexedDBTransaction* transaction);
111 void Abort(int64_t transaction_id);
112 void Abort(int64_t transaction_id, const IndexedDBDatabaseError& error);
113 112
114 void CreateIndex(int64_t transaction_id, 113 void CreateIndex(IndexedDBTransaction* transaction,
115 int64_t object_store_id, 114 int64_t object_store_id,
116 int64_t index_id, 115 int64_t index_id,
117 const base::string16& name, 116 const base::string16& name,
118 const IndexedDBKeyPath& key_path, 117 const IndexedDBKeyPath& key_path,
119 bool unique, 118 bool unique,
120 bool multi_entry); 119 bool multi_entry);
121 void DeleteIndex(int64_t transaction_id, 120 void DeleteIndex(IndexedDBTransaction* transaction,
122 int64_t object_store_id, 121 int64_t object_store_id,
123 int64_t index_id); 122 int64_t index_id);
124 void RenameIndex(int64_t transaction_id, 123 void RenameIndex(IndexedDBTransaction* transaction,
125 int64_t object_store_id, 124 int64_t object_store_id,
126 int64_t index_id, 125 int64_t index_id,
127 const base::string16& new_name); 126 const base::string16& new_name);
128 127
129 IndexedDBTransactionCoordinator& transaction_coordinator() { 128 IndexedDBTransactionCoordinator& transaction_coordinator() {
130 return transaction_coordinator_; 129 return transaction_coordinator_;
131 } 130 }
132 const IndexedDBTransactionCoordinator& transaction_coordinator() const { 131 const IndexedDBTransactionCoordinator& transaction_coordinator() const {
133 return transaction_coordinator_; 132 return transaction_coordinator_;
134 } 133 }
135 134
136 void TransactionCreated(IndexedDBTransaction* transaction); 135 void TransactionCreated(IndexedDBTransaction* transaction);
137 void TransactionFinished(IndexedDBTransaction* transaction, bool committed); 136 void TransactionFinished(IndexedDBTransaction* transaction, bool committed);
138 137
139 void AddPendingObserver(int64_t transaction_id, 138 void AddPendingObserver(IndexedDBTransaction* transaction,
140 int32_t observer_id, 139 int32_t observer_id,
141 const IndexedDBObserver::Options& options); 140 const IndexedDBObserver::Options& options);
142 void RemovePendingObservers(IndexedDBConnection* connection,
143 const std::vector<int32_t>& pending_observer_ids);
144 141
145 void FilterObservation(IndexedDBTransaction*, 142 void FilterObservation(IndexedDBTransaction*,
146 int64_t object_store_id, 143 int64_t object_store_id,
147 blink::WebIDBOperationType type, 144 blink::WebIDBOperationType type,
148 const IndexedDBKeyRange& key_range); 145 const IndexedDBKeyRange& key_range);
149 void SendObservations( 146 void SendObservations(
150 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> change_map); 147 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> change_map);
151 148
152 void Get(int64_t transaction_id, 149 void Get(IndexedDBTransaction* transaction,
153 int64_t object_store_id, 150 int64_t object_store_id,
154 int64_t index_id, 151 int64_t index_id,
155 std::unique_ptr<IndexedDBKeyRange> key_range, 152 std::unique_ptr<IndexedDBKeyRange> key_range,
156 bool key_only, 153 bool key_only,
157 scoped_refptr<IndexedDBCallbacks> callbacks); 154 scoped_refptr<IndexedDBCallbacks> callbacks);
158 void GetAll(int64_t transaction_id, 155 void GetAll(IndexedDBTransaction* transaction,
159 int64_t object_store_id, 156 int64_t object_store_id,
160 int64_t index_id, 157 int64_t index_id,
161 std::unique_ptr<IndexedDBKeyRange> key_range, 158 std::unique_ptr<IndexedDBKeyRange> key_range,
162 bool key_only, 159 bool key_only,
163 int64_t max_count, 160 int64_t max_count,
164 scoped_refptr<IndexedDBCallbacks> callbacks); 161 scoped_refptr<IndexedDBCallbacks> callbacks);
165 void Put(int64_t transaction_id, 162 void Put(IndexedDBTransaction* transaction,
166 int64_t object_store_id, 163 int64_t object_store_id,
167 IndexedDBValue* value, 164 IndexedDBValue* value,
168 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles, 165 std::vector<std::unique_ptr<storage::BlobDataHandle>>* handles,
169 std::unique_ptr<IndexedDBKey> key, 166 std::unique_ptr<IndexedDBKey> key,
170 blink::WebIDBPutMode mode, 167 blink::WebIDBPutMode mode,
171 scoped_refptr<IndexedDBCallbacks> callbacks, 168 scoped_refptr<IndexedDBCallbacks> callbacks,
172 const std::vector<IndexedDBIndexKeys>& index_keys); 169 const std::vector<IndexedDBIndexKeys>& index_keys);
173 void SetIndexKeys(int64_t transaction_id, 170 void SetIndexKeys(IndexedDBTransaction* transaction,
174 int64_t object_store_id, 171 int64_t object_store_id,
175 std::unique_ptr<IndexedDBKey> primary_key, 172 std::unique_ptr<IndexedDBKey> primary_key,
176 const std::vector<IndexedDBIndexKeys>& index_keys); 173 const std::vector<IndexedDBIndexKeys>& index_keys);
177 void SetIndexesReady(int64_t transaction_id, 174 void SetIndexesReady(IndexedDBTransaction* transaction,
178 int64_t object_store_id, 175 int64_t object_store_id,
179 const std::vector<int64_t>& index_ids); 176 const std::vector<int64_t>& index_ids);
180 void OpenCursor(int64_t transaction_id, 177 void OpenCursor(IndexedDBTransaction* transaction,
181 int64_t object_store_id, 178 int64_t object_store_id,
182 int64_t index_id, 179 int64_t index_id,
183 std::unique_ptr<IndexedDBKeyRange> key_range, 180 std::unique_ptr<IndexedDBKeyRange> key_range,
184 blink::WebIDBCursorDirection, 181 blink::WebIDBCursorDirection,
185 bool key_only, 182 bool key_only,
186 blink::WebIDBTaskType task_type, 183 blink::WebIDBTaskType task_type,
187 scoped_refptr<IndexedDBCallbacks> callbacks); 184 scoped_refptr<IndexedDBCallbacks> callbacks);
188 void Count(int64_t transaction_id, 185 void Count(IndexedDBTransaction* transaction,
189 int64_t object_store_id, 186 int64_t object_store_id,
190 int64_t index_id, 187 int64_t index_id,
191 std::unique_ptr<IndexedDBKeyRange> key_range, 188 std::unique_ptr<IndexedDBKeyRange> key_range,
192 scoped_refptr<IndexedDBCallbacks> callbacks); 189 scoped_refptr<IndexedDBCallbacks> callbacks);
193 void DeleteRange(int64_t transaction_id, 190 void DeleteRange(IndexedDBTransaction* transaction,
194 int64_t object_store_id, 191 int64_t object_store_id,
195 std::unique_ptr<IndexedDBKeyRange> key_range, 192 std::unique_ptr<IndexedDBKeyRange> key_range,
196 scoped_refptr<IndexedDBCallbacks> callbacks); 193 scoped_refptr<IndexedDBCallbacks> callbacks);
197 void Clear(int64_t transaction_id, 194 void Clear(IndexedDBTransaction* transaction,
198 int64_t object_store_id, 195 int64_t object_store_id,
199 scoped_refptr<IndexedDBCallbacks> callbacks); 196 scoped_refptr<IndexedDBCallbacks> callbacks);
200 197
201 // Number of connections that have progressed passed initial open call. 198 // Number of connections that have progressed passed initial open call.
202 size_t ConnectionCount() const { return connections_.size(); } 199 size_t ConnectionCount() const { return connections_.size(); }
203 200
204 // Number of active open/delete calls (running or blocked on other 201 // Number of active open/delete calls (running or blocked on other
205 // connections). 202 // connections).
206 size_t ActiveOpenDeleteCount() const { return active_request_ ? 1 : 0; } 203 size_t ActiveOpenDeleteCount() const { return active_request_ ? 1 : 0; }
207 204
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // requests, the queue will be synchronously processed. 296 // requests, the queue will be synchronously processed.
300 void RequestComplete(ConnectionRequest* request); 297 void RequestComplete(ConnectionRequest* request);
301 298
302 // Pop the first request from the queue and start it. 299 // Pop the first request from the queue and start it.
303 void ProcessRequestQueue(); 300 void ProcessRequestQueue();
304 301
305 std::unique_ptr<IndexedDBConnection> CreateConnection( 302 std::unique_ptr<IndexedDBConnection> CreateConnection(
306 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 303 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
307 int child_process_id); 304 int child_process_id);
308 305
309 IndexedDBTransaction* GetTransaction(int64_t transaction_id) const;
310
311 bool ValidateObjectStoreId(int64_t object_store_id) const; 306 bool ValidateObjectStoreId(int64_t object_store_id) const;
312 bool ValidateObjectStoreIdAndIndexId(int64_t object_store_id, 307 bool ValidateObjectStoreIdAndIndexId(int64_t object_store_id,
313 int64_t index_id) const; 308 int64_t index_id) const;
314 bool ValidateObjectStoreIdAndOptionalIndexId(int64_t object_store_id, 309 bool ValidateObjectStoreIdAndOptionalIndexId(int64_t object_store_id,
315 int64_t index_id) const; 310 int64_t index_id) const;
316 bool ValidateObjectStoreIdAndNewIndexId(int64_t object_store_id, 311 bool ValidateObjectStoreIdAndNewIndexId(int64_t object_store_id,
317 int64_t index_id) const; 312 int64_t index_id) const;
318 313
319 scoped_refptr<IndexedDBBackingStore> backing_store_; 314 scoped_refptr<IndexedDBBackingStore> backing_store_;
320 IndexedDBDatabaseMetadata metadata_; 315 IndexedDBDatabaseMetadata metadata_;
321 316
322 const Identifier identifier_; 317 const Identifier identifier_;
323 scoped_refptr<IndexedDBFactory> factory_; 318 scoped_refptr<IndexedDBFactory> factory_;
324 319
325 IndexedDBTransactionCoordinator transaction_coordinator_; 320 IndexedDBTransactionCoordinator transaction_coordinator_;
326 321 int64_t transaction_count_ = 0;
327 std::map<int64_t, IndexedDBTransaction*> transactions_;
328 322
329 list_set<IndexedDBConnection*> connections_; 323 list_set<IndexedDBConnection*> connections_;
330 324
331 // This holds the first open or delete request that is currently being 325 // This holds the first open or delete request that is currently being
332 // processed. The request has already broadcast OnVersionChange if 326 // processed. The request has already broadcast OnVersionChange if
333 // necessary. 327 // necessary.
334 std::unique_ptr<ConnectionRequest> active_request_; 328 std::unique_ptr<ConnectionRequest> active_request_;
335 329
336 // This holds open or delete requests that are waiting for the active 330 // This holds open or delete requests that are waiting for the active
337 // request to be completed. The requests have not yet broadcast 331 // request to be completed. The requests have not yet broadcast
338 // OnVersionChange (if necessary). 332 // OnVersionChange (if necessary).
339 std::queue<std::unique_ptr<ConnectionRequest>> pending_requests_; 333 std::queue<std::unique_ptr<ConnectionRequest>> pending_requests_;
340 334
341 // The |processing_pending_requests_| flag is set while ProcessRequestQueue() 335 // The |processing_pending_requests_| flag is set while ProcessRequestQueue()
342 // is executing. It prevents rentrant calls if the active request completes 336 // is executing. It prevents rentrant calls if the active request completes
343 // synchronously. 337 // synchronously.
344 bool processing_pending_requests_ = false; 338 bool processing_pending_requests_ = false;
345 339
346 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabase); 340 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabase);
347 }; 341 };
348 342
349 } // namespace content 343 } // namespace content
350 344
351 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_ 345 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698