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

Unified Diff: base/memory/memory_pressure_monitor_mac.cc

Issue 2097753002: Make memory pressure notifier configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win 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
« no previous file with comments | « base/memory/memory_pressure_monitor_mac.h ('k') | base/memory/memory_pressure_monitor_win.h » ('j') | 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 ec807eeec32e02fc3de28ce434f633bb7909e1c4..d3430e94ca45a1ad9150c3cfe8f3342faf02ffe6 100644
--- a/base/memory/memory_pressure_monitor_mac.cc
+++ b/base/memory/memory_pressure_monitor_mac.cc
@@ -8,6 +8,8 @@
#include <stddef.h>
#include <sys/sysctl.h>
+#include "base/bind.h"
+#include "base/logging.h"
#include "base/mac/mac_util.h"
// Redeclare for partial 10.9 availability.
@@ -32,11 +34,12 @@ MemoryPressureMonitor::MemoryPressureLevelForMacMemoryPressure(
}
void MemoryPressureMonitor::NotifyMemoryPressureChanged(
- dispatch_source_s* event_source) {
+ dispatch_source_s* event_source,
+ const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
int mac_memory_pressure = dispatch_source_get_data(event_source);
MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
- MemoryPressureListener::NotifyMemoryPressure(memory_pressure_level);
+ dispatch_callback.Run(memory_pressure_level);
}
MemoryPressureMonitor::MemoryPressureMonitor()
@@ -47,9 +50,12 @@ MemoryPressureMonitor::MemoryPressureMonitor()
DISPATCH_SOURCE_TYPE_MEMORYPRESSURE,
0,
DISPATCH_MEMORYPRESSURE_WARN | DISPATCH_MEMORYPRESSURE_CRITICAL,
- dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0))) {
+ dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0))),
+ dispatch_callback_(
+ base::Bind(&MemoryPressureListener::NotifyMemoryPressure)) {
dispatch_source_set_event_handler(memory_level_event_source_, ^{
- NotifyMemoryPressureChanged(memory_level_event_source_.get());
+ NotifyMemoryPressureChanged(memory_level_event_source_.get(),
+ dispatch_callback_);
});
dispatch_resume(memory_level_event_source_);
}
@@ -67,5 +73,10 @@ MemoryPressureMonitor::GetCurrentPressureLevel() const {
return MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
}
+void MemoryPressureMonitor::SetDispatchCallback(
+ const DispatchCallback& callback) {
+ dispatch_callback_ = callback;
+}
+
} // namespace mac
} // namespace base
« no previous file with comments | « base/memory/memory_pressure_monitor_mac.h ('k') | base/memory/memory_pressure_monitor_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698