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

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

Powered by Google App Engine
This is Rietveld 408576698