Commit 190c0e45 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[IndexedDB] Renamings and cleanups in Blob integration

This change does some renamings to match the terminology outlined here:
https://chromium.googlesource.com/chromium/src/+/master/content/browser/indexed_db/docs/README.md

It also adds more comments to the IndexedDBActiveBlobRegistry, and
splits up the method MarkDeletedCheckIfUsed into:
* MarkDatabaseDeletedAndCheckIfReferenced
* MarkBlobInfoDeletedAndCheckIfReferenced
and changes the following methods to be more accurate:
* AddBlobRef -> MarkBlobActive
* RemoveBlobRef -> MarkBlobInactive

Future CLs will continue renaming parts of the system to match the new
README.

Work planning doc:
https://docs.google.com/document/d/18suNOOzuEJbqgRJF0MB2VqdTyYqS4cvI2PGaCpyPXSw/edit?pli=1#heading=h.wwk24xdiduw5

R=enne@chromium.org

Bug: 1027737, 1024966
Change-Id: I3f569bad802e64eee2ccf55cacafbb170f099d14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912828
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Auto-Submit: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718876}
parent 4de1c6cf
...@@ -23,92 +23,102 @@ IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry( ...@@ -23,92 +23,102 @@ IndexedDBActiveBlobRegistry::IndexedDBActiveBlobRegistry(
IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() {} IndexedDBActiveBlobRegistry::~IndexedDBActiveBlobRegistry() {}
bool IndexedDBActiveBlobRegistry::MarkDeletedCheckIfUsed(int64_t database_id, bool IndexedDBActiveBlobRegistry::MarkDatabaseDeletedAndCheckIfReferenced(
int64_t blob_key) { int64_t database_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
const auto& db_pair = use_tracker_.find(database_id); const auto& db_pair = blob_reference_tracker_.find(database_id);
if (db_pair == use_tracker_.end()) if (db_pair == blob_reference_tracker_.end())
return false; return false;
if (blob_key == DatabaseMetaDataKey::kAllBlobsKey) {
deleted_dbs_.insert(database_id); deleted_dbs_.insert(database_id);
return true; return true;
} }
bool IndexedDBActiveBlobRegistry::MarkBlobInfoDeletedAndCheckIfReferenced(
int64_t database_id,
int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_NE(blob_number, DatabaseMetaDataKey::kAllBlobsKey);
DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
const auto& db_pair = blob_reference_tracker_.find(database_id);
if (db_pair == blob_reference_tracker_.end())
return false;
SingleDBMap& single_db = db_pair->second; SingleDBMap& single_db = db_pair->second;
auto iter = single_db.find(blob_key); auto iter = single_db.find(blob_number);
if (iter == single_db.end()) if (iter == single_db.end())
return false; return false;
iter->second = BlobState::kDeleted; iter->second = BlobState::kUnlinked;
return true; return true;
} }
IndexedDBBlobInfo::ReleaseCallback IndexedDBBlobInfo::ReleaseCallback
IndexedDBActiveBlobRegistry::GetFinalReleaseCallback(int64_t database_id, IndexedDBActiveBlobRegistry::GetFinalReleaseCallback(int64_t database_id,
int64_t blob_key) { int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::BindRepeating( return base::BindRepeating(
&IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe, &IndexedDBActiveBlobRegistry::MarkBlobInactiveThreadSafe,
base::SequencedTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr(),
database_id, blob_key); database_id, blob_number);
} }
base::RepeatingClosure IndexedDBActiveBlobRegistry::GetAddBlobRefCallback( base::RepeatingClosure IndexedDBActiveBlobRegistry::GetMarkBlobActiveCallback(
int64_t database_id, int64_t database_id,
int64_t blob_key) { int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::BindRepeating(&IndexedDBActiveBlobRegistry::AddBlobRef, return base::BindRepeating(&IndexedDBActiveBlobRegistry::MarkBlobActive,
weak_factory_.GetWeakPtr(), database_id, blob_key); weak_factory_.GetWeakPtr(), database_id,
blob_number);
} }
void IndexedDBActiveBlobRegistry::ForceShutdown() { void IndexedDBActiveBlobRegistry::ForceShutdown() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
weak_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
use_tracker_.clear(); blob_reference_tracker_.clear();
report_outstanding_blobs_.Reset(); report_outstanding_blobs_.Reset();
report_unused_blob_.Reset(); report_unused_blob_.Reset();
} }
void IndexedDBActiveBlobRegistry::AddBlobRef(int64_t database_id, void IndexedDBActiveBlobRegistry::MarkBlobActive(int64_t database_id,
int64_t blob_key) { int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(report_outstanding_blobs_); DCHECK(report_outstanding_blobs_);
DCHECK(report_unused_blob_); DCHECK(report_unused_blob_);
DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_number));
DCHECK(!base::Contains(deleted_dbs_, database_id)); DCHECK(!base::Contains(deleted_dbs_, database_id));
bool outstanding_blobs_in_backing_store = !use_tracker_.empty(); bool outstanding_blobs_in_backing_store = !blob_reference_tracker_.empty();
SingleDBMap& blobs_in_db = use_tracker_[database_id]; SingleDBMap& blobs_in_db = blob_reference_tracker_[database_id];
auto iter = blobs_in_db.find(blob_key); auto iter = blobs_in_db.find(blob_number);
if (iter == blobs_in_db.end()) { if (iter == blobs_in_db.end()) {
blobs_in_db[blob_key] = BlobState::kAlive; blobs_in_db[blob_number] = BlobState::kLinked;
if (!outstanding_blobs_in_backing_store) if (!outstanding_blobs_in_backing_store)
report_outstanding_blobs_.Run(true); report_outstanding_blobs_.Run(true);
} else { } else {
DCHECK(outstanding_blobs_in_backing_store); DCHECK(outstanding_blobs_in_backing_store);
// You can't add a reference once it's been deleted. // You can't add a reference once it's been deleted.
DCHECK(iter->second == BlobState::kAlive); DCHECK(iter->second == BlobState::kLinked);
} }
} }
void IndexedDBActiveBlobRegistry::ReleaseBlobRef(int64_t database_id, void IndexedDBActiveBlobRegistry::MarkBlobInactive(int64_t database_id,
int64_t blob_key) { int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(report_outstanding_blobs_); DCHECK(report_outstanding_blobs_);
DCHECK(report_unused_blob_); DCHECK(report_unused_blob_);
DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_key)); DCHECK(DatabaseMetaDataKey::IsValidBlobKey(blob_number));
const auto& db_pair = use_tracker_.find(database_id); const auto& db_pair = blob_reference_tracker_.find(database_id);
if (db_pair == use_tracker_.end()) { if (db_pair == blob_reference_tracker_.end()) {
NOTREACHED(); NOTREACHED();
return; return;
} }
SingleDBMap& blobs_in_db = db_pair->second; SingleDBMap& blobs_in_db = db_pair->second;
auto blob_in_db_it = blobs_in_db.find(blob_key); auto blob_in_db_it = blobs_in_db.find(blob_number);
if (blob_in_db_it == blobs_in_db.end()) { if (blob_in_db_it == blobs_in_db.end()) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -119,31 +129,31 @@ void IndexedDBActiveBlobRegistry::ReleaseBlobRef(int64_t database_id, ...@@ -119,31 +129,31 @@ void IndexedDBActiveBlobRegistry::ReleaseBlobRef(int64_t database_id,
// Don't bother deleting the file if we're going to delete its whole // Don't bother deleting the file if we're going to delete its whole
// database directory soon. // database directory soon.
delete_blob_in_backend = delete_blob_in_backend =
blob_in_db_it->second == BlobState::kDeleted && !db_marked_for_deletion; blob_in_db_it->second == BlobState::kUnlinked && !db_marked_for_deletion;
blobs_in_db.erase(blob_in_db_it); blobs_in_db.erase(blob_in_db_it);
if (blobs_in_db.empty()) { if (blobs_in_db.empty()) {
use_tracker_.erase(db_pair); blob_reference_tracker_.erase(db_pair);
if (db_marked_for_deletion) { if (db_marked_for_deletion) {
delete_blob_in_backend = true; delete_blob_in_backend = true;
blob_key = DatabaseMetaDataKey::kAllBlobsKey; blob_number = DatabaseMetaDataKey::kAllBlobsKey;
deleted_dbs_.erase(deleted_database_it); deleted_dbs_.erase(deleted_database_it);
} }
} }
if (delete_blob_in_backend) if (delete_blob_in_backend)
report_unused_blob_.Run(database_id, blob_key); report_unused_blob_.Run(database_id, blob_number);
if (use_tracker_.empty()) if (blob_reference_tracker_.empty())
report_outstanding_blobs_.Run(false); report_outstanding_blobs_.Run(false);
} }
void IndexedDBActiveBlobRegistry::ReleaseBlobRefThreadSafe( void IndexedDBActiveBlobRegistry::MarkBlobInactiveThreadSafe(
scoped_refptr<base::TaskRunner> task_runner, scoped_refptr<base::TaskRunner> task_runner,
base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr,
int64_t database_id, int64_t database_id,
int64_t blob_key, int64_t blob_number,
const base::FilePath& unused) { const base::FilePath& unused) {
task_runner->PostTask( task_runner->PostTask(
FROM_HERE, base::BindOnce(&IndexedDBActiveBlobRegistry::ReleaseBlobRef, FROM_HERE, base::BindOnce(&IndexedDBActiveBlobRegistry::MarkBlobInactive,
std::move(weak_ptr), database_id, blob_key)); std::move(weak_ptr), database_id, blob_number));
} }
} // namespace content } // namespace content
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
namespace content { namespace content {
// Keeps track of blobs that have been sent to the renderer as database // Keeps track of blobs that have been sent to clients as database responses,
// responses, and determines when the file should be deleted. The database entry // and determines when Blob files can be deleted. The database entry that links
// that the blob files live in could be deleted in the database, but the file // to the blob file can be deleted in the database, but the blob file still
// would need to stay alive while it is still used in the renderer. // needs to stay alive while it is still active (i.e. referenced by a client).
// This class must be used on a single sequence, and will call the given // This class must be used on a single sequence, and will call the given
// callbacks back on the same sequence it is constructed on. // callbacks back on the same sequence it is constructed on.
class CONTENT_EXPORT IndexedDBActiveBlobRegistry { class CONTENT_EXPORT IndexedDBActiveBlobRegistry {
...@@ -32,7 +32,7 @@ class CONTENT_EXPORT IndexedDBActiveBlobRegistry { ...@@ -32,7 +32,7 @@ class CONTENT_EXPORT IndexedDBActiveBlobRegistry {
using ReportOutstandingBlobsCallback = base::RepeatingCallback<void(bool)>; using ReportOutstandingBlobsCallback = base::RepeatingCallback<void(bool)>;
using ReportUnusedBlobCallback = using ReportUnusedBlobCallback =
base::RepeatingCallback<void(int64_t /*database_id*/, base::RepeatingCallback<void(int64_t /*database_id*/,
int64_t /*blob_key*/)>; int64_t /*blob_number*/)>;
explicit IndexedDBActiveBlobRegistry( explicit IndexedDBActiveBlobRegistry(
ReportOutstandingBlobsCallback report_outstanding_blobs, ReportOutstandingBlobsCallback report_outstanding_blobs,
...@@ -40,48 +40,61 @@ class CONTENT_EXPORT IndexedDBActiveBlobRegistry { ...@@ -40,48 +40,61 @@ class CONTENT_EXPORT IndexedDBActiveBlobRegistry {
~IndexedDBActiveBlobRegistry(); ~IndexedDBActiveBlobRegistry();
// Most methods of this class, and the closure returned by // Most methods of this class, and the closure returned by
// GetAddBlobRefCallback, should only be called on the backing_store's task // GetMarkBlobActiveCallback, should only be called on the backing_store's
// runner. The exception is the closure returned by GetFinalReleaseCallback, // task runner. The exception is the closure returned by
// which just calls ReleaseBlobRefThreadSafe. // GetFinalReleaseCallback, which just calls MarkBlobInactiveThreadSafe.
// Marks a given blob or a while database as deleted by a transaction, and // Called when the given database is deleted (and all blob infos inside of
// returns if the given blob key (or database) was previously used. // it). Returns true if any of the deleted blobs are active (i.e. referenced
// Use DatabaseMetaDataKey::AllBlobsKey for "the whole database". // by a client).
bool MarkDeletedCheckIfUsed(int64_t database_id, int64_t blob_key); bool MarkDatabaseDeletedAndCheckIfReferenced(int64_t database_id);
// Called when the given blob handle is deleted by a transaction, and returns
// if the blob file has one or more external references.
bool MarkBlobInfoDeletedAndCheckIfReferenced(int64_t database_id,
int64_t blob_number);
// When called, the returned callback will mark the given blob entry as
// inactive (i.e. no longer referenced by a client).
IndexedDBBlobInfo::ReleaseCallback GetFinalReleaseCallback( IndexedDBBlobInfo::ReleaseCallback GetFinalReleaseCallback(
int64_t database_id, int64_t database_id,
int64_t blob_key); int64_t blob_number);
// This closure holds a raw pointer to the IndexedDBActiveBlobRegistry,
// and may not be called after it is deleted. // When called, the returned closure will mark the given blob entry as active
base::RepeatingClosure GetAddBlobRefCallback(int64_t database_id, // (i.e. referenced by the client). Calling this multiple times does nothing.
int64_t blob_key); // This closure holds a raw pointer to the IndexedDBActiveBlobRegistry, and
// may not be called after it is deleted.
base::RepeatingClosure GetMarkBlobActiveCallback(int64_t database_id,
int64_t blob_number);
// Call this to force the registry to drop its use counts, permitting the // Call this to force the registry to drop its use counts, permitting the
// factory to drop any blob-related refcount for the backing store. // factory to drop any blob-related refcount for the backing store.
// This will also turn any outstanding callbacks into no-ops. // This will also turn any outstanding callbacks into no-ops.
void ForceShutdown(); void ForceShutdown();
private: private:
enum class BlobState { kAlive, kDeleted }; enum class BlobState { kLinked, kUnlinked };
// Maps blob_key -> BlobState; if the record's absent, it's not in active use // Maps blob_number -> BlobState; if the record's absent, it's not in active
// and we don't care if it's deleted. // use and we don't care if it's deleted.
typedef std::map<int64_t, BlobState> SingleDBMap; typedef std::map<int64_t, BlobState> SingleDBMap;
void AddBlobRef(int64_t database_id, int64_t blob_key); void MarkBlobActive(int64_t database_id, int64_t blob_number);
// Removes a reference to the given blob. // Removes a reference to the given blob.
void ReleaseBlobRef(int64_t database_id, int64_t blob_key); void MarkBlobInactive(int64_t database_id, int64_t blob_number);
static void ReleaseBlobRefThreadSafe( static void MarkBlobInactiveThreadSafe(
scoped_refptr<base::TaskRunner> task_runner, scoped_refptr<base::TaskRunner> task_runner,
base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr, base::WeakPtr<IndexedDBActiveBlobRegistry> weak_ptr,
int64_t database_id, int64_t database_id,
int64_t blob_key, int64_t blob_number,
const base::FilePath& unused); const base::FilePath& unused);
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
std::map<int64_t, SingleDBMap> use_tracker_; // This stores, for every database, the blobs that are currently being used in
// Databases that have been marked as deleted by MarkDeletedCheckIfUsed. // that database.
std::map<int64_t, SingleDBMap> blob_reference_tracker_;
// Databases that have been marked as deleted by
// MarkDatabaseDeletedAndCheckIfReferenced.
std::set<int64_t> deleted_dbs_; std::set<int64_t> deleted_dbs_;
ReportOutstandingBlobsCallback report_outstanding_blobs_; ReportOutstandingBlobsCallback report_outstanding_blobs_;
ReportUnusedBlobCallback report_unused_blob_; ReportUnusedBlobCallback report_unused_blob_;
......
...@@ -87,7 +87,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteUnused) { ...@@ -87,7 +87,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteUnused) {
EXPECT_TRUE(report_outstanding_state_.no_calls()); EXPECT_TRUE(report_outstanding_state_.no_calls());
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
EXPECT_FALSE(registry()->MarkDeletedCheckIfUsed(kDatabaseId0, kBlobKey0)); EXPECT_FALSE(registry()->MarkBlobInfoDeletedAndCheckIfReferenced(kDatabaseId0,
kBlobKey0));
RunUntilIdle(); RunUntilIdle();
EXPECT_TRUE(report_outstanding_state_.no_calls()); EXPECT_TRUE(report_outstanding_state_.no_calls());
...@@ -99,7 +100,7 @@ TEST_F(IndexedDBActiveBlobRegistryTest, SimpleUse) { ...@@ -99,7 +100,7 @@ TEST_F(IndexedDBActiveBlobRegistryTest, SimpleUse) {
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
base::Closure add_ref = base::Closure add_ref =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey0); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey0);
ReleaseCallback release = ReleaseCallback release =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0);
std::move(add_ref).Run(); std::move(add_ref).Run();
...@@ -122,7 +123,7 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteWhileInUse) { ...@@ -122,7 +123,7 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteWhileInUse) {
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
base::Closure add_ref = base::Closure add_ref =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey0); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey0);
ReleaseCallback release = ReleaseCallback release =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0);
...@@ -133,7 +134,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteWhileInUse) { ...@@ -133,7 +134,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, DeleteWhileInUse) {
EXPECT_EQ(0, report_outstanding_state_.false_calls); EXPECT_EQ(0, report_outstanding_state_.false_calls);
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
EXPECT_TRUE(registry()->MarkDeletedCheckIfUsed(kDatabaseId0, kBlobKey0)); EXPECT_TRUE(registry()->MarkBlobInfoDeletedAndCheckIfReferenced(kDatabaseId0,
kBlobKey0));
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(1, report_outstanding_state_.true_calls); EXPECT_EQ(1, report_outstanding_state_.true_calls);
...@@ -155,19 +157,19 @@ TEST_F(IndexedDBActiveBlobRegistryTest, MultipleBlobs) { ...@@ -155,19 +157,19 @@ TEST_F(IndexedDBActiveBlobRegistryTest, MultipleBlobs) {
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
base::Closure add_ref_00 = base::Closure add_ref_00 =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey0); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey0);
ReleaseCallback release_00 = ReleaseCallback release_00 =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0);
base::Closure add_ref_01 = base::Closure add_ref_01 =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey1); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey1);
ReleaseCallback release_01 = ReleaseCallback release_01 =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey1); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey1);
base::Closure add_ref_10 = base::Closure add_ref_10 =
registry()->GetAddBlobRefCallback(kDatabaseId1, kBlobKey0); registry()->GetMarkBlobActiveCallback(kDatabaseId1, kBlobKey0);
ReleaseCallback release_10 = ReleaseCallback release_10 =
registry()->GetFinalReleaseCallback(kDatabaseId1, kBlobKey0); registry()->GetFinalReleaseCallback(kDatabaseId1, kBlobKey0);
base::Closure add_ref_11 = base::Closure add_ref_11 =
registry()->GetAddBlobRefCallback(kDatabaseId1, kBlobKey1); registry()->GetMarkBlobActiveCallback(kDatabaseId1, kBlobKey1);
ReleaseCallback release_11 = ReleaseCallback release_11 =
registry()->GetFinalReleaseCallback(kDatabaseId1, kBlobKey1); registry()->GetFinalReleaseCallback(kDatabaseId1, kBlobKey1);
...@@ -188,7 +190,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, MultipleBlobs) { ...@@ -188,7 +190,8 @@ TEST_F(IndexedDBActiveBlobRegistryTest, MultipleBlobs) {
EXPECT_EQ(0, report_outstanding_state_.false_calls); EXPECT_EQ(0, report_outstanding_state_.false_calls);
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
EXPECT_TRUE(registry()->MarkDeletedCheckIfUsed(kDatabaseId0, kBlobKey1)); EXPECT_TRUE(registry()->MarkBlobInfoDeletedAndCheckIfReferenced(kDatabaseId0,
kBlobKey1));
RunUntilIdle(); RunUntilIdle();
EXPECT_EQ(1, report_outstanding_state_.true_calls); EXPECT_EQ(1, report_outstanding_state_.true_calls);
...@@ -220,11 +223,11 @@ TEST_F(IndexedDBActiveBlobRegistryTest, ForceShutdown) { ...@@ -220,11 +223,11 @@ TEST_F(IndexedDBActiveBlobRegistryTest, ForceShutdown) {
EXPECT_TRUE(unused_blobs_.empty()); EXPECT_TRUE(unused_blobs_.empty());
base::Closure add_ref_0 = base::Closure add_ref_0 =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey0); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey0);
ReleaseCallback release_0 = ReleaseCallback release_0 =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey0);
base::Closure add_ref_1 = base::Closure add_ref_1 =
registry()->GetAddBlobRefCallback(kDatabaseId0, kBlobKey1); registry()->GetMarkBlobActiveCallback(kDatabaseId0, kBlobKey1);
ReleaseCallback release_1 = ReleaseCallback release_1 =
registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey1); registry()->GetFinalReleaseCallback(kDatabaseId0, kBlobKey1);
......
...@@ -424,7 +424,7 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -424,7 +424,7 @@ class CONTENT_EXPORT IndexedDBBackingStore {
// Initializes the backing store. This must be called before doing any // Initializes the backing store. This must be called before doing any
// operations or method calls on this object. // operations or method calls on this object.
leveldb::Status Initialize(bool clean_live_blob_journal); leveldb::Status Initialize(bool clean_active_blob_journal);
const url::Origin& origin() const { return origin_; } const url::Origin& origin() const { return origin_; }
base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); }
...@@ -518,7 +518,7 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -518,7 +518,7 @@ class CONTENT_EXPORT IndexedDBBackingStore {
std::unique_ptr<blink::IndexedDBKey>* found_primary_key, std::unique_ptr<blink::IndexedDBKey>* found_primary_key,
bool* exists) WARN_UNUSED_RESULT; bool* exists) WARN_UNUSED_RESULT;
// Public for IndexedDBActiveBlobRegistry::ReleaseBlobRef. // Public for IndexedDBActiveBlobRegistry::MarkBlobInactive.
virtual void ReportBlobUnused(int64_t database_id, int64_t blob_key); virtual void ReportBlobUnused(int64_t database_id, int64_t blob_key);
base::FilePath GetBlobFileName(int64_t database_id, int64_t key) const; base::FilePath GetBlobFileName(int64_t database_id, int64_t key) const;
...@@ -613,16 +613,16 @@ class CONTENT_EXPORT IndexedDBBackingStore { ...@@ -613,16 +613,16 @@ class CONTENT_EXPORT IndexedDBBackingStore {
// Remove the referenced file on disk. // Remove the referenced file on disk.
virtual bool RemoveBlobFile(int64_t database_id, int64_t key) const; virtual bool RemoveBlobFile(int64_t database_id, int64_t key) const;
// Schedule a call to CleanPrimaryJournalIgnoreReturn() via // Schedule a call to CleanRecoveryJournalIgnoreReturn() via
// an owned timer. If this object is destroyed, the timer // an owned timer. If this object is destroyed, the timer
// will automatically be cancelled. // will automatically be cancelled.
virtual void StartJournalCleaningTimer(); virtual void StartJournalCleaningTimer();
// Attempt to clean the primary journal. This will remove // Attempt to clean the recovery journal. This will remove
// any referenced files and delete the journal entry. If any // any referenced files and delete the journal entry. If any
// transaction is currently committing this will be deferred // transaction is currently committing this will be deferred
// via StartJournalCleaningTimer(). // via StartJournalCleaningTimer().
void CleanPrimaryJournalIgnoreReturn(); void CleanRecoveryJournalIgnoreReturn();
private: private:
leveldb::Status FindKeyInIndex( leveldb::Status FindKeyInIndex(
......
...@@ -904,7 +904,7 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, BlobJournalInterleavedTransactions) { ...@@ -904,7 +904,7 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, BlobJournalInterleavedTransactions) {
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
} }
TEST_F(IndexedDBBackingStoreTestWithBlobs, LiveBlobJournal) { TEST_F(IndexedDBBackingStoreTestWithBlobs, ActiveBlobJournal) {
std::unique_ptr<IndexedDBBackingStore::Transaction> transaction1; std::unique_ptr<IndexedDBBackingStore::Transaction> transaction1;
TestCallback callback_creator1; TestCallback callback_creator1;
std::unique_ptr<IndexedDBBackingStore::Transaction> transaction3; std::unique_ptr<IndexedDBBackingStore::Transaction> transaction3;
......
...@@ -919,7 +919,7 @@ IndexedDBFactoryImpl::OpenAndVerifyIndexedDBBackingStore( ...@@ -919,7 +919,7 @@ IndexedDBFactoryImpl::OpenAndVerifyIndexedDBBackingStore(
weak_factory_.GetWeakPtr(), origin), weak_factory_.GetWeakPtr(), origin),
context_->TaskRunner()); context_->TaskRunner());
status = backing_store->Initialize( status = backing_store->Initialize(
/*cleanup_live_journal=*/(!is_incognito_and_in_memory && /*cleanup_active_journal=*/(!is_incognito_and_in_memory &&
first_open_since_startup)); first_open_since_startup));
if (UNLIKELY(!status.ok())) if (UNLIKELY(!status.ok()))
......
...@@ -63,8 +63,8 @@ constexpr unsigned char kBlobEntryIndexId = 3; ...@@ -63,8 +63,8 @@ constexpr unsigned char kBlobEntryIndexId = 3;
constexpr unsigned char kSchemaVersionTypeByte = 0; constexpr unsigned char kSchemaVersionTypeByte = 0;
constexpr unsigned char kMaxDatabaseIdTypeByte = 1; constexpr unsigned char kMaxDatabaseIdTypeByte = 1;
constexpr unsigned char kDataVersionTypeByte = 2; constexpr unsigned char kDataVersionTypeByte = 2;
constexpr unsigned char kBlobJournalTypeByte = 3; constexpr unsigned char kRecoveryBlobJournalTypeByte = 3;
constexpr unsigned char kLiveBlobJournalTypeByte = 4; constexpr unsigned char kActiveBlobJournalTypeByte = 4;
constexpr unsigned char kEarliestSweepTimeTypeByte = 5; constexpr unsigned char kEarliestSweepTimeTypeByte = 5;
constexpr unsigned char kMaxSimpleGlobalMetaDataTypeByte = constexpr unsigned char kMaxSimpleGlobalMetaDataTypeByte =
6; // Insert before this and increment. 6; // Insert before this and increment.
...@@ -1013,11 +1013,11 @@ std::string IndexedDBKeyToDebugString(base::StringPiece key) { ...@@ -1013,11 +1013,11 @@ std::string IndexedDBKeyToDebugString(base::StringPiece key) {
case kDataVersionTypeByte: case kDataVersionTypeByte:
result << "kDataVersionTypeByte"; result << "kDataVersionTypeByte";
break; break;
case kBlobJournalTypeByte: case kRecoveryBlobJournalTypeByte:
result << "kBlobJournalTypeByte"; result << "kRecoveryBlobJournalTypeByte";
break; break;
case kLiveBlobJournalTypeByte: case kActiveBlobJournalTypeByte:
result << "kLiveBlobJournalTypeByte"; result << "kActiveBlobJournalTypeByte";
break; break;
case kEarliestSweepTimeTypeByte: case kEarliestSweepTimeTypeByte:
result << "kEarliestSweepTimeTypeByte"; result << "kEarliestSweepTimeTypeByte";
...@@ -1444,15 +1444,15 @@ std::string DataVersionKey::Encode() { ...@@ -1444,15 +1444,15 @@ std::string DataVersionKey::Encode() {
return ret; return ret;
} }
std::string BlobJournalKey::Encode() { std::string RecoveryBlobJournalKey::Encode() {
std::string ret = KeyPrefix::EncodeEmpty(); std::string ret = KeyPrefix::EncodeEmpty();
ret.push_back(kBlobJournalTypeByte); ret.push_back(kRecoveryBlobJournalTypeByte);
return ret; return ret;
} }
std::string LiveBlobJournalKey::Encode() { std::string ActiveBlobJournalKey::Encode() {
std::string ret = KeyPrefix::EncodeEmpty(); std::string ret = KeyPrefix::EncodeEmpty();
ret.push_back(kLiveBlobJournalTypeByte); ret.push_back(kActiveBlobJournalTypeByte);
return ret; return ret;
} }
......
...@@ -225,12 +225,12 @@ class DataVersionKey { ...@@ -225,12 +225,12 @@ class DataVersionKey {
CONTENT_EXPORT static std::string Encode(); CONTENT_EXPORT static std::string Encode();
}; };
class BlobJournalKey { class RecoveryBlobJournalKey {
public: public:
static std::string Encode(); static std::string Encode();
}; };
class LiveBlobJournalKey { class ActiveBlobJournalKey {
public: public:
static std::string Encode(); static std::string Encode();
}; };
......
...@@ -151,8 +151,8 @@ key | value ...@@ -151,8 +151,8 @@ key | value
«0, 0, 0, 0» | backing store schema version (Int) [`SchemaVersionKey`] «0, 0, 0, 0» | backing store schema version (Int) [`SchemaVersionKey`]
«0, 0, 0, 1» | maximum allocated database (Int) [`MaxDatabaseIdKey`] «0, 0, 0, 1» | maximum allocated database (Int) [`MaxDatabaseIdKey`]
«0, 0, 0, 2» | data format version (Int) [`DataVersionKey`] «0, 0, 0, 2» | data format version (Int) [`DataVersionKey`]
«0, 0, 0, 3» | primary BlobJournal [`BlobJournalKey`] «0, 0, 0, 3» | recovery BlobJournal [`RecoveryBlobJournalKey`]
«0, 0, 0, 4» | live BlobJournal [`LiveBlobJournalKey`] «0, 0, 0, 4» | active BlobJournal [`ActiveBlobJournalKey`]
«0, 0, 0, 5» | earliest sweep time (microseconds) (Int) [`EarliestSweepKey`] «0, 0, 0, 5» | earliest sweep time (microseconds) (Int) [`EarliestSweepKey`]
«0, 0, 0, 100, database id (VarInt)» | Existence implies the database id is in the free list [`DatabaseFreeListKey`] - _obsolete_ «0, 0, 0, 100, database id (VarInt)» | Existence implies the database id is in the free list [`DatabaseFreeListKey`] - _obsolete_
«0, 0, 0, 201, origin (StringWithLength), database name (StringWithLength)» | Database id (Int) [`DatabaseNameKey`] «0, 0, 0, 201, origin (StringWithLength), database name (StringWithLength)» | Database id (Int) [`DatabaseNameKey`]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment