| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_MEMORY_PRESSURE_DIRECT_MEMORY_PRESSURE_CALCULATOR_WIN_H_ | |
| 6 #define COMPONENTS_MEMORY_PRESSURE_DIRECT_MEMORY_PRESSURE_CALCULATOR_WIN_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/process/process_metrics.h" | |
| 10 #include "build/build_config.h" | |
| 11 #include "components/memory_pressure/memory_pressure_calculator.h" | |
| 12 | |
| 13 namespace memory_pressure { | |
| 14 | |
| 15 #if defined(MEMORY_PRESSURE_IS_POLLING) | |
| 16 | |
| 17 // OS-specific implementation of MemoryPressureCalculator. This is only defined | |
| 18 // and used on platforms that do not have native memory pressure signals | |
| 19 // (ChromeOS, Linux, Windows). OSes that do have native signals simply hook into | |
| 20 // the appropriate subsystem (Android, Mac OS X). | |
| 21 class DirectMemoryPressureCalculator : public MemoryPressureCalculator { | |
| 22 public: | |
| 23 // Exposed for unittesting. See .cc file for detailed discussion of these | |
| 24 // constants. | |
| 25 static const int kLargeMemoryThresholdMb; | |
| 26 static const int kSmallMemoryDefaultModerateThresholdMb; | |
| 27 static const int kSmallMemoryDefaultCriticalThresholdMb; | |
| 28 static const int kLargeMemoryDefaultModerateThresholdMb; | |
| 29 static const int kLargeMemoryDefaultCriticalThresholdMb; | |
| 30 | |
| 31 // Default constructor. Will choose thresholds automatically based on the | |
| 32 // actual amount of system memory installed. | |
| 33 DirectMemoryPressureCalculator(); | |
| 34 | |
| 35 // Constructor with explicit memory thresholds. These represent the amount of | |
| 36 // free memory below which the applicable memory pressure state applies. | |
| 37 DirectMemoryPressureCalculator(int moderate_threshold_mb, | |
| 38 int critical_threshold_mb); | |
| 39 | |
| 40 ~DirectMemoryPressureCalculator() override {} | |
| 41 | |
| 42 // Calculates the current pressure level. | |
| 43 MemoryPressureLevel CalculateCurrentPressureLevel() override; | |
| 44 | |
| 45 int moderate_threshold_mb() const { return moderate_threshold_mb_; } | |
| 46 int critical_threshold_mb() const { return critical_threshold_mb_; } | |
| 47 | |
| 48 private: | |
| 49 friend class TestDirectMemoryPressureCalculator; | |
| 50 | |
| 51 // Gets system memory status. This is virtual as a unittesting hook and by | |
| 52 // default this invokes base::GetSystemMemoryInfo. | |
| 53 virtual bool GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info) const; | |
| 54 | |
| 55 // Uses GetSystemMemoryInfo to automatically infer appropriate values for | |
| 56 // moderate_threshold_mb_ and critical_threshold_mb_. | |
| 57 void InferThresholds(); | |
| 58 | |
| 59 // Threshold amounts of available memory that trigger pressure levels. See | |
| 60 // memory_pressure_monitor_win.cc for a discussion of reasonable values for | |
| 61 // these. | |
| 62 int moderate_threshold_mb_; | |
| 63 int critical_threshold_mb_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(DirectMemoryPressureCalculator); | |
| 66 }; | |
| 67 | |
| 68 #endif // defined(MEMORY_PRESSURE_IS_POLLING) | |
| 69 | |
| 70 } // namespace memory_pressure | |
| 71 | |
| 72 #endif // COMPONENTS_MEMORY_PRESSURE_DIRECT_MEMORY_PRESSURE_CALCULATOR_WIN_H_ | |
| OLD | NEW |