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 BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_ | |
6 #define BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_ | |
7 | |
8 #include "base/base_export.h" | |
9 #include "base/memory/memory_pressure_listener.h" | |
10 #include "base/memory/memory_pressure_monitor.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/timer/timer.h" | |
13 | |
14 // Forward declaration. This is defined by windows.h. | |
15 struct _MEMORYSTATUSEX; | |
16 | |
17 namespace base { | |
18 | |
grt (UTC plus 2)
2015/05/05 15:34:00
namespace win {
chrisha
2015/05/05 19:46:13
Done.
| |
19 class TestMemoryPressureMonitor; | |
20 | |
21 // A class to handle the observation of our free memory. It notifies the | |
grt (UTC plus 2)
2015/05/05 15:33:59
please avoid "we", "us" etc in doc comments. an ex
chrisha
2015/05/05 19:46:13
Done.
| |
22 // MemoryPressureListener of memory fill level changes, so that it can take | |
23 // action to reduce memory resources accordingly. | |
24 class BASE_EXPORT MemoryPressureMonitorWin : public MemoryPressureMonitor { | |
25 public: | |
26 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; | |
grt (UTC plus 2)
2015/05/05 15:34:00
is this really needed? does MemoryPressureMonitor:
chrisha
2015/05/05 19:46:13
This is defined in MemoryPressureListener, not Mon
grt (UTC plus 2)
2015/05/06 13:26:36
yes, and MemoryPressureMonitor (this class's paren
| |
27 | |
28 MemoryPressureMonitorWin(); | |
29 virtual ~MemoryPressureMonitorWin() override; | |
30 | |
31 // Redo the memory pressure calculation soon and call again if a critical | |
grt (UTC plus 2)
2015/05/05 15:34:00
for consistency with such things as MessageLoop::D
chrisha
2015/05/05 19:46:12
Done.
| |
32 // memory pressure prevails. Note that this call will trigger an asynchronous | |
33 // action which gives the system time to release memory back into the pool. | |
34 void ScheduleEarlyCheck(); | |
35 | |
36 // Get the current memory pressure level. | |
37 MemoryPressureLevel GetCurrentPressureLevel() const override; | |
38 | |
39 private: | |
40 friend TestMemoryPressureMonitor; | |
41 | |
42 // Starts observing the memory fill level. | |
43 // Calls to StartObserving should always be matched with calls to | |
44 // StopObserving. | |
45 void StartObserving(); | |
46 | |
47 // Stop observing the memory fill level. | |
48 // May be safely called if StartObserving has not been called. | |
49 void StopObserving(); | |
50 | |
51 // The function which gets periodically called to check any changes in the | |
grt (UTC plus 2)
2015/05/05 15:34:00
// Checks the memory pressure, storing the current
chrisha
2015/05/05 19:46:13
Done.
| |
52 // memory pressure. It will report pressure changes as well as continuous | |
53 // critical pressure levels. This contains all the logic for applying | |
54 // hysteresis and determining when to emit a signal. | |
55 void CheckMemoryPressure(); | |
56 | |
57 // The function periodically checks the memory pressure changes and records | |
grt (UTC plus 2)
2015/05/05 15:33:59
// Checks the memory pressure and... This function
chrisha
2015/05/05 19:46:12
Done.
| |
58 // the UMA histogram statistics for the current memory pressure level. | |
59 void CheckMemoryPressureAndRecordStatistics(); | |
60 | |
61 // Calculates the current instantaneous memory pressure level. This does not | |
62 // use any hysteresis and simply returns the result at the current moment. | |
63 MemoryPressureLevel CalculateCurrentPressureLevel(); | |
64 | |
65 // Gets system memory status. This is virtual as a unittesting hook. | |
66 // Returns true if the system call succeeds, false otherwise. | |
67 virtual bool GetSystemMemoryStatus(_MEMORYSTATUSEX* mem_status); | |
68 | |
69 // The current memory pressure. | |
70 MemoryPressureLevel current_memory_pressure_level_; | |
71 | |
72 // A periodic timer to check for memory pressure changes. | |
73 base::RepeatingTimer<MemoryPressureMonitorWin> timer_; | |
74 | |
75 // To slow down the amount of moderate pressure event calls, this gets used to | |
76 // count the number of events since the last event occured. This is used by | |
77 // |CheckMemoryPressure| to apply hysteresis on the raw results of | |
78 // |CalculateCurrentPressureLevel|. | |
79 int moderate_pressure_repeat_count_; | |
80 | |
81 // Weak pointer factory to ourself used for scheduling calls to | |
82 // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|. | |
83 base::WeakPtrFactory<MemoryPressureMonitorWin> weak_ptr_factory_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorWin); | |
86 }; | |
87 | |
grt (UTC plus 2)
2015/05/05 15:34:00
} // namespace win
chrisha
2015/05/05 19:46:12
Done.
| |
88 } // namespace base | |
89 | |
90 #endif // BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_ | |
OLD | NEW |