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

Side by Side Diff: base/sequenced_task_runner_unittest.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « base/sequenced_task_runner.cc ('k') | base/synchronization/atomic_flag_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/sequenced_task_runner.h" 5 #include "base/sequenced_task_runner.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 "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 29 matching lines...) Expand all
40 thread.task_runner(); 40 thread.task_runner();
41 41
42 using SequenceBoundUniquePtr = 42 using SequenceBoundUniquePtr =
43 std::unique_ptr<DeleteCounter, OnTaskRunnerDeleter>; 43 std::unique_ptr<DeleteCounter, OnTaskRunnerDeleter>;
44 44
45 int counter = 0; 45 int counter = 0;
46 SequenceBoundUniquePtr ptr(new DeleteCounter(&counter, current_thread), 46 SequenceBoundUniquePtr ptr(new DeleteCounter(&counter, current_thread),
47 OnTaskRunnerDeleter(current_thread)); 47 OnTaskRunnerDeleter(current_thread));
48 EXPECT_EQ(0, counter); 48 EXPECT_EQ(0, counter);
49 foreign_thread->PostTask( 49 foreign_thread->PostTask(
50 FROM_HERE, 50 FROM_HERE, BindOnce([](SequenceBoundUniquePtr) {}, Passed(&ptr)));
51 Bind([](SequenceBoundUniquePtr) {},
52 Passed(&ptr)));
53 51
54 { 52 {
55 RunLoop run_loop; 53 RunLoop run_loop;
56 foreign_thread->PostTaskAndReply( 54 foreign_thread->PostTaskAndReply(FROM_HERE, BindOnce([] {}),
57 FROM_HERE, 55 run_loop.QuitClosure());
58 Bind([]{}),
59 run_loop.QuitClosure());
60 run_loop.Run(); 56 run_loop.Run();
61 } 57 }
62 EXPECT_EQ(1, counter); 58 EXPECT_EQ(1, counter);
63 59
64 DeleteCounter* raw = new DeleteCounter(&counter, nullptr); 60 DeleteCounter* raw = new DeleteCounter(&counter, nullptr);
65 SequenceBoundUniquePtr ptr2(raw, OnTaskRunnerDeleter(foreign_thread)); 61 SequenceBoundUniquePtr ptr2(raw, OnTaskRunnerDeleter(foreign_thread));
66 EXPECT_EQ(1, counter); 62 EXPECT_EQ(1, counter);
67 63
68 thread.Stop(); 64 thread.Stop();
69 ptr2 = nullptr; 65 ptr2 = nullptr;
70 ASSERT_EQ(1, counter); 66 ASSERT_EQ(1, counter);
71 67
72 delete raw; 68 delete raw;
73 EXPECT_EQ(2, counter); 69 EXPECT_EQ(2, counter);
74 } 70 }
75 71
76 } // namespace base 72 } // namespace base
OLDNEW
« no previous file with comments | « base/sequenced_task_runner.cc ('k') | base/synchronization/atomic_flag_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698