Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 603083002: Remove foreground tab idle handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 using blink::WebScriptController; 166 using blink::WebScriptController;
167 using blink::WebSecurityPolicy; 167 using blink::WebSecurityPolicy;
168 using blink::WebString; 168 using blink::WebString;
169 using blink::WebView; 169 using blink::WebView;
170 170
171 namespace content { 171 namespace content {
172 172
173 namespace { 173 namespace {
174 174
175 const int64 kInitialIdleHandlerDelayMs = 1000; 175 const int64 kInitialIdleHandlerDelayMs = 1000;
176 const int64 kShortIdleHandlerDelayMs = 1000;
177 const int64 kLongIdleHandlerDelayMs = 30*1000; 176 const int64 kLongIdleHandlerDelayMs = 30*1000;
178 const int kIdleCPUUsageThresholdInPercents = 3;
179 177
180 // Maximum allocation size allowed for image scaling filters that 178 // Maximum allocation size allowed for image scaling filters that
181 // require pre-scaling. Skia will fallback to a filter that doesn't 179 // require pre-scaling. Skia will fallback to a filter that doesn't
182 // require pre-scaling if the default filter would require an 180 // require pre-scaling if the default filter would require an
183 // allocation that exceeds this limit. 181 // allocation that exceeds this limit.
184 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; 182 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
185 183
186 const size_t kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden = 184 const size_t kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden =
187 4 * 1024 * 1024; 185 4 * 1024 * 1024;
188 186
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 idle_timer_.Stop(); 996 idle_timer_.Stop();
999 idle_timer_.Start(FROM_HERE, 997 idle_timer_.Start(FROM_HERE,
1000 base::TimeDelta::FromMilliseconds(initial_delay_ms), 998 base::TimeDelta::FromMilliseconds(initial_delay_ms),
1001 this, &RenderThreadImpl::IdleHandler); 999 this, &RenderThreadImpl::IdleHandler);
1002 } 1000 }
1003 1001
1004 void RenderThreadImpl::IdleHandler() { 1002 void RenderThreadImpl::IdleHandler() {
1005 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && 1003 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
1006 GetContentClient()->renderer()-> 1004 GetContentClient()->renderer()->
1007 RunIdleHandlerWhenWidgetsHidden(); 1005 RunIdleHandlerWhenWidgetsHidden();
1008 if (run_in_foreground_tab) { 1006 if (run_in_foreground_tab)
1009 IdleHandlerInForegroundTab();
1010 return; 1007 return;
1011 }
1012 1008
1013 base::allocator::ReleaseFreeMemory(); 1009 base::allocator::ReleaseFreeMemory();
1014 1010
1015 // Continue the idle timer if the webkit shared timer is not suspended or 1011 // Continue the idle timer if the webkit shared timer is not suspended or
1016 // something is left to do. 1012 // something is left to do.
1017 bool continue_timer = !webkit_shared_timer_suspended_; 1013 bool continue_timer = !webkit_shared_timer_suspended_;
1018 1014
1019 if (blink::mainThreadIsolate() && 1015 if (blink::mainThreadIsolate() &&
1020 !blink::mainThreadIsolate()->IdleNotification(1000)) { 1016 !blink::mainThreadIsolate()->IdleNotification(1000)) {
1021 continue_timer = true; 1017 continue_timer = true;
(...skipping 21 matching lines...) Expand all
1043 idle_notification_delay_in_ms_ + 1039 idle_notification_delay_in_ms_ +
1044 1000000 / (idle_notification_delay_in_ms_ + 2000))); 1040 1000000 / (idle_notification_delay_in_ms_ + 2000)));
1045 1041
1046 } else { 1042 } else {
1047 idle_timer_.Stop(); 1043 idle_timer_.Stop();
1048 } 1044 }
1049 1045
1050 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); 1046 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
1051 } 1047 }
1052 1048
1053 void RenderThreadImpl::IdleHandlerInForegroundTab() {
1054 // Increase the delay in the same way as in IdleHandler,
1055 // but make it periodic by reseting it once it is too big.
1056 int64 new_delay_ms = idle_notification_delay_in_ms_ +
1057 1000000 / (idle_notification_delay_in_ms_ + 2000);
1058 if (new_delay_ms >= kLongIdleHandlerDelayMs)
1059 new_delay_ms = kShortIdleHandlerDelayMs;
1060
1061 if (idle_notifications_to_skip_ > 0) {
1062 idle_notifications_to_skip_--;
1063 } else {
1064 int cpu_usage = 0;
1065 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
1066 // Idle notification hint roughly specifies the expected duration of the
1067 // idle pause. We set it proportional to the idle timer delay.
1068 int idle_hint = static_cast<int>(new_delay_ms / 10);
1069 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
1070 base::allocator::ReleaseFreeMemory();
1071
1072 bool finished_idle_work = true;
1073 if (blink::mainThreadIsolate() &&
1074 !blink::mainThreadIsolate()->IdleNotification(idle_hint)) {
1075 finished_idle_work = false;
1076 }
1077 if (!base::DiscardableMemory::ReduceMemoryUsage())
reveman 2014/09/25 13:34:17 where is this moved?
jochen (gone - plz use gerrit) 2014/09/25 14:18:28 nowhere. In our experiments, the idle handler is a
reveman 2014/09/25 15:03:41 This call will discard memory that has not been us
jochen (gone - plz use gerrit) 2014/09/25 15:08:36 so just postTask this call every 30s should be fin
reveman 2014/09/25 16:44:49 Maybe. Is there not a better idle signal we can ho
1078 finished_idle_work = false;
1079
1080 // V8 finished collecting garbage and discardable memory system has no
1081 // more idle work left.
1082 if (finished_idle_work)
1083 new_delay_ms = kLongIdleHandlerDelayMs;
1084 }
1085 }
1086 ScheduleIdleHandler(new_delay_ms);
1087 }
1088
1089 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { 1049 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
1090 return idle_notification_delay_in_ms_; 1050 return idle_notification_delay_in_ms_;
1091 } 1051 }
1092 1052
1093 void RenderThreadImpl::SetIdleNotificationDelayInMs( 1053 void RenderThreadImpl::SetIdleNotificationDelayInMs(
1094 int64 idle_notification_delay_in_ms) { 1054 int64 idle_notification_delay_in_ms) {
1095 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; 1055 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
1096 } 1056 }
1097 1057
1098 void RenderThreadImpl::UpdateHistograms(int sequence_number) { 1058 void RenderThreadImpl::UpdateHistograms(int sequence_number) {
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 hidden_widget_count_--; 1615 hidden_widget_count_--;
1656 1616
1657 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1617 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1658 return; 1618 return;
1659 } 1619 }
1660 1620
1661 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1621 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1662 } 1622 }
1663 1623
1664 } // namespace content 1624 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698