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 "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 | 11 |
| 12 // OVERVIEW: | |
| 13 // | |
| 14 // MemoryCoordinatorClient is an interface which a component can implement to | |
| 15 // respond to memory state changes. Unlike MemoryPressureListener, this is a | |
| 16 // stateful mechanism and clients receive notifications only when memory states | |
| 17 // 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. | |
| 19 | |
| 12 // MemoryState is an indicator that processes can use to guide their memory | 20 // MemoryState is an indicator that processes can use to guide their memory |
| 13 // allocation policies. For example, a process that receives the suspended | 21 // allocation policies. For example, a process that receives the suspended |
| 14 // state can use that as as signal to drop memory caches. | 22 // state can use that as as signal to drop memory caches. |
| 15 enum class MemoryState { | 23 enum class MemoryState { |
| 16 // The state is unknown. | 24 // The state is unknown. |
| 17 UNKNOWN = -1, | 25 UNKNOWN = -1, |
| 18 // No memory constraints. | 26 // No memory constraints. |
| 19 NORMAL = 0, | 27 NORMAL = 0, |
| 20 // Running and interactive but allocation should be throttled. | 28 // Running and interactive but allocation should be throttled. |
| 21 THROTTLED = 1, | 29 THROTTLED = 1, |
| 22 // Still resident in memory but core processing logic has been suspended. | 30 // Still resident in memory but core processing logic has been suspended. |
| 23 SUSPENDED = 2, | 31 SUSPENDED = 2, |
| 24 }; | 32 }; |
| 25 | 33 |
| 26 // This is an interface for components which can respond to memory status | 34 // This is an interface for components which can respond to memory status |
| 27 // changes. | 35 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for |
|
dcheng
2016/09/26 06:01:49
Nit: An -> The
| |
| 36 // threading guarantees and ownership management. | |
| 28 class BASE_EXPORT MemoryCoordinatorClient { | 37 class BASE_EXPORT MemoryCoordinatorClient { |
| 29 public: | 38 public: |
| 30 virtual ~MemoryCoordinatorClient() {} | 39 virtual ~MemoryCoordinatorClient() {} |
| 31 | 40 |
| 32 // Called when memory state has changed. | 41 // Called when memory state has changed. Any transition could occur except for |
|
dcheng
2016/09/26 06:01:49
Nit: could => can
| |
| 42 // UNKNOWN. General guidelines are: | |
| 43 // * NORMAL: Restore the default settings for memory allocation/usage if | |
| 44 // it has changed. | |
| 45 // * THROTTLED: Use smaller limits for memory allocations and caches. | |
| 46 // * SUSPENDED: Purge memory. | |
| 33 virtual void OnMemoryStateChange(MemoryState state) = 0; | 47 virtual void OnMemoryStateChange(MemoryState state) = 0; |
| 34 }; | 48 }; |
| 35 | 49 |
| 36 } // namespace base | 50 } // namespace base |
| 37 | 51 |
| 38 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ | 52 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ |
| OLD | NEW |