| 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 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 | 946 |
| 947 base::allocator::ReleaseFreeMemory(); | 947 base::allocator::ReleaseFreeMemory(); |
| 948 | 948 |
| 949 // Continue the idle timer if the webkit shared timer is not suspended or | 949 // Continue the idle timer if the webkit shared timer is not suspended or |
| 950 // something is left to do. | 950 // something is left to do. |
| 951 bool continue_timer = !webkit_shared_timer_suspended_; | 951 bool continue_timer = !webkit_shared_timer_suspended_; |
| 952 | 952 |
| 953 if (!v8::V8::IdleNotification()) { | 953 if (!v8::V8::IdleNotification()) { |
| 954 continue_timer = true; | 954 continue_timer = true; |
| 955 } | 955 } |
| 956 if (!base::DiscardableMemory::ReduceMemoryUsage()) { |
| 957 continue_timer = true; |
| 958 } |
| 956 | 959 |
| 957 // Schedule next invocation. | 960 // Schedule next invocation. |
| 958 // Dampen the delay using the algorithm (if delay is in seconds): | 961 // Dampen the delay using the algorithm (if delay is in seconds): |
| 959 // delay = delay + 1 / (delay + 2) | 962 // delay = delay + 1 / (delay + 2) |
| 960 // Using floor(delay) has a dampening effect such as: | 963 // Using floor(delay) has a dampening effect such as: |
| 961 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... | 964 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 962 // If the delay is in milliseconds, the above formula is equivalent to: | 965 // If the delay is in milliseconds, the above formula is equivalent to: |
| 963 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) | 966 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) |
| 964 // which is equivalent to | 967 // which is equivalent to |
| 965 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). | 968 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). |
| (...skipping 21 matching lines...) Expand all Loading... |
| 987 if (idle_notifications_to_skip_ > 0) { | 990 if (idle_notifications_to_skip_ > 0) { |
| 988 idle_notifications_to_skip_--; | 991 idle_notifications_to_skip_--; |
| 989 } else { | 992 } else { |
| 990 int cpu_usage = 0; | 993 int cpu_usage = 0; |
| 991 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); | 994 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); |
| 992 // Idle notification hint roughly specifies the expected duration of the | 995 // Idle notification hint roughly specifies the expected duration of the |
| 993 // idle pause. We set it proportional to the idle timer delay. | 996 // idle pause. We set it proportional to the idle timer delay. |
| 994 int idle_hint = static_cast<int>(new_delay_ms / 10); | 997 int idle_hint = static_cast<int>(new_delay_ms / 10); |
| 995 if (cpu_usage < kIdleCPUUsageThresholdInPercents) { | 998 if (cpu_usage < kIdleCPUUsageThresholdInPercents) { |
| 996 base::allocator::ReleaseFreeMemory(); | 999 base::allocator::ReleaseFreeMemory(); |
| 997 if (v8::V8::IdleNotification(idle_hint)) { | 1000 |
| 998 // V8 finished collecting garbage. | 1001 bool finished_idle_work = true; |
| 1002 if (!v8::V8::IdleNotification(idle_hint)) |
| 1003 finished_idle_work = false; |
| 1004 if (!base::DiscardableMemory::ReduceMemoryUsage()) |
| 1005 finished_idle_work = false; |
| 1006 |
| 1007 // V8 finished collecting garbage and discardable memory system has no |
| 1008 // more idle work left. |
| 1009 if (finished_idle_work) |
| 999 new_delay_ms = kLongIdleHandlerDelayMs; | 1010 new_delay_ms = kLongIdleHandlerDelayMs; |
| 1000 } | |
| 1001 } | 1011 } |
| 1002 } | 1012 } |
| 1003 ScheduleIdleHandler(new_delay_ms); | 1013 ScheduleIdleHandler(new_delay_ms); |
| 1004 } | 1014 } |
| 1005 | 1015 |
| 1006 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { | 1016 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
| 1007 return idle_notification_delay_in_ms_; | 1017 return idle_notification_delay_in_ms_; |
| 1008 } | 1018 } |
| 1009 | 1019 |
| 1010 void RenderThreadImpl::SetIdleNotificationDelayInMs( | 1020 void RenderThreadImpl::SetIdleNotificationDelayInMs( |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 hidden_widget_count_--; | 1575 hidden_widget_count_--; |
| 1566 | 1576 |
| 1567 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1577 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1568 return; | 1578 return; |
| 1569 } | 1579 } |
| 1570 | 1580 |
| 1571 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1581 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1572 } | 1582 } |
| 1573 | 1583 |
| 1574 } // namespace content | 1584 } // namespace content |
| OLD | NEW |