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_scheduler_impl.h" | 5 #include "base/task_scheduler/task_scheduler_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | |
10 #include <utility> | 9 #include <utility> |
11 #include <vector> | 10 #include <vector> |
12 | 11 |
13 #include "base/bind.h" | 12 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 14 #include "base/callback.h" |
16 #include "base/macros.h" | 15 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
18 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
19 #include "base/task_scheduler/task_traits.h" | 18 #include "base/task_scheduler/task_traits.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND | 70 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND |
72 ? ThreadPriority::BACKGROUND | 71 ? ThreadPriority::BACKGROUND |
73 : ThreadPriority::NORMAL, | 72 : ThreadPriority::NORMAL, |
74 PlatformThread::GetCurrentThreadPriority()); | 73 PlatformThread::GetCurrentThreadPriority()); |
75 | 74 |
76 #if ENABLE_THREAD_RESTRICTIONS | 75 #if ENABLE_THREAD_RESTRICTIONS |
77 // The #if above is required because GetIOAllowed() always returns true when | 76 // The #if above is required because GetIOAllowed() always returns true when |
78 // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O. | 77 // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O. |
79 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); | 78 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); |
80 #endif | 79 #endif |
81 | |
82 // Verify that the thread the task is running on is named as expected. | |
83 const std::string current_thread_name(PlatformThread::GetName()); | |
84 EXPECT_NE(std::string::npos, current_thread_name.find("TaskScheduler")); | |
85 EXPECT_NE(std::string::npos, | |
86 current_thread_name.find( | |
87 traits.priority() == TaskPriority::BACKGROUND ? "Background" | |
88 : "Foreground")); | |
89 EXPECT_EQ(traits.with_file_io(), | |
90 current_thread_name.find("FileIO") != std::string::npos); | |
91 } | 80 } |
92 | 81 |
93 void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits, | 82 void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits, |
94 WaitableEvent* event) { | 83 WaitableEvent* event) { |
95 DCHECK(event); | 84 DCHECK(event); |
96 VerifyTaskEnvironement(traits); | 85 VerifyTaskEnvironement(traits); |
97 event->Signal(); | 86 event->Signal(); |
98 } | 87 } |
99 | 88 |
100 class ThreadPostingTasks : public SimpleThread { | 89 class ThreadPostingTasks : public SimpleThread { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 199 } |
211 | 200 |
212 scheduler->JoinForTesting(); | 201 scheduler->JoinForTesting(); |
213 } | 202 } |
214 | 203 |
215 // TODO(fdoray): Add tests with Sequences that move around thread pools once | 204 // TODO(fdoray): Add tests with Sequences that move around thread pools once |
216 // child TaskRunners are supported. | 205 // child TaskRunners are supported. |
217 | 206 |
218 } // namespace internal | 207 } // namespace internal |
219 } // namespace base | 208 } // namespace base |
OLD | NEW |