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

Side by Side Diff: sync/internal_api/attachments/on_disk_attachment_store.cc

Issue 982883002: [Sync] Add size and crc32c to AttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" 5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 std::string data_str; 312 std::string data_str;
313 leveldb::Status status = db_->Get( 313 leveldb::Status status = db_->Get(
314 MakeNonCachingReadOptions(), key, &data_str); 314 MakeNonCachingReadOptions(), key, &data_str);
315 if (!status.ok()) { 315 if (!status.ok()) {
316 DVLOG(1) << "DB::Get for data failed: status=" << status.ToString(); 316 DVLOG(1) << "DB::Get for data failed: status=" << status.ToString();
317 return attachment.Pass(); 317 return attachment.Pass();
318 } 318 }
319 scoped_refptr<base::RefCountedMemory> data = 319 scoped_refptr<base::RefCountedMemory> data =
320 base::RefCountedString::TakeString(&data_str); 320 base::RefCountedString::TakeString(&data_str);
321 uint32_t crc32c = ComputeCrc32c(data); 321 uint32_t crc32c = ComputeCrc32c(data);
322 if (record_metadata.has_crc32c() && record_metadata.crc32c() != crc32c) { 322 if (record_metadata.has_crc32c()) {
323 DVLOG(1) << "Attachment crc does not match"; 323 if (record_metadata.crc32c() != crc32c) {
324 return attachment.Pass(); 324 DVLOG(1) << "Attachment crc32c does not match value read from store";
325 return attachment.Pass();
326 }
327 if (record_metadata.crc32c() != attachment_id.GetCrc32c()) {
328 DVLOG(1) << "Attachment crc32c does not match value in AttachmentId";
329 return attachment.Pass();
330 }
325 } 331 }
326 attachment.reset( 332 attachment.reset(
327 new Attachment(Attachment::CreateFromParts(attachment_id, data, crc32c))); 333 new Attachment(Attachment::CreateFromParts(attachment_id, data)));
328 return attachment.Pass(); 334 return attachment.Pass();
329 } 335 }
330 336
331 bool OnDiskAttachmentStore::WriteSingleAttachment( 337 bool OnDiskAttachmentStore::WriteSingleAttachment(
332 const Attachment& attachment) { 338 const Attachment& attachment) {
333 const std::string metadata_key = 339 const std::string metadata_key =
334 MakeMetadataKeyFromAttachmentId(attachment.GetId()); 340 MakeMetadataKeyFromAttachmentId(attachment.GetId());
335 const std::string data_key = MakeDataKeyFromAttachmentId(attachment.GetId()); 341 const std::string data_key = MakeDataKeyFromAttachmentId(attachment.GetId());
336 342
337 std::string metadata_str; 343 std::string metadata_str;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return key; 406 return key;
401 } 407 }
402 408
403 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( 409 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata(
404 const AttachmentId& attachment_id, 410 const AttachmentId& attachment_id,
405 const attachment_store_pb::RecordMetadata& record_metadata) { 411 const attachment_store_pb::RecordMetadata& record_metadata) {
406 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); 412 return AttachmentMetadata(attachment_id, record_metadata.attachment_size());
407 } 413 }
408 414
409 } // namespace syncer 415 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698