| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // All requests completed. Let's notify consumer. | 103 // All requests completed. Let's notify consumer. |
| 104 GetOrDownloadResult result = | 104 GetOrDownloadResult result = |
| 105 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; | 105 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; |
| 106 base::MessageLoop::current()->PostTask( | 106 base::MessageLoop::current()->PostTask( |
| 107 FROM_HERE, | 107 FROM_HERE, |
| 108 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); | 108 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 AttachmentServiceImpl::AttachmentServiceImpl( | 112 AttachmentServiceImpl::AttachmentServiceImpl( |
| 113 scoped_ptr<AttachmentStore> attachment_store, | 113 scoped_refptr<AttachmentStore> 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 : attachment_store_(attachment_store.Pass()), | 117 : attachment_store_(attachment_store), |
| 118 attachment_uploader_(attachment_uploader.Pass()), | 118 attachment_uploader_(attachment_uploader.Pass()), |
| 119 attachment_downloader_(attachment_downloader.Pass()), | 119 attachment_downloader_(attachment_downloader.Pass()), |
| 120 delegate_(delegate), | 120 delegate_(delegate), |
| 121 weak_ptr_factory_(this) { | 121 weak_ptr_factory_(this) { |
| 122 DCHECK(CalledOnValidThread()); | 122 DCHECK(CalledOnValidThread()); |
| 123 DCHECK(attachment_store_); | 123 DCHECK(attachment_store_.get()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 AttachmentServiceImpl::~AttachmentServiceImpl() { | 126 AttachmentServiceImpl::~AttachmentServiceImpl() { |
| 127 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Static. | 130 // Static. |
| 131 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { | 131 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { |
| 132 scoped_ptr<syncer::AttachmentStore> attachment_store( | 132 scoped_refptr<syncer::AttachmentStore> attachment_store( |
| 133 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get())); | 133 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get())); |
| 134 scoped_ptr<AttachmentUploader> attachment_uploader( | 134 scoped_ptr<AttachmentUploader> attachment_uploader( |
| 135 new FakeAttachmentUploader); | 135 new FakeAttachmentUploader); |
| 136 scoped_ptr<AttachmentDownloader> attachment_downloader( | 136 scoped_ptr<AttachmentDownloader> attachment_downloader( |
| 137 new FakeAttachmentDownloader()); | 137 new FakeAttachmentDownloader()); |
| 138 scoped_ptr<syncer::AttachmentService> attachment_service( | 138 scoped_ptr<syncer::AttachmentService> attachment_service( |
| 139 new syncer::AttachmentServiceImpl(attachment_store.Pass(), | 139 new syncer::AttachmentServiceImpl(attachment_store, |
| 140 attachment_uploader.Pass(), | 140 attachment_uploader.Pass(), |
| 141 attachment_downloader.Pass(), | 141 attachment_downloader.Pass(), |
| 142 NULL)); | 142 NULL)); |
| 143 return attachment_service.Pass(); | 143 return attachment_service.Pass(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 AttachmentStore* AttachmentServiceImpl::GetStore() { | 146 AttachmentStore* AttachmentServiceImpl::GetStore() { |
| 147 return attachment_store_.get(); | 147 return attachment_store_.get(); |
| 148 } | 148 } |
| 149 | 149 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 AttachmentMap::const_iterator end = attachments->end(); | 287 AttachmentMap::const_iterator end = attachments->end(); |
| 288 for (; iter != end; ++iter) { | 288 for (; iter != end; ++iter) { |
| 289 attachment_uploader_->UploadAttachment( | 289 attachment_uploader_->UploadAttachment( |
| 290 iter->second, | 290 iter->second, |
| 291 base::Bind(&AttachmentServiceImpl::UploadDone, | 291 base::Bind(&AttachmentServiceImpl::UploadDone, |
| 292 weak_ptr_factory_.GetWeakPtr())); | 292 weak_ptr_factory_.GetWeakPtr())); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace syncer | 296 } // namespace syncer |
| OLD | NEW |