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