Commit 9e592857 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Fix a few missed places where blob numbers were still called keys.

Bug: 1027737
Change-Id: Ifcce67116fc50a604b57dc7e73233eefd4729092
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993645
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729998}
parent bb7a604a
...@@ -94,13 +94,13 @@ Blob journals are zero-or-more instances of the structure: ...@@ -94,13 +94,13 @@ Blob journals are zero-or-more instances of the structure:
``` ```
{ {
database_id (VarInt), database_id (VarInt),
blobKey (VarInt) blob_number (VarInt)
} }
``` ```
There is no length prefix; just read until you run out of data. There is no length prefix; just read until you run out of data.
If the blobKey is `DatabaseMetaDataKey::kAllBlobsKey`, the whole If the blob_number is `DatabaseMetaDataKey::kAllBlobsNumber`, the whole
database should be deleted. database should be deleted.
### BlobEntry (value) ### BlobEntry (value)
...@@ -110,7 +110,7 @@ A blob entry is zero-or-more instances of the structure: ...@@ -110,7 +110,7 @@ A blob entry is zero-or-more instances of the structure:
``` ```
{ {
is_file (Bool), is_file (Bool),
key (VarInt), blob_number (VarInt),
type (StringWithLength), // may be empty type (StringWithLength), // may be empty
/*for Blobs only*/ size (VarInt), /*for Blobs only*/ size (VarInt),
/*for Files only*/ filename (StringWithLength) /*for Files only*/ filename (StringWithLength)
......
...@@ -39,7 +39,7 @@ bool IndexedDBActiveBlobRegistry::MarkBlobInfoDeletedAndCheckIfReferenced( ...@@ -39,7 +39,7 @@ bool IndexedDBActiveBlobRegistry::MarkBlobInfoDeletedAndCheckIfReferenced(
int64_t database_id, int64_t database_id,
int64_t blob_number) { int64_t blob_number) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_NE(blob_number, DatabaseMetaDataKey::kAllBlobsKey); DCHECK_NE(blob_number, DatabaseMetaDataKey::kAllBlobsNumber);
DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
const auto& db_pair = blob_reference_tracker_.find(database_id); const auto& db_pair = blob_reference_tracker_.find(database_id);
if (db_pair == blob_reference_tracker_.end()) if (db_pair == blob_reference_tracker_.end())
...@@ -134,7 +134,7 @@ void IndexedDBActiveBlobRegistry::MarkBlobInactive(int64_t database_id, ...@@ -134,7 +134,7 @@ void IndexedDBActiveBlobRegistry::MarkBlobInactive(int64_t database_id,
blob_reference_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_number = DatabaseMetaDataKey::kAllBlobsKey; blob_number = DatabaseMetaDataKey::kAllBlobsNumber;
deleted_dbs_.erase(deleted_database_it); deleted_dbs_.erase(deleted_database_it);
} }
} }
......
...@@ -117,12 +117,12 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore { ...@@ -117,12 +117,12 @@ class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
return true; return true;
} }
bool RemoveBlobFile(int64_t database_id, int64_t key) const override { bool RemoveBlobFile(int64_t database_id, int64_t blob_number) const override {
if (database_id_ != database_id || if (database_id_ != database_id ||
!KeyPrefix::IsValidDatabaseId(database_id)) { !KeyPrefix::IsValidDatabaseId(database_id)) {
return false; return false;
} }
removals_.push_back(key); removals_.push_back(blob_number);
return true; return true;
} }
...@@ -395,11 +395,11 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest { ...@@ -395,11 +395,11 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest {
return false; return false;
std::set<int64_t> ids; std::set<int64_t> ids;
for (const auto& write : backing_store_->writes()) for (const auto& write : backing_store_->writes())
ids.insert(write.key()); ids.insert(write.blob_number());
if (ids.size() != backing_store_->writes().size()) if (ids.size() != backing_store_->writes().size())
return false; return false;
for (const auto& read : reads) { for (const auto& read : reads) {
if (ids.count(read.key()) != 1) if (ids.count(read.blob_number()) != 1)
return false; return false;
} }
return true; return true;
...@@ -471,8 +471,10 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest { ...@@ -471,8 +471,10 @@ class IndexedDBBackingStoreTestWithBlobs : public IndexedDBBackingStoreTest {
if (backing_store_->removals().size() != backing_store_->writes().size()) if (backing_store_->removals().size() != backing_store_->writes().size())
return false; return false;
for (size_t i = 0; i < backing_store_->writes().size(); ++i) { for (size_t i = 0; i < backing_store_->writes().size(); ++i) {
if (backing_store_->writes()[i].key() != backing_store_->removals()[i]) if (backing_store_->writes()[i].blob_number() !=
backing_store_->removals()[i]) {
return false; return false;
}
} }
return true; return true;
} }
...@@ -758,9 +760,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, DeleteRange) { ...@@ -758,9 +760,9 @@ TEST_F(IndexedDBBackingStoreTestWithBlobs, DeleteRange) {
// Verify blob removals. // Verify blob removals.
ASSERT_EQ(2UL, backing_store()->removals().size()); ASSERT_EQ(2UL, backing_store()->removals().size());
EXPECT_EQ(backing_store()->writes()[1].key(), EXPECT_EQ(backing_store()->writes()[1].blob_number(),
backing_store()->removals()[0]); backing_store()->removals()[0]);
EXPECT_EQ(backing_store()->writes()[2].key(), EXPECT_EQ(backing_store()->writes()[2].blob_number(),
backing_store()->removals()[1]); backing_store()->removals()[1]);
// Clean up on the IDB sequence. // Clean up on the IDB sequence.
......
...@@ -35,10 +35,7 @@ void IndexedDBBlobInfo::ConvertBlobInfo( ...@@ -35,10 +35,7 @@ void IndexedDBBlobInfo::ConvertBlobInfo(
} }
} }
IndexedDBBlobInfo::IndexedDBBlobInfo() IndexedDBBlobInfo::IndexedDBBlobInfo() : is_file_(false), size_(-1) {}
: is_file_(false),
size_(-1),
key_(DatabaseMetaDataKey::kInvalidBlobNumber) {}
IndexedDBBlobInfo::IndexedDBBlobInfo( IndexedDBBlobInfo::IndexedDBBlobInfo(
mojo::PendingRemote<blink::mojom::Blob> blob_remote, mojo::PendingRemote<blink::mojom::Blob> blob_remote,
...@@ -49,13 +46,12 @@ IndexedDBBlobInfo::IndexedDBBlobInfo( ...@@ -49,13 +46,12 @@ IndexedDBBlobInfo::IndexedDBBlobInfo(
blob_remote_(std::move(blob_remote)), blob_remote_(std::move(blob_remote)),
uuid_(uuid), uuid_(uuid),
type_(type), type_(type),
size_(size), size_(size) {}
key_(DatabaseMetaDataKey::kInvalidBlobNumber) {}
IndexedDBBlobInfo::IndexedDBBlobInfo(const base::string16& type, IndexedDBBlobInfo::IndexedDBBlobInfo(const base::string16& type,
int64_t size, int64_t size,
int64_t key) int64_t blob_number)
: is_file_(false), type_(type), size_(size), key_(key) {} : is_file_(false), type_(type), size_(size), blob_number_(blob_number) {}
IndexedDBBlobInfo::IndexedDBBlobInfo( IndexedDBBlobInfo::IndexedDBBlobInfo(
mojo::PendingRemote<blink::mojom::Blob> blob_remote, mojo::PendingRemote<blink::mojom::Blob> blob_remote,
...@@ -69,17 +65,16 @@ IndexedDBBlobInfo::IndexedDBBlobInfo( ...@@ -69,17 +65,16 @@ IndexedDBBlobInfo::IndexedDBBlobInfo(
type_(type), type_(type),
size_(-1), size_(-1),
file_name_(file_name), file_name_(file_name),
file_path_(file_path), file_path_(file_path) {}
key_(DatabaseMetaDataKey::kInvalidBlobNumber) {}
IndexedDBBlobInfo::IndexedDBBlobInfo(int64_t key, IndexedDBBlobInfo::IndexedDBBlobInfo(int64_t blob_number,
const base::string16& type, const base::string16& type,
const base::string16& file_name) const base::string16& file_name)
: is_file_(true), : is_file_(true),
type_(type), type_(type),
size_(-1), size_(-1),
file_name_(file_name), file_name_(file_name),
key_(key) {} blob_number_(blob_number) {}
IndexedDBBlobInfo::IndexedDBBlobInfo(const IndexedDBBlobInfo& other) = default; IndexedDBBlobInfo::IndexedDBBlobInfo(const IndexedDBBlobInfo& other) = default;
...@@ -110,9 +105,9 @@ void IndexedDBBlobInfo::set_last_modified(const base::Time& time) { ...@@ -110,9 +105,9 @@ void IndexedDBBlobInfo::set_last_modified(const base::Time& time) {
last_modified_ = time; last_modified_ = time;
} }
void IndexedDBBlobInfo::set_key(int64_t key) { void IndexedDBBlobInfo::set_blob_number(int64_t blob_number) {
DCHECK_EQ(DatabaseMetaDataKey::kInvalidBlobNumber, key_); DCHECK_EQ(DatabaseMetaDataKey::kInvalidBlobNumber, blob_number_);
key_ = key; blob_number_ = blob_number;
} }
void IndexedDBBlobInfo::set_mark_used_callback( void IndexedDBBlobInfo::set_mark_used_callback(
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/shared_remote.h" #include "mojo/public/cpp/bindings/shared_remote.h"
#include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_data_handle.h"
...@@ -36,14 +37,16 @@ class CONTENT_EXPORT IndexedDBBlobInfo { ...@@ -36,14 +37,16 @@ class CONTENT_EXPORT IndexedDBBlobInfo {
const std::string& uuid, const std::string& uuid,
const base::string16& type, const base::string16& type,
int64_t size); int64_t size);
IndexedDBBlobInfo(const base::string16& type, int64_t size, int64_t key); IndexedDBBlobInfo(const base::string16& type,
int64_t size,
int64_t blob_number);
// These two are used for Files. // These two are used for Files.
IndexedDBBlobInfo(mojo::PendingRemote<blink::mojom::Blob> blob_remote, IndexedDBBlobInfo(mojo::PendingRemote<blink::mojom::Blob> blob_remote,
const std::string& uuid, const std::string& uuid,
const base::FilePath& file_path, const base::FilePath& file_path,
const base::string16& file_name, const base::string16& file_name,
const base::string16& type); const base::string16& type);
IndexedDBBlobInfo(int64_t key, IndexedDBBlobInfo(int64_t blob_number,
const base::string16& type, const base::string16& type,
const base::string16& file_name); const base::string16& file_name);
...@@ -62,7 +65,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo { ...@@ -62,7 +65,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo {
const base::string16& type() const { return type_; } const base::string16& type() const { return type_; }
int64_t size() const { return size_; } int64_t size() const { return size_; }
const base::string16& file_name() const { return file_name_; } const base::string16& file_name() const { return file_name_; }
int64_t key() const { return key_; } int64_t blob_number() const { return blob_number_; }
const base::FilePath& file_path() const { return file_path_; } const base::FilePath& file_path() const { return file_path_; }
const base::Time& last_modified() const { return last_modified_; } const base::Time& last_modified() const { return last_modified_; }
const base::RepeatingClosure& mark_used_callback() const { const base::RepeatingClosure& mark_used_callback() const {
...@@ -75,7 +78,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo { ...@@ -75,7 +78,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo {
void set_size(int64_t size); void set_size(int64_t size);
void set_file_path(const base::FilePath& file_path); void set_file_path(const base::FilePath& file_path);
void set_last_modified(const base::Time& time); void set_last_modified(const base::Time& time);
void set_key(int64_t key); void set_blob_number(int64_t blob_number);
void set_mark_used_callback(base::RepeatingClosure mark_used_callback); void set_mark_used_callback(base::RepeatingClosure mark_used_callback);
void set_release_callback(base::RepeatingClosure release_callback); void set_release_callback(base::RepeatingClosure release_callback);
...@@ -98,7 +101,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo { ...@@ -98,7 +101,7 @@ class CONTENT_EXPORT IndexedDBBlobInfo {
base::Time last_modified_; base::Time last_modified_;
// Valid only when this comes out of the database. // Valid only when this comes out of the database.
int64_t key_; int64_t blob_number_ = DatabaseMetaDataKey::kInvalidBlobNumber;
base::RepeatingClosure mark_used_callback_; base::RepeatingClosure mark_used_callback_;
base::RepeatingClosure release_callback_; base::RepeatingClosure release_callback_;
}; };
......
...@@ -28,22 +28,22 @@ std::unique_ptr<BlobChangeRecord> BlobChangeRecord::Clone() const { ...@@ -28,22 +28,22 @@ std::unique_ptr<BlobChangeRecord> BlobChangeRecord::Clone() const {
} }
WriteDescriptor::WriteDescriptor(mojo::SharedRemote<blink::mojom::Blob> blob, WriteDescriptor::WriteDescriptor(mojo::SharedRemote<blink::mojom::Blob> blob,
int64_t key, int64_t blob_number,
int64_t size, int64_t size,
base::Time last_modified) base::Time last_modified)
: is_file_(false), : is_file_(false),
blob_(std::move(blob)), blob_(std::move(blob)),
key_(key), blob_number_(blob_number),
size_(size), size_(size),
last_modified_(last_modified) {} last_modified_(last_modified) {}
WriteDescriptor::WriteDescriptor(const base::FilePath& file_path, WriteDescriptor::WriteDescriptor(const base::FilePath& file_path,
int64_t key, int64_t blob_number,
int64_t size, int64_t size,
base::Time last_modified) base::Time last_modified)
: is_file_(true), : is_file_(true),
file_path_(file_path), file_path_(file_path),
key_(key), blob_number_(blob_number),
size_(size), size_(size),
last_modified_(last_modified) {} last_modified_(last_modified) {}
......
...@@ -76,11 +76,11 @@ typedef std::vector<std::pair<BlobEntryKey, std::string>> ...@@ -76,11 +76,11 @@ typedef std::vector<std::pair<BlobEntryKey, std::string>>
class CONTENT_EXPORT WriteDescriptor { class CONTENT_EXPORT WriteDescriptor {
public: public:
WriteDescriptor(mojo::SharedRemote<blink::mojom::Blob> blob, WriteDescriptor(mojo::SharedRemote<blink::mojom::Blob> blob,
int64_t key, int64_t blob_number,
int64_t size, int64_t size,
base::Time last_modified); base::Time last_modified);
WriteDescriptor(const base::FilePath& path, WriteDescriptor(const base::FilePath& path,
int64_t key, int64_t blob_number,
int64_t size, int64_t size,
base::Time last_modified); base::Time last_modified);
WriteDescriptor(const WriteDescriptor& other); WriteDescriptor(const WriteDescriptor& other);
...@@ -96,7 +96,7 @@ class CONTENT_EXPORT WriteDescriptor { ...@@ -96,7 +96,7 @@ class CONTENT_EXPORT WriteDescriptor {
DCHECK(is_file_); DCHECK(is_file_);
return file_path_; return file_path_;
} }
int64_t key() const { return key_; } int64_t blob_number() const { return blob_number_; }
int64_t size() const { return size_; } int64_t size() const { return size_; }
base::Time last_modified() const { return last_modified_; } base::Time last_modified() const { return last_modified_; }
...@@ -104,7 +104,7 @@ class CONTENT_EXPORT WriteDescriptor { ...@@ -104,7 +104,7 @@ class CONTENT_EXPORT WriteDescriptor {
bool is_file_; bool is_file_;
mojo::SharedRemote<blink::mojom::Blob> blob_; mojo::SharedRemote<blink::mojom::Blob> blob_;
base::FilePath file_path_; base::FilePath file_path_;
int64_t key_; int64_t blob_number_;
int64_t size_; int64_t size_;
base::Time last_modified_; base::Time last_modified_;
}; };
......
...@@ -476,7 +476,7 @@ bool DecodeBlobJournal(StringPiece* slice, BlobJournalType* journal) { ...@@ -476,7 +476,7 @@ bool DecodeBlobJournal(StringPiece* slice, BlobJournalType* journal) {
if (!DecodeVarInt(slice, &blob_number)) if (!DecodeVarInt(slice, &blob_number))
return false; return false;
if (!DatabaseMetaDataKey::IsValidBlobNumber(blob_number) && if (!DatabaseMetaDataKey::IsValidBlobNumber(blob_number) &&
(blob_number != DatabaseMetaDataKey::kAllBlobsKey)) { (blob_number != DatabaseMetaDataKey::kAllBlobsNumber)) {
return false; return false;
} }
output.push_back({database_id, blob_number}); output.push_back({database_id, blob_number});
...@@ -1570,7 +1570,7 @@ bool DatabaseMetaDataKey::IsValidBlobNumber(int64_t blob_number) { ...@@ -1570,7 +1570,7 @@ bool DatabaseMetaDataKey::IsValidBlobNumber(int64_t blob_number) {
return blob_number >= kBlobNumberGeneratorInitialNumber; return blob_number >= kBlobNumberGeneratorInitialNumber;
} }
const int64_t DatabaseMetaDataKey::kAllBlobsKey = 1; const int64_t DatabaseMetaDataKey::kAllBlobsNumber = 1;
const int64_t DatabaseMetaDataKey::kBlobNumberGeneratorInitialNumber = 2; const int64_t DatabaseMetaDataKey::kBlobNumberGeneratorInitialNumber = 2;
const int64_t DatabaseMetaDataKey::kInvalidBlobNumber = -1; const int64_t DatabaseMetaDataKey::kInvalidBlobNumber = -1;
......
...@@ -291,7 +291,7 @@ class DatabaseMetaDataKey { ...@@ -291,7 +291,7 @@ class DatabaseMetaDataKey {
MAX_SIMPLE_METADATA_TYPE = 6 MAX_SIMPLE_METADATA_TYPE = 6
}; };
CONTENT_EXPORT static const int64_t kAllBlobsKey; CONTENT_EXPORT static const int64_t kAllBlobsNumber;
static const int64_t kBlobNumberGeneratorInitialNumber; static const int64_t kBlobNumberGeneratorInitialNumber;
// All keys <= 0 are invalid. This one's just a convenient example. // All keys <= 0 are invalid. This one's just a convenient example.
static const int64_t kInvalidBlobNumber; static const int64_t kInvalidBlobNumber;
......
...@@ -643,7 +643,7 @@ TEST(IndexedDBLevelDBCodingTest, EncodeDecodeBlobJournal) { ...@@ -643,7 +643,7 @@ TEST(IndexedDBLevelDBCodingTest, EncodeDecodeBlobJournal) {
} }
{ // kAllBlobsKey { // kAllBlobsKey
journals.push_back({{5, DatabaseMetaDataKey::kAllBlobsKey}}); journals.push_back({{5, DatabaseMetaDataKey::kAllBlobsNumber}});
} }
{ // A bunch of items { // A bunch of items
......
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