Chromium Code Reviews| 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_observer_chromeos.h" | 5 #include "base/chromeos/memory_pressure_observer_chromeos.h" |
| 6 | 6 |
| 7 #include "chromeos/chromeos_switches.h" | |
| 8 #include "base/command_line.h" | |
| 7 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | |
| 8 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/process/process_metrics.h" | 12 #include "base/process/process_metrics.h" |
| 10 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 11 | 14 |
| 12 namespace base { | 15 namespace base { |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 // The time between memory pressure checks. While under critical pressure, this | 19 // The time between memory pressure checks. While under critical pressure, this |
| 17 // is also the timer to repeat cleanup attempts. | 20 // is also the timer to repeat cleanup attempts. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 204 |
| 202 // Available memory is the sum of free, swap and easy reclaimable memory. | 205 // Available memory is the sum of free, swap and easy reclaimable memory. |
| 203 int available_memory = | 206 int available_memory = |
| 204 info.free + info.swap_free / kSwapWeight + file_memory; | 207 info.free + info.swap_free / kSwapWeight + file_memory; |
| 205 | 208 |
| 206 DCHECK(available_memory < total_memory); | 209 DCHECK(available_memory < total_memory); |
| 207 int percentage = ((total_memory - available_memory) * 100) / total_memory; | 210 int percentage = ((total_memory - available_memory) * 100) / total_memory; |
| 208 return percentage; | 211 return percentage; |
| 209 } | 212 } |
| 210 | 213 |
| 214 // static function | |
| 215 MemoryPressureObserverChromeOS::MemoryPressureThresholds | |
| 216 MemoryPressureObserverChromeOS::GetMemoryPressureThresholds() { | |
|
Mr4D (OOO till 08-26)
2015/02/06 03:56:35
This should remain in chromeos_switches.cc. Having
| |
| 217 const std::string option = | |
| 218 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 219 chromeos::switches::kMemoryPressureThresholds); | |
| 220 if (option == chromeos::switches::kConservativeThreshold) | |
| 221 return MemoryPressureObserverChromeOS::THRESHOLD_CONSERVATIVE; | |
| 222 if (option == chromeos::switches::kAggressiveCacheDiscardThreshold) | |
| 223 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE_CACHE_DISCARD; | |
| 224 if (option == chromeos::switches::kAggressiveTabDiscardThreshold) | |
| 225 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE_TAB_DISCARD; | |
| 226 if (option == chromeos::switches::kAggressiveThreshold) | |
| 227 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE; | |
| 228 | |
| 229 const std::string group_name = base::FieldTrialList::FindFullName( | |
| 230 chromeos::switches::kMemoryPressureThresholds); | |
| 231 if (group_name == chromeos::switches::kConservativeThreshold) | |
| 232 return MemoryPressureObserverChromeOS::THRESHOLD_CONSERVATIVE; | |
| 233 if (group_name == chromeos::switches::kAggressiveCacheDiscardThreshold) | |
| 234 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE_CACHE_DISCARD; | |
| 235 if (group_name == chromeos::switches::kAggressiveTabDiscardThreshold) | |
| 236 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE_TAB_DISCARD; | |
| 237 if (group_name == chromeos::switches::kAggressiveThreshold) | |
| 238 return MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE; | |
| 239 | |
| 240 return MemoryPressureObserverChromeOS::THRESHOLD_DEFAULT; | |
| 241 } | |
| 242 | |
| 211 } // namespace base | 243 } // namespace base |
| OLD | NEW |