| 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_TASK_SCHEDULER_TASK_TRAITS_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 
| 6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 
| 7 | 7 | 
| 8 #include <stdint.h> | 8 #include <stdint.h> | 
| 9 | 9 | 
| 10 #include <iosfwd> | 10 #include <iosfwd> | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82   //     (1) no I/O, | 82   //     (1) no I/O, | 
| 83   //     (2) low priority, and | 83   //     (2) low priority, and | 
| 84   //     (3) may block shutdown or be skipped on shutdown. | 84   //     (3) may block shutdown or be skipped on shutdown. | 
| 85   // Tasks that require stricter guarantees should highlight those by requesting | 85   // Tasks that require stricter guarantees should highlight those by requesting | 
| 86   // explicit traits below. | 86   // explicit traits below. | 
| 87   TaskTraits(); | 87   TaskTraits(); | 
| 88   TaskTraits(const TaskTraits& other) = default; | 88   TaskTraits(const TaskTraits& other) = default; | 
| 89   TaskTraits& operator=(const TaskTraits& other) = default; | 89   TaskTraits& operator=(const TaskTraits& other) = default; | 
| 90   ~TaskTraits(); | 90   ~TaskTraits(); | 
| 91 | 91 | 
| 92   // Allows tasks with these traits to do file I/O. | 92   // Allows tasks with these traits to wait on synchronous file I/O. | 
| 93   TaskTraits& WithFileIO(); | 93   TaskTraits& WithFileIO(); | 
| 94 | 94 | 
|  | 95   // Allows tasks with these traits to wait on things other than file I/O. In | 
|  | 96   // particular, they may wait on a WaitableEvent or a ConditionVariable, join a | 
|  | 97   // thread or a process, or make a blocking system call that doesn't involve | 
|  | 98   // interactions with the file system. | 
|  | 99   TaskTraits& WithWait(); | 
|  | 100 | 
| 95   // Applies |priority| to tasks with these traits. | 101   // Applies |priority| to tasks with these traits. | 
| 96   TaskTraits& WithPriority(TaskPriority priority); | 102   TaskTraits& WithPriority(TaskPriority priority); | 
| 97 | 103 | 
| 98   // Applies |shutdown_behavior| to tasks with these traits. | 104   // Applies |shutdown_behavior| to tasks with these traits. | 
| 99   TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); | 105   TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); | 
| 100 | 106 | 
| 101   // Returns true if file I/O is allowed by these traits. | 107   // Returns true if waiting on synchronous file I/O is allowed by these traits. | 
| 102   bool with_file_io() const { return with_file_io_; } | 108   bool with_file_io() const { return with_file_io_; } | 
| 103 | 109 | 
|  | 110   // Returns true if waiting on things other than file I/O is allowed by these | 
|  | 111   // traits. | 
|  | 112   bool with_wait() const { return with_wait_; } | 
|  | 113 | 
| 104   // Returns the priority of tasks with these traits. | 114   // Returns the priority of tasks with these traits. | 
| 105   TaskPriority priority() const { return priority_; } | 115   TaskPriority priority() const { return priority_; } | 
| 106 | 116 | 
| 107   // Returns the shutdown behavior of tasks with these traits. | 117   // Returns the shutdown behavior of tasks with these traits. | 
| 108   TaskShutdownBehavior shutdown_behavior() const { return shutdown_behavior_; } | 118   TaskShutdownBehavior shutdown_behavior() const { return shutdown_behavior_; } | 
| 109 | 119 | 
| 110  private: | 120  private: | 
| 111   bool with_file_io_; | 121   bool with_file_io_; | 
|  | 122   bool with_wait_; | 
| 112   TaskPriority priority_; | 123   TaskPriority priority_; | 
| 113   TaskShutdownBehavior shutdown_behavior_; | 124   TaskShutdownBehavior shutdown_behavior_; | 
| 114 }; | 125 }; | 
| 115 | 126 | 
| 116 // Returns string literals for the enums defined in this file. These methods | 127 // Returns string literals for the enums defined in this file. These methods | 
| 117 // should only be used for tracing and debugging. | 128 // should only be used for tracing and debugging. | 
| 118 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority); | 129 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority); | 
| 119 BASE_EXPORT const char* TaskShutdownBehaviorToString( | 130 BASE_EXPORT const char* TaskShutdownBehaviorToString( | 
| 120     TaskShutdownBehavior task_priority); | 131     TaskShutdownBehavior task_priority); | 
| 121 | 132 | 
| 122 // Stream operators so that the enums defined in this file can be used in | 133 // Stream operators so that the enums defined in this file can be used in | 
| 123 // DCHECK and EXPECT statements. | 134 // DCHECK and EXPECT statements. | 
| 124 BASE_EXPORT std::ostream& operator<<(std::ostream& os, | 135 BASE_EXPORT std::ostream& operator<<(std::ostream& os, | 
| 125                                      const TaskPriority& shutdown_behavior); | 136                                      const TaskPriority& shutdown_behavior); | 
| 126 BASE_EXPORT std::ostream& operator<<( | 137 BASE_EXPORT std::ostream& operator<<( | 
| 127     std::ostream& os, | 138     std::ostream& os, | 
| 128     const TaskShutdownBehavior& shutdown_behavior); | 139     const TaskShutdownBehavior& shutdown_behavior); | 
| 129 | 140 | 
| 130 }  // namespace base | 141 }  // namespace base | 
| 131 | 142 | 
| 132 #endif  // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 143 #endif  // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 
| OLD | NEW | 
|---|