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

Side by Side 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 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/memory_pressure_monitor_mac.h" 5 #include "base/memory/memory_pressure_monitor_mac.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/sysctl.h> 9 #include <sys/sysctl.h>
10 10
(...skipping 14 matching lines...) Expand all
25 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; 25 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
26 } 26 }
27 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; 27 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
28 } 28 }
29 29
30 void MemoryPressureMonitor::NotifyMemoryPressureChanged( 30 void MemoryPressureMonitor::NotifyMemoryPressureChanged(
31 dispatch_source_s* event_source) { 31 dispatch_source_s* event_source) {
32 int mac_memory_pressure = dispatch_source_get_data(event_source); 32 int mac_memory_pressure = dispatch_source_get_data(event_source);
33 MemoryPressureListener::MemoryPressureLevel memory_pressure_level = 33 MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
34 MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure); 34 MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
35 MemoryPressureListener::NotifyMemoryPressure(memory_pressure_level); 35 MemoryPressureMonitor::Get()->Notify(memory_pressure_level);
36 } 36 }
37 37
38 MemoryPressureMonitor::MemoryPressureMonitor() 38 MemoryPressureMonitor::MemoryPressureMonitor()
39 : memory_level_event_source_(nullptr) { 39 : memory_level_event_source_(nullptr) {
40 // _dispatch_source_type_memorypressure is not available prior to 10.9. 40 // _dispatch_source_type_memorypressure is not available prior to 10.9.
41 dispatch_source_type_t dispatch_source_memorypressure = 41 dispatch_source_type_t dispatch_source_memorypressure =
42 static_cast<dispatch_source_type_t> 42 static_cast<dispatch_source_type_t>
43 (dlsym(RTLD_NEXT, "_dispatch_source_type_memorypressure")); 43 (dlsym(RTLD_NEXT, "_dispatch_source_type_memorypressure"));
44 if (dispatch_source_memorypressure) { 44 if (dispatch_source_memorypressure) {
45 // The MemoryPressureListener doesn't want to know about transitions to 45 // The MemoryPressureListener doesn't want to know about transitions to
(...skipping 21 matching lines...) Expand all
67 MemoryPressureMonitor::GetCurrentPressureLevel() const { 67 MemoryPressureMonitor::GetCurrentPressureLevel() const {
68 int mac_memory_pressure; 68 int mac_memory_pressure;
69 size_t length = sizeof(int); 69 size_t length = sizeof(int);
70 sysctlbyname("kern.memorystatus_vm_pressure_level", &mac_memory_pressure, 70 sysctlbyname("kern.memorystatus_vm_pressure_level", &mac_memory_pressure,
71 &length, nullptr, 0); 71 &length, nullptr, 0);
72 return MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure); 72 return MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
73 } 73 }
74 74
75 } // namespace mac 75 } // namespace mac
76 } // namespace base 76 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698