| OLD | NEW |
| 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 <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Static. | 158 // Static. |
| 159 int MemoryPressureMonitor::GetSecondsPerUMATick() { | 159 int MemoryPressureMonitor::GetSecondsPerUMATick() { |
| 160 return kUMATickSize; | 160 return kUMATickSize; |
| 161 } | 161 } |
| 162 | 162 |
| 163 MemoryPressureListener::MemoryPressureLevel | 163 MemoryPressureListener::MemoryPressureLevel |
| 164 MemoryPressureMonitor::GetCurrentPressureLevel() { | 164 MemoryPressureMonitor::GetCurrentPressureLevel() { |
| 165 UpdatePressureLevel(); | |
| 166 return last_pressure_level_; | 165 return last_pressure_level_; |
| 167 } | 166 } |
| 168 | 167 |
| 169 void MemoryPressureMonitor::OnMemoryPressureChanged( | 168 void MemoryPressureMonitor::OnMemoryPressureChanged( |
| 170 dispatch_source_s* event_source, | 169 dispatch_source_s* event_source, |
| 171 const MemoryPressureMonitor::DispatchCallback& dispatch_callback) { | 170 const MemoryPressureMonitor::DispatchCallback& dispatch_callback) { |
| 172 // Get the Chrome-equvialent memory pressure level. | 171 // Get the Chrome-equvialent memory pressure level. |
| 173 int mac_memory_pressure_level = dispatch_source_get_data(event_source); | 172 int mac_memory_pressure_level = dispatch_source_get_data(event_source); |
| 174 MemoryPressureListener::MemoryPressureLevel memory_pressure_level = | 173 MemoryPressureListener::MemoryPressureLevel memory_pressure_level = |
| 175 MemoryPressureLevelForMacMemoryPressureLevel(mac_memory_pressure_level); | 174 MemoryPressureLevelForMacMemoryPressureLevel(mac_memory_pressure_level); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 dispatch_callback.Run(memory_pressure_level); | 190 dispatch_callback.Run(memory_pressure_level); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void MemoryPressureMonitor::SetDispatchCallback( | 193 void MemoryPressureMonitor::SetDispatchCallback( |
| 195 const DispatchCallback& callback) { | 194 const DispatchCallback& callback) { |
| 196 dispatch_callback_ = callback; | 195 dispatch_callback_ = callback; |
| 197 } | 196 } |
| 198 | 197 |
| 199 } // namespace mac | 198 } // namespace mac |
| 200 } // namespace base | 199 } // namespace base |
| OLD | NEW |