Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/scheduler/child/idle_helper.h" | 5 #include "components/scheduler/child/idle_helper.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
| 10 #include "components/scheduler/base/real_time_domain.h" | 10 #include "components/scheduler/base/real_time_domain.h" |
| 11 #include "components/scheduler/base/task_queue.h" | 11 #include "components/scheduler/base/task_queue.h" |
| 12 #include "components/scheduler/base/task_queue_manager.h" | 12 #include "components/scheduler/base/task_queue_manager.h" |
| 13 #include "components/scheduler/child/scheduler_helper.h" | 13 #include "components/scheduler/child/scheduler_helper.h" |
| 14 #include "components/scheduler/child/scheduler_tqm_delegate.h" | 14 #include "components/scheduler/child/scheduler_tqm_delegate.h" |
| 15 | 15 |
| 16 namespace scheduler { | 16 namespace scheduler { |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 class IdleTaskObserverForTesting | |
| 21 : public base::MessageLoop::TaskObserver { | |
| 22 public: | |
| 23 IdleTaskObserverForTesting( | |
| 24 scoped_refptr<TaskQueue> idle_queue, | |
| 25 SchedulerHelper* helper, | |
| 26 const base::Closure& finished_callback); | |
| 27 void WillProcessTask(const base::PendingTask& pending_task) override; | |
| 28 void DidProcessTask(const base::PendingTask& pending_task) override; | |
| 29 private: | |
| 30 scoped_refptr<TaskQueue> idle_queue_; | |
| 31 SchedulerHelper* helper_; | |
| 32 base::Closure finished_callback_; | |
| 33 }; | |
| 34 | |
| 35 IdleTaskObserverForTesting::IdleTaskObserverForTesting( | |
| 36 scoped_refptr<TaskQueue> idle_queue, | |
| 37 SchedulerHelper* helper, | |
| 38 const base::Closure& finished_callback) | |
| 39 : idle_queue_(idle_queue), | |
| 40 helper_(helper), | |
| 41 finished_callback_(finished_callback) { | |
| 42 helper_->AddTaskObserver(this); | |
| 43 } | |
| 44 | |
| 45 void IdleTaskObserverForTesting::WillProcessTask( | |
| 46 const base::PendingTask& pending_task) { | |
| 47 } | |
| 48 | |
| 49 void IdleTaskObserverForTesting::DidProcessTask( | |
| 50 const base::PendingTask& pending_task) | |
| 51 { | |
| 52 if (idle_queue_->IsEmpty()) { | |
| 53 idle_queue_->SetQueueEnabled(false); | |
| 54 helper_->DefaultTaskRunner()->PostTask( | |
| 55 FROM_HERE, finished_callback_); | |
| 56 helper_->RemoveTaskObserver(this); | |
| 57 delete this; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 } | |
| 62 | |
| 18 IdleHelper::IdleHelper( | 63 IdleHelper::IdleHelper( |
| 19 SchedulerHelper* helper, | 64 SchedulerHelper* helper, |
| 20 Delegate* delegate, | 65 Delegate* delegate, |
| 21 const char* tracing_category, | 66 const char* tracing_category, |
| 22 const char* disabled_by_default_tracing_category, | 67 const char* disabled_by_default_tracing_category, |
| 23 const char* idle_period_tracing_name, | 68 const char* idle_period_tracing_name, |
| 24 base::TimeDelta required_quiescence_duration_before_long_idle_period) | 69 base::TimeDelta required_quiescence_duration_before_long_idle_period) |
| 25 : helper_(helper), | 70 : helper_(helper), |
| 26 delegate_(delegate), | 71 delegate_(delegate), |
| 27 idle_queue_( | 72 idle_queue_( |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 case IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE: | 520 case IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE: |
| 476 return "in_long_idle_period_with_max_deadline"; | 521 return "in_long_idle_period_with_max_deadline"; |
| 477 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: | 522 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: |
| 478 return "in_long_idle_period_paused"; | 523 return "in_long_idle_period_paused"; |
| 479 default: | 524 default: |
| 480 NOTREACHED(); | 525 NOTREACHED(); |
| 481 return nullptr; | 526 return nullptr; |
| 482 } | 527 } |
| 483 } | 528 } |
| 484 | 529 |
| 530 void IdleHelper::RunIdleTasksForTesting(const base::Closure& callback) { | |
| 531 new IdleTaskObserverForTesting(idle_queue_, helper_, callback); | |
|
szager1
2016/03/23 22:55:13
This is intentional; the instance gets deleted in
Sami
2016/03/29 11:11:17
Instead of using an observer, it might be easier j
szager1
2016/04/06 08:43:17
Done; I was able to get rid of all changes to Idle
| |
| 532 idle_queue_->SetQueueEnabled(true); | |
|
Sami
2016/03/29 11:11:17
I think one problem here is that IdleHelper might
szager1
2016/04/06 08:43:17
Done; added the field in_idle_period_for_testing t
| |
| 533 idle_queue_->PumpQueue(true); | |
| 534 } | |
| 535 | |
| 485 } // namespace scheduler | 536 } // namespace scheduler |
| OLD | NEW |