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

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

Issue 580173003: Set IdleHandler timer on background threads a minimum of 30s in the future after initial run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | 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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 bool continue_timer = !webkit_shared_timer_suspended_; 1010 bool continue_timer = !webkit_shared_timer_suspended_;
1011 1011
1012 if (blink::mainThreadIsolate() && 1012 if (blink::mainThreadIsolate() &&
1013 !blink::mainThreadIsolate()->IdleNotification(1000)) { 1013 !blink::mainThreadIsolate()->IdleNotification(1000)) {
1014 continue_timer = true; 1014 continue_timer = true;
1015 } 1015 }
1016 if (!base::DiscardableMemory::ReduceMemoryUsage()) { 1016 if (!base::DiscardableMemory::ReduceMemoryUsage()) {
1017 continue_timer = true; 1017 continue_timer = true;
1018 } 1018 }
1019 1019
1020 // Schedule next invocation. 1020 // Schedule next invocation. When the tab is originally hidden, an invocation
1021 // is scheduled for kInitialIdleHandlerDelayMs in
1022 // RenderThreadImpl::WidgetHidden in order to race to a minimal heap.
1023 // After that, idle calls can be much less frequent, so run at a maximum of
1024 // once every kLongIdleHandlerDelayMs.
1021 // Dampen the delay using the algorithm (if delay is in seconds): 1025 // Dampen the delay using the algorithm (if delay is in seconds):
1022 // delay = delay + 1 / (delay + 2) 1026 // delay = delay + 1 / (delay + 2)
1023 // Using floor(delay) has a dampening effect such as: 1027 // Using floor(delay) has a dampening effect such as:
1024 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... 1028 // 30s, 30, 30, 31, 31, 31, 31, 32, 32, ...
pasko 2014/10/09 09:32:14 with the new formula the series is actually growin
sullivan 2014/10/10 20:55:27 I added a new patch to try and clarify the comment
1025 // If the delay is in milliseconds, the above formula is equivalent to: 1029 // If the delay is in milliseconds, the above formula is equivalent to:
1026 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) 1030 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
1027 // which is equivalent to 1031 // which is equivalent to
1028 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). 1032 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
1029 // Note that idle_notification_delay_in_ms_ would be reset to
1030 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
pasko 2014/10/09 09:32:14 why deleting this comment?
sullivan 2014/10/10 20:55:27 It was a little misleading, since it's reset to kI
1031 if (continue_timer) { 1033 if (continue_timer) {
1032 ScheduleIdleHandler(idle_notification_delay_in_ms_ + 1034 ScheduleIdleHandler(
1033 1000000 / (idle_notification_delay_in_ms_ + 2000)); 1035 std::max(kLongIdleHandlerDelayMs,
1036 idle_notification_delay_in_ms_ +
1037 1000000 / (idle_notification_delay_in_ms_ + 2000)));
1034 1038
1035 } else { 1039 } else {
1036 idle_timer_.Stop(); 1040 idle_timer_.Stop();
1037 } 1041 }
1038 1042
1039 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); 1043 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
1040 } 1044 }
1041 1045
1042 void RenderThreadImpl::IdleHandlerInForegroundTab() { 1046 void RenderThreadImpl::IdleHandlerInForegroundTab() {
1043 // Increase the delay in the same way as in IdleHandler, 1047 // Increase the delay in the same way as in IdleHandler,
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 hidden_widget_count_--; 1652 hidden_widget_count_--;
1649 1653
1650 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1654 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1651 return; 1655 return;
1652 } 1656 }
1653 1657
1654 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1658 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1655 } 1659 }
1656 1660
1657 } // namespace content 1661 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698