| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "sync/api/attachments/attachment.h" | 16 #include "sync/api/attachments/attachment.h" |
| 16 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 17 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
| 17 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 18 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
| 18 | 19 |
| 19 namespace syncer { | 20 namespace syncer { |
| 20 | 21 |
| 21 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls. | 22 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls. |
| 22 // GetOrDownloadState tracks completion of these calls and posts callback for | 23 // GetOrDownloadState tracks completion of these calls and posts callback for |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 in_progress_attachments_.erase(attachment_id); | 99 in_progress_attachments_.erase(attachment_id); |
| 99 PostResultIfAllRequestsCompleted(); | 100 PostResultIfAllRequestsCompleted(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void | 103 void |
| 103 AttachmentServiceImpl::GetOrDownloadState::PostResultIfAllRequestsCompleted() { | 104 AttachmentServiceImpl::GetOrDownloadState::PostResultIfAllRequestsCompleted() { |
| 104 if (in_progress_attachments_.empty()) { | 105 if (in_progress_attachments_.empty()) { |
| 105 // All requests completed. Let's notify consumer. | 106 // All requests completed. Let's notify consumer. |
| 106 GetOrDownloadResult result = | 107 GetOrDownloadResult result = |
| 107 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; | 108 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; |
| 108 base::MessageLoop::current()->PostTask( | 109 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 109 FROM_HERE, | 110 FROM_HERE, |
| 110 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); | 111 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 AttachmentServiceImpl::AttachmentServiceImpl( | 115 AttachmentServiceImpl::AttachmentServiceImpl( |
| 115 std::unique_ptr<AttachmentStoreForSync> attachment_store, | 116 std::unique_ptr<AttachmentStoreForSync> attachment_store, |
| 116 std::unique_ptr<AttachmentUploader> attachment_uploader, | 117 std::unique_ptr<AttachmentUploader> attachment_uploader, |
| 117 std::unique_ptr<AttachmentDownloader> attachment_downloader, | 118 std::unique_ptr<AttachmentDownloader> attachment_downloader, |
| 118 Delegate* delegate, | 119 Delegate* delegate, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 weak_ptr_factory_.GetWeakPtr())); | 328 weak_ptr_factory_.GetWeakPtr())); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 | 331 |
| 331 void AttachmentServiceImpl::SetTimerForTest( | 332 void AttachmentServiceImpl::SetTimerForTest( |
| 332 std::unique_ptr<base::Timer> timer) { | 333 std::unique_ptr<base::Timer> timer) { |
| 333 upload_task_queue_->SetTimerForTest(std::move(timer)); | 334 upload_task_queue_->SetTimerForTest(std::move(timer)); |
| 334 } | 335 } |
| 335 | 336 |
| 336 } // namespace syncer | 337 } // namespace syncer |
| OLD | NEW |