| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "base/memory/memory_pressure_monitor_chromeos.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/select.h> | 8 #include <sys/select.h> |
| 9 | 9 |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } else if (current_memory_pressure_level_ == | 223 } else if (current_memory_pressure_level_ == |
| 224 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE && | 224 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE && |
| 225 old_pressure == | 225 old_pressure == |
| 226 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 226 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 227 // When we reducing the pressure level from critical to moderate, we | 227 // When we reducing the pressure level from critical to moderate, we |
| 228 // restart the timeout and do not send another notification. | 228 // restart the timeout and do not send another notification. |
| 229 moderate_pressure_repeat_count_ = 0; | 229 moderate_pressure_repeat_count_ = 0; |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 moderate_pressure_repeat_count_ = 0; | 232 moderate_pressure_repeat_count_ = 0; |
| 233 MemoryPressureListener::NotifyMemoryPressure(current_memory_pressure_level_); | 233 Notify(current_memory_pressure_level_); |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Gets the used ChromeOS memory in percent. | 236 // Gets the used ChromeOS memory in percent. |
| 237 int MemoryPressureMonitor::GetUsedMemoryInPercent() { | 237 int MemoryPressureMonitor::GetUsedMemoryInPercent() { |
| 238 base::SystemMemoryInfoKB info; | 238 base::SystemMemoryInfoKB info; |
| 239 if (!base::GetSystemMemoryInfo(&info)) { | 239 if (!base::GetSystemMemoryInfo(&info)) { |
| 240 VLOG(1) << "Cannot determine the free memory of the system."; | 240 VLOG(1) << "Cannot determine the free memory of the system."; |
| 241 return 0; | 241 return 0; |
| 242 } | 242 } |
| 243 // TODO(skuhne): Instead of adding the kernel memory pressure calculation | 243 // TODO(skuhne): Instead of adding the kernel memory pressure calculation |
| (...skipping 22 matching lines...) Expand all Loading... |
| 266 int available_memory = | 266 int available_memory = |
| 267 info.free + info.swap_free / kSwapWeight + file_memory; | 267 info.free + info.swap_free / kSwapWeight + file_memory; |
| 268 | 268 |
| 269 DCHECK(available_memory < total_memory); | 269 DCHECK(available_memory < total_memory); |
| 270 int percentage = ((total_memory - available_memory) * 100) / total_memory; | 270 int percentage = ((total_memory - available_memory) * 100) / total_memory; |
| 271 return percentage; | 271 return percentage; |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace chromeos | 274 } // namespace chromeos |
| 275 } // namespace base | 275 } // namespace base |
| OLD | NEW |