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

Unified Diff: base/win/memory_pressure_monitor_win.h

Issue 1122863005: Create base::win::MemoryPressureMonitor class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: base/win/memory_pressure_monitor_win.h
diff --git a/base/win/memory_pressure_monitor_win.h b/base/win/memory_pressure_monitor_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..8a7606a9c545d1accb97e3cb2fb5d00bb1c13ae4
--- /dev/null
+++ b/base/win/memory_pressure_monitor_win.h
@@ -0,0 +1,90 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_
+#define BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_
+
+#include "base/base_export.h"
+#include "base/memory/memory_pressure_listener.h"
+#include "base/memory/memory_pressure_monitor.h"
+#include "base/memory/weak_ptr.h"
+#include "base/timer/timer.h"
+
+// Forward declaration. This is defined by windows.h.
+struct _MEMORYSTATUSEX;
+
+namespace base {
+
grt (UTC plus 2) 2015/05/05 15:34:00 namespace win {
chrisha 2015/05/05 19:46:13 Done.
+class TestMemoryPressureMonitor;
+
+// 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.
+// MemoryPressureListener of memory fill level changes, so that it can take
+// action to reduce memory resources accordingly.
+class BASE_EXPORT MemoryPressureMonitorWin : public MemoryPressureMonitor {
+ public:
+ 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
+
+ MemoryPressureMonitorWin();
+ virtual ~MemoryPressureMonitorWin() override;
+
+ // 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.
+ // memory pressure prevails. Note that this call will trigger an asynchronous
+ // action which gives the system time to release memory back into the pool.
+ void ScheduleEarlyCheck();
+
+ // Get the current memory pressure level.
+ MemoryPressureLevel GetCurrentPressureLevel() const override;
+
+ private:
+ friend TestMemoryPressureMonitor;
+
+ // Starts observing the memory fill level.
+ // Calls to StartObserving should always be matched with calls to
+ // StopObserving.
+ void StartObserving();
+
+ // Stop observing the memory fill level.
+ // May be safely called if StartObserving has not been called.
+ void StopObserving();
+
+ // 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.
+ // memory pressure. It will report pressure changes as well as continuous
+ // critical pressure levels. This contains all the logic for applying
+ // hysteresis and determining when to emit a signal.
+ void CheckMemoryPressure();
+
+ // 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.
+ // the UMA histogram statistics for the current memory pressure level.
+ void CheckMemoryPressureAndRecordStatistics();
+
+ // Calculates the current instantaneous memory pressure level. This does not
+ // use any hysteresis and simply returns the result at the current moment.
+ MemoryPressureLevel CalculateCurrentPressureLevel();
+
+ // Gets system memory status. This is virtual as a unittesting hook.
+ // Returns true if the system call succeeds, false otherwise.
+ virtual bool GetSystemMemoryStatus(_MEMORYSTATUSEX* mem_status);
+
+ // The current memory pressure.
+ MemoryPressureLevel current_memory_pressure_level_;
+
+ // A periodic timer to check for memory pressure changes.
+ base::RepeatingTimer<MemoryPressureMonitorWin> timer_;
+
+ // To slow down the amount of moderate pressure event calls, this gets used to
+ // count the number of events since the last event occured. This is used by
+ // |CheckMemoryPressure| to apply hysteresis on the raw results of
+ // |CalculateCurrentPressureLevel|.
+ int moderate_pressure_repeat_count_;
+
+ // Weak pointer factory to ourself used for scheduling calls to
+ // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|.
+ base::WeakPtrFactory<MemoryPressureMonitorWin> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorWin);
+};
+
grt (UTC plus 2) 2015/05/05 15:34:00 } // namespace win
chrisha 2015/05/05 19:46:12 Done.
+} // namespace base
+
+#endif // BASE_WIN_MEMORY_PRESSURE_MONITOR_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698