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

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

Issue 995683002: Revert of [Sync] Add size and crc32c to AttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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()) { 322 if (record_metadata.has_crc32c() && record_metadata.crc32c() != crc32c) {
323 if (record_metadata.crc32c() != crc32c) { 323 DVLOG(1) << "Attachment crc does not match";
324 DVLOG(1) << "Attachment crc32c does not match value read from store"; 324 return attachment.Pass();
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 }
331 } 325 }
332 attachment.reset( 326 attachment.reset(
333 new Attachment(Attachment::CreateFromParts(attachment_id, data))); 327 new Attachment(Attachment::CreateFromParts(attachment_id, data, crc32c)));
334 return attachment.Pass(); 328 return attachment.Pass();
335 } 329 }
336 330
337 bool OnDiskAttachmentStore::WriteSingleAttachment( 331 bool OnDiskAttachmentStore::WriteSingleAttachment(
338 const Attachment& attachment) { 332 const Attachment& attachment) {
339 const std::string metadata_key = 333 const std::string metadata_key =
340 MakeMetadataKeyFromAttachmentId(attachment.GetId()); 334 MakeMetadataKeyFromAttachmentId(attachment.GetId());
341 const std::string data_key = MakeDataKeyFromAttachmentId(attachment.GetId()); 335 const std::string data_key = MakeDataKeyFromAttachmentId(attachment.GetId());
342 336
343 std::string metadata_str; 337 std::string metadata_str;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 return key; 400 return key;
407 } 401 }
408 402
409 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( 403 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata(
410 const AttachmentId& attachment_id, 404 const AttachmentId& attachment_id,
411 const attachment_store_pb::RecordMetadata& record_metadata) { 405 const attachment_store_pb::RecordMetadata& record_metadata) {
412 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); 406 return AttachmentMetadata(attachment_id, record_metadata.attachment_size());
413 } 407 }
414 408
415 } // namespace syncer 409 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698