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

Side by Side Diff: content/browser/memory/memory_coordinator_impl.h

Issue 2594513002: Use MockRenderProcessHost in memory coordinator unittests (Closed)
Patch Set: Created 4 years 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/memory/memory_coordinator_impl.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 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 10 matching lines...) Expand all
21 namespace content { 21 namespace content {
22 22
23 // NOTE: Memory coordinator is under development and not fully working. 23 // NOTE: Memory coordinator is under development and not fully working.
24 // TODO(bashi): Add content::MemoryCoordinator which is a pure virtual 24 // TODO(bashi): Add content::MemoryCoordinator which is a pure virtual
25 // interface to expose APIs outside content/. 25 // interface to expose APIs outside content/.
26 26
27 class MemoryCoordinatorHandleImpl; 27 class MemoryCoordinatorHandleImpl;
28 class MemoryCoordinatorImplTest; 28 class MemoryCoordinatorImplTest;
29 class MemoryMonitor; 29 class MemoryMonitor;
30 class MemoryStateUpdater; 30 class MemoryStateUpdater;
31 class RenderProcessHost;
31 struct MemoryCoordinatorSingletonTraits; 32 struct MemoryCoordinatorSingletonTraits;
32 33
33 // MemoryCoordinatorImpl is an implementation of MemoryCoordinator. 34 // MemoryCoordinatorImpl is an implementation of MemoryCoordinator.
34 // The current implementation uses MemoryStateUpdater to update the global 35 // The current implementation uses MemoryStateUpdater to update the global
35 // memory state. See comments in MemoryStateUpdater for details. 36 // memory state. See comments in MemoryStateUpdater for details.
36 class CONTENT_EXPORT MemoryCoordinatorImpl : public NotificationObserver, 37 class CONTENT_EXPORT MemoryCoordinatorImpl : public NotificationObserver,
37 public base::NonThreadSafe { 38 public base::NonThreadSafe {
38 public: 39 public:
39 using MemoryState = base::MemoryState; 40 using MemoryState = base::MemoryState;
40 41
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // remains the same until |duration| is passed or another call of this method. 90 // remains the same until |duration| is passed or another call of this method.
90 void ForceSetGlobalState(base::MemoryState new_state, 91 void ForceSetGlobalState(base::MemoryState new_state,
91 base::TimeDelta duration); 92 base::TimeDelta duration);
92 93
93 // Changes the global state and notifies state changes to clients (lives in 94 // Changes the global state and notifies state changes to clients (lives in
94 // the browser) and child processes (renderers) if needed. Returns true when 95 // the browser) and child processes (renderers) if needed. Returns true when
95 // the state is actually changed. 96 // the state is actually changed.
96 bool ChangeStateIfNeeded(MemoryState prev_state, MemoryState next_state); 97 bool ChangeStateIfNeeded(MemoryState prev_state, MemoryState next_state);
97 98
98 protected: 99 protected:
100 // Returns the RenderProcessHost which is correspond to the given id.
101 // Returns nullptr if there is no corresponding RenderProcessHost.
102 // This is a virtual method so that we can write tests without having
103 // actual RenderProcessHost.
104 virtual RenderProcessHost* GetRenderProcessHost(int render_process_id);
105
106 // Sets a delegate for testing.
107 void SetDelegateForTesting(
108 std::unique_ptr<MemoryCoordinatorDelegate> delegate);
109
99 // Adds the given ChildMemoryCoordinator as a child of this coordinator. 110 // Adds the given ChildMemoryCoordinator as a child of this coordinator.
100 void AddChildForTesting(int dummy_render_process_id, 111 void AddChildForTesting(int dummy_render_process_id,
101 mojom::ChildMemoryCoordinatorPtr child); 112 mojom::ChildMemoryCoordinatorPtr child);
102 113
103 // Callback invoked by mojo when the child connection goes down. Exposed 114 // Callback invoked by mojo when the child connection goes down. Exposed
104 // for testing. 115 // for testing.
105 void OnConnectionError(int render_process_id); 116 void OnConnectionError(int render_process_id);
106 117
107 // Returns true when a given renderer can be suspended. 118 // Returns true when a given renderer can be suspended.
108 bool CanSuspendRenderer(int render_process_id); 119 bool CanSuspendRenderer(int render_process_id);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 friend class MemoryCoordinatorHandleImpl; 152 friend class MemoryCoordinatorHandleImpl;
142 153
143 // Called when ChildMemoryCoordinator calls AddChild(). 154 // Called when ChildMemoryCoordinator calls AddChild().
144 void OnChildAdded(int render_process_id); 155 void OnChildAdded(int render_process_id);
145 156
146 // Called by SetChildMemoryState() to determine a child memory state based on 157 // Called by SetChildMemoryState() to determine a child memory state based on
147 // the current status of the child process. 158 // the current status of the child process.
148 MemoryState OverrideGlobalState(MemoryState memroy_state, 159 MemoryState OverrideGlobalState(MemoryState memroy_state,
149 const ChildInfo& child); 160 const ChildInfo& child);
150 161
151 void SetDelegateForTesting(
152 std::unique_ptr<MemoryCoordinatorDelegate> delegate);
153
154 // Helper function of CreateHandle and AddChildForTesting. 162 // Helper function of CreateHandle and AddChildForTesting.
155 void CreateChildInfoMapEntry( 163 void CreateChildInfoMapEntry(
156 int render_process_id, 164 int render_process_id,
157 std::unique_ptr<MemoryCoordinatorHandleImpl> handle); 165 std::unique_ptr<MemoryCoordinatorHandleImpl> handle);
158 166
159 // Notifies a state change to in-process clients. 167 // Notifies a state change to in-process clients.
160 void NotifyStateToClients(); 168 void NotifyStateToClients();
161 169
162 // Notifies a state change to child processes. 170 // Notifies a state change to child processes.
163 void NotifyStateToChildren(); 171 void NotifyStateToChildren();
(...skipping 15 matching lines...) Expand all
179 // MemoryCoordinator and removed automatically when an underlying binding is 187 // MemoryCoordinator and removed automatically when an underlying binding is
180 // disconnected. 188 // disconnected.
181 ChildInfoMap children_; 189 ChildInfoMap children_;
182 190
183 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl); 191 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImpl);
184 }; 192 };
185 193
186 } // namespace content 194 } // namespace content
187 195
188 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_ 196 #endif // CONTENT_BROWSER_MEMORY_MEMORY_COORDINATOR_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/memory/memory_coordinator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698