| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "content/browser/indexed_db/indexed_db_metadata.h" | 29 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 30 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 30 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
| 31 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 31 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
| 32 #include "content/common/content_export.h" | 32 #include "content/common/content_export.h" |
| 33 #include "content/common/indexed_db/indexed_db_key.h" | 33 #include "content/common/indexed_db/indexed_db_key.h" |
| 34 #include "content/common/indexed_db/indexed_db_key_path.h" | 34 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 35 #include "content/common/indexed_db/indexed_db_key_range.h" | 35 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 36 #include "storage/browser/blob/blob_data_handle.h" | 36 #include "storage/browser/blob/blob_data_handle.h" |
| 37 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 37 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
| 39 #include "url/origin.h" |
| 39 | 40 |
| 40 namespace base { | 41 namespace base { |
| 41 class SequencedTaskRunner; | 42 class SequencedTaskRunner; |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace storage { | 45 namespace storage { |
| 45 class FileWriterDelegate; | 46 class FileWriterDelegate; |
| 46 } | 47 } |
| 47 | 48 |
| 48 namespace net { | 49 namespace net { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // case has additional complexity of not being symmetric with | 353 // case has additional complexity of not being symmetric with |
| 353 // NextNoDuplicate. | 354 // NextNoDuplicate. |
| 354 bool ContinuePrevious(const IndexedDBKey* key, | 355 bool ContinuePrevious(const IndexedDBKey* key, |
| 355 const IndexedDBKey* primary_key, | 356 const IndexedDBKey* primary_key, |
| 356 IteratorState state, | 357 IteratorState state, |
| 357 leveldb::Status*); | 358 leveldb::Status*); |
| 358 | 359 |
| 359 DISALLOW_COPY_AND_ASSIGN(Cursor); | 360 DISALLOW_COPY_AND_ASSIGN(Cursor); |
| 360 }; | 361 }; |
| 361 | 362 |
| 362 const GURL& origin_url() const { return origin_url_; } | 363 const url::Origin& origin() const { return origin_; } |
| 363 IndexedDBFactory* factory() const { return indexed_db_factory_; } | 364 IndexedDBFactory* factory() const { return indexed_db_factory_; } |
| 364 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } | 365 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } |
| 365 base::OneShotTimer* close_timer() { return &close_timer_; } | 366 base::OneShotTimer* close_timer() { return &close_timer_; } |
| 366 IndexedDBActiveBlobRegistry* active_blob_registry() { | 367 IndexedDBActiveBlobRegistry* active_blob_registry() { |
| 367 return &active_blob_registry_; | 368 return &active_blob_registry_; |
| 368 } | 369 } |
| 369 | 370 |
| 370 static scoped_refptr<IndexedDBBackingStore> Open( | 371 static scoped_refptr<IndexedDBBackingStore> Open( |
| 371 IndexedDBFactory* indexed_db_factory, | 372 IndexedDBFactory* indexed_db_factory, |
| 372 const GURL& origin_url, | 373 const url::Origin& origin, |
| 373 const base::FilePath& path_base, | 374 const base::FilePath& path_base, |
| 374 net::URLRequestContext* request_context, | 375 net::URLRequestContext* request_context, |
| 375 blink::WebIDBDataLoss* data_loss, | 376 blink::WebIDBDataLoss* data_loss, |
| 376 std::string* data_loss_message, | 377 std::string* data_loss_message, |
| 377 bool* disk_full, | 378 bool* disk_full, |
| 378 base::SequencedTaskRunner* task_runner, | 379 base::SequencedTaskRunner* task_runner, |
| 379 bool clean_journal, | 380 bool clean_journal, |
| 380 leveldb::Status* status); | 381 leveldb::Status* status); |
| 381 static scoped_refptr<IndexedDBBackingStore> Open( | 382 static scoped_refptr<IndexedDBBackingStore> Open( |
| 382 IndexedDBFactory* indexed_db_factory, | 383 IndexedDBFactory* indexed_db_factory, |
| 383 const GURL& origin_url, | 384 const url::Origin& origin, |
| 384 const base::FilePath& path_base, | 385 const base::FilePath& path_base, |
| 385 net::URLRequestContext* request_context, | 386 net::URLRequestContext* request_context, |
| 386 blink::WebIDBDataLoss* data_loss, | 387 blink::WebIDBDataLoss* data_loss, |
| 387 std::string* data_loss_message, | 388 std::string* data_loss_message, |
| 388 bool* disk_full, | 389 bool* disk_full, |
| 389 LevelDBFactory* leveldb_factory, | 390 LevelDBFactory* leveldb_factory, |
| 390 base::SequencedTaskRunner* task_runner, | 391 base::SequencedTaskRunner* task_runner, |
| 391 bool clean_journal, | 392 bool clean_journal, |
| 392 leveldb::Status* status); | 393 leveldb::Status* status); |
| 393 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 394 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 394 const GURL& origin_url, | 395 const url::Origin& origin, |
| 395 base::SequencedTaskRunner* task_runner, | 396 base::SequencedTaskRunner* task_runner, |
| 396 leveldb::Status* status); | 397 leveldb::Status* status); |
| 397 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( | 398 static scoped_refptr<IndexedDBBackingStore> OpenInMemory( |
| 398 const GURL& origin_url, | 399 const url::Origin& origin, |
| 399 LevelDBFactory* leveldb_factory, | 400 LevelDBFactory* leveldb_factory, |
| 400 base::SequencedTaskRunner* task_runner, | 401 base::SequencedTaskRunner* task_runner, |
| 401 leveldb::Status* status); | 402 leveldb::Status* status); |
| 402 | 403 |
| 403 void GrantChildProcessPermissions(int child_process_id); | 404 void GrantChildProcessPermissions(int child_process_id); |
| 404 | 405 |
| 405 // Compact is public for testing. | 406 // Compact is public for testing. |
| 406 virtual void Compact(); | 407 virtual void Compact(); |
| 407 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); | 408 virtual std::vector<base::string16> GetDatabaseNames(leveldb::Status*); |
| 408 virtual leveldb::Status GetIDBDatabaseMetaData( | 409 virtual leveldb::Status GetIDBDatabaseMetaData( |
| 409 const base::string16& name, | 410 const base::string16& name, |
| 410 IndexedDBDatabaseMetadata* metadata, | 411 IndexedDBDatabaseMetadata* metadata, |
| 411 bool* success) WARN_UNUSED_RESULT; | 412 bool* success) WARN_UNUSED_RESULT; |
| 412 virtual leveldb::Status CreateIDBDatabaseMetaData(const base::string16& name, | 413 virtual leveldb::Status CreateIDBDatabaseMetaData(const base::string16& name, |
| 413 int64_t version, | 414 int64_t version, |
| 414 int64_t* row_id); | 415 int64_t* row_id); |
| 415 virtual bool UpdateIDBDatabaseIntVersion( | 416 virtual bool UpdateIDBDatabaseIntVersion( |
| 416 IndexedDBBackingStore::Transaction* transaction, | 417 IndexedDBBackingStore::Transaction* transaction, |
| 417 int64_t row_id, | 418 int64_t row_id, |
| 418 int64_t version); | 419 int64_t version); |
| 419 virtual leveldb::Status DeleteDatabase(const base::string16& name); | 420 virtual leveldb::Status DeleteDatabase(const base::string16& name); |
| 420 | 421 |
| 421 // Assumes caller has already closed the backing store. | 422 // Assumes caller has already closed the backing store. |
| 422 static leveldb::Status DestroyBackingStore(const base::FilePath& path_base, | 423 static leveldb::Status DestroyBackingStore(const base::FilePath& path_base, |
| 423 const GURL& origin_url); | 424 const url::Origin& origin); |
| 424 static bool RecordCorruptionInfo(const base::FilePath& path_base, | 425 static bool RecordCorruptionInfo(const base::FilePath& path_base, |
| 425 const GURL& origin_url, | 426 const url::Origin& origin, |
| 426 const std::string& message); | 427 const std::string& message); |
| 427 leveldb::Status GetObjectStores( | 428 leveldb::Status GetObjectStores( |
| 428 int64_t database_id, | 429 int64_t database_id, |
| 429 IndexedDBDatabaseMetadata::ObjectStoreMap* map) WARN_UNUSED_RESULT; | 430 IndexedDBDatabaseMetadata::ObjectStoreMap* map) WARN_UNUSED_RESULT; |
| 430 virtual leveldb::Status CreateObjectStore( | 431 virtual leveldb::Status CreateObjectStore( |
| 431 IndexedDBBackingStore::Transaction* transaction, | 432 IndexedDBBackingStore::Transaction* transaction, |
| 432 int64_t database_id, | 433 int64_t database_id, |
| 433 int64_t object_store_id, | 434 int64_t object_store_id, |
| 434 const base::string16& name, | 435 const base::string16& name, |
| 435 const IndexedDBKeyPath& key_path, | 436 const IndexedDBKeyPath& key_path, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 int64_t object_store_id, | 557 int64_t object_store_id, |
| 557 int64_t index_id, | 558 int64_t index_id, |
| 558 const IndexedDBKeyRange& key_range, | 559 const IndexedDBKeyRange& key_range, |
| 559 blink::WebIDBCursorDirection, | 560 blink::WebIDBCursorDirection, |
| 560 leveldb::Status*); | 561 leveldb::Status*); |
| 561 | 562 |
| 562 protected: | 563 protected: |
| 563 friend class base::RefCounted<IndexedDBBackingStore>; | 564 friend class base::RefCounted<IndexedDBBackingStore>; |
| 564 | 565 |
| 565 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, | 566 IndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, |
| 566 const GURL& origin_url, | 567 const url::Origin& origin, |
| 567 const base::FilePath& blob_path, | 568 const base::FilePath& blob_path, |
| 568 net::URLRequestContext* request_context, | 569 net::URLRequestContext* request_context, |
| 569 std::unique_ptr<LevelDBDatabase> db, | 570 std::unique_ptr<LevelDBDatabase> db, |
| 570 std::unique_ptr<LevelDBComparator> comparator, | 571 std::unique_ptr<LevelDBComparator> comparator, |
| 571 base::SequencedTaskRunner* task_runner); | 572 base::SequencedTaskRunner* task_runner); |
| 572 virtual ~IndexedDBBackingStore(); | 573 virtual ~IndexedDBBackingStore(); |
| 573 | 574 |
| 574 bool is_incognito() const { return !indexed_db_factory_; } | 575 bool is_incognito() const { return !indexed_db_factory_; } |
| 575 | 576 |
| 576 leveldb::Status SetUpMetadata(); | 577 leveldb::Status SetUpMetadata(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 590 | 591 |
| 591 // Attempt to clean the primary journal. This will remove | 592 // Attempt to clean the primary journal. This will remove |
| 592 // any referenced files and delete the journal entry. If any | 593 // any referenced files and delete the journal entry. If any |
| 593 // transaction is currently committing this will be deferred | 594 // transaction is currently committing this will be deferred |
| 594 // via StartJournalCleaningTimer(). | 595 // via StartJournalCleaningTimer(). |
| 595 void CleanPrimaryJournalIgnoreReturn(); | 596 void CleanPrimaryJournalIgnoreReturn(); |
| 596 | 597 |
| 597 private: | 598 private: |
| 598 static scoped_refptr<IndexedDBBackingStore> Create( | 599 static scoped_refptr<IndexedDBBackingStore> Create( |
| 599 IndexedDBFactory* indexed_db_factory, | 600 IndexedDBFactory* indexed_db_factory, |
| 600 const GURL& origin_url, | 601 const url::Origin& origin, |
| 601 const base::FilePath& blob_path, | 602 const base::FilePath& blob_path, |
| 602 net::URLRequestContext* request_context, | 603 net::URLRequestContext* request_context, |
| 603 std::unique_ptr<LevelDBDatabase> db, | 604 std::unique_ptr<LevelDBDatabase> db, |
| 604 std::unique_ptr<LevelDBComparator> comparator, | 605 std::unique_ptr<LevelDBComparator> comparator, |
| 605 base::SequencedTaskRunner* task_runner, | 606 base::SequencedTaskRunner* task_runner, |
| 606 leveldb::Status* status); | 607 leveldb::Status* status); |
| 607 | 608 |
| 608 static bool ReadCorruptionInfo(const base::FilePath& path_base, | 609 static bool ReadCorruptionInfo(const base::FilePath& path_base, |
| 609 const GURL& origin_url, | 610 const url::Origin& origin, |
| 610 std::string* message); | 611 std::string* message); |
| 611 | 612 |
| 612 leveldb::Status FindKeyInIndex( | 613 leveldb::Status FindKeyInIndex( |
| 613 IndexedDBBackingStore::Transaction* transaction, | 614 IndexedDBBackingStore::Transaction* transaction, |
| 614 int64_t database_id, | 615 int64_t database_id, |
| 615 int64_t object_store_id, | 616 int64_t object_store_id, |
| 616 int64_t index_id, | 617 int64_t index_id, |
| 617 const IndexedDBKey& key, | 618 const IndexedDBKey& key, |
| 618 std::string* found_encoded_primary_key, | 619 std::string* found_encoded_primary_key, |
| 619 bool* found); | 620 bool* found); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 631 // This must not be used while temporary entries are present e.g. during | 632 // This must not be used while temporary entries are present e.g. during |
| 632 // a two-stage transaction commit with blobs. | 633 // a two-stage transaction commit with blobs. |
| 633 leveldb::Status CleanUpBlobJournal(const std::string& level_db_key) const; | 634 leveldb::Status CleanUpBlobJournal(const std::string& level_db_key) const; |
| 634 | 635 |
| 635 // Synchronously delete the files and/or directories on disk referenced by | 636 // Synchronously delete the files and/or directories on disk referenced by |
| 636 // the blob journal. | 637 // the blob journal. |
| 637 leveldb::Status CleanUpBlobJournalEntries( | 638 leveldb::Status CleanUpBlobJournalEntries( |
| 638 const BlobJournalType& journal) const; | 639 const BlobJournalType& journal) const; |
| 639 | 640 |
| 640 IndexedDBFactory* indexed_db_factory_; | 641 IndexedDBFactory* indexed_db_factory_; |
| 641 const GURL origin_url_; | 642 const url::Origin origin_; |
| 642 base::FilePath blob_path_; | 643 base::FilePath blob_path_; |
| 643 | 644 |
| 644 // The origin identifier is a key prefix unique to the origin used in the | 645 // The origin identifier is a key prefix unique to the origin used in the |
| 645 // leveldb backing store to partition data by origin. It is a normalized | 646 // leveldb backing store to partition data by origin. It is a normalized |
| 646 // version of the origin URL with a versioning suffix appended, e.g. | 647 // version of the origin URL with a versioning suffix appended, e.g. |
| 647 // "http_localhost_81@1" Since only one origin is stored per backing store | 648 // "http_localhost_81@1" Since only one origin is stored per backing store |
| 648 // this is redundant but necessary for backwards compatibility; the suffix | 649 // this is redundant but necessary for backwards compatibility; the suffix |
| 649 // provides for future flexibility. | 650 // provides for future flexibility. |
| 650 const std::string origin_identifier_; | 651 const std::string origin_identifier_; |
| 651 | 652 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 666 // complete. While > 0, temporary journal entries may exist so out-of-band | 667 // complete. While > 0, temporary journal entries may exist so out-of-band |
| 667 // journal cleaning must be deferred. | 668 // journal cleaning must be deferred. |
| 668 size_t committing_transaction_count_; | 669 size_t committing_transaction_count_; |
| 669 | 670 |
| 670 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); | 671 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStore); |
| 671 }; | 672 }; |
| 672 | 673 |
| 673 } // namespace content | 674 } // namespace content |
| 674 | 675 |
| 675 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ | 676 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_BACKING_STORE_H_ |
| OLD | NEW |