| 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_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 |
| 11 #include <list> | 11 #include <list> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <queue> | 14 #include <queue> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <utility> | 16 #include <utility> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "content/browser/indexed_db/indexed_db.h" | 21 #include "content/browser/indexed_db/indexed_db.h" |
| 22 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 22 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 23 #include "content/browser/indexed_db/indexed_db_callbacks.h" | |
| 24 #include "content/browser/indexed_db/indexed_db_metadata.h" | 23 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 25 #include "content/browser/indexed_db/indexed_db_observer.h" | 24 #include "content/browser/indexed_db/indexed_db_observer.h" |
| 26 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | |
| 27 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 25 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 28 #include "content/browser/indexed_db/list_set.h" | 26 #include "content/browser/indexed_db/list_set.h" |
| 29 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
| 30 | 28 |
| 31 namespace url { | 29 namespace url { |
| 32 class Origin; | 30 class Origin; |
| 33 } | 31 } |
| 34 | 32 |
| 35 namespace content { | 33 namespace content { |
| 36 | 34 |
| 37 class IndexedDBBlobInfo; | 35 class IndexedDBBlobInfo; |
| 36 class IndexedDBChangeHandler; |
| 38 class IndexedDBConnection; | 37 class IndexedDBConnection; |
| 39 class IndexedDBDatabaseCallbacks; | 38 class IndexedDBContext; |
| 39 class IndexedDBDatabaseError; |
| 40 class IndexedDBFactory; | 40 class IndexedDBFactory; |
| 41 class IndexedDBKey; | 41 class IndexedDBKey; |
| 42 class IndexedDBKeyPath; | 42 class IndexedDBKeyPath; |
| 43 class IndexedDBKeyRange; | 43 class IndexedDBKeyRange; |
| 44 class IndexedDBObservation; | 44 class IndexedDBObservation; |
| 45 class IndexedDBObserverChanges; | 45 class IndexedDBObserverChanges; |
| 46 class IndexedDBPendingConnection; |
| 47 class IndexedDBPendingDelete; |
| 46 class IndexedDBTransaction; | 48 class IndexedDBTransaction; |
| 47 struct IndexedDBValue; | 49 struct IndexedDBValue; |
| 48 | 50 |
| 49 class CONTENT_EXPORT IndexedDBDatabase | 51 class CONTENT_EXPORT IndexedDBDatabase |
| 50 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBDatabase>) { | 52 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBDatabase>) { |
| 51 public: | 53 public: |
| 52 // An index and corresponding set of keys | 54 // An index and corresponding set of keys |
| 53 using IndexKeys = std::pair<int64_t, std::vector<IndexedDBKey>>; | 55 using IndexKeys = std::pair<int64_t, std::vector<IndexedDBKey>>; |
| 54 | 56 |
| 55 // Identifier is pair of (origin, database name). | 57 // Identifier is pair of (origin, database name). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 73 | 75 |
| 74 void AddObjectStore(const IndexedDBObjectStoreMetadata& metadata, | 76 void AddObjectStore(const IndexedDBObjectStoreMetadata& metadata, |
| 75 int64_t new_max_object_store_id); | 77 int64_t new_max_object_store_id); |
| 76 void RemoveObjectStore(int64_t object_store_id); | 78 void RemoveObjectStore(int64_t object_store_id); |
| 77 void AddIndex(int64_t object_store_id, | 79 void AddIndex(int64_t object_store_id, |
| 78 const IndexedDBIndexMetadata& metadata, | 80 const IndexedDBIndexMetadata& metadata, |
| 79 int64_t new_max_index_id); | 81 int64_t new_max_index_id); |
| 80 void RemoveIndex(int64_t object_store_id, int64_t index_id); | 82 void RemoveIndex(int64_t object_store_id, int64_t index_id); |
| 81 | 83 |
| 82 void OpenConnection(std::unique_ptr<IndexedDBPendingConnection> connection); | 84 void OpenConnection(std::unique_ptr<IndexedDBPendingConnection> connection); |
| 83 void DeleteDatabase(scoped_refptr<IndexedDBCallbacks> callbacks); | 85 void DeleteDatabase(std::unique_ptr<IndexedDBPendingDelete> pending_delete); |
| 84 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; } | 86 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; } |
| 85 | 87 |
| 86 void CreateObjectStore(int64_t transaction_id, | 88 void CreateObjectStore(int64_t transaction_id, |
| 87 int64_t object_store_id, | 89 int64_t object_store_id, |
| 88 const base::string16& name, | 90 const base::string16& name, |
| 89 const IndexedDBKeyPath& key_path, | 91 const IndexedDBKeyPath& key_path, |
| 90 bool auto_increment); | 92 bool auto_increment); |
| 91 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); | 93 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); |
| 92 | 94 |
| 93 // Returns a pointer to a newly created transaction. The object is owned | 95 // Returns a pointer to a newly created transaction. The object is owned |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 int64_t object_store_id, | 145 int64_t object_store_id, |
| 144 blink::WebIDBOperationType type, | 146 blink::WebIDBOperationType type, |
| 145 const IndexedDBKeyRange& key_range); | 147 const IndexedDBKeyRange& key_range); |
| 146 void SendObservations( | 148 void SendObservations( |
| 147 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> change_map); | 149 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> change_map); |
| 148 | 150 |
| 149 void Get(int64_t transaction_id, | 151 void Get(int64_t transaction_id, |
| 150 int64_t object_store_id, | 152 int64_t object_store_id, |
| 151 int64_t index_id, | 153 int64_t index_id, |
| 152 std::unique_ptr<IndexedDBKeyRange> key_range, | 154 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 153 bool key_only, | 155 bool key_only); |
| 154 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 155 void GetAll(int64_t transaction_id, | 156 void GetAll(int64_t transaction_id, |
| 156 int64_t object_store_id, | 157 int64_t object_store_id, |
| 157 int64_t index_id, | 158 int64_t index_id, |
| 158 std::unique_ptr<IndexedDBKeyRange> key_range, | 159 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 159 bool key_only, | 160 bool key_only, |
| 160 int64_t max_count, | 161 int64_t max_count); |
| 161 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 162 void Put(int64_t transaction_id, | 162 void Put(int64_t transaction_id, |
| 163 int64_t object_store_id, | 163 int64_t object_store_id, |
| 164 IndexedDBValue* value, | 164 IndexedDBValue* value, |
| 165 ScopedVector<storage::BlobDataHandle>* handles, | 165 ScopedVector<storage::BlobDataHandle>* handles, |
| 166 std::unique_ptr<IndexedDBKey> key, | 166 std::unique_ptr<IndexedDBKey> key, |
| 167 blink::WebIDBPutMode mode, | 167 blink::WebIDBPutMode mode, |
| 168 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 169 const std::vector<IndexKeys>& index_keys); | 168 const std::vector<IndexKeys>& index_keys); |
| 170 void SetIndexKeys(int64_t transaction_id, | 169 void SetIndexKeys(int64_t transaction_id, |
| 171 int64_t object_store_id, | 170 int64_t object_store_id, |
| 172 std::unique_ptr<IndexedDBKey> primary_key, | 171 std::unique_ptr<IndexedDBKey> primary_key, |
| 173 const std::vector<IndexKeys>& index_keys); | 172 const std::vector<IndexKeys>& index_keys); |
| 174 void SetIndexesReady(int64_t transaction_id, | 173 void SetIndexesReady(int64_t transaction_id, |
| 175 int64_t object_store_id, | 174 int64_t object_store_id, |
| 176 const std::vector<int64_t>& index_ids); | 175 const std::vector<int64_t>& index_ids); |
| 177 void OpenCursor(int64_t transaction_id, | 176 void OpenCursor(int64_t transaction_id, |
| 178 int64_t object_store_id, | 177 int64_t object_store_id, |
| 179 int64_t index_id, | 178 int64_t index_id, |
| 180 std::unique_ptr<IndexedDBKeyRange> key_range, | 179 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 181 blink::WebIDBCursorDirection, | 180 blink::WebIDBCursorDirection, |
| 182 bool key_only, | 181 bool key_only, |
| 183 blink::WebIDBTaskType task_type, | 182 blink::WebIDBTaskType task_type); |
| 184 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 185 void Count(int64_t transaction_id, | 183 void Count(int64_t transaction_id, |
| 186 int64_t object_store_id, | 184 int64_t object_store_id, |
| 187 int64_t index_id, | 185 int64_t index_id, |
| 188 std::unique_ptr<IndexedDBKeyRange> key_range, | 186 std::unique_ptr<IndexedDBKeyRange> key_range); |
| 189 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 190 void DeleteRange(int64_t transaction_id, | 187 void DeleteRange(int64_t transaction_id, |
| 191 int64_t object_store_id, | 188 int64_t object_store_id, |
| 192 std::unique_ptr<IndexedDBKeyRange> key_range, | 189 std::unique_ptr<IndexedDBKeyRange> key_range); |
| 193 scoped_refptr<IndexedDBCallbacks> callbacks); | 190 void Clear(int64_t transaction_id, int64_t object_store_id); |
| 194 void Clear(int64_t transaction_id, | |
| 195 int64_t object_store_id, | |
| 196 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 197 | 191 |
| 198 // Number of connections that have progressed passed initial open call. | 192 // Number of connections that have progressed passed initial open call. |
| 199 size_t ConnectionCount() const { return connections_.size(); } | 193 size_t ConnectionCount() const { return connections_.size(); } |
| 200 | 194 |
| 201 // Number of active open/delete calls (running or blocked on other | 195 // Number of active open/delete calls (running or blocked on other |
| 202 // connections). | 196 // connections). |
| 203 size_t ActiveOpenDeleteCount() const { return active_request_ ? 1 : 0; } | 197 size_t ActiveOpenDeleteCount() const { return active_request_ ? 1 : 0; } |
| 204 | 198 |
| 205 // Number of open/delete calls that are waiting their turn. | 199 // Number of open/delete calls that are waiting their turn. |
| 206 size_t PendingOpenDeleteCount() const { return pending_requests_.size(); } | 200 size_t PendingOpenDeleteCount() const { return pending_requests_.size(); } |
| 207 | 201 |
| 208 // Asynchronous tasks scheduled within transactions: | 202 // Asynchronous tasks scheduled within transactions: |
| 209 void CreateObjectStoreAbortOperation(int64_t object_store_id, | 203 void CreateObjectStoreAbortOperation(int64_t object_store_id, |
| 210 IndexedDBTransaction* transaction); | 204 IndexedDBTransaction* transaction); |
| 211 void DeleteObjectStoreOperation(int64_t object_store_id, | 205 void DeleteObjectStoreOperation(int64_t object_store_id, |
| 212 IndexedDBTransaction* transaction); | 206 IndexedDBTransaction* transaction); |
| 213 void DeleteObjectStoreAbortOperation( | 207 void DeleteObjectStoreAbortOperation( |
| 214 const IndexedDBObjectStoreMetadata& object_store_metadata, | 208 const IndexedDBObjectStoreMetadata& object_store_metadata, |
| 215 IndexedDBTransaction* transaction); | 209 IndexedDBTransaction* transaction); |
| 216 void VersionChangeOperation(int64_t version, | 210 void VersionChangeOperation( |
| 217 scoped_refptr<IndexedDBCallbacks> callbacks, | 211 const IndexedDBPendingConnection* pending_connection, |
| 218 IndexedDBTransaction* transaction); | 212 IndexedDBTransaction* transaction); |
| 219 void VersionChangeAbortOperation(int64_t previous_version, | 213 void VersionChangeAbortOperation(int64_t previous_version, |
| 220 IndexedDBTransaction* transaction); | 214 IndexedDBTransaction* transaction); |
| 221 void DeleteIndexOperation(int64_t object_store_id, | 215 void DeleteIndexOperation(int64_t object_store_id, |
| 222 int64_t index_id, | 216 int64_t index_id, |
| 223 IndexedDBTransaction* transaction); | 217 IndexedDBTransaction* transaction); |
| 224 void CreateIndexAbortOperation(int64_t object_store_id, | 218 void CreateIndexAbortOperation(int64_t object_store_id, |
| 225 int64_t index_id, | 219 int64_t index_id, |
| 226 IndexedDBTransaction* transaction); | 220 IndexedDBTransaction* transaction); |
| 227 void DeleteIndexAbortOperation(int64_t object_store_id, | 221 void DeleteIndexAbortOperation(int64_t object_store_id, |
| 228 const IndexedDBIndexMetadata& index_metadata, | 222 const IndexedDBIndexMetadata& index_metadata, |
| 229 IndexedDBTransaction* transaction); | 223 IndexedDBTransaction* transaction); |
| 230 void GetOperation(int64_t object_store_id, | 224 void GetOperation(int64_t object_store_id, |
| 231 int64_t index_id, | 225 int64_t index_id, |
| 232 std::unique_ptr<IndexedDBKeyRange> key_range, | 226 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 233 indexed_db::CursorType cursor_type, | 227 indexed_db::CursorType cursor_type, |
| 234 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 235 IndexedDBTransaction* transaction); | 228 IndexedDBTransaction* transaction); |
| 236 void GetAllOperation(int64_t object_store_id, | 229 void GetAllOperation(int64_t object_store_id, |
| 237 int64_t index_id, | 230 int64_t index_id, |
| 238 std::unique_ptr<IndexedDBKeyRange> key_range, | 231 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 239 indexed_db::CursorType cursor_type, | 232 indexed_db::CursorType cursor_type, |
| 240 int64_t max_count, | 233 int64_t max_count, |
| 241 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 242 IndexedDBTransaction* transaction); | 234 IndexedDBTransaction* transaction); |
| 243 struct PutOperationParams; | 235 struct PutOperationParams; |
| 244 void PutOperation(std::unique_ptr<PutOperationParams> params, | 236 void PutOperation(std::unique_ptr<PutOperationParams> params, |
| 245 IndexedDBTransaction* transaction); | 237 IndexedDBTransaction* transaction); |
| 246 void SetIndexesReadyOperation(size_t index_count, | 238 void SetIndexesReadyOperation(size_t index_count, |
| 247 IndexedDBTransaction* transaction); | 239 IndexedDBTransaction* transaction); |
| 248 struct OpenCursorOperationParams; | 240 struct OpenCursorOperationParams; |
| 249 void OpenCursorOperation(std::unique_ptr<OpenCursorOperationParams> params, | 241 void OpenCursorOperation(std::unique_ptr<OpenCursorOperationParams> params, |
| 250 IndexedDBTransaction* transaction); | 242 IndexedDBTransaction* transaction); |
| 251 void CountOperation(int64_t object_store_id, | 243 void CountOperation(int64_t object_store_id, |
| 252 int64_t index_id, | 244 int64_t index_id, |
| 253 std::unique_ptr<IndexedDBKeyRange> key_range, | 245 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 254 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 255 IndexedDBTransaction* transaction); | 246 IndexedDBTransaction* transaction); |
| 256 void DeleteRangeOperation(int64_t object_store_id, | 247 void DeleteRangeOperation(int64_t object_store_id, |
| 257 std::unique_ptr<IndexedDBKeyRange> key_range, | 248 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 258 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 259 IndexedDBTransaction* transaction); | 249 IndexedDBTransaction* transaction); |
| 260 void ClearOperation(int64_t object_store_id, | 250 void ClearOperation(int64_t object_store_id, |
| 261 scoped_refptr<IndexedDBCallbacks> callbacks, | |
| 262 IndexedDBTransaction* transaction); | 251 IndexedDBTransaction* transaction); |
| 263 | 252 |
| 253 IndexedDBContext* context() const; |
| 254 |
| 264 protected: | 255 protected: |
| 265 IndexedDBDatabase(const base::string16& name, | 256 IndexedDBDatabase(const base::string16& name, |
| 266 IndexedDBBackingStore* backing_store, | 257 IndexedDBBackingStore* backing_store, |
| 267 IndexedDBFactory* factory, | 258 IndexedDBFactory* factory, |
| 268 const Identifier& unique_identifier); | 259 const Identifier& unique_identifier); |
| 269 virtual ~IndexedDBDatabase(); | 260 virtual ~IndexedDBDatabase(); |
| 270 | 261 |
| 271 // May be overridden in tests. | 262 // May be overridden in tests. |
| 272 virtual size_t GetMaxMessageSizeInBytes() const; | 263 virtual size_t GetMaxMessageSizeInBytes() const; |
| 273 | 264 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 287 | 278 |
| 288 // Called by requests when complete. The request will be freed, so the | 279 // Called by requests when complete. The request will be freed, so the |
| 289 // request must do no other work after calling this. If there are pending | 280 // request must do no other work after calling this. If there are pending |
| 290 // requests, the queue will be synchronously processed. | 281 // requests, the queue will be synchronously processed. |
| 291 void RequestComplete(ConnectionRequest* request); | 282 void RequestComplete(ConnectionRequest* request); |
| 292 | 283 |
| 293 // Pop the first request from the queue and start it. | 284 // Pop the first request from the queue and start it. |
| 294 void ProcessRequestQueue(); | 285 void ProcessRequestQueue(); |
| 295 | 286 |
| 296 std::unique_ptr<IndexedDBConnection> CreateConnection( | 287 std::unique_ptr<IndexedDBConnection> CreateConnection( |
| 297 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 288 scoped_refptr<IndexedDBChangeHandler> change_handler, |
| 298 int child_process_id); | 289 int child_process_id); |
| 299 | 290 |
| 300 IndexedDBTransaction* GetTransaction(int64_t transaction_id) const; | 291 IndexedDBTransaction* GetTransaction(int64_t transaction_id) const; |
| 301 | 292 |
| 302 bool ValidateObjectStoreId(int64_t object_store_id) const; | 293 bool ValidateObjectStoreId(int64_t object_store_id) const; |
| 303 bool ValidateObjectStoreIdAndIndexId(int64_t object_store_id, | 294 bool ValidateObjectStoreIdAndIndexId(int64_t object_store_id, |
| 304 int64_t index_id) const; | 295 int64_t index_id) const; |
| 305 bool ValidateObjectStoreIdAndOptionalIndexId(int64_t object_store_id, | 296 bool ValidateObjectStoreIdAndOptionalIndexId(int64_t object_store_id, |
| 306 int64_t index_id) const; | 297 int64_t index_id) const; |
| 307 bool ValidateObjectStoreIdAndNewIndexId(int64_t object_store_id, | 298 bool ValidateObjectStoreIdAndNewIndexId(int64_t object_store_id, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 335 bool processing_pending_requests_ = false; | 326 bool processing_pending_requests_ = false; |
| 336 | 327 |
| 337 bool experimental_web_platform_features_enabled_; | 328 bool experimental_web_platform_features_enabled_; |
| 338 | 329 |
| 339 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabase); | 330 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabase); |
| 340 }; | 331 }; |
| 341 | 332 |
| 342 } // namespace content | 333 } // namespace content |
| 343 | 334 |
| 344 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_ | 335 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_H_ |
| OLD | NEW |