| 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 "components/sync/model_impl/attachments/attachment_service_impl.h" | 5 #include "components/sync/model_impl/attachments/attachment_service_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 download_requests.insert(std::make_pair(id, callback)); | 142 download_requests.insert(std::make_pair(id, callback)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Multiple requests to download will be active at the same time. | 145 // Multiple requests to download will be active at the same time. |
| 146 // RespondToDownload should respond to only one of them. | 146 // RespondToDownload should respond to only one of them. |
| 147 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { | 147 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { |
| 148 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); | 148 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); |
| 149 std::unique_ptr<Attachment> attachment; | 149 std::unique_ptr<Attachment> attachment; |
| 150 if (result == DOWNLOAD_SUCCESS) { | 150 if (result == DOWNLOAD_SUCCESS) { |
| 151 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); | 151 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); |
| 152 attachment.reset(new Attachment(Attachment::CreateFromParts(id, data))); | 152 attachment = |
| 153 base::MakeUnique<Attachment>(Attachment::CreateFromParts(id, data)); |
| 153 } | 154 } |
| 154 base::ThreadTaskRunnerHandle::Get()->PostTask( | 155 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 155 FROM_HERE, | 156 FROM_HERE, |
| 156 base::Bind(download_requests[id], result, base::Passed(&attachment))); | 157 base::Bind(download_requests[id], result, base::Passed(&attachment))); |
| 157 | 158 |
| 158 download_requests.erase(id); | 159 download_requests.erase(id); |
| 159 } | 160 } |
| 160 | 161 |
| 161 std::map<AttachmentId, DownloadCallback> download_requests; | 162 std::map<AttachmentId, DownloadCallback> download_requests; |
| 162 | 163 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 std::unique_ptr<AttachmentStore> attachment_store = | 232 std::unique_ptr<AttachmentStore> attachment_store = |
| 232 AttachmentStore::CreateMockStoreForTest( | 233 AttachmentStore::CreateMockStoreForTest( |
| 233 std::move(attachment_store_backend)); | 234 std::move(attachment_store_backend)); |
| 234 | 235 |
| 235 if (uploader.get()) { | 236 if (uploader.get()) { |
| 236 attachment_uploader_ = uploader->AsWeakPtr(); | 237 attachment_uploader_ = uploader->AsWeakPtr(); |
| 237 } | 238 } |
| 238 if (downloader.get()) { | 239 if (downloader.get()) { |
| 239 attachment_downloader_ = downloader->AsWeakPtr(); | 240 attachment_downloader_ = downloader->AsWeakPtr(); |
| 240 } | 241 } |
| 241 attachment_service_.reset(new AttachmentServiceImpl( | 242 attachment_service_ = base::MakeUnique<AttachmentServiceImpl>( |
| 242 attachment_store->CreateAttachmentStoreForSync(), std::move(uploader), | 243 attachment_store->CreateAttachmentStoreForSync(), std::move(uploader), |
| 243 std::move(downloader), delegate, base::TimeDelta::FromMinutes(1), | 244 std::move(downloader), delegate, base::TimeDelta::FromMinutes(1), |
| 244 base::TimeDelta::FromMinutes(8))); | 245 base::TimeDelta::FromMinutes(8)); |
| 245 | 246 |
| 246 std::unique_ptr<base::MockTimer> timer_to_pass( | 247 std::unique_ptr<base::MockTimer> timer_to_pass( |
| 247 new base::MockTimer(false, false)); | 248 new base::MockTimer(false, false)); |
| 248 mock_timer_ = timer_to_pass.get(); | 249 mock_timer_ = timer_to_pass.get(); |
| 249 attachment_service_->SetTimerForTest(std::move(timer_to_pass)); | 250 attachment_service_->SetTimerForTest(std::move(timer_to_pass)); |
| 250 } | 251 } |
| 251 | 252 |
| 252 AttachmentService* attachment_service() { return attachment_service_.get(); } | 253 AttachmentService* attachment_service() { return attachment_service_.get(); } |
| 253 | 254 |
| 254 base::MockTimer* mock_timer() { return mock_timer_; } | 255 base::MockTimer* mock_timer() { return mock_timer_; } |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 628 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
| 628 net::NetworkChangeNotifier::CONNECTION_WIFI); | 629 net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 629 RunLoop(); | 630 RunLoop(); |
| 630 | 631 |
| 631 // No longer in backoff. | 632 // No longer in backoff. |
| 632 ASSERT_TRUE(mock_timer()->IsRunning()); | 633 ASSERT_TRUE(mock_timer()->IsRunning()); |
| 633 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); | 634 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); |
| 634 } | 635 } |
| 635 | 636 |
| 636 } // namespace syncer | 637 } // namespace syncer |
| OLD | NEW |