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

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: updates 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
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 idle_timer_.Start(FROM_HERE, 1007 idle_timer_.Start(FROM_HERE,
1010 base::TimeDelta::FromMilliseconds(initial_delay_ms), 1008 base::TimeDelta::FromMilliseconds(initial_delay_ms),
1011 this, &RenderThreadImpl::IdleHandler); 1009 this, &RenderThreadImpl::IdleHandler);
1012 } 1010 }
1013 1011
1014 void RenderThreadImpl::IdleHandler() { 1012 void RenderThreadImpl::IdleHandler() {
1015 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && 1013 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) &&
1016 GetContentClient()->renderer()-> 1014 GetContentClient()->renderer()->
1017 RunIdleHandlerWhenWidgetsHidden(); 1015 RunIdleHandlerWhenWidgetsHidden();
1018 if (run_in_foreground_tab) { 1016 if (run_in_foreground_tab) {
1019 IdleHandlerInForegroundTab(); 1017 if (idle_notifications_to_skip_ > 0) {
1018 --idle_notifications_to_skip_;
1019 } else {
1020 base::allocator::ReleaseFreeMemory();
1021 base::DiscardableMemory::ReduceMemoryUsage();
1022 }
1023 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1020 return; 1024 return;
1021 } 1025 }
1022 1026
1023 base::allocator::ReleaseFreeMemory(); 1027 base::allocator::ReleaseFreeMemory();
1024 1028
1025 // Continue the idle timer if the webkit shared timer is not suspended or 1029 // Continue the idle timer if the webkit shared timer is not suspended or
1026 // something is left to do. 1030 // something is left to do.
1027 bool continue_timer = !webkit_shared_timer_suspended_; 1031 bool continue_timer = !webkit_shared_timer_suspended_;
1028 1032
1029 if (blink::mainThreadIsolate() && 1033 if (blink::mainThreadIsolate() &&
(...skipping 23 matching lines...) Expand all
1053 idle_notification_delay_in_ms_ + 1057 idle_notification_delay_in_ms_ +
1054 1000000 / (idle_notification_delay_in_ms_ + 2000))); 1058 1000000 / (idle_notification_delay_in_ms_ + 2000)));
1055 1059
1056 } else { 1060 } else {
1057 idle_timer_.Stop(); 1061 idle_timer_.Stop();
1058 } 1062 }
1059 1063
1060 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); 1064 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
1061 } 1065 }
1062 1066
1063 void RenderThreadImpl::IdleHandlerInForegroundTab() {
1064 // Increase the delay in the same way as in IdleHandler,
1065 // but make it periodic by reseting it once it is too big.
1066 int64 new_delay_ms = idle_notification_delay_in_ms_ +
1067 1000000 / (idle_notification_delay_in_ms_ + 2000);
1068 if (new_delay_ms >= kLongIdleHandlerDelayMs)
1069 new_delay_ms = kShortIdleHandlerDelayMs;
1070
1071 if (idle_notifications_to_skip_ > 0) {
1072 idle_notifications_to_skip_--;
1073 } else {
1074 int cpu_usage = 0;
1075 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
1076 // Idle notification hint roughly specifies the expected duration of the
1077 // idle pause. We set it proportional to the idle timer delay.
1078 int idle_hint = static_cast<int>(new_delay_ms / 10);
1079 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
1080 base::allocator::ReleaseFreeMemory();
1081
1082 bool finished_idle_work = true;
1083 if (blink::mainThreadIsolate() &&
1084 !blink::mainThreadIsolate()->IdleNotification(idle_hint)) {
1085 finished_idle_work = false;
1086 }
1087 if (!base::DiscardableMemory::ReduceMemoryUsage())
1088 finished_idle_work = false;
1089
1090 // V8 finished collecting garbage and discardable memory system has no
1091 // more idle work left.
1092 if (finished_idle_work)
1093 new_delay_ms = kLongIdleHandlerDelayMs;
1094 }
1095 }
1096 ScheduleIdleHandler(new_delay_ms);
1097 }
1098
1099 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { 1067 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
1100 return idle_notification_delay_in_ms_; 1068 return idle_notification_delay_in_ms_;
1101 } 1069 }
1102 1070
1103 void RenderThreadImpl::SetIdleNotificationDelayInMs( 1071 void RenderThreadImpl::SetIdleNotificationDelayInMs(
1104 int64 idle_notification_delay_in_ms) { 1072 int64 idle_notification_delay_in_ms) {
1105 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; 1073 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
1106 } 1074 }
1107 1075
1108 void RenderThreadImpl::UpdateHistograms(int sequence_number) { 1076 void RenderThreadImpl::UpdateHistograms(int sequence_number) {
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 hidden_widget_count_--; 1633 hidden_widget_count_--;
1666 1634
1667 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1635 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1668 return; 1636 return;
1669 } 1637 }
1670 1638
1671 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1639 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1672 } 1640 }
1673 1641
1674 } // namespace content 1642 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698