OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "sync/api/attachments/attachment_service_proxy.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "sync/api/sync_data.h" |
| 10 |
| 11 namespace syncer { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // These ProxyFooCallback functions are used to invoke a callback in a specific |
| 16 // thread. |
| 17 |
| 18 // Invokes |callback| with |result| and |attachments| in the |task_runner| |
| 19 // thread. |
| 20 void ProxyGetOrDownloadCallback( |
| 21 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 22 const AttachmentService::GetOrDownloadCallback& callback, |
| 23 const AttachmentService::GetOrDownloadResult& result, |
| 24 const AttachmentMap& attachments) { |
| 25 task_runner->PostTask(FROM_HERE, base::Bind(callback, result, attachments)); |
| 26 } |
| 27 |
| 28 // Invokes |callback| with |result| and |attachments| in the |task_runner| |
| 29 // thread. |
| 30 void ProxyDropCallback( |
| 31 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 32 const AttachmentService::DropCallback& callback, |
| 33 const AttachmentService::DropResult& result) { |
| 34 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 AttachmentServiceProxy::AttachmentServiceProxy( |
| 40 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
| 41 base::WeakPtr<syncer::AttachmentService> wrapped) |
| 42 : wrapped_task_runner_(wrapped_task_runner), |
| 43 wrapped_(wrapped), |
| 44 weak_ptr_factory_(this) {} |
| 45 |
| 46 AttachmentServiceProxy::~AttachmentServiceProxy() {} |
| 47 |
| 48 void AttachmentServiceProxy::GetOrDownloadAttachments( |
| 49 const AttachmentIdList& attachment_ids, |
| 50 const GetOrDownloadCallback& callback) { |
| 51 GetOrDownloadCallback proxy_callback = base::Bind( |
| 52 &ProxyGetOrDownloadCallback, base::MessageLoopProxy::current(), callback); |
| 53 wrapped_task_runner_->PostTask( |
| 54 FROM_HERE, |
| 55 base::Bind(&AttachmentService::GetOrDownloadAttachments, |
| 56 wrapped_, |
| 57 attachment_ids, |
| 58 proxy_callback)); |
| 59 } |
| 60 |
| 61 void AttachmentServiceProxy::DropAttachments( |
| 62 const AttachmentIdList& attachment_ids, |
| 63 const DropCallback& callback) { |
| 64 DropCallback proxy_callback = base::Bind( |
| 65 &ProxyDropCallback, base::MessageLoopProxy::current(), callback); |
| 66 wrapped_task_runner_->PostTask(FROM_HERE, |
| 67 base::Bind(&AttachmentService::DropAttachments, |
| 68 wrapped_, |
| 69 attachment_ids, |
| 70 proxy_callback)); |
| 71 } |
| 72 |
| 73 void AttachmentServiceProxy::OnSyncDataAdd(const SyncData& sync_data) { |
| 74 wrapped_task_runner_->PostTask( |
| 75 FROM_HERE, |
| 76 base::Bind(&AttachmentService::OnSyncDataAdd, wrapped_, sync_data)); |
| 77 } |
| 78 |
| 79 void AttachmentServiceProxy::OnSyncDataDelete(const SyncData& sync_data) { |
| 80 wrapped_task_runner_->PostTask( |
| 81 FROM_HERE, |
| 82 base::Bind(&AttachmentService::OnSyncDataDelete, wrapped_, sync_data)); |
| 83 } |
| 84 |
| 85 void AttachmentServiceProxy::OnSyncDataUpdate( |
| 86 const AttachmentIdList& old_attachment_ids, |
| 87 const SyncData& updated_sync_data) { |
| 88 wrapped_task_runner_->PostTask( |
| 89 FROM_HERE, |
| 90 base::Bind(&AttachmentService::OnSyncDataUpdate, |
| 91 wrapped_, |
| 92 old_attachment_ids, |
| 93 updated_sync_data)); |
| 94 } |
| 95 |
| 96 base::WeakPtr<AttachmentService> AttachmentServiceProxy::AsWeakPtr() { |
| 97 return weak_ptr_factory_.GetWeakPtr(); |
| 98 } |
| 99 |
| 100 } // namespace syncer |
OLD | NEW |