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

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

Powered by Google App Engine
This is Rietveld 408576698