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

Side by Side Diff: base/chromeos/memory_pressure_monitor_chromeos.cc

Issue 1100773004: base: Remove most uses of MessageLoopProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing includes. Created 5 years, 7 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
« no previous file with comments | « base/cancelable_callback_unittest.cc ('k') | base/critical_closure.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
12 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
13 #include "base/process/process_metrics.h" 12 #include "base/process/process_metrics.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 namespace { 19 namespace {
19 20
20 // The time between memory pressure checks. While under critical pressure, this 21 // The time between memory pressure checks. While under critical pressure, this
21 // is also the timer to repeat cleanup attempts. 22 // is also the timer to repeat cleanup attempts.
22 const int kMemoryPressureIntervalMs = 1000; 23 const int kMemoryPressureIntervalMs = 1000;
23 24
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 weak_ptr_factory_(this) { 114 weak_ptr_factory_(this) {
114 StartObserving(); 115 StartObserving();
115 LOG_IF(ERROR, !low_mem_file_.is_valid()) << "Cannot open kernel listener"; 116 LOG_IF(ERROR, !low_mem_file_.is_valid()) << "Cannot open kernel listener";
116 } 117 }
117 118
118 MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() { 119 MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() {
119 StopObserving(); 120 StopObserving();
120 } 121 }
121 122
122 void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() { 123 void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() {
123 MessageLoop::current()->PostTask( 124 ThreadTaskRunnerHandle::Get()->PostTask(
124 FROM_HERE, 125 FROM_HERE, Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure,
125 Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure, 126 weak_ptr_factory_.GetWeakPtr()));
126 weak_ptr_factory_.GetWeakPtr()));
127 } 127 }
128 128
129 MemoryPressureListener::MemoryPressureLevel 129 MemoryPressureListener::MemoryPressureLevel
130 MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const { 130 MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const {
131 return current_memory_pressure_level_; 131 return current_memory_pressure_level_;
132 } 132 }
133 133
134 void MemoryPressureMonitorChromeOS::StartObserving() { 134 void MemoryPressureMonitorChromeOS::StartObserving() {
135 timer_.Start(FROM_HERE, 135 timer_.Start(FROM_HERE,
136 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), 136 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // 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.
256 int available_memory = 256 int available_memory =
257 info.free + info.swap_free / kSwapWeight + file_memory; 257 info.free + info.swap_free / kSwapWeight + file_memory;
258 258
259 DCHECK(available_memory < total_memory); 259 DCHECK(available_memory < total_memory);
260 int percentage = ((total_memory - available_memory) * 100) / total_memory; 260 int percentage = ((total_memory - available_memory) * 100) / total_memory;
261 return percentage; 261 return percentage;
262 } 262 }
263 263
264 } // namespace base 264 } // namespace base
OLDNEW
« no previous file with comments | « base/cancelable_callback_unittest.cc ('k') | base/critical_closure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698