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

Side by Side Diff: sync/internal_api/attachments/attachment_store_frontend.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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sync/internal_api/public/attachments/attachment_store_frontend.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/sequenced_task_runner.h"
12 #include "sync/api/attachments/attachment.h"
13 #include "sync/api/attachments/attachment_store_backend.h"
14
15 namespace syncer {
16
17 namespace {
18
19 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreFrontend dtor.
20 // It doesn't need to do anything.
21 void NoOp(std::unique_ptr<AttachmentStoreBackend> backend) {}
22
23 } // namespace
24
25 AttachmentStoreFrontend::AttachmentStoreFrontend(
26 std::unique_ptr<AttachmentStoreBackend> backend,
27 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner)
28 : backend_(std::move(backend)), backend_task_runner_(backend_task_runner) {
29 DCHECK(backend_);
30 DCHECK(backend_task_runner_.get());
31 }
32
33 AttachmentStoreFrontend::~AttachmentStoreFrontend() {
34 DCHECK(backend_);
35 // To delete backend post task that doesn't do anything, but binds backend
36 // through base::Passed. This way backend will be deleted regardless whether
37 // task runs or not.
38 backend_task_runner_->PostTask(FROM_HERE,
39 base::Bind(&NoOp, base::Passed(&backend_)));
40 }
41
42 void AttachmentStoreFrontend::Init(
43 const AttachmentStore::InitCallback& callback) {
44 DCHECK(CalledOnValidThread());
45 backend_task_runner_->PostTask(
46 FROM_HERE, base::Bind(&AttachmentStoreBackend::Init,
47 base::Unretained(backend_.get()), callback));
48 }
49
50 void AttachmentStoreFrontend::Read(
51 AttachmentStore::Component component,
52 const AttachmentIdList& ids,
53 const AttachmentStore::ReadCallback& callback) {
54 DCHECK(CalledOnValidThread());
55 backend_task_runner_->PostTask(
56 FROM_HERE,
57 base::Bind(&AttachmentStoreBackend::Read,
58 base::Unretained(backend_.get()), component, ids, callback));
59 }
60
61 void AttachmentStoreFrontend::Write(
62 AttachmentStore::Component component,
63 const AttachmentList& attachments,
64 const AttachmentStore::WriteCallback& callback) {
65 DCHECK(CalledOnValidThread());
66 backend_task_runner_->PostTask(
67 FROM_HERE, base::Bind(&AttachmentStoreBackend::Write,
68 base::Unretained(backend_.get()), component,
69 attachments, callback));
70 }
71
72 void AttachmentStoreFrontend::SetReference(AttachmentStore::Component component,
73 const AttachmentIdList& ids) {
74 DCHECK(CalledOnValidThread());
75 backend_task_runner_->PostTask(
76 FROM_HERE, base::Bind(&AttachmentStoreBackend::SetReference,
77 base::Unretained(backend_.get()), component, ids));
78 }
79
80 void AttachmentStoreFrontend::DropReference(
81 AttachmentStore::Component component,
82 const AttachmentIdList& ids,
83 const AttachmentStore::DropCallback& callback) {
84 DCHECK(CalledOnValidThread());
85 backend_task_runner_->PostTask(
86 FROM_HERE,
87 base::Bind(&AttachmentStoreBackend::DropReference,
88 base::Unretained(backend_.get()), component, ids, callback));
89 }
90
91 void AttachmentStoreFrontend::ReadMetadataById(
92 AttachmentStore::Component component,
93 const AttachmentIdList& ids,
94 const AttachmentStore::ReadMetadataCallback& callback) {
95 DCHECK(CalledOnValidThread());
96 backend_task_runner_->PostTask(
97 FROM_HERE,
98 base::Bind(&AttachmentStoreBackend::ReadMetadataById,
99 base::Unretained(backend_.get()), component, ids, callback));
100 }
101
102 void AttachmentStoreFrontend::ReadMetadata(
103 AttachmentStore::Component component,
104 const AttachmentStore::ReadMetadataCallback& callback) {
105 DCHECK(CalledOnValidThread());
106 backend_task_runner_->PostTask(
107 FROM_HERE,
108 base::Bind(&AttachmentStoreBackend::ReadMetadata,
109 base::Unretained(backend_.get()), component, callback));
110 }
111
112 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698