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.
5 #include "sync/internal_api/public/attachments/attachment_store_frontend.h"
8 #include "base/location.h"
9 #include "base/sequenced_task_runner.h"
10 #include "sync/api/attachments/attachment.h"
11 #include "sync/api/attachments/attachment_store_backend.h"
17 // NoOp is needed to bind base::Passed(backend) in AttachmentStoreFrontend dtor.
18 // It doesn't need to do anything.
19 void NoOp(scoped_ptr
<AttachmentStoreBackend
> backend
) {
24 AttachmentStoreFrontend::AttachmentStoreFrontend(
25 scoped_ptr
<AttachmentStoreBackend
> backend
,
26 const scoped_refptr
<base::SequencedTaskRunner
>& backend_task_runner
)
27 : backend_(backend
.Pass()), backend_task_runner_(backend_task_runner
) {
29 DCHECK(backend_task_runner_
.get());
32 AttachmentStoreFrontend::~AttachmentStoreFrontend() {
34 // To delete backend post task that doesn't do anything, but binds backend
35 // through base::Passed. This way backend will be deleted regardless whether
37 backend_task_runner_
->PostTask(FROM_HERE
,
38 base::Bind(&NoOp
, base::Passed(&backend_
)));
41 void AttachmentStoreFrontend::Init(
42 const AttachmentStore::InitCallback
& callback
) {
43 DCHECK(CalledOnValidThread());
44 backend_task_runner_
->PostTask(
45 FROM_HERE
, base::Bind(&AttachmentStoreBackend::Init
,
46 base::Unretained(backend_
.get()), callback
));
49 void AttachmentStoreFrontend::Read(
50 AttachmentStore::Component component
,
51 const AttachmentIdList
& ids
,
52 const AttachmentStore::ReadCallback
& callback
) {
53 DCHECK(CalledOnValidThread());
54 backend_task_runner_
->PostTask(
56 base::Bind(&AttachmentStoreBackend::Read
,
57 base::Unretained(backend_
.get()), component
, ids
, callback
));
60 void AttachmentStoreFrontend::Write(
61 AttachmentStore::Component component
,
62 const AttachmentList
& attachments
,
63 const AttachmentStore::WriteCallback
& callback
) {
64 DCHECK(CalledOnValidThread());
65 backend_task_runner_
->PostTask(
66 FROM_HERE
, base::Bind(&AttachmentStoreBackend::Write
,
67 base::Unretained(backend_
.get()), component
,
68 attachments
, callback
));
71 void AttachmentStoreFrontend::SetReference(AttachmentStore::Component component
,
72 const AttachmentIdList
& ids
) {
73 DCHECK(CalledOnValidThread());
74 backend_task_runner_
->PostTask(
75 FROM_HERE
, base::Bind(&AttachmentStoreBackend::SetReference
,
76 base::Unretained(backend_
.get()), component
, ids
));
79 void AttachmentStoreFrontend::DropReference(
80 AttachmentStore::Component component
,
81 const AttachmentIdList
& ids
,
82 const AttachmentStore::DropCallback
& callback
) {
83 DCHECK(CalledOnValidThread());
84 backend_task_runner_
->PostTask(
86 base::Bind(&AttachmentStoreBackend::DropReference
,
87 base::Unretained(backend_
.get()), component
, ids
, callback
));
90 void AttachmentStoreFrontend::ReadMetadataById(
91 AttachmentStore::Component component
,
92 const AttachmentIdList
& ids
,
93 const AttachmentStore::ReadMetadataCallback
& callback
) {
94 DCHECK(CalledOnValidThread());
95 backend_task_runner_
->PostTask(
97 base::Bind(&AttachmentStoreBackend::ReadMetadataById
,
98 base::Unretained(backend_
.get()), component
, ids
, callback
));
101 void AttachmentStoreFrontend::ReadMetadata(
102 AttachmentStore::Component component
,
103 const AttachmentStore::ReadMetadataCallback
& callback
) {
104 DCHECK(CalledOnValidThread());
105 backend_task_runner_
->PostTask(
107 base::Bind(&AttachmentStoreBackend::ReadMetadata
,
108 base::Unretained(backend_
.get()), component
, callback
));
111 } // namespace syncer