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
3 // found in the LICENSE file.
5 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/thread_task_runner_handle.h"
15 // These ProxyFooCallback functions are used to invoke a callback in a specific
18 // Invokes |callback| with |result| and |attachments| in the |task_runner|
20 void ProxyGetOrDownloadCallback(
21 const scoped_refptr
<base::SequencedTaskRunner
>& task_runner
,
22 const AttachmentService::GetOrDownloadCallback
& callback
,
23 const AttachmentService::GetOrDownloadResult
& result
,
24 scoped_ptr
<AttachmentMap
> attachments
) {
25 task_runner
->PostTask(
26 FROM_HERE
, base::Bind(callback
, result
, base::Passed(&attachments
)));
29 // Invokes |callback| with |result| and |attachments| in the |task_runner|
31 void ProxyDropCallback(
32 const scoped_refptr
<base::SequencedTaskRunner
>& task_runner
,
33 const AttachmentService::DropCallback
& callback
,
34 const AttachmentService::DropResult
& result
) {
35 task_runner
->PostTask(FROM_HERE
, base::Bind(callback
, result
));
38 // Invokes |callback| with |result| and |attachments| in the |task_runner|
40 void ProxyStoreCallback(
41 const scoped_refptr
<base::SequencedTaskRunner
>& task_runner
,
42 const AttachmentService::StoreCallback
& callback
,
43 const AttachmentService::StoreResult
& result
) {
44 task_runner
->PostTask(FROM_HERE
, base::Bind(callback
, result
));
49 AttachmentServiceProxy::AttachmentServiceProxy() {
52 AttachmentServiceProxy::AttachmentServiceProxy(
53 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
54 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
55 : wrapped_task_runner_(wrapped_task_runner
), core_(new Core(wrapped
)) {
56 DCHECK(wrapped_task_runner_
.get());
59 AttachmentServiceProxy::AttachmentServiceProxy(
60 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
61 const scoped_refptr
<Core
>& core
)
62 : wrapped_task_runner_(wrapped_task_runner
), core_(core
) {
63 DCHECK(wrapped_task_runner_
.get());
67 AttachmentServiceProxy::~AttachmentServiceProxy() {
70 void AttachmentServiceProxy::GetOrDownloadAttachments(
71 const AttachmentIdList
& attachment_ids
,
72 const GetOrDownloadCallback
& callback
) {
73 DCHECK(wrapped_task_runner_
.get());
74 GetOrDownloadCallback proxy_callback
=
75 base::Bind(&ProxyGetOrDownloadCallback
,
76 base::ThreadTaskRunnerHandle::Get(),
78 wrapped_task_runner_
->PostTask(
80 base::Bind(&AttachmentService::GetOrDownloadAttachments
,
86 void AttachmentServiceProxy::DropAttachments(
87 const AttachmentIdList
& attachment_ids
,
88 const DropCallback
& callback
) {
89 DCHECK(wrapped_task_runner_
.get());
90 DropCallback proxy_callback
= base::Bind(
91 &ProxyDropCallback
, base::ThreadTaskRunnerHandle::Get(), callback
);
92 wrapped_task_runner_
->PostTask(FROM_HERE
,
93 base::Bind(&AttachmentService::DropAttachments
,
99 void AttachmentServiceProxy::StoreAttachments(const AttachmentList
& attachments
,
100 const StoreCallback
& callback
) {
101 DCHECK(wrapped_task_runner_
.get());
102 StoreCallback proxy_callback
= base::Bind(
103 &ProxyStoreCallback
, base::ThreadTaskRunnerHandle::Get(), callback
);
104 wrapped_task_runner_
->PostTask(
106 base::Bind(&AttachmentService::StoreAttachments
,
112 AttachmentServiceProxy::Core::Core(
113 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
114 : wrapped_(wrapped
) {
117 AttachmentServiceProxy::Core::~Core() {
120 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
121 const AttachmentIdList
& attachment_ids
,
122 const GetOrDownloadCallback
& callback
) {
126 wrapped_
->GetOrDownloadAttachments(attachment_ids
, callback
);
129 void AttachmentServiceProxy::Core::DropAttachments(
130 const AttachmentIdList
& attachment_ids
,
131 const DropCallback
& callback
) {
135 wrapped_
->DropAttachments(attachment_ids
, callback
);
138 void AttachmentServiceProxy::Core::StoreAttachments(
139 const AttachmentList
& attachments
,
140 const StoreCallback
& callback
) {
144 wrapped_
->StoreAttachments(attachments
, callback
);
147 } // namespace syncer