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

Unified Diff: sync/internal_api/attachments/on_disk_attachment_store.cc

Issue 710073003: Store attachment crc in AttachmentStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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: sync/internal_api/attachments/on_disk_attachment_store.cc
diff --git a/sync/internal_api/attachments/on_disk_attachment_store.cc b/sync/internal_api/attachments/on_disk_attachment_store.cc
index 25ad18672ffe99942136a534b7e64bd246955ca3..0af371b130391057edeb6c613c834bb96f922d48 100644
--- a/sync/internal_api/attachments/on_disk_attachment_store.cc
+++ b/sync/internal_api/attachments/on_disk_attachment_store.cc
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/sequenced_task_runner.h"
#include "sync/internal_api/attachments/proto/attachment_store.pb.h"
+#include "sync/internal_api/public/attachments/attachment_util.h"
#include "sync/protocol/attachments.pb.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
@@ -211,16 +212,35 @@ scoped_ptr<Attachment> OnDiskAttachmentStore::ReadSingleAttachment(
scoped_ptr<Attachment> attachment;
const std::string key = MakeDataKeyFromAttachmentId(attachment_id);
+ const std::string metadata_key =
+ MakeMetadataKeyFromAttachmentId(attachment_id);
+ leveldb::Status status;
+ std::string metadata_str;
+ status = db_->Get(MakeMetadataReadOptions(), metadata_key, &metadata_str);
+ if (!status.ok()) {
+ DVLOG(1) << "DB::Get for metadata failed: status=" << status.ToString();
+ return attachment.Pass();
+ }
+ attachment_store_pb::RecordMetadata record_metadata;
+ if (!record_metadata.ParseFromString(metadata_str)) {
+ DVLOG(1) << "RecordMetadata::ParseFromString failed";
+ return attachment.Pass();
+ }
std::string data_str;
- leveldb::Status status = db_->Get(MakeDataReadOptions(), key, &data_str);
- if (status.ok()) {
- scoped_refptr<base::RefCountedMemory> data =
- base::RefCountedString::TakeString(&data_str);
- attachment.reset(
- new Attachment(Attachment::CreateWithId(attachment_id, data)));
- } else {
- DVLOG(1) << "DB::Get failed: status=" << status.ToString();
+ status = db_->Get(MakeDataReadOptions(), key, &data_str);
+ if (!status.ok()) {
+ DVLOG(1) << "DB::Get for data failed: status=" << status.ToString();
+ return attachment.Pass();
+ }
+ scoped_refptr<base::RefCountedMemory> data =
+ base::RefCountedString::TakeString(&data_str);
+ uint32_t crc = ComputeCrc32c(data);
maniscalco 2014/11/11 00:44:54 crc -> crc32c
pavely 2014/11/11 22:27:15 Done.
+ if (record_metadata.has_crc32c() && record_metadata.crc32c() != crc) {
+ DVLOG(1) << "Attachment crc does not match";
+ return attachment.Pass();
}
+ attachment.reset(
+ new Attachment(Attachment::RestoreExisting(attachment_id, data, crc)));
return attachment.Pass();
}
@@ -247,6 +267,7 @@ bool OnDiskAttachmentStore::WriteSingleAttachment(
// Write metadata.
attachment_store_pb::RecordMetadata metadata;
metadata.set_attachment_size(attachment.GetData()->size());
+ metadata.set_crc32c(attachment.GetCrc32c());
metadata_str = metadata.SerializeAsString();
write_batch.Put(metadata_key, metadata_str);
// Write data.

Powered by Google App Engine
This is Rietveld 408576698