| 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/post_task.h" | 5 #include "base/task_scheduler/post_task.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h" | 10 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 const TaskTraits traits_; | 30 const TaskTraits traits_; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // Returns TaskTraits based on |traits|. If TaskPriority hasn't been set | 33 // Returns TaskTraits based on |traits|. If TaskPriority hasn't been set |
| 34 // explicitly in |traits|, the returned TaskTraits have the current | 34 // explicitly in |traits|, the returned TaskTraits have the current |
| 35 // TaskPriority. | 35 // TaskPriority. |
| 36 TaskTraits GetTaskTraitsWithExplicitPriority(const TaskTraits& traits) { | 36 TaskTraits GetTaskTraitsWithExplicitPriority(const TaskTraits& traits) { |
| 37 return traits.priority_set_explicitly() | 37 if (traits.priority_set_explicitly()) |
| 38 ? traits | 38 return traits; |
| 39 : TaskTraits(traits).WithPriority( | 39 return TaskTraits::Override(traits, |
| 40 internal::GetTaskPriorityForCurrentThread()); | 40 {internal::GetTaskPriorityForCurrentThread()}); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 void PostTask(const tracked_objects::Location& from_here, OnceClosure task) { | 45 void PostTask(const tracked_objects::Location& from_here, OnceClosure task) { |
| 46 PostDelayedTask(from_here, std::move(task), TimeDelta()); | 46 PostDelayedTask(from_here, std::move(task), TimeDelta()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void PostDelayedTask(const tracked_objects::Location& from_here, | 49 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 50 OnceClosure task, | 50 OnceClosure task, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( | 111 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( |
| 112 const TaskTraits& traits) { | 112 const TaskTraits& traits) { |
| 113 DCHECK(TaskScheduler::GetInstance()) | 113 DCHECK(TaskScheduler::GetInstance()) |
| 114 << "Ref. Prerequisite section of post_task.h"; | 114 << "Ref. Prerequisite section of post_task.h"; |
| 115 return TaskScheduler::GetInstance()->CreateCOMSTATaskRunnerWithTraits( | 115 return TaskScheduler::GetInstance()->CreateCOMSTATaskRunnerWithTraits( |
| 116 GetTaskTraitsWithExplicitPriority(traits)); | 116 GetTaskTraitsWithExplicitPriority(traits)); |
| 117 } | 117 } |
| 118 #endif // defined(OS_WIN) | 118 #endif // defined(OS_WIN) |
| 119 | 119 |
| 120 } // namespace base | 120 } // namespace base |
| OLD | NEW |