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

Unified Diff: base/chromeos/memory_pressure_observer_chromeos.h

Issue 815183002: Using the new MemoryPressureListener instead of the LowMemoryObserver when the enhanced memory mana… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed flaky unit test Created 5 years, 11 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
« no previous file with comments | « base/base.gyp ('k') | base/chromeos/memory_pressure_observer_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/chromeos/memory_pressure_observer_chromeos.h
diff --git a/base/chromeos/memory_pressure_observer_chromeos.h b/base/chromeos/memory_pressure_observer_chromeos.h
index 445119efb73853c1f712dab8c85ad190ddb86f6b..23b6b3450d8cf2f9ef7f907be1aab144b69ff58f 100644
--- a/base/chromeos/memory_pressure_observer_chromeos.h
+++ b/base/chromeos/memory_pressure_observer_chromeos.h
@@ -6,12 +6,16 @@
#define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
#include "base/base_export.h"
+#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
+#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
namespace base {
+class TestMemoryPressureObserver;
+
////////////////////////////////////////////////////////////////////////////////
// MemoryPressureObserverChromeOS
//
@@ -21,8 +25,15 @@ namespace base {
//
class BASE_EXPORT MemoryPressureObserverChromeOS {
public:
+ using GetUsedMemoryInPercentCallback = int (*)();
+
MemoryPressureObserverChromeOS();
- ~MemoryPressureObserverChromeOS();
+ virtual ~MemoryPressureObserverChromeOS();
+
+ // Redo the memory pressure calculation soon and call again if a critical
+ // 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.
base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() {
@@ -30,6 +41,7 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
}
private:
+ friend TestMemoryPressureObserver;
// Starts observing the memory fill level.
// Calls to StartObserving should always be matched with calls to
// StopObserving.
@@ -39,10 +51,14 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
// May be safely called if StartObserving has not been called.
void StopObserving();
- // The function which gets periodically be called to check any changes in the
- // memory pressure.
+ // The function which gets periodically called to check any changes in the
+ // memory pressure. It will report pressure changes as well as continuous
+ // critical pressure levels.
void CheckMemoryPressure();
+ // Get the memory pressure in percent (virtual for testing).
+ virtual int GetUsedMemoryInPercent();
+
// The current memory pressure.
base::MemoryPressureListener::MemoryPressureLevel
current_memory_pressure_level_;
@@ -51,6 +67,12 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
// replaced by a kernel triggered event system (see crbug.com/381196).
base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_;
+ // To slow down the amount of moderate pressure event calls, this counter
+ // gets used to count the number of events since the last event occured.
+ int moderate_pressure_repeat_count_;
+
+ base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS);
};
« no previous file with comments | « base/base.gyp ('k') | base/chromeos/memory_pressure_observer_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698