| OLD | NEW |
| 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 #ifndef BASE_TEST_SCOPED_TASK_SCHEDULER_H_ | 5 #ifndef BASE_TEST_SCOPED_TASK_SCHEDULER_H_ |
| 6 #define BASE_TEST_SCOPED_TASK_SCHEDULER_H_ | 6 #define BASE_TEST_SCOPED_TASK_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // base::PostTask(FROM_HERE, base::Bind(&A)); | 34 // base::PostTask(FROM_HERE, base::Bind(&A)); |
| 35 // base::RunLoop::RunUntilIdle(); // Returns after running A. | 35 // base::RunLoop::RunUntilIdle(); // Returns after running A. |
| 36 // | 36 // |
| 37 // In this snippet, run_loop.Run() returns after running "B" and | 37 // In this snippet, run_loop.Run() returns after running "B" and |
| 38 // "RunLoop::Quit". | 38 // "RunLoop::Quit". |
| 39 // base::RunLoop run_loop; | 39 // base::RunLoop run_loop; |
| 40 // base::PostTask(FROM_HERE, base::Bind(&B)); | 40 // base::PostTask(FROM_HERE, base::Bind(&B)); |
| 41 // base::PostTask(FROM_HERE, base::Bind(&RunLoop::Quit, &run_loop)); | 41 // base::PostTask(FROM_HERE, base::Bind(&RunLoop::Quit, &run_loop)); |
| 42 // base::PostTask(FROM_HERE, base::Bind(&C)); | 42 // base::PostTask(FROM_HERE, base::Bind(&C)); |
| 43 // base::PostTaskWithTraits( | 43 // base::PostTaskWithTraits( |
| 44 // base::TaskTraits().WithShutdownBehavior( | 44 // {base::TaskShutdownBehavior::BLOCK_SHUTDOWN}, |
| 45 // base::TaskShutdownBehavior::BLOCK_SHUTDOWN), | |
| 46 // base::Bind(&D)); | 45 // base::Bind(&D)); |
| 47 // run_loop.Run(); // Returns after running B and RunLoop::Quit. | 46 // run_loop.Run(); // Returns after running B and RunLoop::Quit. |
| 48 // | 47 // |
| 49 // At this point, |scoped_task_scheduler| will be destroyed. The destructor | 48 // At this point, |scoped_task_scheduler| will be destroyed. The destructor |
| 50 // runs "D" because it's BLOCK_SHUTDOWN. "C" is skipped. | 49 // runs "D" because it's BLOCK_SHUTDOWN. "C" is skipped. |
| 51 class ScopedTaskScheduler { | 50 class ScopedTaskScheduler { |
| 52 public: | 51 public: |
| 53 // Registers a synchronous TaskScheduler on a thread that doesn't have a | 52 // Registers a synchronous TaskScheduler on a thread that doesn't have a |
| 54 // MessageLoop. | 53 // MessageLoop. |
| 55 // | 54 // |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 const TaskScheduler* task_scheduler_ = nullptr; | 93 const TaskScheduler* task_scheduler_ = nullptr; |
| 95 ThreadChecker thread_checker_; | 94 ThreadChecker thread_checker_; |
| 96 | 95 |
| 97 DISALLOW_COPY_AND_ASSIGN(ScopedTaskScheduler); | 96 DISALLOW_COPY_AND_ASSIGN(ScopedTaskScheduler); |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 } // namespace test | 99 } // namespace test |
| 101 } // namespace base | 100 } // namespace base |
| 102 | 101 |
| 103 #endif // BASE_TEST_SCOPED_TASK_SCHEDULER_H_ | 102 #endif // BASE_TEST_SCOPED_TASK_SCHEDULER_H_ |
| OLD | NEW |