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

Unified Diff: content/browser/memory/memory_coordinator_impl.cc

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 side-by-side diff with in-line comments
Download patch
Index: content/browser/memory/memory_coordinator_impl.cc
diff --git a/content/browser/memory/memory_coordinator_impl.cc b/content/browser/memory/memory_coordinator_impl.cc
index 22e1390e4245f0a5d4067d2a6aa90f3d93747a26..91176c18fbb41ac1040d55144d0bbeec1dd4cc85 100644
--- a/content/browser/memory/memory_coordinator_impl.cc
+++ b/content/browser/memory/memory_coordinator_impl.cc
@@ -316,6 +316,17 @@ bool MemoryCoordinatorImpl::ChangeStateIfNeeded(base::MemoryState prev_state,
return true;
}
+RenderProcessHost* MemoryCoordinatorImpl::GetRenderProcessHost(
+ int render_process_id) {
+ return RenderProcessHost::FromID(render_process_id);
+}
+
+void MemoryCoordinatorImpl::SetDelegateForTesting(
+ std::unique_ptr<MemoryCoordinatorDelegate> delegate) {
+ CHECK(!delegate_);
+ delegate_ = std::move(delegate);
+}
+
void MemoryCoordinatorImpl::AddChildForTesting(
int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) {
mojom::MemoryCoordinatorHandlePtr mch;
@@ -332,14 +343,14 @@ void MemoryCoordinatorImpl::OnConnectionError(int render_process_id) {
}
bool MemoryCoordinatorImpl::CanSuspendRenderer(int render_process_id) {
- // If there is no delegate (i.e. unittests), renderers are always suspendable.
- if (!delegate_)
- return true;
- auto* render_process_host = RenderProcessHost::FromID(render_process_id);
+ auto* render_process_host = GetRenderProcessHost(render_process_id);
if (!render_process_host || !render_process_host->IsProcessBackgrounded())
return false;
if (render_process_host->GetWorkerRefCount() > 0)
return false;
+ // Assumes that we can't suspend renderers if there is no delegate.
+ if (!delegate_)
+ return false;
return delegate_->CanSuspendBackgroundedRenderer(render_process_id);
}
@@ -366,12 +377,6 @@ base::MemoryState MemoryCoordinatorImpl::OverrideGlobalState(
return memory_state;
}
-void MemoryCoordinatorImpl::SetDelegateForTesting(
- std::unique_ptr<MemoryCoordinatorDelegate> delegate) {
- CHECK(!delegate_);
- delegate_ = std::move(delegate);
-}
-
void MemoryCoordinatorImpl::CreateChildInfoMapEntry(
int render_process_id,
std::unique_ptr<MemoryCoordinatorHandleImpl> handle) {
@@ -411,7 +416,7 @@ void MemoryCoordinatorImpl::RecordStateChange(MemoryState prev_state,
total_private_kb += working_set.priv;
for (auto& iter : children()) {
- auto* render_process_host = RenderProcessHost::FromID(iter.first);
+ auto* render_process_host = GetRenderProcessHost(iter.first);
if (!render_process_host ||
render_process_host->GetHandle() == base::kNullProcessHandle)
continue;
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.h ('k') | content/browser/memory/memory_coordinator_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698