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

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

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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_proxy.h" 5 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
12 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "sync/api/attachments/attachment.h" 16 #include "sync/api/attachments/attachment.h"
16 #include "sync/internal_api/public/attachments/attachment_service.h" 17 #include "sync/internal_api/public/attachments/attachment_service.h"
17 #include "sync/internal_api/public/base/model_type.h" 18 #include "sync/internal_api/public/base/model_type.h"
18 #include "sync/protocol/sync.pb.h" 19 #include "sync/protocol/sync.pb.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 11 matching lines...) Expand all
31 DetachFromThread(); 32 DetachFromThread();
32 } 33 }
33 34
34 ~StubAttachmentService() override {} 35 ~StubAttachmentService() override {}
35 36
36 void GetOrDownloadAttachments( 37 void GetOrDownloadAttachments(
37 const AttachmentIdList& attachment_ids, 38 const AttachmentIdList& attachment_ids,
38 const GetOrDownloadCallback& callback) override { 39 const GetOrDownloadCallback& callback) override {
39 CalledOnValidThread(); 40 CalledOnValidThread();
40 Increment(); 41 Increment();
41 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); 42 std::unique_ptr<AttachmentMap> attachments(new AttachmentMap());
42 base::MessageLoop::current()->PostTask( 43 base::MessageLoop::current()->PostTask(
43 FROM_HERE, 44 FROM_HERE,
44 base::Bind(callback, 45 base::Bind(callback,
45 AttachmentService::GET_UNSPECIFIED_ERROR, 46 AttachmentService::GET_UNSPECIFIED_ERROR,
46 base::Passed(&attachments))); 47 base::Passed(&attachments)));
47 } 48 }
48 49
49 void UploadAttachments(const AttachmentIdList& attachments_ids) override { 50 void UploadAttachments(const AttachmentIdList& attachments_ids) override {
50 CalledOnValidThread(); 51 CalledOnValidThread();
51 Increment(); 52 Increment();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // because that's the thread to which its WeakPtrs are bound. 100 // because that's the thread to which its WeakPtrs are bound.
100 if (stub) { 101 if (stub) {
101 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); 102 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release());
102 WaitForStubThread(); 103 WaitForStubThread();
103 } 104 }
104 stub_thread->Stop(); 105 stub_thread->Stop();
105 } 106 }
106 107
107 // a GetOrDownloadCallback 108 // a GetOrDownloadCallback
108 void IncrementGetOrDownload(const AttachmentService::GetOrDownloadResult&, 109 void IncrementGetOrDownload(const AttachmentService::GetOrDownloadResult&,
109 scoped_ptr<AttachmentMap>) { 110 std::unique_ptr<AttachmentMap>) {
110 CalledOnValidThread(); 111 CalledOnValidThread();
111 ++count_callback_get_or_download; 112 ++count_callback_get_or_download;
112 } 113 }
113 114
114 void WaitForStubThread() { 115 void WaitForStubThread() {
115 base::WaitableEvent done(false, false); 116 base::WaitableEvent done(false, false);
116 stub_thread->message_loop()->PostTask( 117 stub_thread->message_loop()->PostTask(
117 FROM_HERE, 118 FROM_HERE,
118 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 119 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
119 done.Wait(); 120 done.Wait();
120 } 121 }
121 122
122 base::MessageLoop loop; 123 base::MessageLoop loop;
123 scoped_ptr<base::Thread> stub_thread; 124 std::unique_ptr<base::Thread> stub_thread;
124 scoped_ptr<StubAttachmentService> stub; 125 std::unique_ptr<StubAttachmentService> stub;
125 scoped_ptr<AttachmentServiceProxy> proxy; 126 std::unique_ptr<AttachmentServiceProxy> proxy;
126 127
127 AttachmentService::GetOrDownloadCallback callback_get_or_download; 128 AttachmentService::GetOrDownloadCallback callback_get_or_download;
128 129
129 // number of times callback_get_or_download was invoked 130 // number of times callback_get_or_download was invoked
130 int count_callback_get_or_download; 131 int count_callback_get_or_download;
131 }; 132 };
132 133
133 // Verify that each of AttachmentServiceProxy's methods are invoked on the stub. 134 // Verify that each of AttachmentServiceProxy's methods are invoked on the stub.
134 // Verify that the methods that take callbacks invoke passed callbacks on this 135 // Verify that the methods that take callbacks invoke passed callbacks on this
135 // thread. 136 // thread.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Now that the wrapped object has been destroyed, call again and see that we 170 // Now that the wrapped object has been destroyed, call again and see that we
170 // don't crash and the count remains the same. 171 // don't crash and the count remains the same.
171 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); 172 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
172 WaitForStubThread(); 173 WaitForStubThread();
173 WaitForStubThread(); 174 WaitForStubThread();
174 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
175 EXPECT_EQ(1, count_callback_get_or_download); 176 EXPECT_EQ(1, count_callback_get_or_download);
176 } 177 }
177 178
178 } // namespace syncer 179 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698