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

Side by Side Diff: athena/resource_manager/memory_pressure_notifier.h

Issue 513523002: Adding Baseframework of the ResourceManager (all hooks and observers) are being put in place with a… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Aaaand another rebase Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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 ATHENA_RESOURCE_MANAGER_MEMORY_PRESSURE_NOTIFIER_H_
6 #define ATHENA_RESOURCE_MANAGER_MEMORY_PRESSURE_NOTIFIER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/timer.h"
11
12 namespace athena {
13
14 class MemoryPressureNotifierImpl;
15 class ResourceManagerDelegate;
16
17 ////////////////////////////////////////////////////////////////////////////////
18 // MemoryPressureObserver
19 //
20 // This observer gets informed once about a |MEMORY_PRESSURE_LOW|. When the
21 // pressure exceeds, the observer will get polled until |MEMORY_PRESSURE_LOW| is
22 // reached again to counter memory consumption.
23 class MemoryPressureObserver {
24 public:
25 MemoryPressureObserver() {}
26 virtual ~MemoryPressureObserver() {}
27
28 // The reported memory pressure. Note: The value is intentionally abstracted
29 // since the real amount of free memory is only estimated (due to e.g. zram).
30 enum MemoryPressure {
31 MEMORY_PRESSURE_UNKNOWN, // The memory pressure cannot be determined.
32 MEMORY_PRESSURE_LOW, // Single call if memory fill level is below 50%.
33 MEMORY_PRESSURE_MODERATE, // Polled for memory fill level of ~50 .. 75%.
34 MEMORY_PRESSURE_HIGH, // Polled for memory fill level of ~75% .. 90%.
35 MEMORY_PRESSURE_CRITICAL, // Polled for memory fill level of above ~90%.
36 };
37 // The observer.
38 virtual void OnMemoryPressure(MemoryPressure pressure) = 0;
39
40 // OS system interface functions. The delegate remains owned by the Observer.
41 virtual ResourceManagerDelegate* GetDelegate() = 0;
42 };
43
44
45 ////////////////////////////////////////////////////////////////////////////////
46 // MemoryPressureNotifier
47 //
48 // Class to handle the observation of our free memory. It notifies the owner of
49 // memory fill level changes, so that it can take action to reduce memory by
50 // reducing active activities.
51 //
52 // The observer will use 3 different fill levels: 50% full, 75% full and 90%
53 // full.
54 class MemoryPressureNotifier {
55 public:
56 // The creator gets the |listener| object. Note that the ownership of the
57 // listener object remains with the creator.
58 explicit MemoryPressureNotifier(MemoryPressureObserver* listener);
59 ~MemoryPressureNotifier();
60
61 // Stop observing the memory fill level.
62 // May be safely called if StartObserving has not been called.
63 void StopObserving();
64
65 private:
66 // Starts observing the memory fill level.
67 // Calls to StartObserving should always be matched with calls to
68 // StopObserving.
69 void StartObserving();
70
71 // The function which gets periodically be called to check any changes in the
72 // memory pressure.
73 void CheckMemoryPressure();
74
75 // Converts free percent of memory into a memory pressure value.
76 MemoryPressureObserver::MemoryPressure GetMemoryPressureLevelFromFillLevel(
77 int memory_fill_level);
78
79 base::RepeatingTimer<MemoryPressureNotifier> timer_;
80
81 // The listener which needs to be informed about memory pressure.
82 MemoryPressureObserver* listener_;
83
84 // Our current memory pressure.
85 MemoryPressureObserver::MemoryPressure current_pressure_;
86
87 DISALLOW_COPY_AND_ASSIGN(MemoryPressureNotifier);
88 };
89
90 } // namespace athena
91
92 #endif // ATHENA_RESOURCE_MANAGER_MEMORY_PRESSURE_NOTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698