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

Side by Side 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: Addressed Created 6 years 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 unified diff | Download patch
OLDNEW
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 #ifndef BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ 5 #ifndef BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
6 #define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ 6 #define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/gtest_prod_util.h"
James Cook 2015/01/05 18:41:19 Are you using this?
Mr4D (OOO till 08-26) 2015/01/06 22:22:06 With your requested change I need it again. :)
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/memory_pressure_listener.h" 11 #include "base/memory/memory_pressure_listener.h"
12 #include "base/memory/weak_ptr.h"
11 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
12 14
13 namespace base { 15 namespace base {
14 16
15 //////////////////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////////////////
16 // MemoryPressureObserverChromeOS 18 // MemoryPressureObserverChromeOS
17 // 19 //
18 // A class to handle the observation of our free memory. It notifies the 20 // A class to handle the observation of our free memory. It notifies the
19 // MemoryPressureListener of memory fill level changes, so that it can take 21 // MemoryPressureListener of memory fill level changes, so that it can take
20 // action to reduce memory resources accordingly. 22 // action to reduce memory resources accordingly.
21 // 23 //
22 class BASE_EXPORT MemoryPressureObserverChromeOS { 24 class BASE_EXPORT MemoryPressureObserverChromeOS {
23 public: 25 public:
26 using GetUsedMemoryInPercentCallback = int (*)();
27
24 MemoryPressureObserverChromeOS(); 28 MemoryPressureObserverChromeOS();
25 ~MemoryPressureObserverChromeOS(); 29 virtual ~MemoryPressureObserverChromeOS();
30
31 // Redo the memory pressure calculation soon and call again if a critical
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();
26 35
27 // Get the current memory pressure level. 36 // Get the current memory pressure level.
28 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() { 37 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() {
29 return current_memory_pressure_level_; 38 return current_memory_pressure_level_;
30 } 39 }
31 40
32 private: 41 protected:
James Cook 2015/01/05 18:41:19 If you decide to FRIEND_TEST this could be private
Mr4D (OOO till 08-26) 2015/01/06 22:22:06 Done.
33 // Starts observing the memory fill level. 42 // Starts observing the memory fill level.
34 // Calls to StartObserving should always be matched with calls to 43 // Calls to StartObserving should always be matched with calls to
35 // StopObserving. 44 // StopObserving.
36 void StartObserving(); 45 void StartObserving();
37 46
38 // Stop observing the memory fill level. 47 // Stop observing the memory fill level.
39 // May be safely called if StartObserving has not been called. 48 // May be safely called if StartObserving has not been called.
40 void StopObserving(); 49 void StopObserving();
41 50
42 // The function which gets periodically be called to check any changes in the 51 // The function which gets periodically called to check any changes in the
43 // memory pressure. 52 // memory pressure. It will report pressure changes as well as continuous
53 // critical pressure levels.
44 void CheckMemoryPressure(); 54 void CheckMemoryPressure();
45 55
56 // Get the memory pressure in percent.
James Cook 2015/01/05 18:41:19 Note "virtual for testing" if that's the only reas
Mr4D (OOO till 08-26) 2015/01/06 22:22:06 Done.
57 virtual int GetUsedMemoryInPercent();
58
59 private:
46 // The current memory pressure. 60 // The current memory pressure.
47 base::MemoryPressureListener::MemoryPressureLevel 61 base::MemoryPressureListener::MemoryPressureLevel
48 current_memory_pressure_level_; 62 current_memory_pressure_level_;
49 63
50 // A periodic timer to check for resource pressure changes. This will get 64 // A periodic timer to check for resource pressure changes. This will get
51 // replaced by a kernel triggered event system (see crbug.com/381196). 65 // replaced by a kernel triggered event system (see crbug.com/381196).
52 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_; 66 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_;
53 67
68 // To slow down the amount of moderate pressure event calls, this counter
69 // gets used to count the number of events since the last event occured.
70 int moderate_pressure_repeat_count_;
71
72 base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_;
73
54 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS); 74 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS);
55 }; 75 };
56 76
57 } // namespace base 77 } // namespace base
58 78
59 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ 79 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698