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

Unified Diff: components/memory_coordinator/browser/memory_coordinator.cc

Issue 2150783003: Add memory pressure dispatching callback to MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mc-3-client
Patch Set: rebase Created 4 years, 5 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
Index: components/memory_coordinator/browser/memory_coordinator.cc
diff --git a/components/memory_coordinator/browser/memory_coordinator.cc b/components/memory_coordinator/browser/memory_coordinator.cc
index 634ebf809054e6098c15a500d690643f0cd4fccf..b4e714ab731798c73d0b27712b3ae1a1442356a6 100644
--- a/components/memory_coordinator/browser/memory_coordinator.cc
+++ b/components/memory_coordinator/browser/memory_coordinator.cc
@@ -4,6 +4,8 @@
#include "components/memory_coordinator/browser/memory_coordinator.h"
+#include "base/memory/memory_pressure_listener.h"
+
namespace memory_coordinator {
// The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom
@@ -31,9 +33,23 @@ class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle {
DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl);
};
-MemoryCoordinator::MemoryCoordinator() {}
+MemoryCoordinator::MemoryCoordinator()
+ : pressure_level_dispatcher_(
+ base::Bind(&MemoryCoordinator::OnMemoryPressure,
+ base::Unretained(this))) {
+ auto* monitor = base::MemoryPressureMonitor::Get();
+ if (monitor) {
+ monitor->SetDispatchCallback(pressure_level_dispatcher_);
+ }
+}
-MemoryCoordinator::~MemoryCoordinator() {}
+MemoryCoordinator::~MemoryCoordinator() {
+ auto* monitor = base::MemoryPressureMonitor::Get();
+ if (monitor) {
+ monitor->SetDispatchCallback(
+ base::Bind(&base::MemoryPressureListener::NotifyMemoryPressure));
+ }
+}
void MemoryCoordinator::CreateHandle(
int render_process_id,
@@ -53,4 +69,19 @@ void MemoryCoordinator::OnConnectionError(int render_process_id) {
children_.erase(render_process_id);
}
+void MemoryCoordinator::OnMemoryPressure(
+ base::MemoryPressureMonitor::MemoryPressureLevel level) {
+ // TODO(bashi): The current implementation just translates memory pressure
+ // levels to memory coordinator states. The logic will be replaced with
+ // the priority tracker.
+ if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE) {
+ clients()->Notify(FROM_HERE, &MemoryCoordinatorClient::OnMemoryStateChange,
+ mojom::MemoryState::THROTTLED);
+ } else if (level ==
+ base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
+ clients()->Notify(FROM_HERE, &MemoryCoordinatorClient::OnMemoryStateChange,
+ mojom::MemoryState::SUSPENDED);
+ }
+}
+
} // namespace memory_coordinator

Powered by Google App Engine
This is Rietveld 408576698