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