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/chromeos/memory_pressure_monitor_chromeos.h" | 5 #include "base/chromeos/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/message_loop/message_loop.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
12 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
13 #include "base/thread_task_runner_handle.h" | |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // The time between memory pressure checks. While under critical pressure, this | 20 // The time between memory pressure checks. While under critical pressure, this |
21 // is also the timer to repeat cleanup attempts. | 21 // is also the timer to repeat cleanup attempts. |
22 const int kMemoryPressureIntervalMs = 1000; | 22 const int kMemoryPressureIntervalMs = 1000; |
23 | 23 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 weak_ptr_factory_(this) { | 113 weak_ptr_factory_(this) { |
114 StartObserving(); | 114 StartObserving(); |
115 LOG_IF(ERROR, !low_mem_file_.is_valid()) << "Cannot open kernel listener"; | 115 LOG_IF(ERROR, !low_mem_file_.is_valid()) << "Cannot open kernel listener"; |
116 } | 116 } |
117 | 117 |
118 MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() { | 118 MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() { |
119 StopObserving(); | 119 StopObserving(); |
120 } | 120 } |
121 | 121 |
122 void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() { | 122 void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() { |
123 ThreadTaskRunnerHandle::Get()->PostTask( | 123 MessageLoop::current()->PostTask( |
124 FROM_HERE, Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure, | 124 FROM_HERE, |
125 weak_ptr_factory_.GetWeakPtr())); | 125 Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure, |
| 126 weak_ptr_factory_.GetWeakPtr())); |
126 } | 127 } |
127 | 128 |
128 MemoryPressureListener::MemoryPressureLevel | 129 MemoryPressureListener::MemoryPressureLevel |
129 MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const { | 130 MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const { |
130 return current_memory_pressure_level_; | 131 return current_memory_pressure_level_; |
131 } | 132 } |
132 | 133 |
133 void MemoryPressureMonitorChromeOS::StartObserving() { | 134 void MemoryPressureMonitorChromeOS::StartObserving() { |
134 timer_.Start(FROM_HERE, | 135 timer_.Start(FROM_HERE, |
135 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), | 136 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Available memory is the sum of free, swap and easy reclaimable memory. | 255 // Available memory is the sum of free, swap and easy reclaimable memory. |
255 int available_memory = | 256 int available_memory = |
256 info.free + info.swap_free / kSwapWeight + file_memory; | 257 info.free + info.swap_free / kSwapWeight + file_memory; |
257 | 258 |
258 DCHECK(available_memory < total_memory); | 259 DCHECK(available_memory < total_memory); |
259 int percentage = ((total_memory - available_memory) * 100) / total_memory; | 260 int percentage = ((total_memory - available_memory) * 100) / total_memory; |
260 return percentage; | 261 return percentage; |
261 } | 262 } |
262 | 263 |
263 } // namespace base | 264 } // namespace base |
OLD | NEW |