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

Side by Side Diff: sync/internal_api/attachments/attachment_service_impl.cc

Issue 548373003: Move AttachmentStore ownership to datatype (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SyncableService related changes Created 6 years, 3 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 "sync/internal_api/public/attachments/attachment_service_impl.h" 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "sync/api/attachments/attachment.h" 10 #include "sync/api/attachments/attachment.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // All requests completed. Let's notify consumer. 101 // All requests completed. Let's notify consumer.
102 GetOrDownloadResult result = 102 GetOrDownloadResult result =
103 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR; 103 unavailable_attachments_.empty() ? GET_SUCCESS : GET_UNSPECIFIED_ERROR;
104 base::MessageLoop::current()->PostTask( 104 base::MessageLoop::current()->PostTask(
105 FROM_HERE, 105 FROM_HERE,
106 base::Bind(callback_, result, base::Passed(&retrieved_attachments_))); 106 base::Bind(callback_, result, base::Passed(&retrieved_attachments_)));
107 } 107 }
108 } 108 }
109 109
110 AttachmentServiceImpl::AttachmentServiceImpl( 110 AttachmentServiceImpl::AttachmentServiceImpl(
111 scoped_ptr<AttachmentStore> attachment_store, 111 scoped_refptr<AttachmentStore> attachment_store,
112 scoped_ptr<AttachmentUploader> attachment_uploader, 112 scoped_ptr<AttachmentUploader> attachment_uploader,
113 scoped_ptr<AttachmentDownloader> attachment_downloader, 113 scoped_ptr<AttachmentDownloader> attachment_downloader,
114 Delegate* delegate) 114 Delegate* delegate)
115 : attachment_store_(attachment_store.Pass()), 115 : attachment_store_(attachment_store),
116 attachment_uploader_(attachment_uploader.Pass()), 116 attachment_uploader_(attachment_uploader.Pass()),
117 attachment_downloader_(attachment_downloader.Pass()), 117 attachment_downloader_(attachment_downloader.Pass()),
118 delegate_(delegate), 118 delegate_(delegate),
119 weak_ptr_factory_(this) { 119 weak_ptr_factory_(this) {
120 DCHECK(CalledOnValidThread()); 120 DCHECK(CalledOnValidThread());
121 DCHECK(attachment_store_); 121 DCHECK(attachment_store_);
122 } 122 }
123 123
124 AttachmentServiceImpl::~AttachmentServiceImpl() { 124 AttachmentServiceImpl::~AttachmentServiceImpl() {
125 DCHECK(CalledOnValidThread()); 125 DCHECK(CalledOnValidThread());
126 } 126 }
127 127
128 // Static. 128 // Static.
129 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { 129 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() {
130 scoped_ptr<syncer::AttachmentStore> attachment_store( 130 scoped_refptr<syncer::AttachmentStore> attachment_store(
131 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get())); 131 new syncer::FakeAttachmentStore(base::ThreadTaskRunnerHandle::Get()));
132 scoped_ptr<AttachmentUploader> attachment_uploader( 132 scoped_ptr<AttachmentUploader> attachment_uploader(
133 new FakeAttachmentUploader); 133 new FakeAttachmentUploader);
134 scoped_ptr<AttachmentDownloader> attachment_downloader( 134 scoped_ptr<AttachmentDownloader> attachment_downloader(
135 new FakeAttachmentDownloader()); 135 new FakeAttachmentDownloader());
136 scoped_ptr<syncer::AttachmentService> attachment_service( 136 scoped_ptr<syncer::AttachmentService> attachment_service(
137 new syncer::AttachmentServiceImpl(attachment_store.Pass(), 137 new syncer::AttachmentServiceImpl(attachment_store,
138 attachment_uploader.Pass(), 138 attachment_uploader.Pass(),
139 attachment_downloader.Pass(), 139 attachment_downloader.Pass(),
140 NULL)); 140 NULL));
141 return attachment_service.Pass(); 141 return attachment_service.Pass();
142 } 142 }
143 143
144 void AttachmentServiceImpl::GetOrDownloadAttachments( 144 void AttachmentServiceImpl::GetOrDownloadAttachments(
145 const AttachmentIdList& attachment_ids, 145 const AttachmentIdList& attachment_ids,
146 const GetOrDownloadCallback& callback) { 146 const GetOrDownloadCallback& callback) {
147 DCHECK(CalledOnValidThread()); 147 DCHECK(CalledOnValidThread());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 const AttachmentDownloader::DownloadResult& result, 255 const AttachmentDownloader::DownloadResult& result,
256 scoped_ptr<Attachment> attachment) { 256 scoped_ptr<Attachment> attachment) {
257 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) { 257 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) {
258 state->AddAttachment(*attachment.get()); 258 state->AddAttachment(*attachment.get());
259 } else { 259 } else {
260 state->AddUnavailableAttachmentId(attachment_id); 260 state->AddUnavailableAttachmentId(attachment_id);
261 } 261 }
262 } 262 }
263 263
264 } // namespace syncer 264 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698