summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/attachments/attachment_service_impl.cc
diff options
context:
space:
mode:
authorpavely <pavely@chromium.org>2015-03-25 16:47:54 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-25 23:48:49 +0000
commitdc577c86a31224a121b37e0f46e6de8f5e7f6435 (patch)
tree2ef9a8f05c1a9efc1a597ee07df5a67df3fbb765 /sync/internal_api/attachments/attachment_service_impl.cc
parenta8b89aa94a3320ee053d0f24869835914742c860 (diff)
downloadchromium_src-dc577c86a31224a121b37e0f46e6de8f5e7f6435.zip
chromium_src-dc577c86a31224a121b37e0f46e6de8f5e7f6435.tar.gz
chromium_src-dc577c86a31224a121b37e0f46e6de8f5e7f6435.tar.bz2
[Sync] Introduce AttachmentStoreForSync class
In this change: - Add AttachmentStoreForSync class. It has functions that will be called by AttachmentServiceImpl to manage sync’s references to attachments. - Change AttachmentServiceImpl to call those functions. The rule is that for all attachments that we start uploading call AddSyncReference, for all attachments that we no longer upload (for whatever reason) call DropSyncReference. Couple of notes: - There is no storage implementation for those functions, it will come in the next change. - There is growing confusion between AttachmentIdSet and AttachmentIdList. I’ll resolve this next week in a separate change. BUG=457735 R=maniscalco@chromium.org TEST=No user facing behavior. Change covered by sync_unit_tests. Review URL: https://codereview.chromium.org/1002263005 Cr-Commit-Position: refs/heads/master@{#322263}
Diffstat (limited to 'sync/internal_api/attachments/attachment_service_impl.cc')
-rw-r--r--sync/internal_api/attachments/attachment_service_impl.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/sync/internal_api/attachments/attachment_service_impl.cc b/sync/internal_api/attachments/attachment_service_impl.cc
index 2db63c3..fb65172 100644
--- a/sync/internal_api/attachments/attachment_service_impl.cc
+++ b/sync/internal_api/attachments/attachment_service_impl.cc
@@ -110,7 +110,7 @@ AttachmentServiceImpl::GetOrDownloadState::PostResultIfAllRequestsCompleted() {
}
AttachmentServiceImpl::AttachmentServiceImpl(
- scoped_ptr<AttachmentStore> attachment_store,
+ scoped_ptr<AttachmentStoreForSync> attachment_store,
scoped_ptr<AttachmentUploader> attachment_uploader,
scoped_ptr<AttachmentDownloader> attachment_downloader,
Delegate* delegate,
@@ -151,12 +151,10 @@ scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() {
scoped_ptr<AttachmentDownloader> attachment_downloader(
new FakeAttachmentDownloader());
scoped_ptr<syncer::AttachmentService> attachment_service(
- new syncer::AttachmentServiceImpl(attachment_store.Pass(),
- attachment_uploader.Pass(),
- attachment_downloader.Pass(),
- NULL,
- base::TimeDelta(),
- base::TimeDelta()));
+ new syncer::AttachmentServiceImpl(
+ attachment_store->CreateAttachmentStoreForSync(),
+ attachment_uploader.Pass(), attachment_downloader.Pass(), NULL,
+ base::TimeDelta(), base::TimeDelta()));
return attachment_service.Pass();
}
@@ -223,8 +221,11 @@ void AttachmentServiceImpl::UploadDone(
const AttachmentUploader::UploadResult& result,
const AttachmentId& attachment_id) {
DCHECK(CalledOnValidThread());
+ AttachmentIdList ids;
+ ids.push_back(attachment_id);
switch (result) {
case AttachmentUploader::UPLOAD_SUCCESS:
+ attachment_store_->DropSyncReference(ids);
upload_task_queue_->MarkAsSucceeded(attachment_id);
if (delegate_) {
delegate_->OnAttachmentUploaded(attachment_id);
@@ -236,6 +237,7 @@ void AttachmentServiceImpl::UploadDone(
break;
case AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR:
// TODO(pavely): crbug/372622: Deal with UploadAttachment failures.
+ attachment_store_->DropSyncReference(ids);
upload_task_queue_->MarkAsFailed(attachment_id);
break;
}
@@ -278,6 +280,8 @@ void AttachmentServiceImpl::UploadAttachments(
if (!attachment_uploader_.get()) {
return;
}
+ attachment_store_->SetSyncReference(attachment_ids);
+
for (auto iter = attachment_ids.begin(); iter != attachment_ids.end();
++iter) {
upload_task_queue_->AddToQueue(*iter);
@@ -304,6 +308,7 @@ void AttachmentServiceImpl::ReadDoneNowUpload(
for (; iter != end; ++iter) {
upload_task_queue_->Cancel(*iter);
}
+ attachment_store_->DropSyncReference(*unavailable_attachment_ids);
}
AttachmentMap::const_iterator iter = attachments->begin();