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 CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/memory_coordinator_client.h" | 9 #include "base/memory/memory_coordinator_client.h" |
10 #include "base/memory/memory_pressure_monitor.h" | 10 #include "base/memory/memory_pressure_monitor.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // coordinator will start dispatching state changes. | 50 // coordinator will start dispatching state changes. |
51 void Start(); | 51 void Start(); |
52 | 52 |
53 // Creates a handle to the provided child process. | 53 // Creates a handle to the provided child process. |
54 void CreateHandle(int render_process_id, | 54 void CreateHandle(int render_process_id, |
55 mojom::MemoryCoordinatorHandleRequest request); | 55 mojom::MemoryCoordinatorHandleRequest request); |
56 | 56 |
57 // Dispatches a memory state change to the provided process. Returns true if | 57 // Dispatches a memory state change to the provided process. Returns true if |
58 // the process is tracked by this coordinator and successfully dispatches, | 58 // the process is tracked by this coordinator and successfully dispatches, |
59 // returns false otherwise. | 59 // returns false otherwise. |
60 bool SetChildMemoryState( | 60 bool SetChildMemoryState(int render_process_id, MemoryState memory_state); |
61 int render_process_id, mojom::MemoryState memory_state); | |
62 | 61 |
63 // Returns the memory state of the specified render process. Returns UNKNOWN | 62 // Returns the memory state of the specified render process. Returns UNKNOWN |
64 // if the process is not tracked by this coordinator. | 63 // if the process is not tracked by this coordinator. |
65 mojom::MemoryState GetChildMemoryState(int render_process_id) const; | 64 MemoryState GetChildMemoryState(int render_process_id) const; |
66 | 65 |
67 // Records memory pressure notifications. Called by MemoryPressureMonitor. | 66 // Records memory pressure notifications. Called by MemoryPressureMonitor. |
68 // TODO(bashi): Remove this when MemoryPressureMonitor is retired. | 67 // TODO(bashi): Remove this when MemoryPressureMonitor is retired. |
69 void RecordMemoryPressure( | 68 void RecordMemoryPressure( |
70 base::MemoryPressureMonitor::MemoryPressureLevel level); | 69 base::MemoryPressureMonitor::MemoryPressureLevel level); |
71 | 70 |
72 // Returns the global memory state. | 71 // Returns the global memory state. |
73 virtual MemoryState GetGlobalMemoryState() const; | 72 virtual MemoryState GetGlobalMemoryState() const; |
74 | 73 |
75 // Returns the browser's current memory state. Note that the current state | 74 // Returns the browser's current memory state. Note that the current state |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // Returns true when a given renderer can be suspended. | 107 // Returns true when a given renderer can be suspended. |
109 bool CanSuspendRenderer(int render_process_id); | 108 bool CanSuspendRenderer(int render_process_id); |
110 | 109 |
111 // Stores information about any known child processes. | 110 // Stores information about any known child processes. |
112 struct ChildInfo { | 111 struct ChildInfo { |
113 // This object must be compatible with STL containers. | 112 // This object must be compatible with STL containers. |
114 ChildInfo(); | 113 ChildInfo(); |
115 ChildInfo(const ChildInfo& rhs); | 114 ChildInfo(const ChildInfo& rhs); |
116 ~ChildInfo(); | 115 ~ChildInfo(); |
117 | 116 |
118 mojom::MemoryState memory_state; | 117 MemoryState memory_state; |
119 bool is_visible = false; | 118 bool is_visible = false; |
120 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; | 119 std::unique_ptr<MemoryCoordinatorHandleImpl> handle; |
121 }; | 120 }; |
122 | 121 |
123 // A map from process ID (RenderProcessHost::GetID()) to child process info. | 122 // A map from process ID (RenderProcessHost::GetID()) to child process info. |
124 using ChildInfoMap = std::map<int, ChildInfo>; | 123 using ChildInfoMap = std::map<int, ChildInfo>; |
125 | 124 |
126 ChildInfoMap& children() { return children_; } | 125 ChildInfoMap& children() { return children_; } |
127 | 126 |
128 private: | 127 private: |
(...skipping 10 matching lines...) Expand all Loading... |
139 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState); | 138 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState); |
140 | 139 |
141 friend struct MemoryCoordinatorSingletonTraits; | 140 friend struct MemoryCoordinatorSingletonTraits; |
142 friend class MemoryCoordinatorHandleImpl; | 141 friend class MemoryCoordinatorHandleImpl; |
143 | 142 |
144 // Called when ChildMemoryCoordinator calls AddChild(). | 143 // Called when ChildMemoryCoordinator calls AddChild(). |
145 void OnChildAdded(int render_process_id); | 144 void OnChildAdded(int render_process_id); |
146 | 145 |
147 // Called by SetChildMemoryState() to determine a child memory state based on | 146 // Called by SetChildMemoryState() to determine a child memory state based on |
148 // the current status of the child process. | 147 // the current status of the child process. |
149 mojom::MemoryState OverrideGlobalState(mojom::MemoryState memroy_state, | 148 MemoryState OverrideGlobalState(MemoryState memroy_state, |
150 const ChildInfo& child); | 149 const ChildInfo& child); |
151 | 150 |
152 void SetDelegateForTesting( | 151 void SetDelegateForTesting( |
153 std::unique_ptr<MemoryCoordinatorDelegate> delegate); | 152 std::unique_ptr<MemoryCoordinatorDelegate> delegate); |
154 | 153 |
155 // Helper function of CreateHandle and AddChildForTesting. | 154 // Helper function of CreateHandle and AddChildForTesting. |
156 void CreateChildInfoMapEntry( | 155 void CreateChildInfoMapEntry( |
157 int render_process_id, | 156 int render_process_id, |
158 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); | 157 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); |
159 | 158 |
160 // Notifies a state change to in-process clients. | 159 // Notifies a state change to in-process clients. |
(...skipping 19 matching lines...) Expand all Loading... |
180 // MemoryCoordinator and removed automatically when an underlying binding is | 179 // MemoryCoordinator and removed automatically when an underlying binding is |
181 // disconnected. | 180 // disconnected. |
182 ChildInfoMap children_; | 181 ChildInfoMap children_; |
183 | 182 |
184 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); | 183 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); |
185 }; | 184 }; |
186 | 185 |
187 } // namespace content | 186 } // namespace content |
188 | 187 |
189 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ | 188 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ |
OLD | NEW |