Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: content/browser/indexed_db/indexed_db_backing_store.cc

Issue 2773823002: Use a two-part data format version in IndexedDB metadata. (Closed)
Patch Set: jsbell, cmumford Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_backing_store.cc
diff --git a/content/browser/indexed_db/indexed_db_backing_store.cc b/content/browser/indexed_db/indexed_db_backing_store.cc
index a05267af2ed2409edf8c62b1908c75fc1ed33681..4b3e3877026cdcfb43c5a6527f5b31bf5ff7d758 100644
--- a/content/browser/indexed_db/indexed_db_backing_store.cc
+++ b/content/browser/indexed_db/indexed_db_backing_store.cc
@@ -46,7 +46,6 @@
#include "storage/common/database/database_identifier.h"
#include "storage/common/fileapi/file_system_mount_option.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
-#include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h"
#include "third_party/leveldatabase/env_chromium.h"
using base::FilePath;
@@ -318,7 +317,10 @@ int CompareIndexKeys(const StringPiece& a, const StringPiece& b) {
return Compare(a, b, true /*index_keys*/);
}
-WARN_UNUSED_RESULT bool IsSchemaKnown(LevelDBDatabase* db, bool* known) {
+WARN_UNUSED_RESULT bool IsSchemaKnown(
+ LevelDBDatabase* db,
+ const IndexedDBDataFormatVersion& latest_known_data_version,
+ bool* known) {
int64_t db_schema_version = 0;
bool found = false;
Status s = GetInt(db, SchemaVersionKey::Encode(), &db_schema_version, &found);
@@ -335,19 +337,19 @@ WARN_UNUSED_RESULT bool IsSchemaKnown(LevelDBDatabase* db, bool* known) {
return true;
}
- const uint32_t latest_known_data_version =
- blink::kSerializedScriptValueVersion;
- int64_t db_data_version = 0;
- s = GetInt(db, DataVersionKey::Encode(), &db_data_version, &found);
+ int64_t raw_db_data_version = 0;
+ s = GetInt(db, DataVersionKey::Encode(), &raw_db_data_version, &found);
if (!s.ok())
return false;
if (!found) {
*known = true;
return true;
}
- if (db_data_version < 0)
+ if (raw_db_data_version < 0)
return false; // Only corruption should cause this.
- if (db_data_version > latest_known_data_version) {
+ IndexedDBDataFormatVersion db_data_version =
+ IndexedDBDataFormatVersion::Decode(raw_db_data_version);
+ if (!latest_known_data_version.IsAtLeast(db_data_version)) {
*known = false;
return true;
}
@@ -1080,6 +1082,7 @@ IndexedDBBackingStore::IndexedDBBackingStore(
IndexedDBFactory* indexed_db_factory,
const Origin& origin,
const FilePath& blob_path,
+ const IndexedDBDataFormatVersion& data_format_version,
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
std::unique_ptr<LevelDBDatabase> db,
std::unique_ptr<LevelDBComparator> comparator,
@@ -1087,6 +1090,7 @@ IndexedDBBackingStore::IndexedDBBackingStore(
: indexed_db_factory_(indexed_db_factory),
origin_(origin),
blob_path_(blob_path),
+ data_format_version_(data_format_version),
origin_identifier_(ComputeOriginIdentifier(origin)),
request_context_getter_(request_context_getter),
task_runner_(task_runner),
@@ -1122,6 +1126,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
IndexedDBFactory* indexed_db_factory,
const Origin& origin,
const FilePath& path_base,
+ const IndexedDBDataFormatVersion& data_format_version,
scoped_refptr<net::URLRequestContextGetter> request_context,
IndexedDBDataLossInfo* data_loss_info,
bool* disk_full,
@@ -1130,8 +1135,9 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
Status* status) {
DefaultLevelDBFactory leveldb_factory;
return IndexedDBBackingStore::Open(
- indexed_db_factory, origin, path_base, request_context, data_loss_info,
- disk_full, &leveldb_factory, task_runner, clean_journal, status);
+ indexed_db_factory, origin, path_base, data_format_version,
+ request_context, data_loss_info, disk_full, &leveldb_factory, task_runner,
+ clean_journal, status);
}
Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base,
@@ -1143,8 +1149,8 @@ Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base,
}
WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
- const uint32_t latest_known_data_version =
- blink::kSerializedScriptValueVersion;
+ const IndexedDBDataFormatVersion latest_known_data_version =
+ data_format_version_;
const std::string schema_version_key = SchemaVersionKey::Encode();
const std::string data_version_key = DataVersionKey::Encode();
@@ -1152,7 +1158,7 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
IndexedDBClassFactory::Get()->CreateLevelDBTransaction(db_.get());
int64_t db_schema_version = 0;
- int64_t db_data_version = 0;
+ IndexedDBDataFormatVersion db_data_version;
bool found = false;
Status s =
GetInt(transaction.get(), schema_version_key, &db_schema_version, &found);
@@ -1165,7 +1171,7 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
db_schema_version = kLatestKnownSchemaVersion;
PutInt(transaction.get(), schema_version_key, db_schema_version);
db_data_version = latest_known_data_version;
- PutInt(transaction.get(), data_version_key, db_data_version);
+ PutInt(transaction.get(), data_version_key, db_data_version.Encode());
// If a blob directory already exists for this database, blow it away. It's
// leftover from a partially-purged previous generation of data.
if (!base::DeleteFile(blob_path_, true)) {
@@ -1206,8 +1212,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
if (s.ok() && db_schema_version < 2) {
db_schema_version = 2;
PutInt(transaction.get(), schema_version_key, db_schema_version);
- db_data_version = blink::kSerializedScriptValueVersion;
- PutInt(transaction.get(), data_version_key, db_data_version);
+ db_data_version = latest_known_data_version;
+ PutInt(transaction.get(), data_version_key, db_data_version.Encode());
}
if (db_schema_version < 3) {
db_schema_version = 3;
@@ -1225,7 +1231,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
// All new values will be written using this serialization version.
found = false;
- s = GetInt(transaction.get(), data_version_key, &db_data_version, &found);
+ int64_t raw_db_data_version = 0;
+ s = GetInt(transaction.get(), data_version_key, &raw_db_data_version, &found);
if (!s.ok()) {
INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA);
return s;
@@ -1234,13 +1241,20 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA);
return InternalInconsistencyStatus();
}
- if (db_data_version < latest_known_data_version) {
+ db_data_version = IndexedDBDataFormatVersion::Decode(raw_db_data_version);
+ if (latest_known_data_version == db_data_version) {
+ // Up to date. Nothing to do.
+ } else if (latest_known_data_version.IsAtLeast(db_data_version)) {
db_data_version = latest_known_data_version;
- PutInt(transaction.get(), data_version_key, db_data_version);
+ PutInt(transaction.get(), data_version_key, db_data_version.Encode());
+ } else {
+ // |db_data_version| is in the future according to at least one component.
+ INTERNAL_CONSISTENCY_ERROR(SET_UP_METADATA);
+ return InternalInconsistencyStatus();
}
DCHECK_EQ(db_schema_version, kLatestKnownSchemaVersion);
- DCHECK_EQ(db_data_version, latest_known_data_version);
+ DCHECK(db_data_version == latest_known_data_version);
s = transaction->Commit();
if (!s.ok())
@@ -1312,6 +1326,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
IndexedDBFactory* indexed_db_factory,
const Origin& origin,
const FilePath& path_base,
+ const IndexedDBDataFormatVersion& data_format_version,
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
IndexedDBDataLossInfo* data_loss_info,
bool* is_disk_full,
@@ -1377,7 +1392,8 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
data_loss_info->status = blink::WebIDBDataLossTotal;
data_loss_info->message =
"IndexedDB (database was corrupt): " + corruption_message;
- } else if (!IsSchemaKnown(db.get(), &is_schema_known)) {
+ } else if (!IsSchemaKnown(db.get(), data_format_version,
+ &is_schema_known)) {
LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as "
"failure to open";
HistogramOpenStatus(
@@ -1438,8 +1454,9 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
base::trace_event::MemoryDumpProvider::Options());
scoped_refptr<IndexedDBBackingStore> backing_store =
- Create(indexed_db_factory, origin, blob_path, request_context_getter,
- std::move(db), std::move(comparator), task_runner, status);
+ Create(indexed_db_factory, origin, blob_path, data_format_version,
+ request_context_getter, std::move(db), std::move(comparator),
+ task_runner, status);
if (clean_journal && backing_store.get()) {
*status = backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode());
@@ -1455,16 +1472,18 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
// static
scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory(
const Origin& origin,
+ const IndexedDBDataFormatVersion& data_format_version,
base::SequencedTaskRunner* task_runner,
Status* status) {
DefaultLevelDBFactory leveldb_factory;
- return IndexedDBBackingStore::OpenInMemory(origin, &leveldb_factory,
- task_runner, status);
+ return IndexedDBBackingStore::OpenInMemory(
+ origin, data_format_version, &leveldb_factory, task_runner, status);
}
// static
scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory(
const Origin& origin,
+ const IndexedDBDataFormatVersion& data_format_version,
LevelDBFactory* leveldb_factory,
base::SequencedTaskRunner* task_runner,
Status* status) {
@@ -1485,7 +1504,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory(
base::trace_event::MemoryDumpProvider::Options());
return Create(NULL /* indexed_db_factory */, origin, FilePath(),
- NULL /* request_context */, std::move(db),
+ data_format_version, NULL /* request_context */, std::move(db),
std::move(comparator), task_runner, status);
}
@@ -1494,6 +1513,7 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create(
IndexedDBFactory* indexed_db_factory,
const Origin& origin,
const FilePath& blob_path,
+ const IndexedDBDataFormatVersion& data_format_version,
scoped_refptr<net::URLRequestContextGetter> request_context,
std::unique_ptr<LevelDBDatabase> db,
std::unique_ptr<LevelDBComparator> comparator,
@@ -1501,8 +1521,8 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create(
Status* status) {
// TODO(jsbell): Handle comparator name changes.
scoped_refptr<IndexedDBBackingStore> backing_store(new IndexedDBBackingStore(
- indexed_db_factory, origin, blob_path, request_context, std::move(db),
- std::move(comparator), task_runner));
+ indexed_db_factory, origin, blob_path, data_format_version,
+ request_context, std::move(db), std::move(comparator), task_runner));
*status = backing_store->SetUpMetadata();
if (!status->ok())
return scoped_refptr<IndexedDBBackingStore>();

Powered by Google App Engine
This is Rietveld 408576698