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/api/attachments/attachment_service_proxy.h"
8 #include "base/message_loop/message_loop.h"
9 #include "sync/api/sync_data.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_);
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_);
67 AttachmentServiceProxy::~AttachmentServiceProxy() {
70 void AttachmentServiceProxy::GetOrDownloadAttachments(
71 const AttachmentIdList& attachment_ids,
72 const GetOrDownloadCallback& callback) {
73 DCHECK(wrapped_task_runner_);
74 GetOrDownloadCallback proxy_callback = base::Bind(
75 &ProxyGetOrDownloadCallback, base::MessageLoopProxy::current(), callback);
76 wrapped_task_runner_->PostTask(
78 base::Bind(&AttachmentService::GetOrDownloadAttachments,
84 void AttachmentServiceProxy::DropAttachments(
85 const AttachmentIdList& attachment_ids,
86 const DropCallback& callback) {
87 DCHECK(wrapped_task_runner_);
88 DropCallback proxy_callback = base::Bind(
89 &ProxyDropCallback, base::MessageLoopProxy::current(), callback);
90 wrapped_task_runner_->PostTask(FROM_HERE,
91 base::Bind(&AttachmentService::DropAttachments,
97 void AttachmentServiceProxy::StoreAttachments(const AttachmentList& attachments,
98 const StoreCallback& callback) {
99 DCHECK(wrapped_task_runner_);
100 StoreCallback proxy_callback = base::Bind(
101 &ProxyStoreCallback, base::MessageLoopProxy::current(), callback);
102 wrapped_task_runner_->PostTask(
104 base::Bind(&AttachmentService::StoreAttachments,
110 void AttachmentServiceProxy::OnSyncDataDelete(const SyncData& sync_data) {
111 DCHECK(wrapped_task_runner_);
112 wrapped_task_runner_->PostTask(
114 base::Bind(&AttachmentService::OnSyncDataDelete, core_, sync_data));
117 void AttachmentServiceProxy::OnSyncDataUpdate(
118 const AttachmentIdList& old_attachment_ids,
119 const SyncData& updated_sync_data) {
120 DCHECK(wrapped_task_runner_);
121 wrapped_task_runner_->PostTask(
123 base::Bind(&AttachmentService::OnSyncDataUpdate,
129 AttachmentServiceProxy::Core::Core(
130 const base::WeakPtr<syncer::AttachmentService>& wrapped)
131 : wrapped_(wrapped) {
134 AttachmentServiceProxy::Core::~Core() {
137 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
138 const AttachmentIdList& attachment_ids,
139 const GetOrDownloadCallback& callback) {
143 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
146 void AttachmentServiceProxy::Core::DropAttachments(
147 const AttachmentIdList& attachment_ids,
148 const DropCallback& callback) {
152 wrapped_->DropAttachments(attachment_ids, callback);
155 void AttachmentServiceProxy::Core::StoreAttachments(
156 const AttachmentList& attachments,
157 const StoreCallback& callback) {
161 wrapped_->StoreAttachments(attachments, callback);
164 void AttachmentServiceProxy::Core::OnSyncDataDelete(const SyncData& sync_data) {
168 wrapped_->OnSyncDataDelete(sync_data);
171 void AttachmentServiceProxy::Core::OnSyncDataUpdate(
172 const AttachmentIdList& old_attachment_ids,
173 const SyncData& updated_sync_data) {
177 wrapped_->OnSyncDataUpdate(old_attachment_ids, updated_sync_data);
180 } // namespace syncer