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

Side by Side Diff: base/chromeos/memory_pressure_observer_chromeos.h

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « base/chromeos/OWNERS ('k') | base/chromeos/memory_pressure_observer_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
6 #define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
7
8 #include "base/base_export.h"
9 #include "base/macros.h"
10 #include "base/memory/memory_pressure_listener.h"
11 #include "base/timer/timer.h"
12
13 namespace base {
14
15 ////////////////////////////////////////////////////////////////////////////////
16 // MemoryPressureObserverChromeOS
17 //
18 // 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
20 // action to reduce memory resources accordingly.
21 //
22 class BASE_EXPORT MemoryPressureObserverChromeOS {
23 public:
24 // This is like the |MemoryPressureListener::MemoryPressureLevel| but it has
25 // more states to allow for a finer grained control as well as a request for
26 // the current status.
27 // TODO(skuhne): If the |MemoryPressureListener| will get extended to support
28 // all these levels, this can be removed.
29 enum MemoryPressureLevel {
30 // There is enough memory available to use.
31 MEMORY_PRESSURE_LEVEL_LOW = 0,
32
33 // Modules are advised to free buffers that are cheap to re-allocate and not
34 // immediately needed.
35 MEMORY_PRESSURE_LEVEL_MODERATE = 1,
36
37 // Modules are advised that they might get unloaded dependent on the OS.
38 // As such they should start to release more memory if possible.
39 MEMORY_PRESSURE_LEVEL_HIGH = 2,
40
41 // At this level, modules are advised to free all possible memory. The
42 // alternative is to be killed by the system, which means all memory will
43 // have to be re-created, plus the cost of a cold start.
44 MEMORY_PRESSURE_LEVEL_CRITICAL = 3,
45 };
46
47 MemoryPressureObserverChromeOS();
48 ~MemoryPressureObserverChromeOS();
49
50 // Get the current memory pressure level.
51 MemoryPressureLevel GetCurrentPressureLevel() {
52 return current_memory_pressure_level_;
53 }
54
55 private:
56 // Starts observing the memory fill level.
57 // Calls to StartObserving should always be matched with calls to
58 // StopObserving.
59 void StartObserving();
60
61 // Stop observing the memory fill level.
62 // May be safely called if StartObserving has not been called.
63 void StopObserving();
64
65 // The function which gets periodically be called to check any changes in the
66 // memory pressure.
67 void CheckMemoryPressure();
68
69 // The current memory pressure.
70 MemoryPressureLevel current_memory_pressure_level_;
71
72 // A periodic timer to check for resource pressure changes. This will get
73 // replaced by a kernel triggered event system (see crbug.com/381196).
74 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_;
75
76 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS);
77 };
78
79 } // namespace base
80
81 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
OLDNEW
« no previous file with comments | « base/chromeos/OWNERS ('k') | base/chromeos/memory_pressure_observer_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698