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/api/attachments/attachment_service_impl.h" | 5 #include "sync/api/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 "sync/api/attachments/attachment.h" | 9 #include "sync/api/attachments/attachment.h" |
10 #include "sync/internal_api/public/attachments/fake_attachment_store.h" | 10 #include "sync/internal_api/public/attachments/fake_attachment_store.h" |
11 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 11 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 AttachmentServiceImpl::AttachmentServiceImpl( | 15 AttachmentServiceImpl::AttachmentServiceImpl( |
16 scoped_ptr<AttachmentStore> attachment_store, | 16 scoped_ptr<AttachmentStore> attachment_store, |
17 scoped_ptr<AttachmentUploader> attachment_uploader) | 17 scoped_ptr<AttachmentUploader> attachment_uploader, |
18 Delegate* delegate) | |
18 : attachment_store_(attachment_store.Pass()), | 19 : attachment_store_(attachment_store.Pass()), |
19 attachment_uploader_(attachment_uploader.Pass()), | 20 attachment_uploader_(attachment_uploader.Pass()), |
21 delegate_(delegate), | |
20 weak_ptr_factory_(this) { | 22 weak_ptr_factory_(this) { |
21 DCHECK(CalledOnValidThread()); | 23 DCHECK(CalledOnValidThread()); |
22 DCHECK(attachment_store_); | 24 DCHECK(attachment_store_); |
23 DCHECK(attachment_uploader_); | 25 DCHECK(attachment_uploader_); |
24 } | 26 } |
25 | 27 |
26 AttachmentServiceImpl::~AttachmentServiceImpl() { | 28 AttachmentServiceImpl::~AttachmentServiceImpl() { |
27 DCHECK(CalledOnValidThread()); | 29 DCHECK(CalledOnValidThread()); |
28 } | 30 } |
29 | 31 |
30 // Static. | 32 // Static. |
31 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { | 33 scoped_ptr<syncer::AttachmentService> AttachmentServiceImpl::CreateForTest() { |
32 scoped_ptr<syncer::AttachmentStore> attachment_store( | 34 scoped_ptr<syncer::AttachmentStore> attachment_store( |
33 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); | 35 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); |
34 scoped_ptr<AttachmentUploader> attachment_uploader( | 36 scoped_ptr<AttachmentUploader> attachment_uploader( |
35 new FakeAttachmentUploader); | 37 new FakeAttachmentUploader); |
36 scoped_ptr<syncer::AttachmentService> attachment_service( | 38 scoped_ptr<syncer::AttachmentService> attachment_service( |
37 new syncer::AttachmentServiceImpl(attachment_store.Pass(), | 39 new syncer::AttachmentServiceImpl( |
38 attachment_uploader.Pass())); | 40 attachment_store.Pass(), attachment_uploader.Pass(), NULL)); |
39 return attachment_service.Pass(); | 41 return attachment_service.Pass(); |
40 } | 42 } |
41 | 43 |
42 void AttachmentServiceImpl::GetOrDownloadAttachments( | 44 void AttachmentServiceImpl::GetOrDownloadAttachments( |
43 const AttachmentIdList& attachment_ids, | 45 const AttachmentIdList& attachment_ids, |
44 const GetOrDownloadCallback& callback) { | 46 const GetOrDownloadCallback& callback) { |
45 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
46 attachment_store_->Read(attachment_ids, | 48 attachment_store_->Read(attachment_ids, |
47 base::Bind(&AttachmentServiceImpl::ReadDone, | 49 base::Bind(&AttachmentServiceImpl::ReadDone, |
48 weak_ptr_factory_.GetWeakPtr(), | 50 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 10 matching lines...) Expand all Loading... | |
59 callback)); | 61 callback)); |
60 } | 62 } |
61 | 63 |
62 void AttachmentServiceImpl::StoreAttachments(const AttachmentList& attachments, | 64 void AttachmentServiceImpl::StoreAttachments(const AttachmentList& attachments, |
63 const StoreCallback& callback) { | 65 const StoreCallback& callback) { |
64 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
65 attachment_store_->Write(attachments, | 67 attachment_store_->Write(attachments, |
66 base::Bind(&AttachmentServiceImpl::WriteDone, | 68 base::Bind(&AttachmentServiceImpl::WriteDone, |
67 weak_ptr_factory_.GetWeakPtr(), | 69 weak_ptr_factory_.GetWeakPtr(), |
68 callback)); | 70 callback)); |
69 // TODO(maniscalco): Ensure the linked attachments are schedule for upload to | 71 for (AttachmentList::const_iterator iter = attachments.begin(); |
70 // the server (bug 356351). | 72 iter != attachments.end(); |
73 ++iter) { | |
74 attachment_uploader_->UploadAttachment( | |
75 *iter, | |
76 base::Bind(&AttachmentServiceImpl::UploadDone, | |
77 weak_ptr_factory_.GetWeakPtr())); | |
78 } | |
71 } | 79 } |
72 | 80 |
73 void AttachmentServiceImpl::OnSyncDataDelete(const SyncData& sync_data) { | 81 void AttachmentServiceImpl::OnSyncDataDelete(const SyncData& sync_data) { |
74 DCHECK(CalledOnValidThread()); | 82 DCHECK(CalledOnValidThread()); |
75 // TODO(maniscalco): One or more of sync_data's attachments may no longer be | 83 // TODO(maniscalco): One or more of sync_data's attachments may no longer be |
76 // referenced anywhere. We should probably delete them at this point (bug | 84 // referenced anywhere. We should probably delete them at this point (bug |
77 // 356351). | 85 // 356351). |
78 } | 86 } |
79 | 87 |
80 void AttachmentServiceImpl::OnSyncDataUpdate( | 88 void AttachmentServiceImpl::OnSyncDataUpdate( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 AttachmentService::StoreResult store_result = | 125 AttachmentService::StoreResult store_result = |
118 AttachmentService::STORE_UNSPECIFIED_ERROR; | 126 AttachmentService::STORE_UNSPECIFIED_ERROR; |
119 if (result == AttachmentStore::SUCCESS) { | 127 if (result == AttachmentStore::SUCCESS) { |
120 store_result = AttachmentService::STORE_SUCCESS; | 128 store_result = AttachmentService::STORE_SUCCESS; |
121 } | 129 } |
122 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). | 130 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). |
123 base::MessageLoop::current()->PostTask(FROM_HERE, | 131 base::MessageLoop::current()->PostTask(FROM_HERE, |
124 base::Bind(callback, store_result)); | 132 base::Bind(callback, store_result)); |
125 } | 133 } |
126 | 134 |
135 void AttachmentServiceImpl::UploadDone( | |
136 const AttachmentUploader::UploadResult& result, | |
137 const AttachmentId& attachment_id) { | |
138 DCHECK(delegate_); | |
maniscalco
2014/05/15 20:09:28
Based on our last talk, I was thinking delegate_ w
pavely
2014/05/16 00:19:10
I made this change but lost it between revisions 5
| |
139 // TODO(pavely): crbug/372622: Deal with UploadAttachment failures. | |
140 if (result != AttachmentUploader::UPLOAD_SUCCESS) | |
141 return; | |
142 delegate_->OnAttachmentUploaded(attachment_id); | |
143 } | |
144 | |
127 } // namespace syncer | 145 } // namespace syncer |
OLD | NEW |