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 #include "base/task_scheduler/task_traits.h" | 5 #include "base/task_scheduler/task_traits.h" |
6 | 6 |
7 #include <ostream> | |
8 | |
7 namespace base { | 9 namespace base { |
8 | 10 |
9 // Do not rely on defaults hard-coded below beyond the guarantees described in | 11 // Do not rely on defaults hard-coded below beyond the guarantees described in |
10 // the header; anything else is subject to change. Tasks should explicitly | 12 // the header; anything else is subject to change. Tasks should explicitly |
11 // request defaults if the behavior is critical to the task. | 13 // request defaults if the behavior is critical to the task. |
12 TaskTraits::TaskTraits() | 14 TaskTraits::TaskTraits() |
13 : with_file_io_(false), | 15 : with_file_io_(false), |
14 priority_(TaskPriority::BACKGROUND), | 16 priority_(TaskPriority::BACKGROUND), |
15 shutdown_behavior_(TaskShutdownBehavior::BLOCK_SHUTDOWN) {} | 17 shutdown_behavior_(TaskShutdownBehavior::BLOCK_SHUTDOWN) {} |
16 | 18 |
17 TaskTraits::~TaskTraits() = default; | 19 TaskTraits::~TaskTraits() = default; |
18 | 20 |
19 TaskTraits& TaskTraits::WithFileIO() { | 21 TaskTraits& TaskTraits::WithFileIO() { |
20 with_file_io_ = true; | 22 with_file_io_ = true; |
21 return *this; | 23 return *this; |
22 } | 24 } |
23 | 25 |
24 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { | 26 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { |
25 priority_ = priority; | 27 priority_ = priority; |
26 return *this; | 28 return *this; |
27 } | 29 } |
28 | 30 |
29 TaskTraits& TaskTraits::WithShutdownBehavior( | 31 TaskTraits& TaskTraits::WithShutdownBehavior( |
30 TaskShutdownBehavior shutdown_behavior) { | 32 TaskShutdownBehavior shutdown_behavior) { |
31 shutdown_behavior_ = shutdown_behavior; | 33 shutdown_behavior_ = shutdown_behavior; |
32 return *this; | 34 return *this; |
33 } | 35 } |
34 | 36 |
37 void PrintTo(const TaskPriority& task_priority, std::ostream* os) { | |
robliao
2016/02/19 02:33:43
Can this go in a test only utils file?
fdoray
2016/02/19 14:12:15
See comment in task_traits.h
| |
38 switch (task_priority) { | |
39 case TaskPriority::BACKGROUND: | |
40 *os << "BACKGROUND"; | |
41 break; | |
42 case TaskPriority::USER_VISIBLE: | |
43 *os << "USER_VISIBLE"; | |
44 break; | |
45 case TaskPriority::USER_BLOCKING: | |
46 *os << "USER_BLOCKING"; | |
47 break; | |
robliao
2016/02/19 02:33:43
default case: DCHECK(false).
fdoray
2016/02/19 14:12:15
See gab's comment https://codereview.chromium.org/
| |
48 } | |
49 } | |
50 | |
35 } // namespace base | 51 } // namespace base |
OLD | NEW |