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

Side by Side Diff: base/memory/memory_coordinator_client.h

Issue 2482783002: Add StateOn{Moderate,Critical}NotificationReceived metrics (Closed)
Patch Set: Wrap -> Make Created 4 years, 1 month 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
OLDNEW
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: 12 // OVERVIEW:
13 // 13 //
14 // MemoryCoordinatorClient is an interface which a component can implement to 14 // MemoryCoordinatorClient is an interface which a component can implement to
15 // respond to memory state changes. Unlike MemoryPressureListener, this is a 15 // respond to memory state changes. Unlike MemoryPressureListener, this is a
16 // stateful mechanism and clients receive notifications only when memory states 16 // stateful mechanism and clients receive notifications only when memory states
17 // are changed. State transitions are throttled to avoid thrashing; the exact 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. 18 // 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 19 // Clients are expected to make changes in memory usage that persist for the
20 // duration of the memory state. 20 // duration of the memory state.
21 21
22 // MemoryState is an indicator that processes can use to guide their memory 22 // MemoryState is an indicator that processes can use to guide their memory
23 // allocation policies. For example, a process that receives the suspended 23 // allocation policies. For example, a process that receives the suspended
24 // state can use that as as signal to drop memory caches. 24 // state can use that as as signal to drop memory caches.
Ilya Sherman 2016/11/07 19:28:51 Please document that this enum is used to back an
bashi 2016/11/08 00:33:35 Done.
25 enum class MemoryState { 25 enum class MemoryState : int {
26 // The state is unknown. 26 // The state is unknown.
27 UNKNOWN = -1, 27 UNKNOWN = -1,
28 // No memory constraints. 28 // No memory constraints.
29 NORMAL = 0, 29 NORMAL = 0,
30 // Running and interactive but allocation should be throttled. 30 // Running and interactive but allocation should be throttled.
31 // Clients should free up any memory that is used as an optimization but 31 // 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). 32 // that is not necessary for the process to run (e.g. caches).
33 THROTTLED = 1, 33 THROTTLED = 1,
34 // Still resident in memory but core processing logic has been suspended. 34 // 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 35 // 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 36 // 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). 37 // the suspended state (e.g. parsed resource that can be reloaded from disk).
38 SUSPENDED = 2, 38 SUSPENDED = 2,
39 }; 39 };
40 40
41 const int kMemoryStateMax = static_cast<int>(MemoryState::SUSPENDED) + 1;
42
41 // Returns a string representation of MemoryState. 43 // Returns a string representation of MemoryState.
42 BASE_EXPORT const char* MemoryStateToString(MemoryState state); 44 BASE_EXPORT const char* MemoryStateToString(MemoryState state);
43 45
44 // This is an interface for components which can respond to memory status 46 // This is an interface for components which can respond to memory status
45 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for 47 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for
46 // threading guarantees and ownership management. 48 // threading guarantees and ownership management.
47 class BASE_EXPORT MemoryCoordinatorClient { 49 class BASE_EXPORT MemoryCoordinatorClient {
48 public: 50 public:
49 // Called when memory state has changed. Any transition can occur except for 51 // Called when memory state has changed. Any transition can occur except for
50 // UNKNOWN. General guidelines are: 52 // UNKNOWN. General guidelines are:
51 // * NORMAL: Restore the default settings for memory allocation/usage if 53 // * NORMAL: Restore the default settings for memory allocation/usage if
52 // it has changed. 54 // it has changed.
53 // * THROTTLED: Use smaller limits for memory allocations and caches. 55 // * THROTTLED: Use smaller limits for memory allocations and caches.
54 // * SUSPENDED: Purge memory. 56 // * SUSPENDED: Purge memory.
55 virtual void OnMemoryStateChange(MemoryState state) = 0; 57 virtual void OnMemoryStateChange(MemoryState state) = 0;
56 58
57 protected: 59 protected:
58 virtual ~MemoryCoordinatorClient() {} 60 virtual ~MemoryCoordinatorClient() {}
59 }; 61 };
60 62
61 } // namespace base 63 } // namespace base
62 64
63 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ 65 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_main_loop.cc » ('j') | content/browser/memory/memory_coordinator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698