RenderProcessHost: Expose base::Process::Priority
This gets rid of IsProcessBackgrounded() in favor of
GetPriority(), and changes a lot of its use cases.
In the future, there will be more priority states than just
"foregrounded" and "backgrounded". For now, "foregrounded" maps
to "kUserBlocking" and "backgrounded" maps to "kBestEffort".
The current plans for the additional priority state is to
differentiate between different foreground states, so replacing
"IsProcessBackgrounded()" with "GetPriority() == kBestEffort" is
better than replacing it with "GetPriority() != kUserBlocking".
Bug: 348148939
Change-Id: Ibfc1663489465cba00f13ee3ca49a5f9265cfc5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5713290
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1331968}
diff --git a/chrome/browser/crash_recovery_browsertest.cc b/chrome/browser/crash_recovery_browsertest.cc
index d3c9909..848ed7b8 100644
--- a/chrome/browser/crash_recovery_browsertest.cc
+++ b/chrome/browser/crash_recovery_browsertest.cc
@@ -116,10 +116,10 @@
EXPECT_NE(title_before_crash, title_after_crash);
ASSERT_TRUE(
GetActiveWebContents()->GetPrimaryMainFrame()->GetView()->IsShowing());
- ASSERT_FALSE(GetActiveWebContents()
- ->GetPrimaryMainFrame()
- ->GetProcess()
- ->IsProcessBackgrounded());
+ ASSERT_NE(base::Process::Priority::kBestEffort, GetActiveWebContents()
+ ->GetPrimaryMainFrame()
+ ->GetProcess()
+ ->GetPriority());
}
// Test that reload after a crash forces a cache revalidation.
diff --git a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
index bc9d245..5a1fb0be 100644
--- a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
+++ b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
@@ -383,7 +383,8 @@
void VerifyProcessPriority(content::RenderProcessHost* process,
bool expected_is_backgrounded) {
EXPECT_TRUE(process->IsInitializedAndNotDead());
- EXPECT_EQ(expected_is_backgrounded, process->IsProcessBackgrounded());
+ EXPECT_EQ(expected_is_backgrounded,
+ process->GetPriority() == base::Process::Priority::kBestEffort);
if (base::Process::CanSetPriority()) {
base::Process p = ProcessFromHandle(process->GetProcess().Handle());
diff --git a/components/performance_manager/graph/policies/process_priority_policy.cc b/components/performance_manager/graph/policies/process_priority_policy.cc
index 1ead31c..071ade05 100644
--- a/components/performance_manager/graph/policies/process_priority_policy.cc
+++ b/components/performance_manager/graph/policies/process_priority_policy.cc
@@ -27,25 +27,21 @@
// the RenderProcessHost.
ProcessPriorityPolicy::SetPriorityOnUiThreadCallback* g_callback = nullptr;
-// Maps a TaskPriority to a "is_foreground" bool. Process priorities are
-// currently simply "background" or "foreground", despite there actually being
-// more expressive power on most platforms.
-bool IsForegroundTaskPriority(base::TaskPriority priority) {
+base::Process::Priority ToProcessPriority(base::TaskPriority priority) {
switch (priority) {
case base::TaskPriority::BEST_EFFORT:
- return false;
+ return base::Process::Priority::kBestEffort;
+ // Only one foreground priority for now.
case base::TaskPriority::USER_VISIBLE:
case base::TaskPriority::USER_BLOCKING:
- break;
+ return base::Process::Priority::kUserBlocking;
}
-
- return true;
}
// Helper function for setting the RenderProcessHost priority.
void SetProcessPriorityOnUIThread(RenderProcessHostProxy rph_proxy,
- bool foreground) {
+ base::Process::Priority priority) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Deliver the policy message if the RPH still exists by the time the
@@ -53,18 +49,18 @@
// the process launcher thread.
auto* rph = rph_proxy.Get();
if (rph)
- rph->SetPriorityOverride(foreground);
+ rph->SetPriorityOverride(priority);
// Invoke the testing seam callback if one was provided.
if (g_callback && !g_callback->is_null())
- g_callback->Run(rph_proxy, foreground);
+ g_callback->Run(rph_proxy, priority);
}
// Dispatches a process priority change to the RenderProcessHost associated with
// a given ProcessNode. The task is posted to the UI thread, where the RPH
// lives.
void DispatchSetProcessPriority(const ProcessNode* process_node,
- bool foreground) {
+ base::Process::Priority priority) {
if (process_node->GetProcessType() != content::PROCESS_TYPE_RENDERER) {
// This is triggered from ProcessNode observers that fire for all process
// types, but only renderer processes have a RenderProcessHostProxy.
@@ -75,7 +71,7 @@
// skipping the thread-hop.
if (base::FeatureList::IsEnabled(features::kRunOnMainThreadSync)) {
SetProcessPriorityOnUIThread(process_node->GetRenderProcessHostProxy(),
- foreground);
+ priority);
return;
}
@@ -86,7 +82,7 @@
const auto& proxy = process_node->GetRenderProcessHostProxy();
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
- base::BindOnce(&SetProcessPriorityOnUIThread, proxy, foreground));
+ base::BindOnce(&SetProcessPriorityOnUIThread, proxy, priority));
}
} // namespace
@@ -139,20 +135,21 @@
// TODO(chrisha): Make process creation take a detour through the graph in
// order to get the initial priority parameter that is set here. Currently
// this is effectively a nop.
- DispatchSetProcessPriority(
- process_node, IsForegroundTaskPriority(process_node->GetPriority()));
+ DispatchSetProcessPriority(process_node,
+ ToProcessPriority(process_node->GetPriority()));
}
void ProcessPriorityPolicy::OnPriorityChanged(
const ProcessNode* process_node,
base::TaskPriority previous_value) {
- bool previous_foreground = IsForegroundTaskPriority(previous_value);
- bool current_foreground =
- IsForegroundTaskPriority(process_node->GetPriority());
+ base::Process::Priority previous_priority = ToProcessPriority(previous_value);
+ base::Process::Priority current_priority =
+ ToProcessPriority(process_node->GetPriority());
// Only dispatch a message if the resulting process priority has changed.
- if (previous_foreground != current_foreground)
- DispatchSetProcessPriority(process_node, current_foreground);
+ if (previous_priority != current_priority) {
+ DispatchSetProcessPriority(process_node, current_priority);
+ }
}
} // namespace policies
diff --git a/components/performance_manager/graph/policies/process_priority_policy.h b/components/performance_manager/graph/policies/process_priority_policy.h
index 0e1bd36e..5387646 100644
--- a/components/performance_manager/graph/policies/process_priority_policy.h
+++ b/components/performance_manager/graph/policies/process_priority_policy.h
@@ -23,7 +23,7 @@
public:
using SetPriorityOnUiThreadCallback =
base::RepeatingCallback<void(RenderProcessHostProxy rph_proxy,
- bool foreground)>;
+ base::Process::Priority)>;
ProcessPriorityPolicy();
ProcessPriorityPolicy(const ProcessPriorityPolicy&) = delete;
diff --git a/components/performance_manager/graph/policies/process_priority_policy_unittest.cc b/components/performance_manager/graph/policies/process_priority_policy_unittest.cc
index 538ffb7..d759c7e 100644
--- a/components/performance_manager/graph/policies/process_priority_policy_unittest.cc
+++ b/components/performance_manager/graph/policies/process_priority_policy_unittest.cc
@@ -26,28 +26,25 @@
namespace {
-// Returns a priority that will lead to an opposite process priority.
-base::TaskPriority GetOppositePriority(base::TaskPriority priority) {
+base::TaskPriority ToTaskPriority(base::Process::Priority priority) {
switch (priority) {
- case base::TaskPriority::BEST_EFFORT:
+ case base::Process::Priority::kBestEffort:
+ return base::TaskPriority::BEST_EFFORT;
+ case base::Process::Priority::kUserVisible:
+ return base::TaskPriority::USER_VISIBLE;
+ case base::Process::Priority::kUserBlocking:
return base::TaskPriority::USER_BLOCKING;
-
- case base::TaskPriority::USER_VISIBLE:
- case base::TaskPriority::USER_BLOCKING:
- break;
}
-
- return base::TaskPriority::BEST_EFFORT;
}
-void PostToggleProcessNodePriority(content::RenderProcessHost* rph) {
+void PostProcessNodePriority(content::RenderProcessHost* rph,
+ base::Process::Priority priority) {
auto* rpud = RenderProcessUserData::GetForRenderProcessHost(rph);
auto* process_node = rpud->process_node();
PerformanceManager::CallOnGraph(
- FROM_HERE, base::BindLambdaForTesting([process_node]() {
- process_node->set_priority(
- GetOppositePriority(process_node->GetPriority()));
+ FROM_HERE, base::BindLambdaForTesting([process_node, priority]() {
+ process_node->set_priority(ToTaskPriority(priority));
}));
}
@@ -99,11 +96,13 @@
// This is eventually invoked by the testing callback when the policy sets a
// process priority.
- MOCK_METHOD2(OnSetPriority, void(content::RenderProcessHost*, bool));
+ MOCK_METHOD2(OnSetPriority,
+ void(content::RenderProcessHost*, base::Process::Priority));
private:
- void OnSetPriorityWrapper(RenderProcessHostProxy rph_proxy, bool foreground) {
- OnSetPriority(rph_proxy.Get(), foreground);
+ void OnSetPriorityWrapper(RenderProcessHostProxy rph_proxy,
+ base::Process::Priority priority) {
+ OnSetPriority(rph_proxy.Get(), priority);
quit_closure_.Run();
}
@@ -127,14 +126,15 @@
// Expect a foreground priority override to be set for process creation.
// NOTE: This is going to change once we have provisional frames and the like,
// and can calculate meaningful process startup priorities.
- EXPECT_CALL(*this, OnSetPriority(rph, true));
+ EXPECT_CALL(*this,
+ OnSetPriority(rph, base::Process::Priority::kUserBlocking));
content::NavigationSimulator::NavigateAndCommitFromBrowser(
web_contents(), GURL("https://www.foo.com/"));
RunUntilOnSetPriority();
// Toggle the priority and expect it to change.
- EXPECT_CALL(*this, OnSetPriority(rph, false));
- PostToggleProcessNodePriority(rph);
+ EXPECT_CALL(*this, OnSetPriority(rph, base::Process::Priority::kBestEffort));
+ PostProcessNodePriority(rph, base::Process::Priority::kBestEffort);
RunUntilOnSetPriority();
testing::Mock::VerifyAndClearExpectations(this);
diff --git a/content/browser/back_forward_cache_internal_browsertest.cc b/content/browser/back_forward_cache_internal_browsertest.cc
index 2c1f26f..0d847cfe 100644
--- a/content/browser/back_forward_cache_internal_browsertest.cc
+++ b/content/browser/back_forward_cache_internal_browsertest.cc
@@ -3995,7 +3995,8 @@
bool backgrounded) {
EXPECT_FALSE(rfh.IsDestroyed());
EXPECT_EQ(cached, rfh->IsInBackForwardCache());
- EXPECT_EQ(backgrounded, rfh->GetProcess()->IsProcessBackgrounded());
+ EXPECT_EQ(backgrounded, rfh->GetProcess()->GetPriority() ==
+ base::Process::Priority::kBestEffort);
}
// The number of pages the BackForwardCache can hold per tab.
const size_t kBackForwardCacheSize = 4;
@@ -4017,7 +4018,8 @@
"a.com", base::StringPrintf("/title1.html?i=%zu", i)));
ASSERT_TRUE(NavigateToURL(shell(), url));
rfhs.emplace_back(current_frame_host());
- EXPECT_FALSE(rfhs.back()->GetProcess()->IsProcessBackgrounded());
+ EXPECT_NE(rfhs.back()->GetProcess()->GetPriority(),
+ base::Process::Priority::kBestEffort);
for (size_t j = 0; j <= i; ++j) {
SCOPED_TRACE(j);
@@ -4069,7 +4071,8 @@
"/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), url));
rfhs.emplace_back(current_frame_host());
- EXPECT_FALSE(rfhs.back()->GetProcess()->IsProcessBackgrounded());
+ EXPECT_NE(rfhs.back()->GetProcess()->GetPriority(),
+ base::Process::Priority::kBestEffort);
for (size_t j = 0; j <= i; ++j) {
SCOPED_TRACE(j);
@@ -4134,7 +4137,8 @@
"/title1.html"));
ASSERT_TRUE(NavigateToURL(shell(), url));
rfhs.emplace_back(current_frame_host());
- EXPECT_FALSE(rfhs.back()->GetProcess()->IsProcessBackgrounded());
+ EXPECT_NE(rfhs.back()->GetProcess()->GetPriority(),
+ base::Process::Priority::kBestEffort);
}
// Check that a0-2 are cached and backgrounded.
for (size_t i = 0; i < kBackForwardCacheSize - 1; ++i) {
@@ -4150,7 +4154,8 @@
// Assert that we really have set up the situation we want where the processes
// are shared and in the foreground.
RenderFrameHostImpl* rfh = current_frame_host();
- ASSERT_FALSE(rfh->GetProcess()->IsProcessBackgrounded());
+ ASSERT_NE(rfh->GetProcess()->GetPriority(),
+ base::Process::Priority::kBestEffort);
rfhs[1]->GetProcess()->OnMediaStreamAdded();
rfhs[2]->GetProcess()->OnMediaStreamAdded();
diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
index bed9dc0..e3add3d 100644
--- a/content/browser/child_process_launcher.cc
+++ b/content/browser/child_process_launcher.cc
@@ -59,6 +59,7 @@
void RenderProcessPriority::WriteIntoTrace(
perfetto::TracedProto<TraceProto> proto) const {
+ // TODO(pmonette): Migrate is_background() to GetProcessPriority().
proto->set_is_backgrounded(is_background());
proto->set_has_pending_views(boost_for_pending_views);
@@ -273,8 +274,8 @@
bool RenderProcessPriority::is_background() const {
#if !BUILDFLAG(IS_ANDROID)
- if (foreground_override) {
- return !foreground_override.value();
+ if (priority_override) {
+ return *priority_override == base::Process::Priority::kBestEffort;
}
#endif
return !visible && !has_media_stream && !boost_for_pending_views &&
@@ -282,6 +283,11 @@
}
base::Process::Priority RenderProcessPriority::GetProcessPriority() const {
+#if !BUILDFLAG(IS_ANDROID)
+ if (priority_override) {
+ return *priority_override;
+ }
+#endif
return is_background() ? base::Process::Priority::kBestEffort
: base::Process::Priority::kUserBlocking;
}
diff --git a/content/browser/child_process_launcher.h b/content/browser/child_process_launcher.h
index 278d34b..f1773a1 100644
--- a/content/browser/child_process_launcher.h
+++ b/content/browser/child_process_launcher.h
@@ -95,7 +95,7 @@
#endif
#if !BUILDFLAG(IS_ANDROID)
,
- std::optional<bool> foreground_override
+ std::optional<base::Process::Priority> priority_override
#endif
)
: visible(visible),
@@ -111,12 +111,13 @@
#endif
#if !BUILDFLAG(IS_ANDROID)
,
- foreground_override(foreground_override)
+ priority_override(priority_override)
#endif
{
}
// Returns true if the child process is backgrounded.
+ // DEPRECATED NOTICE: Use GetProcessPriority() instead.
bool is_background() const;
// Returns the process priority for this child process.
@@ -128,9 +129,8 @@
using TraceProto = perfetto::protos::pbzero::ChildProcessLauncherPriority;
void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
- // Prefer `is_background()` or `GetProcessPriority()` to inspecting these
- // fields individually (to ensure all logic uses the same notion of
- // "backgrounded").
+ // Prefer `GetProcessPriority()` to inspecting these fields individually (to
+ // ensure all priority logic is consistent).
// |visible| is true if the process is responsible for one or more widget(s)
// in foreground tabs. The notion of "visible" is determined by the embedder
@@ -175,10 +175,8 @@
#if !BUILDFLAG(IS_ANDROID)
// If this is set then the built-in process priority calculation system is
- // ignored, and an externally computed process priority is used. Set to true
- // and the process will stay foreground priority; set to false and it will
- // stay background priority.
- std::optional<bool> foreground_override;
+ // ignored, and an externally computed process priority is used.
+ std::optional<base::Process::Priority> priority_override;
#endif
};
diff --git a/content/browser/preloading/prerender/prerender_browsertest.cc b/content/browser/preloading/prerender/prerender_browsertest.cc
index 92bcb87..849d95f 100644
--- a/content/browser/preloading/prerender/prerender_browsertest.cc
+++ b/content/browser/preloading/prerender/prerender_browsertest.cc
@@ -11709,18 +11709,19 @@
RenderProcessHost* prerender_process_host =
prerender_frame_host->GetProcess();
ASSERT_NE(prerender_frame_host, nullptr);
- // Ensure that a prerender process is invisible in
- // ChildProcessLauncherPriority. This will put prerender processes in lower
- // priority compared to other active processes. (See
+ // Ensure that a prerender process is backgrounded. This will put prerender
+ // processes in lower priority compared to other active processes. (See
// https://crbug.com/1211665)
- EXPECT_TRUE(prerender_process_host->IsProcessBackgrounded());
+ EXPECT_TRUE(prerender_process_host->GetPriority() ==
+ base::Process::Priority::kBestEffort);
// Activate the prerendered page.
test::PrerenderHostObserver host_observer(*web_contents(), kPrerenderingUrl);
NavigatePrimaryPage(kPrerenderingUrl);
EXPECT_TRUE(host_observer.was_activated());
- // Expect the change in the ChildProcessLauncherPriority to become visible.
- EXPECT_FALSE(prerender_process_host->IsProcessBackgrounded());
+ // Expect the change in the ChildProcessLauncherPriority to increase priority.
+ EXPECT_NE(prerender_process_host->GetPriority(),
+ base::Process::Priority::kBestEffort);
}
class PrerenderPurposePrefetchBrowserTest : public PrerenderBrowserTest {
diff --git a/content/browser/renderer_host/back_forward_cache_impl.cc b/content/browser/renderer_host/back_forward_cache_impl.cc
index 4f345c1..bc2f1774 100644
--- a/content/browser/renderer_host/back_forward_cache_impl.cc
+++ b/content/browser/renderer_host/back_forward_cache_impl.cc
@@ -352,7 +352,8 @@
// this Entry are foregrounded.
bool HasForegroundedProcess(BackForwardCacheImpl::Entry& entry) {
for (const auto& rvh : entry.render_view_hosts()) {
- if (!rvh->GetProcess()->IsProcessBackgrounded()) {
+ if (rvh->GetProcess()->GetPriority() !=
+ base::Process::Priority::kBestEffort) {
return true;
}
}
@@ -564,7 +565,7 @@
dict.Add("render_frame_host", render_frame_host());
}
-void BackForwardCacheImpl::RenderProcessBackgroundedChanged(
+void BackForwardCacheImpl::RenderProcessPriorityChanged(
RenderProcessHostImpl* host) {
EnforceCacheSizeLimit();
}
diff --git a/content/browser/renderer_host/back_forward_cache_impl.h b/content/browser/renderer_host/back_forward_cache_impl.h
index 077e4f2..b0d5be0 100644
--- a/content/browser/renderer_host/back_forward_cache_impl.h
+++ b/content/browser/renderer_host/back_forward_cache_impl.h
@@ -117,7 +117,7 @@
//
// 1. `EnforceCacheSizeLimit()` is called to prune the cache size down on
// storing a new cache entry, or when the renderer process's
-// `IsProcessBackgrounded()` state changes.
+// `GetPriority()` state changes.
// A. [Android-only] The number of entries where `HasForegroundedProcess()`
// is true is pruned to `GetForegroundedEntriesCacheSize()`.
// B. Prunes to `GetCacheSize()` entries no matter what kinds of tabs
@@ -408,7 +408,7 @@
const StoragePartition::StorageKeyMatcherFunction& storage_key_filter);
// RenderProcessHostInternalObserver methods
- void RenderProcessBackgroundedChanged(RenderProcessHostImpl* host) override;
+ void RenderProcessPriorityChanged(RenderProcessHostImpl* host) override;
// Returns true if we are managing the cache size using foreground and
// background limits (if finch parameter "foreground_cache_size" > 0).
diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc
index a2449c8..682a084 100644
--- a/content/browser/renderer_host/navigation_request.cc
+++ b/content/browser/renderer_host/navigation_request.cc
@@ -460,7 +460,7 @@
}
// LOG_NAVIGATION_TIMING_HISTOGRAM logs |value| for "Navigation.<histogram>" UMA
-// as well as supplementary UMAs (depending on |transition| and |is_background|)
+// as well as supplementary UMAs (depending on |transition| and |priority|)
// for BackForward/Reload/NewNavigation variants.
//
// kMaxTime and kBuckets constants are consistent with
@@ -470,7 +470,7 @@
// TODO(csharrison,nasko): This macro is incorrect for subframe navigations,
// which will only have subframe-specific transition types. This means that all
// subframes currently are tagged as NewNavigations.
-#define LOG_NAVIGATION_TIMING_HISTOGRAM(histogram, transition, is_background, \
+#define LOG_NAVIGATION_TIMING_HISTOGRAM(histogram, transition, priority, \
duration) \
do { \
const base::TimeDelta kMinTime = base::Milliseconds(1); \
@@ -491,8 +491,8 @@
} else { \
NOTREACHED_IN_MIGRATION() << "Invalid page transition: " << transition; \
} \
- if (is_background.has_value()) { \
- if (is_background.value()) { \
+ if (priority.has_value()) { \
+ if (priority.value() == base::Process::Priority::kBestEffort) { \
UMA_HISTOGRAM_CUSTOM_TIMES("Navigation." histogram \
".BackgroundProcessPriority", \
duration, kMinTime, kMaxTime, kBuckets); \
@@ -507,44 +507,43 @@
void RecordStartToCommitMetrics(base::TimeTicks navigation_start_time,
ui::PageTransition transition,
const base::TimeTicks& ready_to_commit_time,
- std::optional<bool> is_background,
+ std::optional<base::Process::Priority> priority,
bool is_same_process,
bool is_main_frame) {
base::TimeTicks now = base::TimeTicks::Now();
base::TimeDelta delta = now - navigation_start_time;
- LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit", transition, is_background,
- delta);
+ LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit", transition, priority, delta);
if (is_main_frame) {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.MainFrame", transition,
- is_background, delta);
+ priority, delta);
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.Subframe", transition,
- is_background, delta);
+ priority, delta);
}
if (is_same_process) {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.SameProcess", transition,
- is_background, delta);
+ priority, delta);
if (is_main_frame) {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.SameProcess.MainFrame",
- transition, is_background, delta);
+ transition, priority, delta);
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.SameProcess.Subframe",
- transition, is_background, delta);
+ transition, priority, delta);
}
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.CrossProcess", transition,
- is_background, delta);
+ priority, delta);
if (is_main_frame) {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.CrossProcess.MainFrame",
- transition, is_background, delta);
+ transition, priority, delta);
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("StartToCommit.CrossProcess.Subframe",
- transition, is_background, delta);
+ transition, priority, delta);
}
}
if (!ready_to_commit_time.is_null()) {
LOG_NAVIGATION_TIMING_HISTOGRAM("ReadyToCommitUntilCommit2", transition,
- is_background, now - ready_to_commit_time);
+ priority, now - ready_to_commit_time);
}
}
@@ -610,32 +609,32 @@
// TimeToReadyToCommit2
{
- constexpr std::optional<bool> kIsBackground = std::nullopt;
+ constexpr std::optional<base::Process::Priority> kPriority = std::nullopt;
base::TimeDelta delta =
ready_to_commit_time - common_params.navigation_start;
ui::PageTransition transition =
ui::PageTransitionFromInt(common_params.transition);
LOG_NAVIGATION_TIMING_HISTOGRAM("TimeToReadyToCommit2", transition,
- kIsBackground, delta);
+ kPriority, delta);
if (is_main_frame) {
LOG_NAVIGATION_TIMING_HISTOGRAM("TimeToReadyToCommit2.MainFrame",
- transition, kIsBackground, delta);
+ transition, kPriority, delta);
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("TimeToReadyToCommit2.Subframe",
- transition, kIsBackground, delta);
+ transition, kPriority, delta);
}
if (is_same_process) {
LOG_NAVIGATION_TIMING_HISTOGRAM("TimeToReadyToCommit2.SameProcess",
- transition, kIsBackground, delta);
+ transition, kPriority, delta);
} else {
LOG_NAVIGATION_TIMING_HISTOGRAM("TimeToReadyToCommit2.CrossProcess",
- transition, kIsBackground, delta);
+ transition, kPriority, delta);
}
if (did_receive_early_hints_before_cross_origin_redirect) {
LOG_NAVIGATION_TIMING_HISTOGRAM(
"TimeToReadyToCommit2.CrossOriginRedirectAfterEarlyHints", transition,
- kIsBackground, delta);
+ kPriority, delta);
}
}
@@ -7672,12 +7671,12 @@
if (!IsSameDocument() && state_ != DID_COMMIT_ERROR_PAGE) {
ui::PageTransition transition =
ui::PageTransitionFromInt(common_params_->transition);
- std::optional<bool> is_background =
- GetRenderFrameHost()->GetProcess()->IsProcessBackgrounded();
+ base::Process::Priority priority =
+ GetRenderFrameHost()->GetProcess()->GetPriority();
RecordStartToCommitMetrics(
common_params_->navigation_start, transition, ready_to_commit_time_,
- is_background, is_same_process_, frame_tree_node_->IsMainFrame());
+ priority, is_same_process_, frame_tree_node_->IsMainFrame());
}
DCHECK(!frame_tree_node_->IsMainFrame() || navigation_entry_committed)
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
index a62a63a3..ba4144d 100644
--- a/content/browser/renderer_host/render_frame_host_impl.cc
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
@@ -1342,10 +1342,10 @@
}
void RecordIsProcessBackgrounded(const char* timing_string,
- bool is_process_backgrounded) {
+ base::Process::Priority process_priority) {
base::UmaHistogramBoolean(
base::StrCat({"Navigation.IsProcessBackgrounded.", timing_string}),
- is_process_backgrounded);
+ process_priority == base::Process::Priority::kBestEffort);
}
// These are directly cast to UKM enums of the same name and logged,
@@ -5707,7 +5707,7 @@
delegate_->DOMContentLoaded(this);
if (last_committed_url_.SchemeIsHTTPOrHTTPS() && IsOutermostMainFrame()) {
RecordIsProcessBackgrounded("OnDOMContentLoaded",
- GetProcess()->IsProcessBackgrounded());
+ GetProcess()->GetPriority());
}
MaybeResetBoostRenderProcessForLoading();
}
@@ -8085,7 +8085,7 @@
delegate_->DOMContentLoaded(this);
if (last_committed_url_.SchemeIsHTTPOrHTTPS() && IsOutermostMainFrame()) {
RecordIsProcessBackgrounded("OnDOMContentLoaded",
- GetProcess()->IsProcessBackgrounded());
+ GetProcess()->GetPriority());
}
MaybeResetBoostRenderProcessForLoading();
}
@@ -11547,8 +11547,7 @@
if (IsTargetUrlOfBoostRenderProcessForLoading(common_params->url)) {
BoostRenderProcessForLoading();
}
- RecordIsProcessBackgrounded("OnCommit",
- GetProcess()->IsProcessBackgrounded());
+ RecordIsProcessBackgrounded("OnCommit", GetProcess()->GetPriority());
}
SendCommitNavigation(
diff --git a/content/browser/renderer_host/render_frame_host_manager_browsertest.cc b/content/browser/renderer_host/render_frame_host_manager_browsertest.cc
index 04dadb5..012cee8 100644
--- a/content/browser/renderer_host/render_frame_host_manager_browsertest.cc
+++ b/content/browser/renderer_host/render_frame_host_manager_browsertest.cc
@@ -6038,7 +6038,8 @@
// TODO(gab, nasko): On Android IsProcessBackgrounded is currently giving
// incorrect value at this stage of the process lifetime. This should be
// fixed in follow up cleanup work. See https://crbug.com/560446.
- EXPECT_FALSE(speculative_rph->IsProcessBackgrounded());
+ EXPECT_NE(speculative_rph->GetPriority(),
+ base::Process::Priority::kBestEffort);
#endif
// Wait for the underlying OS process to have launched and be ready to
@@ -6087,7 +6088,7 @@
RenderProcessHost* spare_rph =
RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
EXPECT_TRUE(spare_rph);
- EXPECT_TRUE(spare_rph->IsProcessBackgrounded());
+ EXPECT_EQ(spare_rph->GetPriority(), base::Process::Priority::kBestEffort);
// Start a navigation to b.com to ensure a cross-process navigation is
// in progress and ensure the process for the speculative host is
@@ -6121,7 +6122,7 @@
// The creation of the speculative RenderFrameHost should change the
// RenderProcessHost's copy of the priority of the spare process from
// background to foreground.
- EXPECT_FALSE(spare_rph->IsProcessBackgrounded());
+ EXPECT_NE(spare_rph->GetPriority(), base::Process::Priority::kBestEffort);
// The OS process itself is updated on the process launcher thread, so it
// cannot be observed immediately here. Perform a thread hop to and back to
diff --git a/content/browser/renderer_host/render_process_host_browsertest.cc b/content/browser/renderer_host/render_process_host_browsertest.cc
index 37c8457..f81dbfe 100644
--- a/content/browser/renderer_host/render_process_host_browsertest.cc
+++ b/content/browser/renderer_host/render_process_host_browsertest.cc
@@ -1011,21 +1011,21 @@
host_observation_.Observe(host);
}
- void RenderProcessBackgroundedChanged(RenderProcessHostImpl* host) override {
- backgrounded_ = host->IsProcessBackgrounded();
+ void RenderProcessPriorityChanged(RenderProcessHostImpl* host) override {
+ priority_ = host->GetPriority();
}
// Returns the latest recorded value if there was one and resets the recorded
// value to |nullopt|.
- std::optional<bool> TakeValue() {
- auto value = backgrounded_;
- backgrounded_ = std::nullopt;
+ std::optional<base::Process::Priority> TakeValue() {
+ auto value = priority_;
+ priority_ = std::nullopt;
return value;
}
private:
- // Stores the last observed value of IsProcessBackgrounded for a host.
- std::optional<bool> backgrounded_;
+ // Stores the last observed value of GetPriority() for a host.
+ std::optional<base::Process::Priority> priority_;
base::ScopedObservation<RenderProcessHostImpl,
RenderProcessHostInternalObserver>
host_observation_{this};
@@ -1045,36 +1045,36 @@
// It starts off as normal priority with no override.
EXPECT_FALSE(process->HasPriorityOverride());
- EXPECT_FALSE(process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kUserBlocking);
EXPECT_FALSE(observer.TakeValue().has_value());
- process->SetPriorityOverride(false /* foreground */);
+ process->SetPriorityOverride(base::Process::Priority::kBestEffort);
EXPECT_TRUE(process->HasPriorityOverride());
- EXPECT_TRUE(process->IsProcessBackgrounded());
- EXPECT_EQ(observer.TakeValue().value(), process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kBestEffort);
+ EXPECT_EQ(observer.TakeValue().value(), process->GetPriority());
- process->SetPriorityOverride(true /* foreground */);
+ process->SetPriorityOverride(base::Process::Priority::kUserBlocking);
EXPECT_TRUE(process->HasPriorityOverride());
- EXPECT_FALSE(process->IsProcessBackgrounded());
- EXPECT_EQ(observer.TakeValue().value(), process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kUserBlocking);
+ EXPECT_EQ(observer.TakeValue().value(), process->GetPriority());
- process->SetPriorityOverride(false /* foreground */);
+ process->SetPriorityOverride(base::Process::Priority::kBestEffort);
EXPECT_TRUE(process->HasPriorityOverride());
- EXPECT_TRUE(process->IsProcessBackgrounded());
- EXPECT_EQ(observer.TakeValue().value(), process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kBestEffort);
+ EXPECT_EQ(observer.TakeValue().value(), process->GetPriority());
// Add a pending view, and expect the process to *stay* backgrounded.
process->AddPendingView();
EXPECT_TRUE(process->HasPriorityOverride());
- EXPECT_TRUE(process->IsProcessBackgrounded());
- EXPECT_EQ(observer.TakeValue().value(), process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kBestEffort);
+ EXPECT_EQ(observer.TakeValue().value(), process->GetPriority());
// Clear the override. The pending view should cause the process to go back to
// being foregrounded.
process->ClearPriorityOverride();
EXPECT_FALSE(process->HasPriorityOverride());
- EXPECT_FALSE(process->IsProcessBackgrounded());
- EXPECT_EQ(observer.TakeValue().value(), process->IsProcessBackgrounded());
+ EXPECT_EQ(process->GetPriority(), base::Process::Priority::kUserBlocking);
+ EXPECT_EQ(observer.TakeValue().value(), process->GetPriority());
// Clear the pending view so the test doesn't explode.
process->RemovePendingView();
@@ -1121,7 +1121,8 @@
RenderProcessHost* render_process_host = render_frame_host->GetProcess();
// Emulate render_process_host is not visible to users.
SetVisibleClients(render_process_host, 0);
- EXPECT_EQ(render_process_host->IsProcessBackgrounded(),
+ EXPECT_EQ(render_process_host->GetPriority() ==
+ base::Process::Priority::kBestEffort,
GetParam().expect_render_process_backgrounded_);
}
@@ -1178,7 +1179,8 @@
// Emulate render_process_host is not visible to users.
SetVisibleClients(render_process_host, 0);
- EXPECT_TRUE(render_process_host->IsProcessBackgrounded());
+ EXPECT_EQ(render_process_host->GetPriority(),
+ base::Process::Priority::kBestEffort);
}
// This test verifies properties of RenderProcessHostImpl *before* Init method
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index c6741cc..e781d19 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -2423,8 +2423,8 @@
return last_init_time_;
}
-bool RenderProcessHostImpl::IsProcessBackgrounded() {
- return priority_.is_background();
+base::Process::Priority RenderProcessHostImpl::GetPriority() {
+ return priority_.GetProcessPriority();
}
void RenderProcessHostImpl::IncrementKeepAliveRefCount(uint64_t handle_id) {
@@ -3987,17 +3987,18 @@
}
#if !BUILDFLAG(IS_ANDROID)
-void RenderProcessHostImpl::SetPriorityOverride(bool foregrounded) {
- foreground_override_ = foregrounded;
+void RenderProcessHostImpl::SetPriorityOverride(
+ base::Process::Priority priority) {
+ priority_override_ = priority;
UpdateProcessPriority();
}
bool RenderProcessHostImpl::HasPriorityOverride() {
- return foreground_override_.has_value();
+ return priority_override_.has_value();
}
void RenderProcessHostImpl::ClearPriorityOverride() {
- foreground_override_.reset();
+ priority_override_.reset();
UpdateProcessPriority();
}
#endif // !BUILDFLAG(IS_ANDROID)
@@ -4967,14 +4968,15 @@
#endif
#if !BUILDFLAG(IS_ANDROID)
,
- foreground_override_
+ priority_override_
#endif
);
- if (priority_ == priority)
+ if (priority_ == priority) {
return;
- const bool background_state_changed =
- priority_.is_background() != priority.is_background();
+ }
+ const bool priority_state_changed =
+ priority_.GetProcessPriority() != priority.GetProcessPriority();
const bool visibility_state_changed = priority_.visible != priority.visible;
TRACE_EVENT("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority",
@@ -5006,16 +5008,16 @@
}
// Notify the child process of the change in state.
- if ((background_state_changed) || visibility_state_changed) {
+ if (priority_state_changed || visibility_state_changed) {
SendProcessStateToRenderer();
}
for (auto& observer : internal_observers_)
- observer.RenderProcessBackgroundedChanged(this);
+ observer.RenderProcessPriorityChanged(this);
// Update the priority of the process running the controller service worker
// when client's background state changed. We can make the service worker
// process backgrounded if all of its clients are backgrounded.
- if (background_state_changed) {
+ if (priority_state_changed) {
UpdateControllerServiceWorkerProcessPriority();
}
}
@@ -5066,7 +5068,7 @@
if (child_process_launcher_) {
DCHECK(child_process_launcher_->GetProcess().IsValid());
// TODO(crbug.com/40590142): This should be based on
- // |priority_.is_background()|, see similar check below.
+ // |priority_.GetProcessPriority()|, see similar check below.
DCHECK_EQ(blink::kLaunchingProcessIsBackgrounded, !priority_.visible);
// Unpause the channel now that the process is launched. We don't flush it
@@ -5094,7 +5096,7 @@
// Android child process priority works differently and cannot be queried
// directly from base::Process.
// TODO(crbug.com/40590142): Fix initial priority on Android to
- // reflect |priority_.is_background()|.
+ // reflect |priority_.GetProcessPriority()|.
DCHECK_EQ(blink::kLaunchingProcessIsBackgrounded, !priority_.visible);
#else
priority_.visible = child_process_launcher_->GetProcess().GetPriority() ==
diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h
index 742307d..80cacb30 100644
--- a/content/browser/renderer_host/render_process_host_impl.h
+++ b/content/browser/renderer_host/render_process_host_impl.h
@@ -266,7 +266,7 @@
void RemovePriorityClient(
RenderProcessHostPriorityClient* priority_client) override;
#if !BUILDFLAG(IS_ANDROID)
- void SetPriorityOverride(bool foreground) override;
+ void SetPriorityOverride(base::Process::Priority priority) override;
bool HasPriorityOverride() override;
void ClearPriorityOverride() override;
#endif
@@ -295,7 +295,7 @@
std::unique_ptr<base::PersistentMemoryAllocator> TakeMetricsAllocator()
override;
const base::TimeTicks& GetLastInitTime() override;
- bool IsProcessBackgrounded() override;
+ base::Process::Priority GetPriority() override;
std::string GetKeepAliveDurations() const override;
size_t GetShutdownDelayRefCount() const override;
int GetRenderFrameHostCount() const override;
@@ -1300,12 +1300,10 @@
#if !BUILDFLAG(IS_ANDROID)
// If this is set then the built-in process priority calculation system is
- // ignored, and an externally computed process priority is used. Set to true
- // and the process will stay foreground priority; set to false and it will
- // stay background priority.
+ // ignored, and an externally computed process priority is used.
// TODO(pmonette): After experimentation, either remove this or rip out the
// existing logic entirely.
- std::optional<bool> foreground_override_;
+ std::optional<base::Process::Priority> priority_override_;
#endif
// Used to allow a RenderWidgetHost to intercept various messages on the
@@ -1465,6 +1463,7 @@
// atomically communicate the last time the hosted renderer was foregrounded.
// This is preferable to IPC as it ensures the timing is visible immediately
// after recovering from a jank (e.g. important for metrics).
+ // TODO(pmonette): Update this to support all process priority levels.
base::MappedReadOnlyRegion last_foreground_time_region_;
// Tracks active audio and video streams within the render process; used to
diff --git a/content/browser/renderer_host/render_process_host_internal_observer.h b/content/browser/renderer_host/render_process_host_internal_observer.h
index 29fecd8..bb36fd9 100644
--- a/content/browser/renderer_host/render_process_host_internal_observer.h
+++ b/content/browser/renderer_host/render_process_host_internal_observer.h
@@ -17,8 +17,8 @@
: public base::CheckedObserver {
public:
// This method is invoked when the observed RenderProcessHost's value of
- // |IsProcessBackgrounded()| changes.
- virtual void RenderProcessBackgroundedChanged(RenderProcessHostImpl* host) {}
+ // |GetPriority()| changes.
+ virtual void RenderProcessPriorityChanged(RenderProcessHostImpl* host) {}
protected:
~RenderProcessHostInternalObserver() override;
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 68810bc56..b478348 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -3005,7 +3005,7 @@
// Require foreground if the controllee is in different process and is
// foreground.
if (controllee_process_id != worker_process_id &&
- !render_host->IsProcessBackgrounded()) {
+ render_host->GetPriority() != base::Process::Priority::kBestEffort) {
return true;
}
}
diff --git a/content/browser/service_worker/service_worker_version_unittest.cc b/content/browser/service_worker/service_worker_version_unittest.cc
index 64a55f03..51d20fb5 100644
--- a/content/browser/service_worker/service_worker_version_unittest.cc
+++ b/content/browser/service_worker/service_worker_version_unittest.cc
@@ -1531,7 +1531,8 @@
helper_->mock_render_process_host()->foreground_service_worker_count());
// Set controllee process to background priority.
- client_render_process_hosts_[0]->set_is_process_backgrounded(true);
+ client_render_process_hosts_[0]->set_priority(
+ base::Process::Priority::kBestEffort);
version_->UpdateForegroundPriority();
EXPECT_EQ(
@@ -1539,7 +1540,8 @@
helper_->mock_render_process_host()->foreground_service_worker_count());
// Set controllee process to foreground priority.
- client_render_process_hosts_[0]->set_is_process_backgrounded(false);
+ client_render_process_hosts_[0]->set_priority(
+ base::Process::Priority::kUserBlocking);
version_->UpdateForegroundPriority();
EXPECT_EQ(
diff --git a/content/public/browser/render_process_host.h b/content/public/browser/render_process_host.h
index 6133d72..87ea840 100644
--- a/content/public/browser/render_process_host.h
+++ b/content/public/browser/render_process_host.h
@@ -356,7 +356,7 @@
// Sets a process priority override. This overrides the entire built-in
// priority setting mechanism for the process.
// TODO(pmonette): Make this work well on Android.
- virtual void SetPriorityOverride(bool foreground) = 0;
+ virtual void SetPriorityOverride(base::Process::Priority priority) = 0;
virtual bool HasPriorityOverride() = 0;
virtual void ClearPriorityOverride() = 0;
#endif
@@ -448,8 +448,8 @@
// a crash.
virtual const base::TimeTicks& GetLastInitTime() = 0;
- // Returns true if this process currently has backgrounded priority.
- virtual bool IsProcessBackgrounded() = 0;
+ // Returns the priority of this process.
+ virtual base::Process::Priority GetPriority() = 0;
// Returns a list of durations for active KeepAlive requests.
// For debugging only. TODO(wjmaclean): Remove once the causes behind
diff --git a/content/public/test/mock_render_process_host.cc b/content/public/test/mock_render_process_host.cc
index e3388d0a..3a6ce174 100644
--- a/content/public/test/mock_render_process_host.cc
+++ b/content/public/test/mock_render_process_host.cc
@@ -75,7 +75,7 @@
fast_shutdown_started_(false),
deletion_callback_called_(false),
is_for_guests_only_(is_for_guests_only),
- is_process_backgrounded_(false),
+ priority_(base::Process::Priority::kUserBlocking),
is_unused_(true),
worker_ref_count_(0),
pending_reuse_ref_count_(0),
@@ -339,7 +339,8 @@
}
#if !BUILDFLAG(IS_ANDROID)
-void MockRenderProcessHost::SetPriorityOverride(bool foreground) {}
+void MockRenderProcessHost::SetPriorityOverride(
+ base::Process::Priority priority) {}
bool MockRenderProcessHost::HasPriorityOverride() {
return false;
@@ -407,8 +408,8 @@
return dummy_time;
}
-bool MockRenderProcessHost::IsProcessBackgrounded() {
- return is_process_backgrounded_;
+base::Process::Priority MockRenderProcessHost::GetPriority() {
+ return priority_;
}
std::string MockRenderProcessHost::GetKeepAliveDurations() const {
diff --git a/content/public/test/mock_render_process_host.h b/content/public/test/mock_render_process_host.h
index 6ea5dc0..f6081a67 100644
--- a/content/public/test/mock_render_process_host.h
+++ b/content/public/test/mock_render_process_host.h
@@ -131,7 +131,7 @@
void RemovePriorityClient(
RenderProcessHostPriorityClient* priority_client) override;
#if !BUILDFLAG(IS_ANDROID)
- void SetPriorityOverride(bool foreground) override;
+ void SetPriorityOverride(base::Process::Priority priority) override;
bool HasPriorityOverride() override;
void ClearPriorityOverride() override;
#endif
@@ -160,7 +160,7 @@
std::unique_ptr<base::PersistentMemoryAllocator> TakeMetricsAllocator()
override;
const base::TimeTicks& GetLastInitTime() override;
- bool IsProcessBackgrounded() override;
+ base::Process::Priority GetPriority() override;
size_t GetWorkerRefCount() const;
std::string GetKeepAliveDurations() const override;
size_t GetShutdownDelayRefCount() const override;
@@ -293,9 +293,7 @@
bool OnMessageReceived(const IPC::Message& msg) override;
void OnChannelConnected(int32_t peer_pid) override;
- void set_is_process_backgrounded(bool is_process_backgrounded) {
- is_process_backgrounded_ = is_process_backgrounded;
- }
+ void set_priority(base::Process::Priority priority) { priority_ = priority; }
void SetProcess(base::Process&& new_process) {
process = std::move(new_process);
@@ -336,7 +334,7 @@
bool delayed_cleanup_ = false;
bool deletion_callback_called_;
bool is_for_guests_only_;
- bool is_process_backgrounded_;
+ base::Process::Priority priority_;
bool is_unused_;
bool is_ready_ = false;
base::Process process;