| 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 "base/thread_task_runner_handle.h" | |
| 10 #include "sync/api/sync_data.h" | |
| 11 | |
| 12 namespace syncer { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // These ProxyFooCallback functions are used to invoke a callback in a specific | |
| 17 // thread. | |
| 18 | |
| 19 // Invokes |callback| with |result| and |attachments| in the |task_runner| | |
| 20 // thread. | |
| 21 void ProxyGetOrDownloadCallback( | |
| 22 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 23 const AttachmentService::GetOrDownloadCallback& callback, | |
| 24 const AttachmentService::GetOrDownloadResult& result, | |
| 25 scoped_ptr<AttachmentMap> attachments) { | |
| 26 task_runner->PostTask( | |
| 27 FROM_HERE, base::Bind(callback, result, base::Passed(&attachments))); | |
| 28 } | |
| 29 | |
| 30 // Invokes |callback| with |result| and |attachments| in the |task_runner| | |
| 31 // thread. | |
| 32 void ProxyDropCallback( | |
| 33 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 34 const AttachmentService::DropCallback& callback, | |
| 35 const AttachmentService::DropResult& result) { | |
| 36 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); | |
| 37 } | |
| 38 | |
| 39 // Invokes |callback| with |result| and |attachments| in the |task_runner| | |
| 40 // thread. | |
| 41 void ProxyStoreCallback( | |
| 42 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
| 43 const AttachmentService::StoreCallback& callback, | |
| 44 const AttachmentService::StoreResult& result) { | |
| 45 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 AttachmentServiceProxy::AttachmentServiceProxy() { | |
| 51 } | |
| 52 | |
| 53 AttachmentServiceProxy::AttachmentServiceProxy( | |
| 54 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | |
| 55 const base::WeakPtr<syncer::AttachmentService>& wrapped) | |
| 56 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { | |
| 57 DCHECK(wrapped_task_runner_); | |
| 58 } | |
| 59 | |
| 60 AttachmentServiceProxy::AttachmentServiceProxy( | |
| 61 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | |
| 62 const scoped_refptr<Core>& core) | |
| 63 : wrapped_task_runner_(wrapped_task_runner), core_(core) { | |
| 64 DCHECK(wrapped_task_runner_); | |
| 65 DCHECK(core_); | |
| 66 } | |
| 67 | |
| 68 AttachmentServiceProxy::~AttachmentServiceProxy() { | |
| 69 } | |
| 70 | |
| 71 void AttachmentServiceProxy::GetOrDownloadAttachments( | |
| 72 const AttachmentIdList& attachment_ids, | |
| 73 const GetOrDownloadCallback& callback) { | |
| 74 DCHECK(wrapped_task_runner_); | |
| 75 GetOrDownloadCallback proxy_callback = | |
| 76 base::Bind(&ProxyGetOrDownloadCallback, | |
| 77 base::ThreadTaskRunnerHandle::Get(), | |
| 78 callback); | |
| 79 wrapped_task_runner_->PostTask( | |
| 80 FROM_HERE, | |
| 81 base::Bind(&AttachmentService::GetOrDownloadAttachments, | |
| 82 core_, | |
| 83 attachment_ids, | |
| 84 proxy_callback)); | |
| 85 } | |
| 86 | |
| 87 void AttachmentServiceProxy::DropAttachments( | |
| 88 const AttachmentIdList& attachment_ids, | |
| 89 const DropCallback& callback) { | |
| 90 DCHECK(wrapped_task_runner_); | |
| 91 DropCallback proxy_callback = base::Bind( | |
| 92 &ProxyDropCallback, base::ThreadTaskRunnerHandle::Get(), callback); | |
| 93 wrapped_task_runner_->PostTask(FROM_HERE, | |
| 94 base::Bind(&AttachmentService::DropAttachments, | |
| 95 core_, | |
| 96 attachment_ids, | |
| 97 proxy_callback)); | |
| 98 } | |
| 99 | |
| 100 void AttachmentServiceProxy::StoreAttachments(const AttachmentList& attachments, | |
| 101 const StoreCallback& callback) { | |
| 102 DCHECK(wrapped_task_runner_); | |
| 103 StoreCallback proxy_callback = base::Bind( | |
| 104 &ProxyStoreCallback, base::ThreadTaskRunnerHandle::Get(), callback); | |
| 105 wrapped_task_runner_->PostTask( | |
| 106 FROM_HERE, | |
| 107 base::Bind(&AttachmentService::StoreAttachments, | |
| 108 core_, | |
| 109 attachments, | |
| 110 proxy_callback)); | |
| 111 } | |
| 112 | |
| 113 AttachmentServiceProxy::Core::Core( | |
| 114 const base::WeakPtr<syncer::AttachmentService>& wrapped) | |
| 115 : wrapped_(wrapped) { | |
| 116 } | |
| 117 | |
| 118 AttachmentServiceProxy::Core::~Core() { | |
| 119 } | |
| 120 | |
| 121 void AttachmentServiceProxy::Core::GetOrDownloadAttachments( | |
| 122 const AttachmentIdList& attachment_ids, | |
| 123 const GetOrDownloadCallback& callback) { | |
| 124 if (!wrapped_) { | |
| 125 return; | |
| 126 } | |
| 127 wrapped_->GetOrDownloadAttachments(attachment_ids, callback); | |
| 128 } | |
| 129 | |
| 130 void AttachmentServiceProxy::Core::DropAttachments( | |
| 131 const AttachmentIdList& attachment_ids, | |
| 132 const DropCallback& callback) { | |
| 133 if (!wrapped_) { | |
| 134 return; | |
| 135 } | |
| 136 wrapped_->DropAttachments(attachment_ids, callback); | |
| 137 } | |
| 138 | |
| 139 void AttachmentServiceProxy::Core::StoreAttachments( | |
| 140 const AttachmentList& attachments, | |
| 141 const StoreCallback& callback) { | |
| 142 if (!wrapped_) { | |
| 143 return; | |
| 144 } | |
| 145 wrapped_->StoreAttachments(attachments, callback); | |
| 146 } | |
| 147 | |
| 148 } // namespace syncer | |
| OLD | NEW |