OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // MemoryPressure provides static APIs for handling memory pressure on | 5 // MemoryPressure provides static APIs for handling memory pressure on |
6 // platforms that have such signals, such as Android and ChromeOS. | 6 // platforms that have such signals, such as Android and ChromeOS. |
7 // The app will try to discard buffers that aren't deemed essential (individual | 7 // The app will try to discard buffers that aren't deemed essential (individual |
8 // modules will implement their own policy). | 8 // modules will implement their own policy). |
9 | 9 |
10 #ifndef BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_ | 10 #ifndef BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // delete my_listener; | 44 // delete my_listener; |
45 // | 45 // |
46 class BASE_EXPORT MemoryPressureListener { | 46 class BASE_EXPORT MemoryPressureListener { |
47 public: | 47 public: |
48 // A Java counterpart will be generated for this enum. | 48 // A Java counterpart will be generated for this enum. |
49 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base | 49 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base |
50 enum MemoryPressureLevel { | 50 enum MemoryPressureLevel { |
51 // No problems, there is enough memory to use. This event is not sent via | 51 // No problems, there is enough memory to use. This event is not sent via |
52 // callback, but the enum is used in other places to find out the current | 52 // callback, but the enum is used in other places to find out the current |
53 // state of the system. | 53 // state of the system. |
54 MEMORY_PRESSURE_LEVEL_NONE = -1, | 54 MEMORY_PRESSURE_LEVEL_NONE, |
55 | 55 |
56 // Modules are advised to free buffers that are cheap to re-allocate and not | 56 // Modules are advised to free buffers that are cheap to re-allocate and not |
57 // immediately needed. | 57 // immediately needed. |
58 MEMORY_PRESSURE_LEVEL_MODERATE = 0, | 58 MEMORY_PRESSURE_LEVEL_MODERATE, |
59 | 59 |
60 // At this level, modules are advised to free all possible memory. The | 60 // At this level, modules are advised to free all possible memory. The |
61 // alternative is to be killed by the system, which means all memory will | 61 // alternative is to be killed by the system, which means all memory will |
62 // have to be re-created, plus the cost of a cold start. | 62 // have to be re-created, plus the cost of a cold start. |
63 MEMORY_PRESSURE_LEVEL_CRITICAL = 2, | 63 MEMORY_PRESSURE_LEVEL_CRITICAL, |
64 }; | 64 }; |
65 | 65 |
66 typedef base::Callback<void(MemoryPressureLevel)> MemoryPressureCallback; | 66 typedef Callback<void(MemoryPressureLevel)> MemoryPressureCallback; |
| 67 typedef Callback<void(MemoryPressureLevel)> SyncMemoryPressureCallback; |
67 | 68 |
68 explicit MemoryPressureListener( | 69 explicit MemoryPressureListener( |
69 const MemoryPressureCallback& memory_pressure_callback); | 70 const MemoryPressureCallback& memory_pressure_callback); |
| 71 MemoryPressureListener( |
| 72 const MemoryPressureCallback& memory_pressure_callback, |
| 73 const SyncMemoryPressureCallback& sync_memory_pressure_callback); |
| 74 |
70 ~MemoryPressureListener(); | 75 ~MemoryPressureListener(); |
71 | 76 |
72 // Intended for use by the platform specific implementation. | 77 // Intended for use by the platform specific implementation. |
73 static void NotifyMemoryPressure(MemoryPressureLevel memory_pressure_level); | 78 static void NotifyMemoryPressure(MemoryPressureLevel memory_pressure_level); |
74 | 79 |
75 // These methods should not be used anywhere else but in memory measurement | 80 // These methods should not be used anywhere else but in memory measurement |
76 // code, where they are intended to maintain stable conditions across | 81 // code, where they are intended to maintain stable conditions across |
77 // measurements. | 82 // measurements. |
78 static bool AreNotificationsSuppressed(); | 83 static bool AreNotificationsSuppressed(); |
79 static void SetNotificationsSuppressed(bool suppressed); | 84 static void SetNotificationsSuppressed(bool suppressed); |
80 static void SimulatePressureNotification( | 85 static void SimulatePressureNotification( |
81 MemoryPressureLevel memory_pressure_level); | 86 MemoryPressureLevel memory_pressure_level); |
82 | 87 |
| 88 void Notify(MemoryPressureLevel memory_pressure_level); |
| 89 void SyncNotify(MemoryPressureLevel memory_pressure_level); |
| 90 |
83 private: | 91 private: |
84 void Notify(MemoryPressureLevel memory_pressure_level); | |
85 | |
86 static void DoNotifyMemoryPressure(MemoryPressureLevel memory_pressure_level); | 92 static void DoNotifyMemoryPressure(MemoryPressureLevel memory_pressure_level); |
87 | 93 |
88 MemoryPressureCallback callback_; | 94 MemoryPressureCallback callback_; |
| 95 SyncMemoryPressureCallback sync_memory_pressure_callback_; |
89 | 96 |
90 DISALLOW_COPY_AND_ASSIGN(MemoryPressureListener); | 97 DISALLOW_COPY_AND_ASSIGN(MemoryPressureListener); |
91 }; | 98 }; |
92 | 99 |
93 } // namespace base | 100 } // namespace base |
94 | 101 |
95 #endif // BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_ | 102 #endif // BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_ |
OLD | NEW |