Commit 6f03d35f authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

[MemoryPressureListeners] Ignore transitions to the no pressure state

https://chromium-review.googlesource.com/c/chromium/src/+/2017582 change
how the listeners are notified about memory pressure, they'll know
receive a notification when the system exit memory pressure.

This CL update some of the listeners to make sure that Chrome doesn't
try to free some memory when the system is not under pressure.

Change-Id: I426a878797550ccde1b00cc6822dd72a0fc4387d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022258Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735884}
parent 96067e4c
......@@ -20,6 +20,7 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
......@@ -871,6 +872,12 @@ void HistoryBackend::InitImpl(
void HistoryBackend::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
if (db_)
db_->TrimMemory();
if (thumbnail_db_)
......
......@@ -1688,6 +1688,11 @@ void WebMediaPlayerImpl::OnMemoryPressure(
DCHECK(base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC));
DCHECK(chunk_demuxer_);
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
// The new value of |memory_pressure_level| will take effect on the next
// garbage collection. Typically this means the next SourceBuffer append()
// operation, since per MSE spec, the garbage collection must only occur
......
......@@ -172,6 +172,12 @@ void ChunkDemuxerStream::OnMemoryPressure(
base::TimeDelta media_time,
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
bool force_instant_gc) {
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
base::AutoLock auto_lock(lock_);
return stream_->OnMemoryPressure(media_time, memory_pressure_level,
force_instant_gc);
......@@ -804,6 +810,12 @@ void ChunkDemuxer::OnMemoryPressure(
base::TimeDelta currentMediaTime,
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
bool force_instant_gc) {
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
base::AutoLock auto_lock(lock_);
for (const auto& itr : source_state_map_) {
itr.second->OnMemoryPressure(currentMediaTime, memory_pressure_level,
......
......@@ -316,6 +316,13 @@ void SourceBufferState::OnMemoryPressure(
base::TimeDelta media_time,
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
bool force_instant_gc) {
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
// Notify video streams about memory pressure first, since video typically
// takes up the most memory and that's where we can expect most savings.
for (const auto& it : video_streams_) {
......
......@@ -757,6 +757,13 @@ void SourceBufferStream::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
bool force_instant_gc) {
DVLOG(4) << __func__ << " level=" << memory_pressure_level;
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
memory_pressure_level_ = memory_pressure_level;
if (force_instant_gc)
......
......@@ -1039,6 +1039,13 @@ void BlobMemoryController::OnEvictionComplete(
void BlobMemoryController::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
// TODO(sebmarchand): Check if MEMORY_PRESSURE_LEVEL_MODERATE should also be
// ignored.
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
return;
}
auto time_from_last_evicion = base::TimeTicks::Now() - last_eviction_time_;
if (last_eviction_time_ != base::TimeTicks() &&
time_from_last_evicion.InSeconds() < kMinSecondsForPressureEvictions) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment