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

Unified Diff: base/memory/memory_pressure_monitor_mac.cc

Issue 2877573002: [Mac] Fix race condition in memory pressure level reporting. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/memory_pressure_monitor_mac.cc
diff --git a/base/memory/memory_pressure_monitor_mac.cc b/base/memory/memory_pressure_monitor_mac.cc
index 9ca520e8f8a0df2d9e898662ede6503bd4d2c829..678c276d3c80752c4ccfece87c3f12ac39b0d9f5 100644
--- a/base/memory/memory_pressure_monitor_mac.cc
+++ b/base/memory/memory_pressure_monitor_mac.cc
@@ -168,26 +168,17 @@ MemoryPressureMonitor::GetCurrentPressureLevel() {
void MemoryPressureMonitor::OnMemoryPressureChanged(
dispatch_source_s* event_source,
const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
- // Get the Chrome-equvialent memory pressure level.
- int mac_memory_pressure_level = dispatch_source_get_data(event_source);
- MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
- MemoryPressureLevelForMacMemoryPressureLevel(mac_memory_pressure_level);
+ // The OS has sent a notification that the memory pressure level has changed.
+ // Go through the normal memory pressure level checking mechanism so that
+ // last_pressure_level_ and UMA get updated to the current value.
+ UpdatePressureLevel();
// Run the callback that's waiting on memory pressure change notifications.
- // Note that we don't bother with updating |last_pressure_level_| or
- // causing memory pressure stats to be sent to UMA. Memory pressure change
- // notifications are delayed on the Mac, so the current actual memory pressure
- // level may be different than the incoming pressure level from the event.
- //
- // In general we don't want to take action (such as freeing memory) on
- // memory pressure change events, but that's how the current system is
- // designed. Given that it's incorrect to act on either stale or current
- // pressure level info, it's not clear which level is better to send. For
- // now stick with how it's been implemented to date, which is to send the
- // stale value.
- if (memory_pressure_level !=
+ // The convention is to not send notifiations on memory pressure returning to
+ // normal.
+ if (last_pressure_level_ !=
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE)
- dispatch_callback.Run(memory_pressure_level);
+ dispatch_callback.Run(last_pressure_level_);
}
void MemoryPressureMonitor::SetDispatchCallback(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698