Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: components/sync/api_impl/attachments/attachment_service_impl.cc

Issue 2399953002: [Sync] Move attachments code out of core/. (Closed)
Patch Set: Address comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/core/attachments/attachment_service_impl.h" 5 #include "components/sync/api_impl/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/location.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/sync/api/attachments/attachment.h" 15 #include "components/sync/api/attachments/attachment.h"
16 #include "components/sync/core/attachments/fake_attachment_downloader.h" 16 #include "components/sync/engine/attachments/fake_attachment_downloader.h"
17 #include "components/sync/core/attachments/fake_attachment_uploader.h" 17 #include "components/sync/engine/attachments/fake_attachment_uploader.h"
18 18
19 namespace syncer { 19 namespace syncer {
20 20
21 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls. 21 // GetOrDownloadAttachments starts multiple parallel DownloadAttachment calls.
22 // GetOrDownloadState tracks completion of these calls and posts callback for 22 // GetOrDownloadState tracks completion of these calls and posts callback for
23 // consumer once all attachments are either retrieved or reported unavailable. 23 // consumer once all attachments are either retrieved or reported unavailable.
24 class AttachmentServiceImpl::GetOrDownloadState 24 class AttachmentServiceImpl::GetOrDownloadState
25 : public base::RefCounted<GetOrDownloadState>, 25 : public base::RefCounted<GetOrDownloadState>,
26 public base::NonThreadSafe { 26 public base::NonThreadSafe {
27 public: 27 public:
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 initial_backoff_delay, max_backoff_delay)); 135 initial_backoff_delay, max_backoff_delay));
136 136
137 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 137 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
138 } 138 }
139 139
140 AttachmentServiceImpl::~AttachmentServiceImpl() { 140 AttachmentServiceImpl::~AttachmentServiceImpl() {
141 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
142 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 142 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
143 } 143 }
144 144
145 // Static.
146 std::unique_ptr<AttachmentService> AttachmentServiceImpl::CreateForTest() {
147 std::unique_ptr<AttachmentStore> attachment_store =
148 AttachmentStore::CreateInMemoryStore();
149 std::unique_ptr<AttachmentUploader> attachment_uploader(
150 new FakeAttachmentUploader);
151 std::unique_ptr<AttachmentDownloader> attachment_downloader(
152 new FakeAttachmentDownloader());
153 std::unique_ptr<AttachmentService> attachment_service(
154 new AttachmentServiceImpl(
155 attachment_store->CreateAttachmentStoreForSync(),
156 std::move(attachment_uploader), std::move(attachment_downloader),
157 NULL, base::TimeDelta(), base::TimeDelta()));
158 return attachment_service;
159 }
160
161 void AttachmentServiceImpl::GetOrDownloadAttachments( 145 void AttachmentServiceImpl::GetOrDownloadAttachments(
162 const AttachmentIdList& attachment_ids, 146 const AttachmentIdList& attachment_ids,
163 const GetOrDownloadCallback& callback) { 147 const GetOrDownloadCallback& callback) {
164 DCHECK(CalledOnValidThread()); 148 DCHECK(CalledOnValidThread());
165 scoped_refptr<GetOrDownloadState> state( 149 scoped_refptr<GetOrDownloadState> state(
166 new GetOrDownloadState(attachment_ids, callback)); 150 new GetOrDownloadState(attachment_ids, callback));
167 // SetModelTypeReference() makes attachments visible for model type. 151 // SetModelTypeReference() makes attachments visible for model type.
168 // Needed when attachment doesn't have model type reference, but still 152 // Needed when attachment doesn't have model type reference, but still
169 // available in local store. 153 // available in local store.
170 attachment_store_->SetModelTypeReference(attachment_ids); 154 attachment_store_->SetModelTypeReference(attachment_ids);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 weak_ptr_factory_.GetWeakPtr())); 303 weak_ptr_factory_.GetWeakPtr()));
320 } 304 }
321 } 305 }
322 306
323 void AttachmentServiceImpl::SetTimerForTest( 307 void AttachmentServiceImpl::SetTimerForTest(
324 std::unique_ptr<base::Timer> timer) { 308 std::unique_ptr<base::Timer> timer) {
325 upload_task_queue_->SetTimerForTest(std::move(timer)); 309 upload_task_queue_->SetTimerForTest(std::move(timer));
326 } 310 }
327 311
328 } // namespace syncer 312 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698