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/fake_attachment_service.h" | 5 #include "sync/api/attachments/fake_attachment_service.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/api/attachments/fake_attachment_store.h" | 10 #include "sync/api/attachments/fake_attachment_store.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 scoped_ptr<syncer::AttachmentStore> attachment_store( | 32 scoped_ptr<syncer::AttachmentStore> attachment_store( |
33 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); | 33 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current())); |
34 scoped_ptr<AttachmentUploader> attachment_uploader( | 34 scoped_ptr<AttachmentUploader> attachment_uploader( |
35 new FakeAttachmentUploader); | 35 new FakeAttachmentUploader); |
36 scoped_ptr<syncer::AttachmentService> attachment_service( | 36 scoped_ptr<syncer::AttachmentService> attachment_service( |
37 new syncer::FakeAttachmentService(attachment_store.Pass(), | 37 new syncer::FakeAttachmentService(attachment_store.Pass(), |
38 attachment_uploader.Pass())); | 38 attachment_uploader.Pass())); |
39 return attachment_service.Pass(); | 39 return attachment_service.Pass(); |
40 } | 40 } |
41 | 41 |
42 void FakeAttachmentService::SetDelegate(Delegate* delegate) { | |
43 delegate_ = delegate; | |
44 } | |
45 | |
42 void FakeAttachmentService::GetOrDownloadAttachments( | 46 void FakeAttachmentService::GetOrDownloadAttachments( |
43 const AttachmentIdList& attachment_ids, | 47 const AttachmentIdList& attachment_ids, |
44 const GetOrDownloadCallback& callback) { | 48 const GetOrDownloadCallback& callback) { |
45 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
46 attachment_store_->Read(attachment_ids, | 50 attachment_store_->Read(attachment_ids, |
47 base::Bind(&FakeAttachmentService::ReadDone, | 51 base::Bind(&FakeAttachmentService::ReadDone, |
48 weak_ptr_factory_.GetWeakPtr(), | 52 weak_ptr_factory_.GetWeakPtr(), |
49 callback)); | 53 callback)); |
50 } | 54 } |
51 | 55 |
52 void FakeAttachmentService::DropAttachments( | 56 void FakeAttachmentService::DropAttachments( |
53 const AttachmentIdList& attachment_ids, | 57 const AttachmentIdList& attachment_ids, |
54 const DropCallback& callback) { | 58 const DropCallback& callback) { |
55 DCHECK(CalledOnValidThread()); | 59 DCHECK(CalledOnValidThread()); |
56 attachment_store_->Drop(attachment_ids, | 60 attachment_store_->Drop(attachment_ids, |
57 base::Bind(&FakeAttachmentService::DropDone, | 61 base::Bind(&FakeAttachmentService::DropDone, |
58 weak_ptr_factory_.GetWeakPtr(), | 62 weak_ptr_factory_.GetWeakPtr(), |
59 callback)); | 63 callback)); |
60 } | 64 } |
61 | 65 |
62 void FakeAttachmentService::StoreAttachments(const AttachmentList& attachments, | 66 void FakeAttachmentService::StoreAttachments(const AttachmentList& attachments, |
63 const StoreCallback& callback) { | 67 const StoreCallback& callback) { |
64 DCHECK(CalledOnValidThread()); | 68 DCHECK(CalledOnValidThread()); |
65 attachment_store_->Write(attachments, | 69 attachment_store_->Write(attachments, |
66 base::Bind(&FakeAttachmentService::WriteDone, | 70 base::Bind(&FakeAttachmentService::WriteDone, |
67 weak_ptr_factory_.GetWeakPtr(), | 71 weak_ptr_factory_.GetWeakPtr(), |
68 callback)); | 72 callback)); |
69 // TODO(maniscalco): Ensure the linked attachments are schedule for upload to | 73 for (AttachmentList::const_iterator iter = attachments.begin(); |
70 // the server (bug 356351). | 74 iter != attachments.end(); |
75 ++iter) { | |
76 attachment_uploader_->UploadAttachment( | |
77 *iter, | |
78 base::Bind(&FakeAttachmentService::UploadDone, | |
79 weak_ptr_factory_.GetWeakPtr())); | |
80 } | |
71 } | 81 } |
72 | 82 |
73 void FakeAttachmentService::OnSyncDataDelete(const SyncData& sync_data) { | 83 void FakeAttachmentService::OnSyncDataDelete(const SyncData& sync_data) { |
74 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
75 // TODO(maniscalco): One or more of sync_data's attachments may no longer be | 85 // 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 | 86 // referenced anywhere. We should probably delete them at this point (bug |
77 // 356351). | 87 // 356351). |
78 } | 88 } |
79 | 89 |
80 void FakeAttachmentService::OnSyncDataUpdate( | 90 void FakeAttachmentService::OnSyncDataUpdate( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 AttachmentService::StoreResult store_result = | 127 AttachmentService::StoreResult store_result = |
118 AttachmentService::STORE_UNSPECIFIED_ERROR; | 128 AttachmentService::STORE_UNSPECIFIED_ERROR; |
119 if (result == AttachmentStore::SUCCESS) { | 129 if (result == AttachmentStore::SUCCESS) { |
120 store_result = AttachmentService::STORE_SUCCESS; | 130 store_result = AttachmentService::STORE_SUCCESS; |
121 } | 131 } |
122 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). | 132 // TODO(maniscalco): Deal with case where an error occurred (bug 361251). |
123 base::MessageLoop::current()->PostTask(FROM_HERE, | 133 base::MessageLoop::current()->PostTask(FROM_HERE, |
124 base::Bind(callback, store_result)); | 134 base::Bind(callback, store_result)); |
125 } | 135 } |
126 | 136 |
137 void FakeAttachmentService::UploadDone( | |
138 const AttachmentUploader::UploadResult& result, | |
139 const AttachmentId& attachment_id) { | |
140 DCHECK(delegate_); | |
maniscalco
2014/05/09 18:12:11
I thought having a delegate_ was optional, no?
pavely
2014/05/13 23:06:44
No, having delegate is not optional, I would rathe
| |
141 if (result != AttachmentUploader::UPLOAD_SUCCESS) | |
maniscalco
2014/05/09 18:12:11
Please add a TODO for dealing with error results.
pavely
2014/05/13 23:06:44
Done.
| |
142 return; | |
143 delegate_->OnAttachmentUploaded(attachment_id); | |
144 } | |
145 | |
127 } // namespace syncer | 146 } // namespace syncer |
OLD | NEW |