| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_single_thread_task_runner_manager.h" | 5 #include "base/task_scheduler/scheduler_single_thread_task_runner_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 DCHECK_EQ(sequence, sequence_); | 88 DCHECK_EQ(sequence, sequence_); |
| 89 has_work_ = true; | 89 has_work_ = true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); } | 92 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); } |
| 93 | 93 |
| 94 bool CanDetach(SchedulerWorker* worker) override { return false; } | 94 bool CanDetach(SchedulerWorker* worker) override { return false; } |
| 95 | 95 |
| 96 void OnDetach() override { NOTREACHED(); } | 96 void OnDetach() override { NOTREACHED(); } |
| 97 | 97 |
| 98 bool RunsTasksOnCurrentThread() { | 98 bool RunsTasksInCurrentSequence() { |
| 99 // We check the thread ref instead of the sequence for the benefit of COM | 99 // We check the thread ref instead of the sequence for the benefit of COM |
| 100 // callbacks which may execute without a sequence context. | 100 // callbacks which may execute without a sequence context. |
| 101 return thread_ref_checker_.IsCurrentThreadSameAsSetThread(); | 101 return thread_ref_checker_.IsCurrentThreadSameAsSetThread(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void OnMainExit() override { | 104 void OnMainExit() override { |
| 105 // Move |sequence_| to |local_sequence| so that if we have the last | 105 // Move |sequence_| to |local_sequence| so that if we have the last |
| 106 // reference to the sequence we don't destroy it (and its tasks) within | 106 // reference to the sequence we don't destroy it (and its tasks) within |
| 107 // |sequence_lock_|. | 107 // |sequence_lock_|. |
| 108 scoped_refptr<Sequence> local_sequence; | 108 scoped_refptr<Sequence> local_sequence; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 274 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 275 OnceClosure closure, | 275 OnceClosure closure, |
| 276 TimeDelta delay) override { | 276 TimeDelta delay) override { |
| 277 // Tasks are never nested within the task scheduler. | 277 // Tasks are never nested within the task scheduler. |
| 278 return PostDelayedTask(from_here, std::move(closure), delay); | 278 return PostDelayedTask(from_here, std::move(closure), delay); |
| 279 } | 279 } |
| 280 | 280 |
| 281 bool RunsTasksOnCurrentThread() const override { | 281 bool RunsTasksInCurrentSequence() const override { |
| 282 return GetDelegate()->RunsTasksOnCurrentThread(); | 282 return GetDelegate()->RunsTasksInCurrentSequence(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 private: | 285 private: |
| 286 ~SchedulerSingleThreadTaskRunner() override { | 286 ~SchedulerSingleThreadTaskRunner() override { |
| 287 outer_->UnregisterSchedulerWorker(worker_); | 287 outer_->UnregisterSchedulerWorker(worker_); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void PostTaskNow(std::unique_ptr<Task> task) { | 290 void PostTaskNow(std::unique_ptr<Task> task) { |
| 291 scoped_refptr<Sequence> sequence = GetDelegate()->sequence(); | 291 scoped_refptr<Sequence> sequence = GetDelegate()->sequence(); |
| 292 // If |sequence| is null, then the thread is effectively gone (either | 292 // If |sequence| is null, then the thread is effectively gone (either |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 }); | 444 }); |
| 445 DCHECK(worker_iter != workers_.end()); | 445 DCHECK(worker_iter != workers_.end()); |
| 446 worker_to_destroy = std::move(*worker_iter); | 446 worker_to_destroy = std::move(*worker_iter); |
| 447 workers_.erase(worker_iter); | 447 workers_.erase(worker_iter); |
| 448 } | 448 } |
| 449 worker_to_destroy->Cleanup(); | 449 worker_to_destroy->Cleanup(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace internal | 452 } // namespace internal |
| 453 } // namespace base | 453 } // namespace base |
| OLD | NEW |