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
)));
31 AttachmentServiceProxy::AttachmentServiceProxy() {
34 AttachmentServiceProxy::AttachmentServiceProxy(
35 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
36 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
37 : wrapped_task_runner_(wrapped_task_runner
), core_(new Core(wrapped
)) {
38 DCHECK(wrapped_task_runner_
.get());
41 AttachmentServiceProxy::AttachmentServiceProxy(
42 const scoped_refptr
<base::SequencedTaskRunner
>& wrapped_task_runner
,
43 const scoped_refptr
<Core
>& core
)
44 : wrapped_task_runner_(wrapped_task_runner
), core_(core
) {
45 DCHECK(wrapped_task_runner_
.get());
49 AttachmentServiceProxy::~AttachmentServiceProxy() {
52 void AttachmentServiceProxy::GetOrDownloadAttachments(
53 const AttachmentIdList
& attachment_ids
,
54 const GetOrDownloadCallback
& callback
) {
55 DCHECK(wrapped_task_runner_
.get());
56 GetOrDownloadCallback proxy_callback
=
57 base::Bind(&ProxyGetOrDownloadCallback
,
58 base::ThreadTaskRunnerHandle::Get(),
60 wrapped_task_runner_
->PostTask(
62 base::Bind(&AttachmentService::GetOrDownloadAttachments
,
68 void AttachmentServiceProxy::UploadAttachments(
69 const AttachmentIdList
& attachment_ids
) {
70 DCHECK(wrapped_task_runner_
.get());
71 wrapped_task_runner_
->PostTask(
73 base::Bind(&AttachmentService::UploadAttachments
, core_
, attachment_ids
));
76 AttachmentServiceProxy::Core::Core(
77 const base::WeakPtr
<syncer::AttachmentService
>& wrapped
)
81 AttachmentServiceProxy::Core::~Core() {
84 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
85 const AttachmentIdList
& attachment_ids
,
86 const GetOrDownloadCallback
& callback
) {
90 wrapped_
->GetOrDownloadAttachments(attachment_ids
, callback
);
93 void AttachmentServiceProxy::Core::UploadAttachments(
94 const AttachmentIdList
& attachment_ids
) {
98 wrapped_
->UploadAttachments(attachment_ids
);
101 } // namespace syncer