OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/scheduler/task_queue_manager.h" | 5 #include "components/scheduler/child/task_queue_manager.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
13 #include "content/child/scheduler/nestable_single_thread_task_runner.h" | 13 #include "components/scheduler/child/nestable_single_thread_task_runner.h" |
14 #include "content/child/scheduler/task_queue_selector.h" | 14 #include "components/scheduler/child/task_queue_selector.h" |
15 #include "content/child/scheduler/time_source.h" | 15 #include "components/scheduler/child/time_source.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); | 18 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); |
19 } | 19 } |
20 | 20 |
21 namespace content { | 21 namespace scheduler { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 // Now() is somewhat expensive so it makes sense not to call Now() unless we | 24 // Now() is somewhat expensive so it makes sense not to call Now() unless we |
25 // really need to. | 25 // really need to. |
26 class LazyNow { | 26 class LazyNow { |
27 public: | 27 public: |
28 explicit LazyNow(base::TimeTicks now) | 28 explicit LazyNow(base::TimeTicks now) |
29 : task_queue_manager_(nullptr), now_(now) { | 29 : task_queue_manager_(nullptr), now_(now) { |
30 DCHECK(!now.is_null()); | 30 DCHECK(!now.is_null()); |
31 } | 31 } |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 (base::Closure())); | 599 (base::Closure())); |
600 for (int i = 0; i < work_batch_size_; i++) { | 600 for (int i = 0; i < work_batch_size_; i++) { |
601 size_t queue_index; | 601 size_t queue_index; |
602 if (!SelectWorkQueueToService(&queue_index)) | 602 if (!SelectWorkQueueToService(&queue_index)) |
603 return; | 603 return; |
604 // Note that this function won't post another call to DoWork if one is | 604 // Note that this function won't post another call to DoWork if one is |
605 // already pending, so it is safe to call it in a loop. | 605 // already pending, so it is safe to call it in a loop. |
606 MaybePostDoWorkOnMainRunner(); | 606 MaybePostDoWorkOnMainRunner(); |
607 | 607 |
608 if (ProcessTaskFromWorkQueue(queue_index, i > 0, &previous_task)) | 608 if (ProcessTaskFromWorkQueue(queue_index, i > 0, &previous_task)) |
609 return; // The TaskQueueManager got deleted, we must bail out. | 609 return; // The TaskQueueManager got deleted, we must bail out. |
610 | 610 |
611 if (!UpdateWorkQueues(&previous_task)) | 611 if (!UpdateWorkQueues(&previous_task)) |
612 return; | 612 return; |
613 } | 613 } |
614 } | 614 } |
615 | 615 |
616 bool TaskQueueManager::SelectWorkQueueToService(size_t* out_queue_index) { | 616 bool TaskQueueManager::SelectWorkQueueToService(size_t* out_queue_index) { |
617 bool should_run = selector_->SelectWorkQueueToService(out_queue_index); | 617 bool should_run = selector_->SelectWorkQueueToService(out_queue_index); |
618 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 618 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
619 disabled_by_default_tracing_category_, "TaskQueueManager", this, | 619 disabled_by_default_tracing_category_, "TaskQueueManager", this, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 if (should_run) | 734 if (should_run) |
735 state->SetInteger("selected_queue", selected_queue); | 735 state->SetInteger("selected_queue", selected_queue); |
736 return state; | 736 return state; |
737 } | 737 } |
738 | 738 |
739 void TaskQueueManager::OnTaskQueueEnabled() { | 739 void TaskQueueManager::OnTaskQueueEnabled() { |
740 DCHECK(main_thread_checker_.CalledOnValidThread()); | 740 DCHECK(main_thread_checker_.CalledOnValidThread()); |
741 MaybePostDoWorkOnMainRunner(); | 741 MaybePostDoWorkOnMainRunner(); |
742 } | 742 } |
743 | 743 |
744 } // namespace content | 744 } // namespace scheduler |
OLD | NEW |