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

Unified Diff: content/browser/memory/memory_coordinator.cc

Issue 2553553002: memory coordinator: Throttle foreground renderers on SUSPENDED state (Closed)
Patch Set: Fix unittests Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/memory/memory_coordinator.cc
diff --git a/content/browser/memory/memory_coordinator.cc b/content/browser/memory/memory_coordinator.cc
index 6de5c0ca688b1d10772033751d8973d96459278d..5bf29c78e1d6afbb11fe113de6507c3193f24188 100644
--- a/content/browser/memory/memory_coordinator.cc
+++ b/content/browser/memory/memory_coordinator.cc
@@ -88,15 +88,15 @@ bool MemoryCoordinator::SetChildMemoryState(int render_process_id,
if (!iter->second.handle->child().is_bound())
return false;
+ // We don't suspend foreground renderers. Throttle them instead.
+ if (memory_state == mojom::MemoryState::SUSPENDED &&
+ iter->second.is_visible)
+ memory_state = mojom::MemoryState::THROTTLED;
+
// A nop doesn't need to be sent, but is considered successful.
if (iter->second.memory_state == memory_state)
return true;
- // Can't throttle the given renderer.
- if (memory_state == mojom::MemoryState::THROTTLED &&
- !CanThrottleRenderer(render_process_id))
- return false;
-
// Can't suspend the given renderer.
if (memory_state == mojom::MemoryState::SUSPENDED &&
!CanSuspendRenderer(render_process_id))
@@ -163,17 +163,6 @@ void MemoryCoordinator::OnConnectionError(int render_process_id) {
children_.erase(render_process_id);
}
-bool MemoryCoordinator::CanThrottleRenderer(int render_process_id) {
- // If there is no delegate (i.e. unittests), renderers are always
- // throttleable.
- // TODO(bashi): We check |delegate_| to avoid calling FromID() on a
- // wrong thread in tests. Figure out a better way to handle tests.
- if (!delegate_)
- return true;
- auto* render_process_host = RenderProcessHost::FromID(render_process_id);
- return render_process_host && render_process_host->IsProcessBackgrounded();
-}
-
bool MemoryCoordinator::CanSuspendRenderer(int render_process_id) {
// If there is no delegate (i.e. unittests), renderers are always suspendable.
if (!delegate_)
@@ -199,6 +188,7 @@ void MemoryCoordinator::CreateChildInfoMapEntry(
// corresponding renderer process is ready to communicate. Renderer processes
// call AddChild() when they are ready.
child_info.memory_state = mojom::MemoryState::NORMAL;
+ child_info.is_visible = true;
child_info.handle = std::move(handle);
}
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | content/browser/memory/memory_coordinator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698