OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 } | 874 } |
875 | 875 |
876 void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) { | 876 void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) { |
877 idle_notification_delay_in_ms_ = initial_delay_ms; | 877 idle_notification_delay_in_ms_ = initial_delay_ms; |
878 idle_timer_.Stop(); | 878 idle_timer_.Stop(); |
879 idle_timer_.Start(FROM_HERE, | 879 idle_timer_.Start(FROM_HERE, |
880 base::TimeDelta::FromMilliseconds(initial_delay_ms), | 880 base::TimeDelta::FromMilliseconds(initial_delay_ms), |
881 this, &RenderThreadImpl::IdleHandler); | 881 this, &RenderThreadImpl::IdleHandler); |
882 } | 882 } |
883 | 883 |
884 void RenderThreadImpl::IdleHandler() { | 884 void RenderThreadImpl::IdleHandler() { |
reveman
2014/06/23 14:59:40
Using this idle handler seem to work Ok but there
willchan no longer on Chromium
2014/06/24 16:33:00
I'm not going to bother with the review until Jame
| |
885 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && | 885 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
886 GetContentClient()->renderer()-> | 886 GetContentClient()->renderer()-> |
887 RunIdleHandlerWhenWidgetsHidden(); | 887 RunIdleHandlerWhenWidgetsHidden(); |
888 if (run_in_foreground_tab) { | 888 if (run_in_foreground_tab) { |
889 IdleHandlerInForegroundTab(); | 889 IdleHandlerInForegroundTab(); |
890 return; | 890 return; |
891 } | 891 } |
892 | 892 |
893 base::allocator::ReleaseFreeMemory(); | 893 base::allocator::ReleaseFreeMemory(); |
894 | 894 |
895 // Continue the idle timer if the webkit shared timer is not suspended or | 895 // Continue the idle timer if the webkit shared timer is not suspended or |
896 // something is left to do. | 896 // something is left to do. |
897 bool continue_timer = !webkit_shared_timer_suspended_; | 897 bool continue_timer = !webkit_shared_timer_suspended_; |
898 | 898 |
899 if (!v8::V8::IdleNotification()) { | 899 if (!v8::V8::IdleNotification()) { |
900 continue_timer = true; | 900 continue_timer = true; |
901 } | 901 } |
902 if (!base::DiscardableMemory::IdleNotification()) { | |
903 continue_timer = true; | |
904 } | |
902 | 905 |
903 // Schedule next invocation. | 906 // Schedule next invocation. |
904 // Dampen the delay using the algorithm (if delay is in seconds): | 907 // Dampen the delay using the algorithm (if delay is in seconds): |
905 // delay = delay + 1 / (delay + 2) | 908 // delay = delay + 1 / (delay + 2) |
906 // Using floor(delay) has a dampening effect such as: | 909 // Using floor(delay) has a dampening effect such as: |
907 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... | 910 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
908 // If the delay is in milliseconds, the above formula is equivalent to: | 911 // If the delay is in milliseconds, the above formula is equivalent to: |
909 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) | 912 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
910 // which is equivalent to | 913 // which is equivalent to |
911 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). | 914 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
(...skipping 21 matching lines...) Expand all Loading... | |
933 if (idle_notifications_to_skip_ > 0) { | 936 if (idle_notifications_to_skip_ > 0) { |
934 idle_notifications_to_skip_--; | 937 idle_notifications_to_skip_--; |
935 } else { | 938 } else { |
936 int cpu_usage = 0; | 939 int cpu_usage = 0; |
937 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); | 940 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); |
938 // Idle notification hint roughly specifies the expected duration of the | 941 // Idle notification hint roughly specifies the expected duration of the |
939 // idle pause. We set it proportional to the idle timer delay. | 942 // idle pause. We set it proportional to the idle timer delay. |
940 int idle_hint = static_cast<int>(new_delay_ms / 10); | 943 int idle_hint = static_cast<int>(new_delay_ms / 10); |
941 if (cpu_usage < kIdleCPUUsageThresholdInPercents) { | 944 if (cpu_usage < kIdleCPUUsageThresholdInPercents) { |
942 base::allocator::ReleaseFreeMemory(); | 945 base::allocator::ReleaseFreeMemory(); |
943 if (v8::V8::IdleNotification(idle_hint)) { | 946 |
944 // V8 finished collecting garbage. | 947 bool finished_idle_work = true; |
948 if (!v8::V8::IdleNotification(idle_hint)) | |
949 finished_idle_work = false; | |
950 if (!base::DiscardableMemory::IdleNotification()) | |
951 finished_idle_work = false; | |
952 | |
953 // V8 finished collecting garbage and discardable memory system has no | |
954 // more idle work left. | |
955 if (finished_idle_work) | |
945 new_delay_ms = kLongIdleHandlerDelayMs; | 956 new_delay_ms = kLongIdleHandlerDelayMs; |
946 } | |
947 } | 957 } |
948 } | 958 } |
949 ScheduleIdleHandler(new_delay_ms); | 959 ScheduleIdleHandler(new_delay_ms); |
950 } | 960 } |
951 | 961 |
952 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { | 962 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
953 return idle_notification_delay_in_ms_; | 963 return idle_notification_delay_in_ms_; |
954 } | 964 } |
955 | 965 |
956 void RenderThreadImpl::SetIdleNotificationDelayInMs( | 966 void RenderThreadImpl::SetIdleNotificationDelayInMs( |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 hidden_widget_count_--; | 1530 hidden_widget_count_--; |
1521 | 1531 |
1522 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1532 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
1523 return; | 1533 return; |
1524 } | 1534 } |
1525 | 1535 |
1526 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1536 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
1527 } | 1537 } |
1528 | 1538 |
1529 } // namespace content | 1539 } // namespace content |
OLD | NEW |