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

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

Issue 2399293002: Add MemoryCoordinatorDelegate (Closed)
Patch Set: Add a separate delegate class Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/memory/memory_coordinator.cc
diff --git a/content/browser/memory/memory_coordinator.cc b/content/browser/memory/memory_coordinator.cc
index 52ee2ece71f8a47def79edd5401bd9c791680b49..622d8b92aaaa6c928d8672675d878e05637adc44 100644
--- a/content/browser/memory/memory_coordinator.cc
+++ b/content/browser/memory/memory_coordinator.cc
@@ -5,6 +5,9 @@
#include "content/browser/memory/memory_coordinator.h"
#include "base/memory/memory_coordinator_client_registry.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
namespace content {
@@ -41,7 +44,9 @@ MemoryCoordinator* MemoryCoordinator::GetInstance() {
base::LeakySingletonTraits<MemoryCoordinator>>::get();
}
-MemoryCoordinator::MemoryCoordinator() {}
+MemoryCoordinator::MemoryCoordinator()
+ : delegate_(GetContentClient()->browser()->GetMemoryCoordinatorDelegate()) {
+}
MemoryCoordinator::~MemoryCoordinator() {}
@@ -75,6 +80,11 @@ bool MemoryCoordinator::SetMemoryState(int render_process_id,
if (iter->second.memory_state == memory_state)
return true;
+ // Can't suspend the given renderer.
+ if (memory_state == mojom::MemoryState::SUSPENDED &&
+ !CanSuspendRenderer(render_process_id))
+ return false;
+
// Update the internal state and send the message.
iter->second.memory_state = memory_state;
iter->second.handle->child()->OnStateChange(memory_state);
@@ -103,6 +113,16 @@ void MemoryCoordinator::OnConnectionError(int render_process_id) {
children_.erase(render_process_id);
}
+bool MemoryCoordinator::CanSuspendRenderer(int render_process_id) {
+ // If there is no delegate (i.e. tests), renderers are always suspendable.
+ if (!delegate_)
+ return true;
+ auto* render_process_host = RenderProcessHost::FromID(render_process_id);
+ if (!render_process_host->IsProcessBackgrounded())
+ return false;
+ return delegate_->CanSuspendBackgroundedRenderer(render_process_id);
+}
+
void MemoryCoordinator::CreateChildInfoMapEntry(
int render_process_id,
std::unique_ptr<MemoryCoordinatorHandleImpl> handle) {
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698