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