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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // Invokes |callback| with |result| and |attachments| in the |task_runner| | 29 // Invokes |callback| with |result| and |attachments| in the |task_runner| |
30 // thread. | 30 // thread. |
31 void ProxyDropCallback( | 31 void ProxyDropCallback( |
32 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 32 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
33 const AttachmentService::DropCallback& callback, | 33 const AttachmentService::DropCallback& callback, |
34 const AttachmentService::DropResult& result) { | 34 const AttachmentService::DropResult& result) { |
35 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); | 35 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); |
36 } | 36 } |
37 | 37 |
| 38 // Invokes |callback| with |result| and |attachments| in the |task_runner| |
| 39 // thread. |
| 40 void ProxyStoreCallback( |
| 41 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 42 const AttachmentService::StoreCallback& callback, |
| 43 const AttachmentService::StoreResult& result) { |
| 44 task_runner->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 45 } |
| 46 |
38 } // namespace | 47 } // namespace |
39 | 48 |
40 AttachmentServiceProxy::AttachmentServiceProxy() { | 49 AttachmentServiceProxy::AttachmentServiceProxy() { |
41 } | 50 } |
42 | 51 |
43 AttachmentServiceProxy::AttachmentServiceProxy( | 52 AttachmentServiceProxy::AttachmentServiceProxy( |
44 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 53 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
45 const base::WeakPtr<syncer::AttachmentService>& wrapped) | 54 const base::WeakPtr<syncer::AttachmentService>& wrapped) |
46 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { | 55 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) { |
47 DCHECK(wrapped_task_runner_.get()); | 56 DCHECK(wrapped_task_runner_.get()); |
48 } | 57 } |
49 | 58 |
50 AttachmentServiceProxy::AttachmentServiceProxy( | 59 AttachmentServiceProxy::AttachmentServiceProxy( |
51 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, | 60 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner, |
52 const scoped_refptr<Core>& core) | 61 const scoped_refptr<Core>& core) |
53 : wrapped_task_runner_(wrapped_task_runner), core_(core) { | 62 : wrapped_task_runner_(wrapped_task_runner), core_(core) { |
54 DCHECK(wrapped_task_runner_.get()); | 63 DCHECK(wrapped_task_runner_.get()); |
55 DCHECK(core_.get()); | 64 DCHECK(core_.get()); |
56 } | 65 } |
57 | 66 |
58 AttachmentServiceProxy::~AttachmentServiceProxy() { | 67 AttachmentServiceProxy::~AttachmentServiceProxy() { |
59 } | 68 } |
60 | 69 |
61 AttachmentStore* AttachmentServiceProxy::GetStore() { | |
62 return NULL; | |
63 } | |
64 | |
65 void AttachmentServiceProxy::GetOrDownloadAttachments( | 70 void AttachmentServiceProxy::GetOrDownloadAttachments( |
66 const AttachmentIdList& attachment_ids, | 71 const AttachmentIdList& attachment_ids, |
67 const GetOrDownloadCallback& callback) { | 72 const GetOrDownloadCallback& callback) { |
68 DCHECK(wrapped_task_runner_.get()); | 73 DCHECK(wrapped_task_runner_.get()); |
69 GetOrDownloadCallback proxy_callback = | 74 GetOrDownloadCallback proxy_callback = |
70 base::Bind(&ProxyGetOrDownloadCallback, | 75 base::Bind(&ProxyGetOrDownloadCallback, |
71 base::ThreadTaskRunnerHandle::Get(), | 76 base::ThreadTaskRunnerHandle::Get(), |
72 callback); | 77 callback); |
73 wrapped_task_runner_->PostTask( | 78 wrapped_task_runner_->PostTask( |
74 FROM_HERE, | 79 FROM_HERE, |
75 base::Bind(&AttachmentService::GetOrDownloadAttachments, | 80 base::Bind(&AttachmentService::GetOrDownloadAttachments, |
76 core_, | 81 core_, |
77 attachment_ids, | 82 attachment_ids, |
78 proxy_callback)); | 83 proxy_callback)); |
79 } | 84 } |
80 | 85 |
81 void AttachmentServiceProxy::DropAttachments( | 86 void AttachmentServiceProxy::DropAttachments( |
82 const AttachmentIdList& attachment_ids, | 87 const AttachmentIdList& attachment_ids, |
83 const DropCallback& callback) { | 88 const DropCallback& callback) { |
84 DCHECK(wrapped_task_runner_.get()); | 89 DCHECK(wrapped_task_runner_.get()); |
85 DropCallback proxy_callback = base::Bind( | 90 DropCallback proxy_callback = base::Bind( |
86 &ProxyDropCallback, base::ThreadTaskRunnerHandle::Get(), callback); | 91 &ProxyDropCallback, base::ThreadTaskRunnerHandle::Get(), callback); |
87 wrapped_task_runner_->PostTask(FROM_HERE, | 92 wrapped_task_runner_->PostTask(FROM_HERE, |
88 base::Bind(&AttachmentService::DropAttachments, | 93 base::Bind(&AttachmentService::DropAttachments, |
89 core_, | 94 core_, |
90 attachment_ids, | 95 attachment_ids, |
91 proxy_callback)); | 96 proxy_callback)); |
92 } | 97 } |
93 | 98 |
94 void AttachmentServiceProxy::UploadAttachments( | 99 void AttachmentServiceProxy::StoreAttachments(const AttachmentList& attachments, |
95 const AttachmentIdSet& attachment_ids) { | 100 const StoreCallback& callback) { |
96 DCHECK(wrapped_task_runner_); | 101 DCHECK(wrapped_task_runner_.get()); |
| 102 StoreCallback proxy_callback = base::Bind( |
| 103 &ProxyStoreCallback, base::ThreadTaskRunnerHandle::Get(), callback); |
97 wrapped_task_runner_->PostTask( | 104 wrapped_task_runner_->PostTask( |
98 FROM_HERE, | 105 FROM_HERE, |
99 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids)); | 106 base::Bind(&AttachmentService::StoreAttachments, |
| 107 core_, |
| 108 attachments, |
| 109 proxy_callback)); |
100 } | 110 } |
101 | 111 |
102 AttachmentServiceProxy::Core::Core( | 112 AttachmentServiceProxy::Core::Core( |
103 const base::WeakPtr<syncer::AttachmentService>& wrapped) | 113 const base::WeakPtr<syncer::AttachmentService>& wrapped) |
104 : wrapped_(wrapped) { | 114 : wrapped_(wrapped) { |
105 } | 115 } |
106 | 116 |
107 AttachmentServiceProxy::Core::~Core() { | 117 AttachmentServiceProxy::Core::~Core() { |
108 } | 118 } |
109 | 119 |
110 AttachmentStore* AttachmentServiceProxy::Core::GetStore() { | |
111 return NULL; | |
112 } | |
113 | |
114 void AttachmentServiceProxy::Core::GetOrDownloadAttachments( | 120 void AttachmentServiceProxy::Core::GetOrDownloadAttachments( |
115 const AttachmentIdList& attachment_ids, | 121 const AttachmentIdList& attachment_ids, |
116 const GetOrDownloadCallback& callback) { | 122 const GetOrDownloadCallback& callback) { |
117 if (!wrapped_) { | 123 if (!wrapped_) { |
118 return; | 124 return; |
119 } | 125 } |
120 wrapped_->GetOrDownloadAttachments(attachment_ids, callback); | 126 wrapped_->GetOrDownloadAttachments(attachment_ids, callback); |
121 } | 127 } |
122 | 128 |
123 void AttachmentServiceProxy::Core::DropAttachments( | 129 void AttachmentServiceProxy::Core::DropAttachments( |
124 const AttachmentIdList& attachment_ids, | 130 const AttachmentIdList& attachment_ids, |
125 const DropCallback& callback) { | 131 const DropCallback& callback) { |
126 if (!wrapped_) { | 132 if (!wrapped_) { |
127 return; | 133 return; |
128 } | 134 } |
129 wrapped_->DropAttachments(attachment_ids, callback); | 135 wrapped_->DropAttachments(attachment_ids, callback); |
130 } | 136 } |
131 | 137 |
132 void AttachmentServiceProxy::Core::UploadAttachments( | 138 void AttachmentServiceProxy::Core::StoreAttachments( |
133 const AttachmentIdSet& attachment_ids) { | 139 const AttachmentList& attachments, |
| 140 const StoreCallback& callback) { |
134 if (!wrapped_) { | 141 if (!wrapped_) { |
135 return; | 142 return; |
136 } | 143 } |
137 wrapped_->UploadAttachments(attachment_ids); | 144 wrapped_->StoreAttachments(attachments, callback); |
138 } | 145 } |
139 | 146 |
140 } // namespace syncer | 147 } // namespace syncer |
OLD | NEW |