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/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/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 write_attachments.pop_back(); | 76 write_attachments.pop_back(); |
77 base::MessageLoop::current()->PostTask(FROM_HERE, | 77 base::MessageLoop::current()->PostTask(FROM_HERE, |
78 base::Bind(callback, result)); | 78 base::Bind(callback, result)); |
79 } | 79 } |
80 | 80 |
81 std::vector<AttachmentIdList> read_ids; | 81 std::vector<AttachmentIdList> read_ids; |
82 std::vector<ReadCallback> read_callbacks; | 82 std::vector<ReadCallback> read_callbacks; |
83 std::vector<AttachmentList> write_attachments; | 83 std::vector<AttachmentList> write_attachments; |
84 std::vector<WriteCallback> write_callbacks; | 84 std::vector<WriteCallback> write_callbacks; |
85 | 85 |
| 86 private: |
| 87 virtual ~MockAttachmentStore() {} |
| 88 |
86 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore); | 89 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore); |
87 }; | 90 }; |
88 | 91 |
89 class MockAttachmentDownloader | 92 class MockAttachmentDownloader |
90 : public AttachmentDownloader, | 93 : public AttachmentDownloader, |
91 public base::SupportsWeakPtr<MockAttachmentDownloader> { | 94 public base::SupportsWeakPtr<MockAttachmentDownloader> { |
92 public: | 95 public: |
93 MockAttachmentDownloader() {} | 96 MockAttachmentDownloader() {} |
94 | 97 |
95 virtual void DownloadAttachment(const AttachmentId& id, | 98 virtual void DownloadAttachment(const AttachmentId& id, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // AttachmentService::Delegate implementation. | 169 // AttachmentService::Delegate implementation. |
167 virtual void OnAttachmentUploaded( | 170 virtual void OnAttachmentUploaded( |
168 const AttachmentId& attachment_id) OVERRIDE { | 171 const AttachmentId& attachment_id) OVERRIDE { |
169 on_attachment_uploaded_list_.push_back(attachment_id); | 172 on_attachment_uploaded_list_.push_back(attachment_id); |
170 } | 173 } |
171 | 174 |
172 void InitializeAttachmentService( | 175 void InitializeAttachmentService( |
173 scoped_ptr<MockAttachmentUploader> uploader, | 176 scoped_ptr<MockAttachmentUploader> uploader, |
174 scoped_ptr<MockAttachmentDownloader> downloader, | 177 scoped_ptr<MockAttachmentDownloader> downloader, |
175 AttachmentService::Delegate* delegate) { | 178 AttachmentService::Delegate* delegate) { |
176 scoped_ptr<MockAttachmentStore> attachment_store(new MockAttachmentStore()); | 179 scoped_refptr<MockAttachmentStore> attachment_store( |
| 180 new MockAttachmentStore()); |
177 attachment_store_ = attachment_store->AsWeakPtr(); | 181 attachment_store_ = attachment_store->AsWeakPtr(); |
178 | 182 |
179 if (uploader.get()) { | 183 if (uploader.get()) { |
180 attachment_uploader_ = uploader->AsWeakPtr(); | 184 attachment_uploader_ = uploader->AsWeakPtr(); |
181 } | 185 } |
182 if (downloader.get()) { | 186 if (downloader.get()) { |
183 attachment_downloader_ = downloader->AsWeakPtr(); | 187 attachment_downloader_ = downloader->AsWeakPtr(); |
184 } | 188 } |
185 attachment_service_.reset( | 189 attachment_service_.reset( |
186 new AttachmentServiceImpl(attachment_store.PassAs<AttachmentStore>(), | 190 new AttachmentServiceImpl(attachment_store, |
187 uploader.PassAs<AttachmentUploader>(), | 191 uploader.PassAs<AttachmentUploader>(), |
188 downloader.PassAs<AttachmentDownloader>(), | 192 downloader.PassAs<AttachmentDownloader>(), |
189 delegate)); | 193 delegate)); |
190 } | 194 } |
191 | 195 |
192 AttachmentService* attachment_service() { return attachment_service_.get(); } | 196 AttachmentService* attachment_service() { return attachment_service_.get(); } |
193 | 197 |
194 AttachmentService::GetOrDownloadCallback download_callback() { | 198 AttachmentService::GetOrDownloadCallback download_callback() { |
195 return base::Bind(&AttachmentServiceImplTest::DownloadDone, | 199 return base::Bind(&AttachmentServiceImplTest::DownloadDone, |
196 base::Unretained(this)); | 200 base::Unretained(this)); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 EXPECT_EQ(1U, store()->write_attachments.size()); | 447 EXPECT_EQ(1U, store()->write_attachments.size()); |
444 | 448 |
445 store()->RespondToWrite(AttachmentStore::SUCCESS); | 449 store()->RespondToWrite(AttachmentStore::SUCCESS); |
446 RunLoop(); | 450 RunLoop(); |
447 ASSERT_EQ(1U, store_results().size()); | 451 ASSERT_EQ(1U, store_results().size()); |
448 EXPECT_EQ(AttachmentService::STORE_SUCCESS, store_results()[0]); | 452 EXPECT_EQ(AttachmentService::STORE_SUCCESS, store_results()[0]); |
449 EXPECT_TRUE(on_attachment_uploaded_list().empty()); | 453 EXPECT_TRUE(on_attachment_uploaded_list().empty()); |
450 } | 454 } |
451 | 455 |
452 } // namespace syncer | 456 } // namespace syncer |
OLD | NEW |