Chromium Code Reviews| 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_BACKING_STORE_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "content/browser/indexed_db/indexed_db.h" | 16 #include "content/browser/indexed_db/indexed_db.h" |
| 17 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" | |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 18 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 19 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
| 19 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 20 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
| 20 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 21 #include "content/common/indexed_db/indexed_db_key.h" | 22 #include "content/common/indexed_db/indexed_db_key.h" |
| 22 #include "content/common/indexed_db/indexed_db_key_path.h" | 23 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 23 #include "content/common/indexed_db/indexed_db_key_range.h" | 24 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 24 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 25 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 28 namespace base { | |
| 29 class TaskRunner; | |
| 30 } | |
| 31 | |
| 27 namespace content { | 32 namespace content { |
| 28 | 33 |
| 34 class IndexedDBFactory; | |
| 29 class LevelDBComparator; | 35 class LevelDBComparator; |
| 30 class LevelDBDatabase; | 36 class LevelDBDatabase; |
| 31 struct IndexedDBValue; | 37 struct IndexedDBValue; |
| 32 | 38 |
| 33 class LevelDBFactory { | 39 class LevelDBFactory { |
| 34 public: | 40 public: |
| 35 virtual ~LevelDBFactory() {} | 41 virtual ~LevelDBFactory() {} |
| 36 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, | 42 virtual leveldb::Status OpenLevelDB(const base::FilePath& file_name, |
| 37 const LevelDBComparator* comparator, | 43 const LevelDBComparator* comparator, |
| 38 scoped_ptr<LevelDBDatabase>* db, | 44 scoped_ptr<LevelDBDatabase>* db, |
| 39 bool* is_disk_full) = 0; | 45 bool* is_disk_full) = 0; |
| 40 virtual leveldb::Status DestroyLevelDB(const base::FilePath& file_name) = 0; | 46 virtual leveldb::Status DestroyLevelDB(const base::FilePath& file_name) = 0; |
| 41 }; | 47 }; |
| 42 | 48 |
| 43 class CONTENT_EXPORT IndexedDBBackingStore | 49 class CONTENT_EXPORT IndexedDBBackingStore |
| 44 : public base::RefCounted<IndexedDBBackingStore> { | 50 : public base::RefCounted<IndexedDBBackingStore> { |
| 45 public: | 51 public: |
| 46 class CONTENT_EXPORT Transaction; | 52 class CONTENT_EXPORT Transaction; |
| 47 | 53 |
| 48 const GURL& origin_url() const { return origin_url_; } | 54 const GURL& origin_url() const { return origin_url_; } |
| 55 IndexedDBFactory* factory() const { return indexed_db_factory_; } | |
| 56 base::TaskRunner* task_runner() const { return task_runner_; } | |
| 49 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { | 57 base::OneShotTimer<IndexedDBBackingStore>* close_timer() { |
| 50 return &close_timer_; | 58 return &close_timer_; |
| 51 } | 59 } |
| 60 IndexedDBActiveBlobRegistry* active_blob_registry() { | |
| 61 return &active_blob_registry_; | |
| 62 } | |
| 52 | 63 |
| 53 static scoped_refptr<IndexedDBBackingStore> Open( | 64 static scoped_refptr<IndexedDBBackingStore> Open( |
| 54 const GURL& origin_url, | 65 IndexedDBFactory* indexed_db_factory, |
| 55 const base::FilePath& path_base, | |
| 56 blink::WebIDBDataLoss* data_loss, | |
| 57 std::string* data_loss_message, | |
| 58 bool* disk_full); | |
| 59 | |
| 60 static scoped_refptr<IndexedDBBackingStore> Open( | |
| 61 const GURL& origin_url, | 66 const GURL& origin_url, |
| 62 const base::FilePath& path_base, | 67 const base::FilePath& path_base, |
| 63 blink::WebIDBDataLoss* data_loss, | 68 blink::WebIDBDataLoss* data_loss, |
| 64 std::string* data_loss_message, | 69 std::string* data_loss_message, |
| 65 bool* disk_full, | 70 bool* disk_full, |
| 66 LevelDBFactory* factory); | 71 base::TaskRunner* task_runner); |
| 67 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 72 |
| 68 const GURL& origin_url); | 73 static scoped_refptr<IndexedDBBackingStore> Open( |
| 74 IndexedDBFactory* indexed_db_factory, | |
| 75 const GURL& origin_url, | |
| 76 const base::FilePath& path_base, | |
| 77 blink::WebIDBDataLoss* data_loss, | |
| 78 std::string* data_loss_message, | |
| 79 bool* disk_full, | |
| 80 LevelDBFactory* leveldb_factory, | |
| 81 base::TaskRunner* task_runner); | |
| 69 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 82 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 70 const GURL& origin_url, | 83 const GURL& origin_url, |
| 71 LevelDBFactory* factory); | 84 base::TaskRunner* task_runner); |
| 85 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | |
| 86 const GURL& origin_url, | |
| 87 LevelDBFactory* level_db_factory, | |
| 88 base::TaskRunner* task_runner); | |
| 72 | 89 |
| 73 virtual std::vector<base::string16> GetDatabaseNames(); | 90 virtual std::vector<base::string16> GetDatabaseNames(); |
| 74 virtual leveldb::Status GetIDBDatabaseMetaData( | 91 virtual leveldb::Status GetIDBDatabaseMetaData( |
| 75 const base::string16& name, | 92 const base::string16& name, |
| 76 IndexedDBDatabaseMetadata* metadata, | 93 IndexedDBDatabaseMetadata* metadata, |
| 77 bool* success) WARN_UNUSED_RESULT; | 94 bool* success) WARN_UNUSED_RESULT; |
| 78 virtual leveldb::Status CreateIDBDatabaseMetaData( | 95 virtual leveldb::Status CreateIDBDatabaseMetaData( |
| 79 const base::string16& name, | 96 const base::string16& name, |
| 80 const base::string16& version, | 97 const base::string16& version, |
| 81 int64 int_version, | 98 int64 int_version, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; | 210 scoped_ptr<IndexedDBKey>* primary_key) WARN_UNUSED_RESULT; |
| 194 virtual leveldb::Status KeyExistsInIndex( | 211 virtual leveldb::Status KeyExistsInIndex( |
| 195 IndexedDBBackingStore::Transaction* transaction, | 212 IndexedDBBackingStore::Transaction* transaction, |
| 196 int64 database_id, | 213 int64 database_id, |
| 197 int64 object_store_id, | 214 int64 object_store_id, |
| 198 int64 index_id, | 215 int64 index_id, |
| 199 const IndexedDBKey& key, | 216 const IndexedDBKey& key, |
| 200 scoped_ptr<IndexedDBKey>* found_primary_key, | 217 scoped_ptr<IndexedDBKey>* found_primary_key, |
| 201 bool* exists) WARN_UNUSED_RESULT; | 218 bool* exists) WARN_UNUSED_RESULT; |
| 202 | 219 |
| 220 // Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. | |
| 221 virtual void ReportBlobUnused(int64 database_id, int64 blob_key); | |
| 222 | |
| 203 class Cursor { | 223 class Cursor { |
| 204 public: | 224 public: |
| 205 virtual ~Cursor(); | 225 virtual ~Cursor(); |
| 206 | 226 |
| 207 enum IteratorState { | 227 enum IteratorState { |
| 208 READY = 0, | 228 READY = 0, |
| 209 SEEK | 229 SEEK |
| 210 }; | 230 }; |
| 211 | 231 |
| 212 struct CursorOptions { | 232 struct CursorOptions { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 } | 319 } |
| 300 | 320 |
| 301 LevelDBTransaction* transaction() { return transaction_; } | 321 LevelDBTransaction* transaction() { return transaction_; } |
| 302 | 322 |
| 303 private: | 323 private: |
| 304 IndexedDBBackingStore* backing_store_; | 324 IndexedDBBackingStore* backing_store_; |
| 305 scoped_refptr<LevelDBTransaction> transaction_; | 325 scoped_refptr<LevelDBTransaction> transaction_; |
| 306 }; | 326 }; |
| 307 | 327 |
| 308 protected: | 328 protected: |
| 309 IndexedDBBackingStore(const GURL& origin_url, | 329 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
| 330 const GURL& origin_url, | |
| 310 scoped_ptr<LevelDBDatabase> db, | 331 scoped_ptr<LevelDBDatabase> db, |
| 311 scoped_ptr<LevelDBComparator> comparator); | 332 scoped_ptr<LevelDBComparator> comparator, |
| 333 base::TaskRunner* task_runner); | |
| 312 virtual ~IndexedDBBackingStore(); | 334 virtual ~IndexedDBBackingStore(); |
| 313 friend class base::RefCounted<IndexedDBBackingStore>; | 335 friend class base::RefCounted<IndexedDBBackingStore>; |
| 314 | 336 |
| 315 private: | 337 private: |
| 316 static scoped_refptr<IndexedDBBackingStore> Create( | 338 static scoped_refptr<IndexedDBBackingStore> Create( |
| 339 IndexedDBFactory* indexed_db_factory, | |
| 317 const GURL& origin_url, | 340 const GURL& origin_url, |
| 318 scoped_ptr<LevelDBDatabase> db, | 341 scoped_ptr<LevelDBDatabase> db, |
| 319 scoped_ptr<LevelDBComparator> comparator); | 342 scoped_ptr<LevelDBComparator> comparator, |
| 343 base::TaskRunner* task_runner); | |
| 320 | 344 |
| 321 leveldb::Status FindKeyInIndex( | 345 leveldb::Status FindKeyInIndex( |
| 322 IndexedDBBackingStore::Transaction* transaction, | 346 IndexedDBBackingStore::Transaction* transaction, |
| 323 int64 database_id, | 347 int64 database_id, |
| 324 int64 object_store_id, | 348 int64 object_store_id, |
| 325 int64 index_id, | 349 int64 index_id, |
| 326 const IndexedDBKey& key, | 350 const IndexedDBKey& key, |
| 327 std::string* found_encoded_primary_key, | 351 std::string* found_encoded_primary_key, |
| 328 bool* found); | 352 bool* found); |
| 329 leveldb::Status GetIndexes(int64 database_id, | 353 leveldb::Status GetIndexes(int64 database_id, |
| 330 int64 object_store_id, | 354 int64 object_store_id, |
| 331 IndexedDBObjectStoreMetadata::IndexMap* map) | 355 IndexedDBObjectStoreMetadata::IndexMap* map) |
| 332 WARN_UNUSED_RESULT; | 356 WARN_UNUSED_RESULT; |
| 333 | 357 |
| 358 IndexedDBFactory* indexed_db_factory_; | |
| 334 const GURL origin_url_; | 359 const GURL origin_url_; |
| 335 | 360 |
| 336 // The origin identifier is a key prefix unique to the origin used in the | 361 // The origin identifier is a key prefix unique to the origin used in the |
| 337 // leveldb backing store to partition data by origin. It is a normalized | 362 // leveldb backing store to partition data by origin. It is a normalized |
| 338 // version of the origin URL with a versioning suffix appended, e.g. | 363 // version of the origin URL with a versioning suffix appended, e.g. |
| 339 // "http_localhost_81@1" Since only one origin is stored per backing store | 364 // "http_localhost_81@1" Since only one origin is stored per backing store |
| 340 // this is redundant but necessary for backwards compatibility; the suffix | 365 // this is redundant but necessary for backwards compatibility; the suffix |
| 341 // provides for future flexibility. | 366 // provides for future flexibility. |
| 342 const std::string origin_identifier_; | 367 const std::string origin_identifier_; |
| 368 base::TaskRunner* task_runner_; | |
| 343 | 369 |
| 344 scoped_ptr<LevelDBDatabase> db_; | 370 scoped_ptr<LevelDBDatabase> db_; |
| 345 scoped_ptr<LevelDBComparator> comparator_; | 371 scoped_ptr<LevelDBComparator> comparator_; |
| 372 // The active_blob_registry_ will hold a refcount to this backing store | |
|
jsbell
2014/03/20 18:04:33
Does it?
ericu
2014/03/25 01:22:14
Fixed.
| |
| 373 // whenever any live blobs are registered with it. | |
| 374 IndexedDBActiveBlobRegistry active_blob_registry_; | |
| 346 base::OneShotTimer<IndexedDBBackingStore> close_timer_; | 375 base::OneShotTimer<IndexedDBBackingStore> close_timer_; |
| 347 }; | 376 }; |
| 348 | 377 |
| 349 } // namespace content | 378 } // namespace content |
| 350 | 379 |
| 351 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 380 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| OLD | NEW |