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

Side by Side Diff: base/test/scoped_task_environment.h

Issue 2860063003: Improve usage documentation of scoped task environments. (Closed)
Patch Set: nits + fix nacl compile Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_ENVIRONMENT_H_ 5 #ifndef BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_
6 #define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ 6 #define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 10
(...skipping 10 matching lines...) Expand all
21 // Tests that need either of these APIs should instantiate a 21 // Tests that need either of these APIs should instantiate a
22 // ScopedTaskEnvironment. 22 // ScopedTaskEnvironment.
23 // 23 //
24 // Tasks posted to the (Thread|Sequenced)TaskRunnerHandle run synchronously when 24 // Tasks posted to the (Thread|Sequenced)TaskRunnerHandle run synchronously when
25 // RunLoop::Run(UntilIdle) is called on the thread where the 25 // RunLoop::Run(UntilIdle) is called on the thread where the
26 // ScopedTaskEnvironment lives. 26 // ScopedTaskEnvironment lives.
27 // 27 //
28 // Tasks posted through base/task_scheduler/post_task.h run on dedicated threads 28 // Tasks posted through base/task_scheduler/post_task.h run on dedicated threads
29 // as they are posted. 29 // as they are posted.
30 // 30 //
31 // Usage:
32 //
33 // class MyTestFixture : public testing::Test {
34 // public:
35 // (...)
36 //
37 // protected:
38 // // Must be the first member (or at least before any member that cares
39 // // about tasks) to be initialized first and destroyed last. protected
40 // // instead of private visibility will allow controlling the task
41 // // environment (e.g. clock) once such features are added (see design doc
42 // // below for details), until then it at least doesn't hurt :).
43 // base::test::ScopedTaskEnvironment scoped_task_environment_;
44 //
45 // // Other members go here (or further below in private section.)
46 // };
47 //
31 // Design and future improvements documented in 48 // Design and future improvements documented in
32 // https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3P kk/edit 49 // https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3P kk/edit
33 class ScopedTaskEnvironment { 50 class ScopedTaskEnvironment {
34 public: 51 public:
35 ScopedTaskEnvironment(); 52 ScopedTaskEnvironment();
36 53
37 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending 54 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending
38 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and 55 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and
39 // the (Thread|Sequenced)TaskRunnerHandle. 56 // the (Thread|Sequenced)TaskRunnerHandle.
40 ~ScopedTaskEnvironment(); 57 ~ScopedTaskEnvironment();
41 58
42 private: 59 private:
43 // Note: |message_loop_| is an implementation detail and will be replaced in 60 // Note: |message_loop_| is an implementation detail and will be replaced in
44 // the future, do NOT rely on the presence of a MessageLoop beyond 61 // the future, do NOT rely on the presence of a MessageLoop beyond
45 // (Thread|Sequenced)TaskRunnerHandle and RunLoop. 62 // (Thread|Sequenced)TaskRunnerHandle and RunLoop.
46 MessageLoop message_loop_; 63 MessageLoop message_loop_;
47 64
48 const TaskScheduler* task_scheduler_ = nullptr; 65 const TaskScheduler* task_scheduler_ = nullptr;
49 66
50 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); 67 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment);
51 }; 68 };
52 69
53 } // namespace test 70 } // namespace test
54 } // namespace base 71 } // namespace base
55 72
56 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ 73 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698