Chromium Code Reviews| 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" | |
| 6 | |
| 7 #include <iterator> | 5 #include <iterator> |
| 6 #include <utility> | |
| 8 | 7 |
| 9 #include "base/bind.h" | 8 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 13 #include "sync/api/attachments/attachment.h" | 12 #include "sync/api/attachments/attachment.h" |
| 13 #include "sync/internal_api/public/attachments/attachment_service_impl.h" | |
|
Nicolas Zea
2015/12/18 23:46:54
Keep up top
| |
| 14 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 14 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
| 15 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 15 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace syncer { |
| 18 | 18 |
| 19 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls. | 19 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls. |
| 20 // GetOrDownloadState tracks completion of these calls and posts callback for | 20 // GetOrDownloadState tracks completion of these calls and posts callback for |
| 21 // consumer once all attachments are either retrieved or reported unavailable. | 21 // consumer once all attachments are either retrieved or reported unavailable. |
| 22 class AttachmentServiceImpl::GetOrDownloadState | 22 class AttachmentServiceImpl::GetOrDownloadState |
| 23 : public base::RefCounted<GetOrDownloadState>, | 23 : public base::RefCounted<GetOrDownloadState>, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 AttachmentServiceImpl::AttachmentServiceImpl( | 112 AttachmentServiceImpl::AttachmentServiceImpl( |
| 113 scoped_ptr<AttachmentStoreForSync> attachment_store, | 113 scoped_ptr<AttachmentStoreForSync> attachment_store, |
| 114 scoped_ptr<AttachmentUploader> attachment_uploader, | 114 scoped_ptr<AttachmentUploader> attachment_uploader, |
| 115 scoped_ptr<AttachmentDownloader> attachment_downloader, | 115 scoped_ptr<AttachmentDownloader> attachment_downloader, |
| 116 Delegate* delegate, | 116 Delegate* delegate, |
| 117 const base::TimeDelta& initial_backoff_delay, | 117 const base::TimeDelta& initial_backoff_delay, |
| 118 const base::TimeDelta& max_backoff_delay) | 118 const base::TimeDelta& max_backoff_delay) |
| 119 : attachment_store_(attachment_store.Pass()), | 119 : attachment_store_(std::move(attachment_store)), |
| 120 attachment_uploader_(attachment_uploader.Pass()), | 120 attachment_uploader_(std::move(attachment_uploader)), |
| 121 attachment_downloader_(attachment_downloader.Pass()), | 121 attachment_downloader_(std::move(attachment_downloader)), |
| 122 delegate_(delegate), | 122 delegate_(delegate), |
| 123 weak_ptr_factory_(this) { | 123 weak_ptr_factory_(this) { |
| 124 DCHECK(CalledOnValidThread()); | 124 DCHECK(CalledOnValidThread()); |
| 125 DCHECK(attachment_store_.get()); | 125 DCHECK(attachment_store_.get()); |
| 126 | 126 |
| 127 // TODO(maniscalco): Observe network connectivity change events. When the | 127 // TODO(maniscalco): Observe network connectivity change events. When the |
| 128 // network becomes disconnected, consider suspending queue dispatch. When | 128 // network becomes disconnected, consider suspending queue dispatch. When |
| 129 // connectivity is restored, consider clearing any dispatch backoff (bug | 129 // connectivity is restored, consider clearing any dispatch backoff (bug |
| 130 // 411981). | 130 // 411981). |
| 131 upload_task_queue_.reset(new TaskQueue<AttachmentId>( | 131 upload_task_queue_.reset(new TaskQueue<AttachmentId>( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 146 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { | 146 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { |
| 147 scoped_ptr<syncer::AttachmentStore> attachment_store = | 147 scoped_ptr<syncer::AttachmentStore> attachment_store = |
| 148 AttachmentStore::CreateInMemoryStore(); | 148 AttachmentStore::CreateInMemoryStore(); |
| 149 scoped_ptr<AttachmentUploader> attachment_uploader( | 149 scoped_ptr<AttachmentUploader> attachment_uploader( |
| 150 new FakeAttachmentUploader); | 150 new FakeAttachmentUploader); |
| 151 scoped_ptr<AttachmentDownloader> attachment_downloader( | 151 scoped_ptr<AttachmentDownloader> attachment_downloader( |
| 152 new FakeAttachmentDownloader()); | 152 new FakeAttachmentDownloader()); |
| 153 scoped_ptr<syncer::AttachmentService> attachment_service( | 153 scoped_ptr<syncer::AttachmentService> attachment_service( |
| 154 new syncer::AttachmentServiceImpl( | 154 new syncer::AttachmentServiceImpl( |
| 155 attachment_store->CreateAttachmentStoreForSync(), | 155 attachment_store->CreateAttachmentStoreForSync(), |
| 156 attachment_uploader.Pass(), attachment_downloader.Pass(), NULL, | 156 std::move(attachment_uploader), std::move(attachment_downloader), |
| 157 base::TimeDelta(), base::TimeDelta())); | 157 NULL, base::TimeDelta(), base::TimeDelta())); |
| 158 return attachment_service.Pass(); | 158 return attachment_service; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void AttachmentServiceImpl::GetOrDownloadAttachments( | 161 void AttachmentServiceImpl::GetOrDownloadAttachments( |
| 162 const AttachmentIdList& attachment_ids, | 162 const AttachmentIdList& attachment_ids, |
| 163 const GetOrDownloadCallback& callback) { | 163 const GetOrDownloadCallback& callback) { |
| 164 DCHECK(CalledOnValidThread()); | 164 DCHECK(CalledOnValidThread()); |
| 165 scoped_refptr<GetOrDownloadState> state( | 165 scoped_refptr<GetOrDownloadState> state( |
| 166 new GetOrDownloadState(attachment_ids, callback)); | 166 new GetOrDownloadState(attachment_ids, callback)); |
| 167 // SetModelTypeReference() makes attachments visible for model type. | 167 // SetModelTypeReference() makes attachments visible for model type. |
| 168 // Needed when attachment doesn't have model type reference, but still | 168 // Needed when attachment doesn't have model type reference, but still |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 AttachmentMap::const_iterator end = attachments->end(); | 319 AttachmentMap::const_iterator end = attachments->end(); |
| 320 for (; iter != end; ++iter) { | 320 for (; iter != end; ++iter) { |
| 321 attachment_uploader_->UploadAttachment( | 321 attachment_uploader_->UploadAttachment( |
| 322 iter->second, | 322 iter->second, |
| 323 base::Bind(&AttachmentServiceImpl::UploadDone, | 323 base::Bind(&AttachmentServiceImpl::UploadDone, |
| 324 weak_ptr_factory_.GetWeakPtr())); | 324 weak_ptr_factory_.GetWeakPtr())); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { | 328 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { |
| 329 upload_task_queue_->SetTimerForTest(timer.Pass()); | 329 upload_task_queue_->SetTimerForTest(std::move(timer)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace syncer | 332 } // namespace syncer |
| OLD | NEW |