| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 int actual_fill_level, | 79 int actual_fill_level, |
| 80 int moderate_threshold, | 80 int moderate_threshold, |
| 81 int critical_threshold) { | 81 int critical_threshold) { |
| 82 if (actual_fill_level < moderate_threshold) | 82 if (actual_fill_level < moderate_threshold) |
| 83 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; | 83 return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE; |
| 84 return actual_fill_level < critical_threshold | 84 return actual_fill_level < critical_threshold |
| 85 ? MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE | 85 ? MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE |
| 86 : MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; | 86 : MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // This function will be called less then once a second. It will check if | 89 // This function will be called less than once a second. It will check if |
| 90 // the kernel has detected a low memory situation. | 90 // the kernel has detected a low memory situation. |
| 91 bool IsLowMemoryCondition(int file_descriptor) { | 91 bool IsLowMemoryCondition(int file_descriptor) { |
| 92 fd_set fds; | 92 fd_set fds; |
| 93 struct timeval tv; | 93 struct timeval tv; |
| 94 | 94 |
| 95 FD_ZERO(&fds); | 95 FD_ZERO(&fds); |
| 96 FD_SET(file_descriptor, &fds); | 96 FD_SET(file_descriptor, &fds); |
| 97 | 97 |
| 98 tv.tv_sec = 0; | 98 tv.tv_sec = 0; |
| 99 tv.tv_usec = 0; | 99 tv.tv_usec = 0; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 return percentage; | 273 return percentage; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void MemoryPressureMonitor::SetDispatchCallback( | 276 void MemoryPressureMonitor::SetDispatchCallback( |
| 277 const DispatchCallback& callback) { | 277 const DispatchCallback& callback) { |
| 278 dispatch_callback_ = callback; | 278 dispatch_callback_ = callback; |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace chromeos | 281 } // namespace chromeos |
| 282 } // namespace base | 282 } // namespace base |
| OLD | NEW |