Chromium Code Reviews| 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 "platform/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "platform/scheduler/renderer/renderer_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 static base::TimeDelta maximum_idle_period_duration() { | 624 static base::TimeDelta maximum_idle_period_duration() { |
| 625 return base::TimeDelta::FromMilliseconds( | 625 return base::TimeDelta::FromMilliseconds( |
| 626 IdleHelper::kMaximumIdlePeriodMillis); | 626 IdleHelper::kMaximumIdlePeriodMillis); |
| 627 } | 627 } |
| 628 | 628 |
| 629 static base::TimeDelta end_idle_when_hidden_delay() { | 629 static base::TimeDelta end_idle_when_hidden_delay() { |
| 630 return base::TimeDelta::FromMilliseconds( | 630 return base::TimeDelta::FromMilliseconds( |
| 631 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); | 631 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); |
| 632 } | 632 } |
| 633 | 633 |
| 634 static base::TimeDelta suspend_timers_when_backgrounded_delay() { | |
| 635 return base::TimeDelta::FromMilliseconds( | |
| 636 RendererSchedulerImpl::kSuspendTimersWhenBackgroundedDelayMillis); | |
| 637 } | |
| 638 | |
| 639 static base::TimeDelta rails_response_time() { | 634 static base::TimeDelta rails_response_time() { |
| 640 return base::TimeDelta::FromMilliseconds( | 635 return base::TimeDelta::FromMilliseconds( |
| 641 RendererSchedulerImpl::kRailsResponseTimeMillis); | 636 RendererSchedulerImpl::kRailsResponseTimeMillis); |
| 642 } | 637 } |
| 643 | 638 |
| 644 template <typename E> | 639 template <typename E> |
| 645 static void CallForEachEnumValue(E first, | 640 static void CallForEachEnumValue(E first, |
| 646 E last, | 641 E last, |
| 647 const char* (*function)(E)) { | 642 const char* (*function)(E)) { |
| 648 for (E val = first; val < last; | 643 for (E val = first; val < last; |
| (...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2464 } | 2459 } |
| 2465 | 2460 |
| 2466 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { | 2461 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { |
| 2467 scheduler_->Shutdown(); | 2462 scheduler_->Shutdown(); |
| 2468 std::vector<std::string> run_order; | 2463 std::vector<std::string> run_order; |
| 2469 PostTestTasks(&run_order, "D1 C1"); | 2464 PostTestTasks(&run_order, "D1 C1"); |
| 2470 RunUntilIdle(); | 2465 RunUntilIdle(); |
| 2471 EXPECT_TRUE(run_order.empty()); | 2466 EXPECT_TRUE(run_order.empty()); |
| 2472 } | 2467 } |
| 2473 | 2468 |
| 2474 TEST_F(RendererSchedulerImplTest, TestRendererBackgroundedTimerSuspension) { | |
|
haraken
2017/02/02 08:53:13
It's unfortunate that we're losing the test. Can w
tasak
2017/02/03 03:13:14
I think, render_thread_impl_browsertest. render_th
| |
| 2475 scheduler_->SetTimerQueueSuspensionWhenBackgroundedEnabled(true); | |
| 2476 | |
| 2477 std::vector<std::string> run_order; | |
| 2478 PostTestTasks(&run_order, "T1 T2"); | |
| 2479 | |
| 2480 base::TimeTicks now; | |
| 2481 | |
| 2482 // The background signal will not immediately suspend the timer queue. | |
| 2483 scheduler_->OnRendererBackgrounded(); | |
| 2484 now += base::TimeDelta::FromMilliseconds(1100); | |
| 2485 clock_->SetNowTicks(now); | |
| 2486 RunUntilIdle(); | |
| 2487 EXPECT_THAT(run_order, | |
| 2488 testing::ElementsAre(std::string("T1"), std::string("T2"))); | |
| 2489 | |
| 2490 run_order.clear(); | |
| 2491 PostTestTasks(&run_order, "T3"); | |
| 2492 | |
| 2493 now += base::TimeDelta::FromSeconds(1); | |
| 2494 clock_->SetNowTicks(now); | |
| 2495 RunUntilIdle(); | |
| 2496 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T3"))); | |
| 2497 | |
| 2498 // Advance the time until after the scheduled timer queue suspension. | |
| 2499 now = base::TimeTicks() + suspend_timers_when_backgrounded_delay() + | |
| 2500 base::TimeDelta::FromMilliseconds(10); | |
| 2501 run_order.clear(); | |
| 2502 clock_->SetNowTicks(now); | |
| 2503 RunUntilIdle(); | |
| 2504 ASSERT_TRUE(run_order.empty()); | |
| 2505 | |
| 2506 // Timer tasks should be suspended until the foregrounded signal. | |
| 2507 PostTestTasks(&run_order, "T4 T5"); | |
| 2508 now += base::TimeDelta::FromSeconds(10); | |
| 2509 RunUntilIdle(); | |
| 2510 EXPECT_TRUE(run_order.empty()); | |
| 2511 | |
| 2512 scheduler_->OnRendererForegrounded(); | |
| 2513 RunUntilIdle(); | |
| 2514 EXPECT_THAT(run_order, | |
| 2515 testing::ElementsAre(std::string("T4"), std::string("T5"))); | |
| 2516 | |
| 2517 // Subsequent timer tasks should fire as usual. | |
| 2518 run_order.clear(); | |
| 2519 PostTestTasks(&run_order, "T6"); | |
| 2520 RunUntilIdle(); | |
| 2521 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6"))); | |
| 2522 } | |
| 2523 | |
| 2524 TEST_F(RendererSchedulerImplTest, | 2469 TEST_F(RendererSchedulerImplTest, |
| 2525 ExpensiveLoadingTasksNotBlockedTillFirstBeginMainFrame) { | 2470 ExpensiveLoadingTasksNotBlockedTillFirstBeginMainFrame) { |
| 2526 std::vector<std::string> run_order; | 2471 std::vector<std::string> run_order; |
| 2527 | 2472 |
| 2528 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); | 2473 scheduler_->SetHasVisibleRenderWidgetWithTouchHandler(true); |
| 2529 SimulateExpensiveTasks(loading_task_runner_); | 2474 SimulateExpensiveTasks(loading_task_runner_); |
| 2530 ForceTouchStartToBeExpectedSoon(); | 2475 ForceTouchStartToBeExpectedSoon(); |
| 2531 PostTestTasks(&run_order, "L1 D1"); | 2476 PostTestTasks(&run_order, "L1 D1"); |
| 2532 RunUntilIdle(); | 2477 RunUntilIdle(); |
| 2533 | 2478 |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3790 // While the queueing time estimator is locked, we believe the thread to still | 3735 // While the queueing time estimator is locked, we believe the thread to still |
| 3791 // be unresponsive. | 3736 // be unresponsive. |
| 3792 EXPECT_TRUE(scheduler_->MainThreadSeemsUnresponsive()); | 3737 EXPECT_TRUE(scheduler_->MainThreadSeemsUnresponsive()); |
| 3793 // Once we've dropped the lock, we realize the main thread is responsive. | 3738 // Once we've dropped the lock, we realize the main thread is responsive. |
| 3794 DropQueueingTimeEstimatorLock(); | 3739 DropQueueingTimeEstimatorLock(); |
| 3795 EXPECT_FALSE(scheduler_->MainThreadSeemsUnresponsive()); | 3740 EXPECT_FALSE(scheduler_->MainThreadSeemsUnresponsive()); |
| 3796 } | 3741 } |
| 3797 | 3742 |
| 3798 } // namespace scheduler | 3743 } // namespace scheduler |
| 3799 } // namespace blink | 3744 } // namespace blink |
| OLD | NEW |