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 "components/sync/core/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/threading/thread_task_runner_handle.h" | 9 #include "base/threading/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 std::unique_ptr<AttachmentMap> attachments) { | 24 std::unique_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 } // namespace | 29 } // namespace |
30 | 30 |
31 AttachmentServiceProxy::AttachmentServiceProxy() { | 31 AttachmentServiceProxy::AttachmentServiceProxy() {} |
32 } | |
33 | 32 |
34 AttachmentServiceProxy::AttachmentServiceProxy( | 33 AttachmentServiceProxy::AttachmentServiceProxy( |
35 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 34 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
36 const base::WeakPtr<syncer::AttachmentService>& wrapped) | 35 const base::WeakPtr<syncer::AttachmentService>& wrapped) |
37 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { | 36 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { |
38 DCHECK(wrapped_task_runner_.get()); | 37 DCHECK(wrapped_task_runner_.get()); |
39 } | 38 } |
40 | 39 |
41 AttachmentServiceProxy::AttachmentServiceProxy( | 40 AttachmentServiceProxy::AttachmentServiceProxy( |
42 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 41 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
43 const scoped_refptr<Core>& core) | 42 const scoped_refptr<Core>& core) |
44 : wrapped_task_runner_(wrapped_task_runner), core_(core) { | 43 : wrapped_task_runner_(wrapped_task_runner), core_(core) { |
45 DCHECK(wrapped_task_runner_.get()); | 44 DCHECK(wrapped_task_runner_.get()); |
46 DCHECK(core_.get()); | 45 DCHECK(core_.get()); |
47 } | 46 } |
48 | 47 |
49 AttachmentServiceProxy::AttachmentServiceProxy( | 48 AttachmentServiceProxy::AttachmentServiceProxy( |
50 const AttachmentServiceProxy& other) = default; | 49 const AttachmentServiceProxy& other) = default; |
51 | 50 |
52 AttachmentServiceProxy::~AttachmentServiceProxy() { | 51 AttachmentServiceProxy::~AttachmentServiceProxy() {} |
53 } | |
54 | 52 |
55 void AttachmentServiceProxy::GetOrDownloadAttachments( | 53 void AttachmentServiceProxy::GetOrDownloadAttachments( |
56 const AttachmentIdList& attachment_ids, | 54 const AttachmentIdList& attachment_ids, |
57 const GetOrDownloadCallback& callback) { | 55 const GetOrDownloadCallback& callback) { |
58 DCHECK(wrapped_task_runner_.get()); | 56 DCHECK(wrapped_task_runner_.get()); |
59 GetOrDownloadCallback proxy_callback = | 57 GetOrDownloadCallback proxy_callback = |
60 base::Bind(&ProxyGetOrDownloadCallback, | 58 base::Bind(&ProxyGetOrDownloadCallback, |
61 base::ThreadTaskRunnerHandle::Get(), | 59 base::ThreadTaskRunnerHandle::Get(), callback); |
62 callback); | |
63 wrapped_task_runner_->PostTask( | 60 wrapped_task_runner_->PostTask( |
64 FROM_HERE, | 61 FROM_HERE, base::Bind(&AttachmentService::GetOrDownloadAttachments, core_, |
65 base::Bind(&AttachmentService::GetOrDownloadAttachments, | 62 attachment_ids, proxy_callback)); |
66 core_, | |
67 attachment_ids, | |
68 proxy_callback)); | |
69 } | 63 } |
70 | 64 |
71 void AttachmentServiceProxy::UploadAttachments( | 65 void AttachmentServiceProxy::UploadAttachments( |
72 const AttachmentIdList& attachment_ids) { | 66 const AttachmentIdList& attachment_ids) { |
73 DCHECK(wrapped_task_runner_.get()); | 67 DCHECK(wrapped_task_runner_.get()); |
74 wrapped_task_runner_->PostTask( | 68 wrapped_task_runner_->PostTask( |
75 FROM_HERE, | 69 FROM_HERE, |
76 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids)); | 70 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids)); |
77 } | 71 } |
78 | 72 |
79 AttachmentServiceProxy::Core::Core( | 73 AttachmentServiceProxy::Core::Core( |
80 const base::WeakPtr<syncer::AttachmentService>& wrapped) | 74 const base::WeakPtr<syncer::AttachmentService>& wrapped) |
81 : wrapped_(wrapped) { | 75 : wrapped_(wrapped) {} |
82 } | |
83 | 76 |
84 AttachmentServiceProxy::Core::~Core() { | 77 AttachmentServiceProxy::Core::~Core() {} |
85 } | |
86 | 78 |
87 void AttachmentServiceProxy::Core::GetOrDownloadAttachments( | 79 void AttachmentServiceProxy::Core::GetOrDownloadAttachments( |
88 const AttachmentIdList& attachment_ids, | 80 const AttachmentIdList& attachment_ids, |
89 const GetOrDownloadCallback& callback) { | 81 const GetOrDownloadCallback& callback) { |
90 if (!wrapped_) { | 82 if (!wrapped_) { |
91 return; | 83 return; |
92 } | 84 } |
93 wrapped_->GetOrDownloadAttachments(attachment_ids, callback); | 85 wrapped_->GetOrDownloadAttachments(attachment_ids, callback); |
94 } | 86 } |
95 | 87 |
96 void AttachmentServiceProxy::Core::UploadAttachments( | 88 void AttachmentServiceProxy::Core::UploadAttachments( |
97 const AttachmentIdList& attachment_ids) { | 89 const AttachmentIdList& attachment_ids) { |
98 if (!wrapped_) { | 90 if (!wrapped_) { |
99 return; | 91 return; |
100 } | 92 } |
101 wrapped_->UploadAttachments(attachment_ids); | 93 wrapped_->UploadAttachments(attachment_ids); |
102 } | 94 } |
103 | 95 |
104 } // namespace syncer | 96 } // namespace syncer |
OLD | NEW |