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

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

Issue 2482783002: Add StateOn{Moderate,Critical}NotificationReceived metrics (Closed)
Patch Set: Remove std::move() 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
« no previous file with comments | « no previous file | content/browser/browser_main_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
25 enum class MemoryState { 25 // NOTE: This enum is used to back an UMA histogram, and therefore should be
26 // treated as append-only.
27 enum class MemoryState : int {
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
36 // any memory whose contents can be reproduced when transitioning out of 38 // 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). 39 // the suspended state (e.g. parsed resource that can be reloaded from disk).
38 SUSPENDED = 2, 40 SUSPENDED = 2,
39 }; 41 };
40 42
43 const int kMemoryStateMax = static_cast<int>(MemoryState::SUSPENDED) + 1;
44
41 // Returns a string representation of MemoryState. 45 // Returns a string representation of MemoryState.
42 BASE_EXPORT const char* MemoryStateToString(MemoryState state); 46 BASE_EXPORT const char* MemoryStateToString(MemoryState state);
43 47
44 // This is an interface for components which can respond to memory status 48 // This is an interface for components which can respond to memory status
45 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for 49 // changes. An initial state is NORMAL. See MemoryCoordinatorClientRegistry for
46 // threading guarantees and ownership management. 50 // threading guarantees and ownership management.
47 class BASE_EXPORT MemoryCoordinatorClient { 51 class BASE_EXPORT MemoryCoordinatorClient {
48 public: 52 public:
49 // Called when memory state has changed. Any transition can occur except for 53 // Called when memory state has changed. Any transition can occur except for
50 // UNKNOWN. General guidelines are: 54 // UNKNOWN. General guidelines are:
51 // * NORMAL: Restore the default settings for memory allocation/usage if 55 // * NORMAL: Restore the default settings for memory allocation/usage if
52 // it has changed. 56 // it has changed.
53 // * THROTTLED: Use smaller limits for memory allocations and caches. 57 // * THROTTLED: Use smaller limits for memory allocations and caches.
54 // * SUSPENDED: Purge memory. 58 // * SUSPENDED: Purge memory.
55 virtual void OnMemoryStateChange(MemoryState state) = 0; 59 virtual void OnMemoryStateChange(MemoryState state) = 0;
56 60
57 protected: 61 protected:
58 virtual ~MemoryCoordinatorClient() {} 62 virtual ~MemoryCoordinatorClient() {}
59 }; 63 };
60 64
61 } // namespace base 65 } // namespace base
62 66
63 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_ 67 #endif // BASE_MEMORY_MEMORY_COORDINATOR_CLIENT_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_main_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698