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

Unified Diff: components/sync/model_impl/model_type_store_impl.cc

Issue 2468183005: [Sync] Prepend global metadata key with model type prefix (Closed)
Patch Set: Addressed comments. Created 4 years, 1 month 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: components/sync/model_impl/model_type_store_impl.cc
diff --git a/components/sync/model_impl/model_type_store_impl.cc b/components/sync/model_impl/model_type_store_impl.cc
index 532fe653e149d2a2670ca1df01df90907bf85727..6856d6dd106116f1cb131b635b08471e1099a340 100644
--- a/components/sync/model_impl/model_type_store_impl.cc
+++ b/components/sync/model_impl/model_type_store_impl.cc
@@ -26,24 +26,29 @@ const char kDataPrefix[] = "-dt-";
const char kMetadataPrefix[] = "-md-";
// Key for global metadata record.
-const char kGlobalMetadataKey[] = "GlobalMetadata";
+const char kGlobalMetadataKey[] = "-GlobalMetadata";
void NoOpForBackendDtor(scoped_refptr<ModelTypeStoreBackend> backend) {
// This function was intentionally left blank.
}
-} // namespace
-
-// static
-std::string ModelTypeStoreImpl::FormatDataPrefix(const ModelType type) {
+// Formats key prefix for data records of |type|.
+std::string FormatDataPrefix(ModelType type) {
return std::string(GetModelTypeRootTag(type)) + kDataPrefix;
}
-// static
-std::string ModelTypeStoreImpl::FormatMetaPrefix(const ModelType type) {
+// Formats key prefix for metadata records of |type|.
+std::string FormatMetaPrefix(ModelType type) {
return std::string(GetModelTypeRootTag(type)) + kMetadataPrefix;
}
+// Formats key for global metadata record of |type|.
+std::string FormatGlobalMetadataKey(ModelType type) {
+ return std::string(GetModelTypeRootTag(type)) + kGlobalMetadataKey;
+}
+
+} // namespace
+
// static
leveldb::WriteBatch* ModelTypeStoreImpl::GetLeveldbWriteBatch(
WriteBatch* write_batch) {
@@ -59,13 +64,14 @@ std::string ModelTypeStoreImpl::FormatMetadataKey(const std::string& id) {
}
ModelTypeStoreImpl::ModelTypeStoreImpl(
- const ModelType type,
+ ModelType type,
scoped_refptr<ModelTypeStoreBackend> backend,
scoped_refptr<base::SequencedTaskRunner> backend_task_runner)
: backend_(backend),
backend_task_runner_(backend_task_runner),
data_prefix_(FormatDataPrefix(type)),
metadata_prefix_(FormatMetaPrefix(type)),
+ global_metadata_key_(FormatGlobalMetadataKey(type)),
weak_ptr_factory_(this) {
DCHECK(backend_);
DCHECK(backend_task_runner_);
@@ -79,7 +85,7 @@ ModelTypeStoreImpl::~ModelTypeStoreImpl() {
// static
void ModelTypeStoreImpl::CreateStore(
- const ModelType type,
+ ModelType type,
const std::string& path,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
const InitCallback& callback) {
@@ -98,6 +104,7 @@ void ModelTypeStoreImpl::CreateStore(
// static
void ModelTypeStoreImpl::CreateInMemoryStoreForTest(
+ ModelType type,
const InitCallback& callback) {
DCHECK(!callback.is_null());
@@ -116,7 +123,7 @@ void ModelTypeStoreImpl::CreateInMemoryStoreForTest(
auto task = base::Bind(&ModelTypeStoreBackend::GetOrCreateBackend, path,
base::Passed(&env), result.get());
- auto reply = base::Bind(&ModelTypeStoreImpl::BackendInitDone, UNSPECIFIED,
+ auto reply = base::Bind(&ModelTypeStoreImpl::BackendInitDone, type,
base::Passed(&result), task_runner, callback);
base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE, task, reply);
@@ -124,7 +131,7 @@ void ModelTypeStoreImpl::CreateInMemoryStoreForTest(
// static
void ModelTypeStoreImpl::BackendInitDone(
- const ModelType type,
+ ModelType type,
std::unique_ptr<Result> result,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
const InitCallback& callback,
@@ -226,7 +233,7 @@ void ModelTypeStoreImpl::ReadMetadataRecordsDone(
}
IdList global_metadata_id;
- global_metadata_id.push_back(kGlobalMetadataKey);
+ global_metadata_id.push_back(global_metadata_key_);
std::unique_ptr<RecordList> global_metadata_records(new RecordList());
std::unique_ptr<IdList> missing_id_list(new IdList());
auto task = base::Bind(&ModelTypeStoreBackend::ReadRecordsWithPrefix,
@@ -257,13 +264,13 @@ void ModelTypeStoreImpl::ReadAllMetadataDone(
if (!missing_id_list->empty()) {
// Missing global metadata record is not an error. We shouild return empty
// string in this case.
- DCHECK((*missing_id_list)[0] == kGlobalMetadataKey);
+ DCHECK((*missing_id_list)[0] == global_metadata_key_);
DCHECK(global_metadata_records->empty());
callback.Run(Result::SUCCESS, std::move(metadata_records), std::string());
return;
}
DCHECK(!global_metadata_records->empty());
- DCHECK((*global_metadata_records)[0].id == kGlobalMetadataKey);
+ DCHECK((*global_metadata_records)[0].id == global_metadata_key_);
callback.Run(Result::SUCCESS, std::move(metadata_records),
(*global_metadata_records)[0].value);
}
@@ -314,7 +321,7 @@ void ModelTypeStoreImpl::WriteMetadata(WriteBatch* write_batch,
void ModelTypeStoreImpl::WriteGlobalMetadata(WriteBatch* write_batch,
const std::string& value) {
DCHECK(CalledOnValidThread());
- GetLeveldbWriteBatch(write_batch)->Put(kGlobalMetadataKey, value);
+ GetLeveldbWriteBatch(write_batch)->Put(global_metadata_key_, value);
}
void ModelTypeStoreImpl::DeleteData(WriteBatch* write_batch,
@@ -331,7 +338,7 @@ void ModelTypeStoreImpl::DeleteMetadata(WriteBatch* write_batch,
void ModelTypeStoreImpl::DeleteGlobalMetadata(WriteBatch* write_batch) {
DCHECK(CalledOnValidThread());
- GetLeveldbWriteBatch(write_batch)->Delete(kGlobalMetadataKey);
+ GetLeveldbWriteBatch(write_batch)->Delete(global_metadata_key_);
}
ModelTypeStoreImpl::WriteBatchImpl::WriteBatchImpl() {
« no previous file with comments | « components/sync/model_impl/model_type_store_impl.h ('k') | components/sync/model_impl/model_type_store_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698