| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 // TODO(maniscalco): Observe network connectivity change events. When the | 128 // TODO(maniscalco): Observe network connectivity change events. When the |
| 129 // network becomes disconnected, consider suspending queue dispatch. When | 129 // network becomes disconnected, consider suspending queue dispatch. When |
| 130 // connectivity is restored, consider clearing any dispatch backoff (bug | 130 // connectivity is restored, consider clearing any dispatch backoff (bug |
| 131 // 411981). | 131 // 411981). |
| 132 upload_task_queue_.reset(new TaskQueue<AttachmentId>( | 132 upload_task_queue_.reset(new TaskQueue<AttachmentId>( |
| 133 base::Bind(&AttachmentServiceImpl::BeginUpload, | 133 base::Bind(&AttachmentServiceImpl::BeginUpload, |
| 134 weak_ptr_factory_.GetWeakPtr()), | 134 weak_ptr_factory_.GetWeakPtr()), |
| 135 initial_backoff_delay, | 135 initial_backoff_delay, |
| 136 max_backoff_delay)); | 136 max_backoff_delay)); |
| 137 |
| 138 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 137 } | 139 } |
| 138 | 140 |
| 139 AttachmentServiceImpl::~AttachmentServiceImpl() { | 141 AttachmentServiceImpl::~AttachmentServiceImpl() { |
| 140 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
| 143 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Static. | 146 // Static. |
| 144 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { | 147 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { |
| 145 scoped_refptr<syncer::AttachmentStore> attachment_store( | 148 scoped_refptr<syncer::AttachmentStore> attachment_store( |
| 146 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get())); | 149 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get())); |
| 147 scoped_ptr<AttachmentUploader> attachment_uploader( | 150 scoped_ptr<AttachmentUploader> attachment_uploader( |
| 148 new FakeAttachmentUploader); | 151 new FakeAttachmentUploader); |
| 149 scoped_ptr<AttachmentDownloader> attachment_downloader( | 152 scoped_ptr<AttachmentDownloader> attachment_downloader( |
| 150 new FakeAttachmentDownloader()); | 153 new FakeAttachmentDownloader()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (!attachment_uploader_.get()) { | 284 if (!attachment_uploader_.get()) { |
| 282 return; | 285 return; |
| 283 } | 286 } |
| 284 AttachmentIdSet::const_iterator iter = attachment_ids.begin(); | 287 AttachmentIdSet::const_iterator iter = attachment_ids.begin(); |
| 285 AttachmentIdSet::const_iterator end = attachment_ids.end(); | 288 AttachmentIdSet::const_iterator end = attachment_ids.end(); |
| 286 for (; iter != end; ++iter) { | 289 for (; iter != end; ++iter) { |
| 287 upload_task_queue_->AddToQueue(*iter); | 290 upload_task_queue_->AddToQueue(*iter); |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 | 293 |
| 294 void AttachmentServiceImpl::OnNetworkChanged( |
| 295 net::NetworkChangeNotifier::ConnectionType type) { |
| 296 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 297 upload_task_queue_->ResetBackoff(); |
| 298 } |
| 299 } |
| 300 |
| 291 void AttachmentServiceImpl::ReadDoneNowUpload( | 301 void AttachmentServiceImpl::ReadDoneNowUpload( |
| 292 const AttachmentStore::Result& result, | 302 const AttachmentStore::Result& result, |
| 293 scoped_ptr<AttachmentMap> attachments, | 303 scoped_ptr<AttachmentMap> attachments, |
| 294 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) { | 304 scoped_ptr<AttachmentIdList> unavailable_attachment_ids) { |
| 295 DCHECK(CalledOnValidThread()); | 305 DCHECK(CalledOnValidThread()); |
| 296 if (!unavailable_attachment_ids->empty()) { | 306 if (!unavailable_attachment_ids->empty()) { |
| 297 // TODO(maniscalco): We failed to read some attachments. What should we do | 307 // TODO(maniscalco): We failed to read some attachments. What should we do |
| 298 // now? | 308 // now? |
| 299 AttachmentIdList::const_iterator iter = unavailable_attachment_ids->begin(); | 309 AttachmentIdList::const_iterator iter = unavailable_attachment_ids->begin(); |
| 300 AttachmentIdList::const_iterator end = unavailable_attachment_ids->end(); | 310 AttachmentIdList::const_iterator end = unavailable_attachment_ids->end(); |
| 301 for (; iter != end; ++iter) { | 311 for (; iter != end; ++iter) { |
| 302 upload_task_queue_->Cancel(*iter); | 312 upload_task_queue_->Cancel(*iter); |
| 303 } | 313 } |
| 304 } | 314 } |
| 305 | 315 |
| 306 AttachmentMap::const_iterator iter = attachments->begin(); | 316 AttachmentMap::const_iterator iter = attachments->begin(); |
| 307 AttachmentMap::const_iterator end = attachments->end(); | 317 AttachmentMap::const_iterator end = attachments->end(); |
| 308 for (; iter != end; ++iter) { | 318 for (; iter != end; ++iter) { |
| 309 attachment_uploader_->UploadAttachment( | 319 attachment_uploader_->UploadAttachment( |
| 310 iter->second, | 320 iter->second, |
| 311 base::Bind(&AttachmentServiceImpl::UploadDone, | 321 base::Bind(&AttachmentServiceImpl::UploadDone, |
| 312 weak_ptr_factory_.GetWeakPtr())); | 322 weak_ptr_factory_.GetWeakPtr())); |
| 313 } | 323 } |
| 314 } | 324 } |
| 315 | 325 |
| 326 void AttachmentServiceImpl::SetTimerForTest(scoped_ptr<base::Timer> timer) { |
| 327 upload_task_queue_->SetTimerForTest(timer.Pass()); |
| 328 } |
| 329 |
| 316 } // namespace syncer | 330 } // namespace syncer |
| OLD | NEW |