Chromium Code Reviews| 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 #include <string> | |
| 10 | |
| 8 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 9 | 12 |
| 10 namespace base { | 13 namespace base { |
| 11 | 14 |
| 12 // OVERVIEW: | 15 // OVERVIEW: |
| 13 // | 16 // |
| 14 // MemoryCoordinatorClient is an interface which a component can implement to | 17 // MemoryCoordinatorClient is an interface which a component can implement to |
| 15 // respond to memory state changes. Unlike MemoryPressureListener, this is a | 18 // respond to memory state changes. Unlike MemoryPressureListener, this is a |
| 16 // stateful mechanism and clients receive notifications only when memory states | 19 // stateful mechanism and clients receive notifications only when memory states |
| 17 // are changed. State transitions are throttled to avoid thrashing; the exact | 20 // 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. | 21 // 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 | 22 // Clients are expected to make changes in memory usage that persist for the |
| 20 // duration of the memory state. | 23 // duration of the memory state. |
| 21 | 24 |
| 22 // MemoryState is an indicator that processes can use to guide their memory | 25 // MemoryState is an indicator that processes can use to guide their memory |
| 23 // allocation policies. For example, a process that receives the suspended | 26 // allocation policies. For example, a process that receives the suspended |
| 24 // state can use that as as signal to drop memory caches. | 27 // state can use that as as signal to drop memory caches. |
| 25 enum class MemoryState { | 28 enum class MemoryState : int32_t { |
|
haraken
2016/11/01 04:20:29
This change wouldn't be needed.
bashi
2016/11/01 05:02:16
Done.
| |
| 26 // The state is unknown. | 29 // The state is unknown. |
| 27 UNKNOWN = -1, | 30 UNKNOWN = -1, |
| 28 // No memory constraints. | 31 // No memory constraints. |
| 29 NORMAL = 0, | 32 NORMAL = 0, |
| 30 // Running and interactive but allocation should be throttled. | 33 // Running and interactive but allocation should be throttled. |
| 31 // Clients should free up any memory that is used as an optimization but | 34 // 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). | 35 // that is not necessary for the process to run (e.g. caches). |
| 33 THROTTLED = 1, | 36 THROTTLED = 1, |
| 34 // Still resident in memory but core processing logic has been suspended. | 37 // 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 | 38 // Clients should free up any memory that is used as an optimization, or |
| 36 // any memory whose contents can be reproduced when transitioning out of | 39 // any memory whose contents can be reproduced when transitioning out of |
| 37 // the suspended state (e.g. parsed resource that can be reloaded from disk). | 40 // the suspended state (e.g. parsed resource that can be reloaded from disk). |
| 38 SUSPENDED = 2, | 41 SUSPENDED = 2, |
| 39 }; | 42 }; |
| 40 | 43 |
| 44 // Returns a string representation of MemoryState. | |
| 45 BASE_EXPORT std::string MemoryStateToString(MemoryState state); | |
|
dcheng
2016/11/01 04:33:37
If possible, let's return const char* to make this
bashi
2016/11/01 05:02:16
Done.
| |
| 46 | |
| 41 // This is an interface for components which can respond to memory status | 47 // This is an interface for components which can respond to memory status |
| 42 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for | 48 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for |
| 43 // threading guarantees and ownership management. | 49 // threading guarantees and ownership management. |
| 44 class BASE_EXPORT MemoryCoordinatorClient { | 50 class BASE_EXPORT MemoryCoordinatorClient { |
| 45 public: | 51 public: |
| 46 // Called when memory state has changed. Any transition can occur except for | 52 // Called when memory state has changed. Any transition can occur except for |
| 47 // UNKNOWN. General guidelines are: | 53 // UNKNOWN. General guidelines are: |
| 48 // * NORMAL: Restore the default settings for memory allocation/usage if | 54 // * NORMAL: Restore the default settings for memory allocation/usage if |
| 49 // it has changed. | 55 // it has changed. |
| 50 // * THROTTLED: Use smaller limits for memory allocations and caches. | 56 // * THROTTLED: Use smaller limits for memory allocations and caches. |
| 51 // * SUSPENDED: Purge memory. | 57 // * SUSPENDED: Purge memory. |
| 52 virtual void OnMemoryStateChange(MemoryState state) = 0; | 58 virtual void OnMemoryStateChange(MemoryState state) = 0; |
| 53 | 59 |
| 54 protected: | 60 protected: |
| 55 virtual ~MemoryCoordinatorClient() {} | 61 virtual ~MemoryCoordinatorClient() {} |
| 56 }; | 62 }; |
| 57 | 63 |
| 58 } // namespace base | 64 } // namespace base |
| 59 | 65 |
| 60 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ | 66 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ |
| OLD | NEW |