Skip to content

Commit 3613d12

Browse files
plmonette-zzcopybara-github
authored andcommitted
[MemoryPressureListener] Notify listeners when returning to no pressure
Eventually, the memory pressure listeners will be migrated to the base::MemoryConsumer API. A major difference is that the base:MemoryConsumer notifications are stateful. You only get notifications when transitioning from a state to another. Memory pressure notifications for MODERATE and CRITICAL state can be sent repeatedly, while the NONE state never triggers any notifications. In order to ease the transition, memory pressure notifications will be modified to be a stateful API. The first step is to notify when transitioning to the NONE state. This is a no-op change as all current listeners were modified to ensure they ignore those notifications correctly. Bug: 462288601 Change-Id: I87ad8fffa0914e7f66b5320a745d708b1929b748 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7168577 Commit-Queue: Patrick Monette <[email protected]> Reviewed-by: Francois Pierre Doray <[email protected]> Reviewed-by: Thomas Anderson <[email protected]> Reviewed-by: Vovo Yang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1550203} NOKEYCHECK=True GitOrigin-RevId: d139d7a70867886298ae3826082bb1ebe168746c
1 parent 00caf5d commit 3613d12

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

memory/memory_pressure_listener_registry.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ void MemoryPressureListenerRegistry::DoNotifyMemoryPressure(
9595
CHECK(
9696
!SingleThreadTaskRunner::HasMainThreadDefault() ||
9797
SingleThreadTaskRunner::GetMainThreadDefault()->BelongsToCurrentThread());
98+
// Don't repeat MEMORY_PRESSURE_LEVEL_NONE notifications.
99+
CHECK(memory_pressure_level != base::MEMORY_PRESSURE_LEVEL_NONE ||
100+
last_memory_pressure_level_ != memory_pressure_level);
101+
last_memory_pressure_level_ = memory_pressure_level;
98102
if (base::FeatureList::IsEnabled(kSuppressMemoryListeners)) {
99103
auto mask = kSuppressMemoryListenersMask.Get();
100104
for (auto& listener : listeners_) {

memory/memory_pressure_listener_registry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class BASE_EXPORT MemoryPressureListenerRegistry {
4949
private:
5050
void DoNotifyMemoryPressure(MemoryPressureLevel memory_pressure_level);
5151

52+
base::MemoryPressureLevel last_memory_pressure_level_ =
53+
base::MEMORY_PRESSURE_LEVEL_NONE;
54+
5255
base::ObserverList<SyncMemoryPressureListenerRegistration>::Unchecked
5356
listeners_;
5457
};

0 commit comments

Comments
 (0)