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

Side by Side Diff: content/browser/memory/memory_coordinator.cc

Issue 2536533002: memory coordinator: Check RenderProcessHost pointers before use them (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 | no next file » | 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 #include "content/browser/memory/memory_coordinator.h" 5 #include "content/browser/memory/memory_coordinator.h"
6 6
7 #include "base/memory/memory_coordinator_client_registry.h" 7 #include "base/memory/memory_coordinator_client_registry.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "content/public/browser/content_browser_client.h" 9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/browser/render_process_host.h" 10 #include "content/public/browser/render_process_host.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 children_.erase(render_process_id); 162 children_.erase(render_process_id);
163 } 163 }
164 164
165 bool MemoryCoordinator::CanThrottleRenderer(int render_process_id) { 165 bool MemoryCoordinator::CanThrottleRenderer(int render_process_id) {
166 // If there is no delegate (i.e. tests), renderers are always throttleable. 166 // If there is no delegate (i.e. tests), renderers are always throttleable.
167 // TODO(bashi): We check |delegate_| to avoid calling FromID() on a 167 // TODO(bashi): We check |delegate_| to avoid calling FromID() on a
168 // wrong thread in tests. Figure out a better way to handle tests. 168 // wrong thread in tests. Figure out a better way to handle tests.
169 if (!delegate_) 169 if (!delegate_)
170 return true; 170 return true;
171 auto* render_process_host = RenderProcessHost::FromID(render_process_id); 171 auto* render_process_host = RenderProcessHost::FromID(render_process_id);
172 return render_process_host->IsProcessBackgrounded(); 172 return render_process_host && render_process_host->IsProcessBackgrounded();
173 } 173 }
174 174
175 bool MemoryCoordinator::CanSuspendRenderer(int render_process_id) { 175 bool MemoryCoordinator::CanSuspendRenderer(int render_process_id) {
176 // If there is no delegate (i.e. tests), renderers are always suspendable. 176 // If there is no delegate (i.e. tests), renderers are always suspendable.
177 if (!delegate_) 177 if (!delegate_)
178 return true; 178 return true;
179 auto* render_process_host = RenderProcessHost::FromID(render_process_id); 179 auto* render_process_host = RenderProcessHost::FromID(render_process_id);
180 if (!render_process_host->IsProcessBackgrounded()) 180 if (!render_process_host || !render_process_host->IsProcessBackgrounded())
181 return false; 181 return false;
182 return delegate_->CanSuspendBackgroundedRenderer(render_process_id); 182 return delegate_->CanSuspendBackgroundedRenderer(render_process_id);
183 } 183 }
184 184
185 void MemoryCoordinator::CreateChildInfoMapEntry( 185 void MemoryCoordinator::CreateChildInfoMapEntry(
186 int render_process_id, 186 int render_process_id,
187 std::unique_ptr<MemoryCoordinatorHandleImpl> handle) { 187 std::unique_ptr<MemoryCoordinatorHandleImpl> handle) {
188 auto& child_info = children_[render_process_id]; 188 auto& child_info = children_[render_process_id];
189 // Process always start with normal memory state. 189 // Process always start with normal memory state.
190 // TODO(chrisha): Consider having memory state be a startup parameter of 190 // TODO(chrisha): Consider having memory state be a startup parameter of
191 // child processes, allowing them to be launched in a restricted state. 191 // child processes, allowing them to be launched in a restricted state.
192 child_info.memory_state = mojom::MemoryState::NORMAL; 192 child_info.memory_state = mojom::MemoryState::NORMAL;
193 child_info.handle = std::move(handle); 193 child_info.handle = std::move(handle);
194 } 194 }
195 195
196 MemoryCoordinator::ChildInfo::ChildInfo() {} 196 MemoryCoordinator::ChildInfo::ChildInfo() {}
197 197
198 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { 198 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) {
199 // This is a nop, but exists for compatibility with STL containers. 199 // This is a nop, but exists for compatibility with STL containers.
200 } 200 }
201 201
202 MemoryCoordinator::ChildInfo::~ChildInfo() {} 202 MemoryCoordinator::ChildInfo::~ChildInfo() {}
203 203
204 } // namespace content 204 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698