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

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

Issue 2033933002: Remove use of deprecated MessageLoop methods in sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h"
10 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
13 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
15 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/threading/thread_task_runner_handle.h"
16 #include "sync/api/attachments/attachment.h" 19 #include "sync/api/attachments/attachment.h"
17 #include "sync/internal_api/public/attachments/attachment_service.h" 20 #include "sync/internal_api/public/attachments/attachment_service.h"
18 #include "sync/internal_api/public/base/model_type.h" 21 #include "sync/internal_api/public/base/model_type.h"
19 #include "sync/protocol/sync.pb.h" 22 #include "sync/protocol/sync.pb.h"
20 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
21 24
22 namespace syncer { 25 namespace syncer {
23 26
24 // A stub implementation of AttachmentService that counts the number of times 27 // A stub implementation of AttachmentService that counts the number of times
25 // its methods are invoked. 28 // its methods are invoked.
26 class StubAttachmentService : public AttachmentService, 29 class StubAttachmentService : public AttachmentService,
27 public base::NonThreadSafe { 30 public base::NonThreadSafe {
28 public: 31 public:
29 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) { 32 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) {
30 // DetachFromThread because we will be constructed in one thread and 33 // DetachFromThread because we will be constructed in one thread and
31 // used/destroyed in another. 34 // used/destroyed in another.
32 DetachFromThread(); 35 DetachFromThread();
33 } 36 }
34 37
35 ~StubAttachmentService() override {} 38 ~StubAttachmentService() override {}
36 39
37 void GetOrDownloadAttachments( 40 void GetOrDownloadAttachments(
38 const AttachmentIdList& attachment_ids, 41 const AttachmentIdList& attachment_ids,
39 const GetOrDownloadCallback& callback) override { 42 const GetOrDownloadCallback& callback) override {
40 CalledOnValidThread(); 43 CalledOnValidThread();
41 Increment(); 44 Increment();
42 std::unique_ptr<AttachmentMap> attachments(new AttachmentMap()); 45 std::unique_ptr<AttachmentMap> attachments(new AttachmentMap());
43 base::MessageLoop::current()->PostTask( 46 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE, 47 FROM_HERE,
45 base::Bind(callback, 48 base::Bind(callback, AttachmentService::GET_UNSPECIFIED_ERROR,
46 AttachmentService::GET_UNSPECIFIED_ERROR,
47 base::Passed(&attachments))); 49 base::Passed(&attachments)));
48 } 50 }
49 51
50 void UploadAttachments(const AttachmentIdList& attachments_ids) override { 52 void UploadAttachments(const AttachmentIdList& attachments_ids) override {
51 CalledOnValidThread(); 53 CalledOnValidThread();
52 Increment(); 54 Increment();
53 } 55 }
54 56
55 virtual base::WeakPtr<AttachmentService> AsWeakPtr() { 57 virtual base::WeakPtr<AttachmentService> AsWeakPtr() {
56 return weak_ptr_factory_.GetWeakPtr(); 58 return weak_ptr_factory_.GetWeakPtr();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Now that the wrapped object has been destroyed, call again and see that we 173 // Now that the wrapped object has been destroyed, call again and see that we
172 // don't crash and the count remains the same. 174 // don't crash and the count remains the same.
173 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); 175 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download);
174 WaitForStubThread(); 176 WaitForStubThread();
175 WaitForStubThread(); 177 WaitForStubThread();
176 base::RunLoop().RunUntilIdle(); 178 base::RunLoop().RunUntilIdle();
177 EXPECT_EQ(1, count_callback_get_or_download); 179 EXPECT_EQ(1, count_callback_get_or_download);
178 } 180 }
179 181
180 } // namespace syncer 182 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698