| 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_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 const GetOrDownloadCallback& callback) { | 169 const GetOrDownloadCallback& callback) { |
| 170 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 171 scoped_refptr<GetOrDownloadState> state( | 171 scoped_refptr<GetOrDownloadState> state( |
| 172 new GetOrDownloadState(attachment_ids, callback)); | 172 new GetOrDownloadState(attachment_ids, callback)); |
| 173 attachment_store_->Read(attachment_ids, | 173 attachment_store_->Read(attachment_ids, |
| 174 base::Bind(&AttachmentServiceImpl::ReadDone, | 174 base::Bind(&AttachmentServiceImpl::ReadDone, |
| 175 weak_ptr_factory_.GetWeakPtr(), | 175 weak_ptr_factory_.GetWeakPtr(), |
| 176 state)); | 176 state)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void AttachmentServiceImpl::DropAttachments( | |
| 180 const AttachmentIdList& attachment_ids, | |
| 181 const DropCallback& callback) { | |
| 182 DCHECK(CalledOnValidThread()); | |
| 183 attachment_store_->Drop(attachment_ids, | |
| 184 base::Bind(&AttachmentServiceImpl::DropDone, | |
| 185 weak_ptr_factory_.GetWeakPtr(), | |
| 186 callback)); | |
| 187 } | |
| 188 | |
| 189 void AttachmentServiceImpl::ReadDone( | 179 void AttachmentServiceImpl::ReadDone( |
| 190 const scoped_refptr<GetOrDownloadState>& state, | 180 const scoped_refptr<GetOrDownloadState>& state, |
| 191 const AttachmentStore::Result& result, | 181 const AttachmentStore::Result& result, |
| 192 scoped_ptr<AttachmentMap> attachments, | 182 scoped_ptr<AttachmentMap> attachments, |
| 193 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) { | 183 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) { |
| 194 // Add read attachments to result. | 184 // Add read attachments to result. |
| 195 for (AttachmentMap::const_iterator iter = attachments->begin(); | 185 for (AttachmentMap::const_iterator iter = attachments->begin(); |
| 196 iter != attachments->end(); | 186 iter != attachments->end(); |
| 197 ++iter) { | 187 ++iter) { |
| 198 state->AddAttachment(iter->second); | 188 state->AddAttachment(iter->second); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 227 case AttachmentStore::SUCCESS: | 217 case AttachmentStore::SUCCESS: |
| 228 state->AddAttachment(attachment); | 218 state->AddAttachment(attachment); |
| 229 break; | 219 break; |
| 230 case AttachmentStore::UNSPECIFIED_ERROR: | 220 case AttachmentStore::UNSPECIFIED_ERROR: |
| 231 case AttachmentStore::STORE_INITIALIZATION_FAILED: | 221 case AttachmentStore::STORE_INITIALIZATION_FAILED: |
| 232 state->AddUnavailableAttachmentId(attachment.GetId()); | 222 state->AddUnavailableAttachmentId(attachment.GetId()); |
| 233 break; | 223 break; |
| 234 } | 224 } |
| 235 } | 225 } |
| 236 | 226 |
| 237 void AttachmentServiceImpl::DropDone(const DropCallback& callback, | |
| 238 const AttachmentStore::Result& result) { | |
| 239 AttachmentService::DropResult drop_result = | |
| 240 AttachmentService::DROP_UNSPECIFIED_ERROR; | |
| 241 if (result == AttachmentStore::SUCCESS) { | |
| 242 drop_result = AttachmentService::DROP_SUCCESS; | |
| 243 } | |
| 244 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). | |
| 245 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 246 base::Bind(callback, drop_result)); | |
| 247 } | |
| 248 | |
| 249 void AttachmentServiceImpl::UploadDone( | 227 void AttachmentServiceImpl::UploadDone( |
| 250 const AttachmentUploader::UploadResult& result, | 228 const AttachmentUploader::UploadResult& result, |
| 251 const AttachmentId& attachment_id) { | 229 const AttachmentId& attachment_id) { |
| 252 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
| 253 switch (result) { | 231 switch (result) { |
| 254 case AttachmentUploader::UPLOAD_SUCCESS: | 232 case AttachmentUploader::UPLOAD_SUCCESS: |
| 255 upload_task_queue_->MarkAsSucceeded(attachment_id); | 233 upload_task_queue_->MarkAsSucceeded(attachment_id); |
| 256 if (delegate_) { | 234 if (delegate_) { |
| 257 delegate_->OnAttachmentUploaded(attachment_id); | 235 delegate_->OnAttachmentUploaded(attachment_id); |
| 258 } | 236 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 base::Bind(&AttachmentServiceImpl::UploadDone, | 320 base::Bind(&AttachmentServiceImpl::UploadDone, |
| 343 weak_ptr_factory_.GetWeakPtr())); | 321 weak_ptr_factory_.GetWeakPtr())); |
| 344 } | 322 } |
| 345 } | 323 } |
| 346 | 324 |
| 347 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { | 325 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { |
| 348 upload_task_queue_->SetTimerForTest(timer.Pass()); | 326 upload_task_queue_->SetTimerForTest(timer.Pass()); |
| 349 } | 327 } |
| 350 | 328 |
| 351 } // namespace syncer | 329 } // namespace syncer |
| OLD | NEW |