| 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/scheduler_service_thread.h" | 5 #include "base/task_scheduler/scheduler_service_thread.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // For delayed tasks with delays that are really close to each other, it is | 45 // For delayed tasks with delays that are really close to each other, it is |
| 46 // possible for the current time to advance beyond the required | 46 // possible for the current time to advance beyond the required |
| 47 // GetDelayedWaitTime. Return a minimum of TimeDelta() in the event that | 47 // GetDelayedWaitTime. Return a minimum of TimeDelta() in the event that |
| 48 // happens. | 48 // happens. |
| 49 TimeDelta sleep_time = next_time - delayed_task_manager_->Now(); | 49 TimeDelta sleep_time = next_time - delayed_task_manager_->Now(); |
| 50 const TimeDelta zero_delta; | 50 const TimeDelta zero_delta; |
| 51 return sleep_time < zero_delta ? zero_delta : sleep_time; | 51 return sleep_time < zero_delta ? zero_delta : sleep_time; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool CanDetach(SchedulerWorker* worker) override { |
| 55 return false; |
| 56 } |
| 57 |
| 54 private: | 58 private: |
| 55 DelayedTaskManager* const delayed_task_manager_; | 59 DelayedTaskManager* const delayed_task_manager_; |
| 56 | 60 |
| 57 DISALLOW_COPY_AND_ASSIGN(ServiceThreadDelegate); | 61 DISALLOW_COPY_AND_ASSIGN(ServiceThreadDelegate); |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace | 64 } // namespace |
| 61 | 65 |
| 62 SchedulerServiceThread::~SchedulerServiceThread() = default; | 66 SchedulerServiceThread::~SchedulerServiceThread() = default; |
| 63 | 67 |
| 64 // static | 68 // static |
| 65 std::unique_ptr<SchedulerServiceThread> SchedulerServiceThread::Create( | 69 std::unique_ptr<SchedulerServiceThread> SchedulerServiceThread::Create( |
| 66 TaskTracker* task_tracker, DelayedTaskManager* delayed_task_manager) { | 70 TaskTracker* task_tracker, DelayedTaskManager* delayed_task_manager) { |
| 67 std::unique_ptr<SchedulerWorker> worker = | 71 std::unique_ptr<SchedulerWorker> worker = |
| 68 SchedulerWorker::Create( | 72 SchedulerWorker::Create( |
| 69 ThreadPriority::NORMAL, | 73 ThreadPriority::NORMAL, |
| 70 WrapUnique(new ServiceThreadDelegate(delayed_task_manager)), | 74 WrapUnique(new ServiceThreadDelegate(delayed_task_manager)), |
| 71 task_tracker); | 75 task_tracker, |
| 76 SchedulerWorker::InitialState::ALIVE); |
| 72 if (!worker) | 77 if (!worker) |
| 73 return nullptr; | 78 return nullptr; |
| 74 | 79 |
| 75 return WrapUnique(new SchedulerServiceThread(std::move(worker))); | 80 return WrapUnique(new SchedulerServiceThread(std::move(worker))); |
| 76 } | 81 } |
| 77 | 82 |
| 78 void SchedulerServiceThread::WakeUp() { | 83 void SchedulerServiceThread::WakeUp() { |
| 79 worker_->WakeUp(); | 84 worker_->WakeUp(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 void SchedulerServiceThread::JoinForTesting() { | 87 void SchedulerServiceThread::JoinForTesting() { |
| 83 worker_->JoinForTesting(); | 88 worker_->JoinForTesting(); |
| 84 } | 89 } |
| 85 | 90 |
| 86 SchedulerServiceThread::SchedulerServiceThread( | 91 SchedulerServiceThread::SchedulerServiceThread( |
| 87 std::unique_ptr<SchedulerWorker> worker) : worker_(std::move(worker)) {} | 92 std::unique_ptr<SchedulerWorker> worker) : worker_(std::move(worker)) {} |
| 88 | 93 |
| 89 } // namespace internal | 94 } // namespace internal |
| 90 } // namespace base | 95 } // namespace base |
| OLD | NEW |