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

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: Self nits 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
10 namespace athena {
11
12 class MemoryPressureNotifierImpl;
13 class ResourceManagerDelegate;
14
15 ////////////////////////////////////////////////////////////////////////////////
16 // MemoryPressureObserver
17 //
18 // This observer gets informed once about a |MEMORY_PRESSURE_LOW|. When the
19 // pressure exceeds, the observer will get polled until |MEMORY_PRESSURE_LOW| is
20 // reached again to counter memory consumption.
21 class MemoryPressureObserver {
22 public:
23 MemoryPressureObserver() {}
24 virtual ~MemoryPressureObserver() {}
25
26 // The reported memory pressure. Note: The value is intentionally abstracted
27 // since the real amount of free memory is only estimated (due to e.g. zram).
28 enum MemoryPressure {
29 MEMORY_PRESSURE_UNKNOWN, // The memory pressure cannot be determined.
30 MEMORY_PRESSURE_LOW, // Single call if memory fill level is below 50%.
31 MEMORY_PRESSURE_MODERATE, // Polled for memory fill level of ~50 .. 75%.
32 MEMORY_PRESSURE_HIGH, // Polled for memory fill level of ~75% .. 90%.
33 MEMORY_PRESSURE_CRITICAL, // Polled for memory fill level of above ~90%.
34 };
35 // The observer.
36 virtual void OnMemoryPressure(MemoryPressure pressure) = 0;
37
38 // OS system interface functions. The delegate remains owned by the Observer.
39 virtual ResourceManagerDelegate* GetDelegate() = 0;
40 };
41
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // MemoryPressureNotifier
45 //
46 // Class to handle the observation of our free memory. It notifies the owner of
47 // memory fill level changes, so that it can take action to reduce memory by
48 // reducing active activities.
49 //
50 // The observer will use 3 different fill levels: 50% full, 75% full and 90%
51 // full.
52 //
53 // This object starts and stops the observation, and can be created or deleted
54 // from any thread, but the observation occurs on the FILE thread, and the
55 // owner gets notified through a UI thread call.
56 class MemoryPressureNotifier {
57 public:
58 // The creator gets the |listener| object. Note that the ownership of the
59 // listener object remains with the creator.
60 explicit MemoryPressureNotifier(MemoryPressureObserver* listener);
61 ~MemoryPressureNotifier();
62
63 private:
64 scoped_refptr<MemoryPressureNotifierImpl> observer_;
65
66 DISALLOW_COPY_AND_ASSIGN(MemoryPressureNotifier);
67 };
68
69 } // namespace athena
70
71 #endif // ATHENA_RESOURCE_MANAGER_MEMORY_PRESSURE_NOTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698