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
));
40 AttachmentServiceProxy::AttachmentServiceProxy() {
43 AttachmentServiceProxy::AttachmentServiceProxy(
44 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
45 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
46 : wrapped_task_runner_(wrapped_task_runner
), core_(new Core(wrapped
)) {
47 DCHECK(wrapped_task_runner_
.get());
50 AttachmentServiceProxy::AttachmentServiceProxy(
51 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
52 const scoped_refptr
<Core
>& core
)
53 : wrapped_task_runner_(wrapped_task_runner
), core_(core
) {
54 DCHECK(wrapped_task_runner_
.get());
58 AttachmentServiceProxy::~AttachmentServiceProxy() {
61 AttachmentStore
* AttachmentServiceProxy::GetStore() {
65 void AttachmentServiceProxy::GetOrDownloadAttachments(
66 const AttachmentIdList
& attachment_ids
,
67 const GetOrDownloadCallback
& callback
) {
68 DCHECK(wrapped_task_runner_
.get());
69 GetOrDownloadCallback proxy_callback
=
70 base::Bind(&ProxyGetOrDownloadCallback
,
71 base::ThreadTaskRunnerHandle::Get(),
73 wrapped_task_runner_
->PostTask(
75 base::Bind(&AttachmentService::GetOrDownloadAttachments
,
81 void AttachmentServiceProxy::DropAttachments(
82 const AttachmentIdList
& attachment_ids
,
83 const DropCallback
& callback
) {
84 DCHECK(wrapped_task_runner_
.get());
85 DropCallback proxy_callback
= base::Bind(
86 &ProxyDropCallback
, base::ThreadTaskRunnerHandle::Get(), callback
);
87 wrapped_task_runner_
->PostTask(FROM_HERE
,
88 base::Bind(&AttachmentService::DropAttachments
,
94 void AttachmentServiceProxy::UploadAttachments(
95 const AttachmentIdSet
& attachment_ids
) {
96 DCHECK(wrapped_task_runner_
.get());
97 wrapped_task_runner_
->PostTask(
99 base::Bind(&AttachmentService::UploadAttachments
, core_
, attachment_ids
));
102 AttachmentServiceProxy::Core::Core(
103 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
104 : wrapped_(wrapped
) {
107 AttachmentServiceProxy::Core::~Core() {
110 AttachmentStore
* AttachmentServiceProxy::Core::GetStore() {
114 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
115 const AttachmentIdList
& attachment_ids
,
116 const GetOrDownloadCallback
& callback
) {
120 wrapped_
->GetOrDownloadAttachments(attachment_ids
, callback
);
123 void AttachmentServiceProxy::Core::DropAttachments(
124 const AttachmentIdList
& attachment_ids
,
125 const DropCallback
& callback
) {
129 wrapped_
->DropAttachments(attachment_ids
, callback
);
132 void AttachmentServiceProxy::Core::UploadAttachments(
133 const AttachmentIdSet
& attachment_ids
) {
137 wrapped_
->UploadAttachments(attachment_ids
);
140 } // namespace syncer