OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ | 5 #ifndef BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ |
6 #define BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ | 6 #define BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include "base/base_export.h" | 10 #include "base/base_export.h" |
9 | 11 |
10 namespace base { | 12 namespace base { |
11 | 13 |
12 // OVERVIEW: | 14 // OVERVIEW: |
13 // | 15 // |
14 // MemoryCoordinatorClient is an interface which a component can implement to | 16 // MemoryCoordinatorClient is an interface which a component can implement to |
15 // respond to memory state changes. Unlike MemoryPressureListener, this is a | 17 // respond to memory state changes. Unlike MemoryPressureListener, this is a |
16 // stateful mechanism and clients receive notifications only when memory states | 18 // stateful mechanism and clients receive notifications only when memory states |
17 // are changed. State transitions are throttled to avoid thrashing; the exact | 19 // are changed. State transitions are throttled to avoid thrashing; the exact |
18 // throttling period is platform dependent, but will be at least 5-10 seconds. | 20 // throttling period is platform dependent, but will be at least 5-10 seconds. |
19 // Clients are expected to make changes in memory usage that persist for the | 21 // Clients are expected to make changes in memory usage that persist for the |
20 // duration of the memory state. | 22 // duration of the memory state. |
21 | 23 |
22 // MemoryState is an indicator that processes can use to guide their memory | 24 // MemoryState is an indicator that processes can use to guide their memory |
23 // allocation policies. For example, a process that receives the suspended | 25 // allocation policies. For example, a process that receives the suspended |
24 // state can use that as as signal to drop memory caches. | 26 // state can use that as as signal to drop memory caches. |
25 enum class MemoryState { | 27 enum class MemoryState : int32_t { |
26 // The state is unknown. | 28 // The state is unknown. |
27 UNKNOWN = -1, | 29 UNKNOWN = -1, |
28 // No memory constraints. | 30 // No memory constraints. |
29 NORMAL = 0, | 31 NORMAL = 0, |
30 // Running and interactive but allocation should be throttled. | 32 // Running and interactive but allocation should be throttled. |
31 // Clients should free up any memory that is used as an optimization but | 33 // Clients should free up any memory that is used as an optimization but |
32 // that is not necessary for the process to run (e.g. caches). | 34 // that is not necessary for the process to run (e.g. caches). |
33 THROTTLED = 1, | 35 THROTTLED = 1, |
34 // Still resident in memory but core processing logic has been suspended. | 36 // Still resident in memory but core processing logic has been suspended. |
35 // Clients should free up any memory that is used as an optimization, or | 37 // Clients should free up any memory that is used as an optimization, or |
(...skipping 15 matching lines...) Expand all Loading... |
51 // * SUSPENDED: Purge memory. | 53 // * SUSPENDED: Purge memory. |
52 virtual void OnMemoryStateChange(MemoryState state) = 0; | 54 virtual void OnMemoryStateChange(MemoryState state) = 0; |
53 | 55 |
54 protected: | 56 protected: |
55 virtual ~MemoryCoordinatorClient() {} | 57 virtual ~MemoryCoordinatorClient() {} |
56 }; | 58 }; |
57 | 59 |
58 } // namespace base | 60 } // namespace base |
59 | 61 |
60 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ | 62 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ |
OLD | NEW |