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

Side by Side Diff: base/test/scoped_task_scheduler.cc

Issue 2628313004: Add TaskScheduler::JoinForTesting(). (Closed)
Patch Set: CR robliao #13 Created 3 years, 11 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 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/test/scoped_task_scheduler.h" 5 #include "base/test/scoped_task_scheduler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 TimeDelta delay) override; 46 TimeDelta delay) override;
47 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( 47 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
48 const TaskTraits& traits) override; 48 const TaskTraits& traits) override;
49 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( 49 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits(
50 const TaskTraits& traits) override; 50 const TaskTraits& traits) override;
51 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( 51 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
52 const TaskTraits& traits) override; 52 const TaskTraits& traits) override;
53 std::vector<const HistogramBase*> GetHistograms() const override; 53 std::vector<const HistogramBase*> GetHistograms() const override;
54 void Shutdown() override; 54 void Shutdown() override;
55 void FlushForTesting() override; 55 void FlushForTesting() override;
56 void JoinForTesting() override;
56 57
57 // Posts |task| to this TaskScheduler with |sequence_token|. Returns true on 58 // Posts |task| to this TaskScheduler with |sequence_token|. Returns true on
58 // success. 59 // success.
59 bool PostTask(std::unique_ptr<internal::Task> task, 60 bool PostTask(std::unique_ptr<internal::Task> task,
60 const SequenceToken& sequence_token); 61 const SequenceToken& sequence_token);
61 62
62 // Runs |task| with |sequence_token| using this TaskScheduler's TaskTracker. 63 // Runs |task| with |sequence_token| using this TaskScheduler's TaskTracker.
63 void RunTask(std::unique_ptr<internal::Task> task, 64 void RunTask(std::unique_ptr<internal::Task> task,
64 const SequenceToken& sequence_token); 65 const SequenceToken& sequence_token);
65 66
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 task_tracker_.SetHasShutdownStartedForTesting(); 162 task_tracker_.SetHasShutdownStartedForTesting();
162 163
163 // Run pending BLOCK_SHUTDOWN tasks. 164 // Run pending BLOCK_SHUTDOWN tasks.
164 RunLoop().RunUntilIdle(); 165 RunLoop().RunUntilIdle();
165 } 166 }
166 167
167 void TestTaskScheduler::FlushForTesting() { 168 void TestTaskScheduler::FlushForTesting() {
168 NOTREACHED(); 169 NOTREACHED();
169 } 170 }
170 171
172 void TestTaskScheduler::JoinForTesting() {
173 NOTREACHED();
174 }
175
171 bool TestTaskScheduler::PostTask(std::unique_ptr<internal::Task> task, 176 bool TestTaskScheduler::PostTask(std::unique_ptr<internal::Task> task,
172 const SequenceToken& sequence_token) { 177 const SequenceToken& sequence_token) {
173 DCHECK(task); 178 DCHECK(task);
174 if (!task_tracker_.WillPostTask(task.get())) 179 if (!task_tracker_.WillPostTask(task.get()))
175 return false; 180 return false;
176 internal::Task* const task_ptr = task.get(); 181 internal::Task* const task_ptr = task.get();
177 return message_loop_task_runner_->PostDelayedTask( 182 return message_loop_task_runner_->PostDelayedTask(
178 task_ptr->posted_from, Bind(&TestTaskScheduler::RunTask, Unretained(this), 183 task_ptr->posted_from, Bind(&TestTaskScheduler::RunTask, Unretained(this),
179 Passed(&task), sequence_token), 184 Passed(&task), sequence_token),
180 task_ptr->delay); 185 task_ptr->delay);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 255 }
251 256
252 ScopedTaskScheduler::~ScopedTaskScheduler() { 257 ScopedTaskScheduler::~ScopedTaskScheduler() {
253 DCHECK(thread_checker_.CalledOnValidThread()); 258 DCHECK(thread_checker_.CalledOnValidThread());
254 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); 259 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance());
255 TaskScheduler::SetInstance(nullptr); 260 TaskScheduler::SetInstance(nullptr);
256 } 261 }
257 262
258 } // namespace test 263 } // namespace test
259 } // namespace base 264 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698