| 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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::ReduceMemoryUsage()) { |
| 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::ReduceMemoryUsage()) |
| 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 |