OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/api/attachments/attachment_service_proxy.h" | 5 #include "sync/api/attachments/attachment_service_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "sync/api/sync_data.h" | 9 #include "sync/api/sync_data.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // Invokes |callback| with |result| and |attachments| in the |task_runner| | 29 // Invokes |callback| with |result| and |attachments| in the |task_runner| |
30 // thread. | 30 // thread. |
31 void ProxyDropCallback( | 31 void ProxyDropCallback( |
32 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 32 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
33 const AttachmentService::DropCallback& callback, | 33 const AttachmentService::DropCallback& callback, |
34 const AttachmentService::DropResult& result) { | 34 const AttachmentService::DropResult& result) { |
35 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); | 35 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); |
36 } | 36 } |
37 | 37 |
38 // Invokes |callback| with |result| and |attachments| in the |task_runner| | |
39 // thread. | |
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)); | |
45 } | |
46 | |
47 } // namespace | 38 } // namespace |
48 | 39 |
49 AttachmentServiceProxy::AttachmentServiceProxy() { | 40 AttachmentServiceProxy::AttachmentServiceProxy() { |
50 } | 41 } |
51 | 42 |
52 AttachmentServiceProxy::AttachmentServiceProxy( | 43 AttachmentServiceProxy::AttachmentServiceProxy( |
53 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 44 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
54 const base::WeakPtr<syncer::AttachmentService>& wrapped) | 45 const base::WeakPtr<syncer::AttachmentService>& wrapped) |
55 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { | 46 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { |
56 DCHECK(wrapped_task_runner_); | 47 DCHECK(wrapped_task_runner_); |
(...skipping 30 matching lines...) Expand all Loading... |
87 DCHECK(wrapped_task_runner_); | 78 DCHECK(wrapped_task_runner_); |
88 DropCallback proxy_callback = base::Bind( | 79 DropCallback proxy_callback = base::Bind( |
89 &ProxyDropCallback, base::MessageLoopProxy::current(), callback); | 80 &ProxyDropCallback, base::MessageLoopProxy::current(), callback); |
90 wrapped_task_runner_->PostTask(FROM_HERE, | 81 wrapped_task_runner_->PostTask(FROM_HERE, |
91 base::Bind(&AttachmentService::DropAttachments, | 82 base::Bind(&AttachmentService::DropAttachments, |
92 core_, | 83 core_, |
93 attachment_ids, | 84 attachment_ids, |
94 proxy_callback)); | 85 proxy_callback)); |
95 } | 86 } |
96 | 87 |
97 void AttachmentServiceProxy::StoreAttachments(const AttachmentList& attachments, | 88 void AttachmentServiceProxy::OnSyncDataAdd(const SyncData& sync_data) { |
98 const StoreCallback& callback) { | |
99 DCHECK(wrapped_task_runner_); | 89 DCHECK(wrapped_task_runner_); |
100 StoreCallback proxy_callback = base::Bind( | |
101 &ProxyStoreCallback, base::MessageLoopProxy::current(), callback); | |
102 wrapped_task_runner_->PostTask( | 90 wrapped_task_runner_->PostTask( |
103 FROM_HERE, | 91 FROM_HERE, |
104 base::Bind(&AttachmentService::StoreAttachments, | 92 base::Bind(&AttachmentService::OnSyncDataAdd, core_, sync_data)); |
105 core_, | |
106 attachments, | |
107 proxy_callback)); | |
108 } | 93 } |
109 | 94 |
110 void AttachmentServiceProxy::OnSyncDataDelete(const SyncData& sync_data) { | 95 void AttachmentServiceProxy::OnSyncDataDelete(const SyncData& sync_data) { |
111 DCHECK(wrapped_task_runner_); | 96 DCHECK(wrapped_task_runner_); |
112 wrapped_task_runner_->PostTask( | 97 wrapped_task_runner_->PostTask( |
113 FROM_HERE, | 98 FROM_HERE, |
114 base::Bind(&AttachmentService::OnSyncDataDelete, core_, sync_data)); | 99 base::Bind(&AttachmentService::OnSyncDataDelete, core_, sync_data)); |
115 } | 100 } |
116 | 101 |
117 void AttachmentServiceProxy::OnSyncDataUpdate( | 102 void AttachmentServiceProxy::OnSyncDataUpdate( |
(...skipping 27 matching lines...) Expand all Loading... |
145 | 130 |
146 void AttachmentServiceProxy::Core::DropAttachments( | 131 void AttachmentServiceProxy::Core::DropAttachments( |
147 const AttachmentIdList& attachment_ids, | 132 const AttachmentIdList& attachment_ids, |
148 const DropCallback& callback) { | 133 const DropCallback& callback) { |
149 if (!wrapped_) { | 134 if (!wrapped_) { |
150 return; | 135 return; |
151 } | 136 } |
152 wrapped_->DropAttachments(attachment_ids, callback); | 137 wrapped_->DropAttachments(attachment_ids, callback); |
153 } | 138 } |
154 | 139 |
155 void AttachmentServiceProxy::Core::StoreAttachments( | 140 void AttachmentServiceProxy::Core::OnSyncDataAdd(const SyncData& sync_data) { |
156 const AttachmentList& attachments, | |
157 const StoreCallback& callback) { | |
158 if (!wrapped_) { | 141 if (!wrapped_) { |
159 return; | 142 return; |
160 } | 143 } |
161 wrapped_->StoreAttachments(attachments, callback); | 144 wrapped_->OnSyncDataAdd(sync_data); |
162 } | 145 } |
163 | 146 |
164 void AttachmentServiceProxy::Core::OnSyncDataDelete(const SyncData& sync_data) { | 147 void AttachmentServiceProxy::Core::OnSyncDataDelete(const SyncData& sync_data) { |
165 if (!wrapped_) { | 148 if (!wrapped_) { |
166 return; | 149 return; |
167 } | 150 } |
168 wrapped_->OnSyncDataDelete(sync_data); | 151 wrapped_->OnSyncDataDelete(sync_data); |
169 } | 152 } |
170 | 153 |
171 void AttachmentServiceProxy::Core::OnSyncDataUpdate( | 154 void AttachmentServiceProxy::Core::OnSyncDataUpdate( |
172 const AttachmentIdList& old_attachment_ids, | 155 const AttachmentIdList& old_attachment_ids, |
173 const SyncData& updated_sync_data) { | 156 const SyncData& updated_sync_data) { |
174 if (!wrapped_) { | 157 if (!wrapped_) { |
175 return; | 158 return; |
176 } | 159 } |
177 wrapped_->OnSyncDataUpdate(old_attachment_ids, updated_sync_data); | 160 wrapped_->OnSyncDataUpdate(old_attachment_ids, updated_sync_data); |
178 } | 161 } |
179 | 162 |
180 } // namespace syncer | 163 } // namespace syncer |
OLD | NEW |