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

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

Issue 548373003: Move AttachmentStore ownership to datatype (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Changes after feedback. 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/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 write_attachments.pop_back(); 77 write_attachments.pop_back();
78 base::MessageLoop::current()->PostTask(FROM_HERE, 78 base::MessageLoop::current()->PostTask(FROM_HERE,
79 base::Bind(callback, result)); 79 base::Bind(callback, result));
80 } 80 }
81 81
82 std::vector<AttachmentIdList> read_ids; 82 std::vector<AttachmentIdList> read_ids;
83 std::vector<ReadCallback> read_callbacks; 83 std::vector<ReadCallback> read_callbacks;
84 std::vector<AttachmentList> write_attachments; 84 std::vector<AttachmentList> write_attachments;
85 std::vector<WriteCallback> write_callbacks; 85 std::vector<WriteCallback> write_callbacks;
86 86
87 private:
88 virtual ~MockAttachmentStore() {}
89
87 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore); 90 DISALLOW_COPY_AND_ASSIGN(MockAttachmentStore);
88 }; 91 };
89 92
90 class MockAttachmentDownloader 93 class MockAttachmentDownloader
91 : public AttachmentDownloader, 94 : public AttachmentDownloader,
92 public base::SupportsWeakPtr<MockAttachmentDownloader> { 95 public base::SupportsWeakPtr<MockAttachmentDownloader> {
93 public: 96 public:
94 MockAttachmentDownloader() {} 97 MockAttachmentDownloader() {}
95 98
96 virtual void DownloadAttachment(const AttachmentId& id, 99 virtual void DownloadAttachment(const AttachmentId& id,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // AttachmentService::Delegate implementation. 170 // AttachmentService::Delegate implementation.
168 virtual void OnAttachmentUploaded( 171 virtual void OnAttachmentUploaded(
169 const AttachmentId& attachment_id) OVERRIDE { 172 const AttachmentId& attachment_id) OVERRIDE {
170 on_attachment_uploaded_list_.push_back(attachment_id); 173 on_attachment_uploaded_list_.push_back(attachment_id);
171 } 174 }
172 175
173 void InitializeAttachmentService( 176 void InitializeAttachmentService(
174 scoped_ptr<MockAttachmentUploader> uploader, 177 scoped_ptr<MockAttachmentUploader> uploader,
175 scoped_ptr<MockAttachmentDownloader> downloader, 178 scoped_ptr<MockAttachmentDownloader> downloader,
176 AttachmentService::Delegate* delegate) { 179 AttachmentService::Delegate* delegate) {
177 scoped_ptr<MockAttachmentStore> attachment_store(new MockAttachmentStore()); 180 scoped_refptr<MockAttachmentStore> attachment_store(
181 new MockAttachmentStore());
178 attachment_store_ = attachment_store->AsWeakPtr(); 182 attachment_store_ = attachment_store->AsWeakPtr();
179 183
180 if (uploader.get()) { 184 if (uploader.get()) {
181 attachment_uploader_ = uploader->AsWeakPtr(); 185 attachment_uploader_ = uploader->AsWeakPtr();
182 } 186 }
183 if (downloader.get()) { 187 if (downloader.get()) {
184 attachment_downloader_ = downloader->AsWeakPtr(); 188 attachment_downloader_ = downloader->AsWeakPtr();
185 } 189 }
186 attachment_service_.reset( 190 attachment_service_.reset(
187 new AttachmentServiceImpl(attachment_store.PassAs<AttachmentStore>(), 191 new AttachmentServiceImpl(attachment_store,
188 uploader.PassAs<AttachmentUploader>(), 192 uploader.PassAs<AttachmentUploader>(),
189 downloader.PassAs<AttachmentDownloader>(), 193 downloader.PassAs<AttachmentDownloader>(),
190 delegate)); 194 delegate));
191 } 195 }
192 196
193 AttachmentService* attachment_service() { return attachment_service_.get(); } 197 AttachmentService* attachment_service() { return attachment_service_.get(); }
194 198
195 AttachmentService::GetOrDownloadCallback download_callback() { 199 AttachmentService::GetOrDownloadCallback download_callback() {
196 return base::Bind(&AttachmentServiceImplTest::DownloadDone, 200 return base::Bind(&AttachmentServiceImplTest::DownloadDone,
197 base::Unretained(this)); 201 base::Unretained(this));
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR); 483 AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR);
480 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first, 484 uploader()->RespondToUpload(uploader()->upload_requests.begin()->first,
481 AttachmentUploader::UPLOAD_SUCCESS); 485 AttachmentUploader::UPLOAD_SUCCESS);
482 EXPECT_EQ(0U, uploader()->upload_requests.size()); 486 EXPECT_EQ(0U, uploader()->upload_requests.size());
483 RunLoop(); 487 RunLoop();
484 488
485 EXPECT_EQ(2U, on_attachment_uploaded_list().size()); 489 EXPECT_EQ(2U, on_attachment_uploaded_list().size());
486 } 490 }
487 491
488 } // namespace syncer 492 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698