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

Side by Side Diff: components/sync/core_impl/attachments/on_disk_attachment_store.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 "components/sync/core/attachments/on_disk_attachment_store.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "sync/internal_api/attachments/proto/attachment_store.pb.h" 18 #include "components/sync/core/attachments/attachment_util.h"
19 #include "sync/internal_api/public/attachments/attachment_util.h" 19 #include "components/sync/core_impl/attachments/proto/attachment_store.pb.h"
20 #include "sync/protocol/attachments.pb.h" 20 #include "components/sync/protocol/attachments.pb.h"
21 #include "third_party/leveldatabase/env_chromium.h" 21 #include "third_party/leveldatabase/env_chromium.h"
22 #include "third_party/leveldatabase/src/include/leveldb/db.h" 22 #include "third_party/leveldatabase/src/include/leveldb/db.h"
23 #include "third_party/leveldatabase/src/include/leveldb/options.h" 23 #include "third_party/leveldatabase/src/include/leveldb/options.h"
24 #include "third_party/leveldatabase/src/include/leveldb/slice.h" 24 #include "third_party/leveldatabase/src/include/leveldb/slice.h"
25 #include "third_party/leveldatabase/src/include/leveldb/status.h" 25 #include "third_party/leveldatabase/src/include/leveldb/status.h"
26 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 26 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
27 27
28 namespace syncer { 28 namespace syncer {
29 29
30 namespace { 30 namespace {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 } 147 }
148 return false; 148 return false;
149 } 149 }
150 150
151 } // namespace 151 } // namespace
152 152
153 OnDiskAttachmentStore::OnDiskAttachmentStore( 153 OnDiskAttachmentStore::OnDiskAttachmentStore(
154 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner, 154 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner,
155 const base::FilePath& path) 155 const base::FilePath& path)
156 : AttachmentStoreBackend(callback_task_runner), path_(path) { 156 : AttachmentStoreBackend(callback_task_runner), path_(path) {}
157 }
158 157
159 OnDiskAttachmentStore::~OnDiskAttachmentStore() { 158 OnDiskAttachmentStore::~OnDiskAttachmentStore() {}
160 }
161 159
162 void OnDiskAttachmentStore::Init( 160 void OnDiskAttachmentStore::Init(
163 const AttachmentStore::InitCallback& callback) { 161 const AttachmentStore::InitCallback& callback) {
164 DCHECK(CalledOnValidThread()); 162 DCHECK(CalledOnValidThread());
165 AttachmentStore::Result result_code = OpenOrCreate(path_); 163 AttachmentStore::Result result_code = OpenOrCreate(path_);
166 UMA_HISTOGRAM_ENUMERATION("Sync.Attachments.StoreInitResult", result_code, 164 UMA_HISTOGRAM_ENUMERATION("Sync.Attachments.StoreInitResult", result_code,
167 AttachmentStore::RESULT_SIZE); 165 AttachmentStore::RESULT_SIZE);
168 PostCallback(base::Bind(callback, result_code)); 166 PostCallback(base::Bind(callback, result_code));
169 } 167 }
170 168
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 attachment_store_pb::RecordMetadata record_metadata; 410 attachment_store_pb::RecordMetadata record_metadata;
413 if (!ReadSingleRecordMetadata(attachment_id, &record_metadata)) { 411 if (!ReadSingleRecordMetadata(attachment_id, &record_metadata)) {
414 return attachment; 412 return attachment;
415 } 413 }
416 if (!AttachmentHasReferenceFromComponent(record_metadata, 414 if (!AttachmentHasReferenceFromComponent(record_metadata,
417 ComponentToProto(component))) 415 ComponentToProto(component)))
418 return attachment; 416 return attachment;
419 417
420 const std::string key = MakeDataKeyFromAttachmentId(attachment_id); 418 const std::string key = MakeDataKeyFromAttachmentId(attachment_id);
421 std::string data_str; 419 std::string data_str;
422 leveldb::Status status = db_->Get( 420 leveldb::Status status =
423 MakeNonCachingReadOptions(), key, &data_str); 421 db_->Get(MakeNonCachingReadOptions(), key, &data_str);
424 if (!status.ok()) { 422 if (!status.ok()) {
425 DVLOG(1) << "DB::Get for data failed: status=" << status.ToString(); 423 DVLOG(1) << "DB::Get for data failed: status=" << status.ToString();
426 return attachment; 424 return attachment;
427 } 425 }
428 scoped_refptr<base::RefCountedMemory> data = 426 scoped_refptr<base::RefCountedMemory> data =
429 base::RefCountedString::TakeString(&data_str); 427 base::RefCountedString::TakeString(&data_str);
430 uint32_t crc32c = ComputeCrc32c(data); 428 uint32_t crc32c = ComputeCrc32c(data);
431 if (record_metadata.has_crc32c()) { 429 if (record_metadata.has_crc32c()) {
432 if (record_metadata.crc32c() != crc32c) { 430 if (record_metadata.crc32c() != crc32c) {
433 DVLOG(1) << "Attachment crc32c does not match value read from store"; 431 DVLOG(1) << "Attachment crc32c does not match value read from store";
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 return key; 532 return key;
535 } 533 }
536 534
537 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( 535 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata(
538 const AttachmentId& attachment_id, 536 const AttachmentId& attachment_id,
539 const attachment_store_pb::RecordMetadata& record_metadata) { 537 const attachment_store_pb::RecordMetadata& record_metadata) {
540 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); 538 return AttachmentMetadata(attachment_id, record_metadata.attachment_size());
541 } 539 }
542 540
543 } // namespace syncer 541 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698