This method is not called for the outermost main frame, but because
it is called from the renderer, it is more correct to crash the child
process instead.
Bug: 394919526
Change-Id: I89196eb2dc7ebbe09898bdf96347d3c5b2615be3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250474
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1421963}
This CL:
- Introduces FrameInputStateDecorator in PM to detect & update
InputScenario of each frame.
- Introduces InputScenarioObserver in PM to monitor & update
InputScenario change to Renderer via shared memory.
Bug: 365586676
Change-Id: Ia6637ddd8193815b8108da1d07af51f73f6b106e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5889659
Commit-Queue: Jiahe Zhang <jiahe.zhang@intel.com>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1419707}
IsAutoDiscardable is set by extensions from the chrome.tabs API, so if
a tab manager extension sets it on a tab and then manually discards
the tab, it expects the value to stay the same even if the discard
swaps in a new WebContents/PageNode for the tab. TabLifecycleUnit was
handling this correctly, but PageLiveStateDecorator was not.
* Copies the state to the new PageNode on discard.
* Adds tests that the IsAutoDiscardable values from TabLifecycleUnit
and PageLiveStateDecorator are in sync.
* Adds convenience accessors to PageLiveStateDecorator to look up
state directly from a WebContents, without needing to explicitly
look up the PageNode. This will be simpler for callers when
TabLifecycleUnit is deprecated for PageLiveStateDecorator.
R=pmonette
Bug: 394889323,40755583
Change-Id: I21b4455c9d9ae8e54b722967b60917a6f35bda23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6244926
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1419514}
Fixes crashes found by this test:
* changes PerformanceManagerTabHelper::TearDown to
TearDownAndSelfDelete to fix a crash in
GetPrimaryPageNodeForWebContents
* changes PerformanceManagerTabHelper::RenderFrameCreated to fix a
crash in GetFrameNodeForRenderFrameHost
Bug: 40755583
Change-Id: I9912862c478847635ea0755bf4fa830f095fbec0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6253751
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1419507}
These factories aren't useful with GraphTestHarness, which can create
stub WorkerNodes directly. Putting them in PerformanceManagerTestHarness
lets any test that uses the content layer easily create workers.
BYPASS_LARGE_CHANGE_WARNING=Moved code.
R=pmonette
Bug: 40755583
Change-Id: I8f5128a0023b08d65da0f43874e4ca09735ad54e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6254144
Auto-Submit: Joe Mason <joenotcharles@google.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1419398}
This is a reland of commit 758f6c0a64
Initialized page_lifecycle_state_ (see diff against PS1).
Original change's description:
> [discard] Ensures FrameNodes transition lifecycle state correctly
>
> The current implementation of web-contents retaining tab discard
> can result in invalid lifecycle state transitions for frozen tabs.
>
> Consider the following event flow:
> 1. A tab is frozen
> 2. The same tab is then discarded
> 3. The page lifecycle state is synchronously updated to DISCARDED
> in TabLifecycleUnit::FinishDiscardAndPreserveWebContents()
> 4. The synchronous shutdown of the RenderProcessHost causes a
> FrameNodeObserver::OnFrameNodeRemoved() event to be queued
> on the performance manager graph thread
> 5. This changes the balance of frozen frames and the frame tree
> is interpreted as ACTIVE
> This queues a update-lifecycle-state ACTIVE event on the
> main thread
> 6. On the main thread a state transition from DISCARDED to ACTIVE
> is attempted (which is invalid, the tab is still discarded)
>
> This results in the tab being set to an invalid page lifecycle
> state. Consequently further discards may be attempted on the tab
> given it is flagged ACTIVE, however these will either fail or no-op
> as the tab is actually discarded.
>
> This CL addresses this issue by updating the TabLifecycleUnit to
> independently keep track of:
> - if the WebContents is discarded in `is_discarded_`
> - the page's LifecycleState in `page_lifecycle_state_`
> this is either kActive or kFrozen (kDiscarded is removed)
>
> The LifecycleUnitState is the computed based on the above. This is
> done since it is possible to end up with a discarded page who's
> lifecycle state is either kActive or kFrozen.
>
> Bug: 394242157
> Change-Id: I42517404b90ddd593c57e12b8bf48b4433e3227a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6229171
> Reviewed-by: Sam McNally <sammc@chromium.org>
> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
> Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1417926}
Bug: 394242157
Change-Id: Ia02ef7345691c60ed2019caecd27689ebca3b87a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6248477
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1418326}
This reverts commit 758f6c0a64.
Reason for revert: CI detected use of uninitialized value in https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20ChromiumOS%20MSan%20Tests/49913/overview.
Looks like page_lifecycle_state_ may be used before being initialized.
Original change's description:
> [discard] Ensures FrameNodes transition lifecycle state correctly
>
> The current implementation of web-contents retaining tab discard
> can result in invalid lifecycle state transitions for frozen tabs.
>
> Consider the following event flow:
> 1. A tab is frozen
> 2. The same tab is then discarded
> 3. The page lifecycle state is synchronously updated to DISCARDED
> in TabLifecycleUnit::FinishDiscardAndPreserveWebContents()
> 4. The synchronous shutdown of the RenderProcessHost causes a
> FrameNodeObserver::OnFrameNodeRemoved() event to be queued
> on the performance manager graph thread
> 5. This changes the balance of frozen frames and the frame tree
> is interpreted as ACTIVE
> This queues a update-lifecycle-state ACTIVE event on the
> main thread
> 6. On the main thread a state transition from DISCARDED to ACTIVE
> is attempted (which is invalid, the tab is still discarded)
>
> This results in the tab being set to an invalid page lifecycle
> state. Consequently further discards may be attempted on the tab
> given it is flagged ACTIVE, however these will either fail or no-op
> as the tab is actually discarded.
>
> This CL addresses this issue by updating the TabLifecycleUnit to
> independently keep track of:
> - if the WebContents is discarded in `is_discarded_`
> - the page's LifecycleState in `page_lifecycle_state_`
> this is either kActive or kFrozen (kDiscarded is removed)
>
> The LifecycleUnitState is the computed based on the above. This is
> done since it is possible to end up with a discarded page who's
> lifecycle state is either kActive or kFrozen.
>
> Bug: 394242157
> Change-Id: I42517404b90ddd593c57e12b8bf48b4433e3227a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6229171
> Reviewed-by: Sam McNally <sammc@chromium.org>
> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
> Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1417926}
Bug: 394242157
Change-Id: I86b23be78c81078b7afda9c0ff97cb543adeef9d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6242498
Commit-Queue: Jiacheng Guo <gjc@google.com>
Auto-Submit: Jiacheng Guo <gjc@google.com>
Owners-Override: Jiacheng Guo <gjc@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1417948}
The current implementation of web-contents retaining tab discard
can result in invalid lifecycle state transitions for frozen tabs.
Consider the following event flow:
1. A tab is frozen
2. The same tab is then discarded
3. The page lifecycle state is synchronously updated to DISCARDED
in TabLifecycleUnit::FinishDiscardAndPreserveWebContents()
4. The synchronous shutdown of the RenderProcessHost causes a
FrameNodeObserver::OnFrameNodeRemoved() event to be queued
on the performance manager graph thread
5. This changes the balance of frozen frames and the frame tree
is interpreted as ACTIVE
This queues a update-lifecycle-state ACTIVE event on the
main thread
6. On the main thread a state transition from DISCARDED to ACTIVE
is attempted (which is invalid, the tab is still discarded)
This results in the tab being set to an invalid page lifecycle
state. Consequently further discards may be attempted on the tab
given it is flagged ACTIVE, however these will either fail or no-op
as the tab is actually discarded.
This CL addresses this issue by updating the TabLifecycleUnit to
independently keep track of:
- if the WebContents is discarded in `is_discarded_`
- the page's LifecycleState in `page_lifecycle_state_`
this is either kActive or kFrozen (kDiscarded is removed)
The LifecycleUnitState is the computed based on the above. This is
done since it is possible to end up with a discarded page who's
lifecycle state is either kActive or kFrozen.
Bug: 394242157
Change-Id: I42517404b90ddd593c57e12b8bf48b4433e3227a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6229171
Reviewed-by: Sam McNally <sammc@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1417926}
This lets ScopedObservation<Graph, FrameNodeObserver> to automatically
call Graph::AddFrameNodeObserver/RemoveFrameNodeObserver, etc.
Converts the NodeImpl unit tests to use ScopedObservation to test that
the traits work.
Bug: pmonette
Change-Id: I163c6afa0ceea475cf2f5c4713afa2b26d1fe0b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6237540
Auto-Submit: Joe Mason <joenotcharles@google.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1417841}
To make performance scenarios build on iOS, adds a new subcomponent
of performance manager, components/performance_manager/scenario_api.
Unlike the main components/performance_manager this has no DEPS on
content/, so it can be used from content and blink.
The main performance_manager component isn't supported on iOS so
scenario_api calls will always return default state on that platform.
The existing headers in third_party/blink/public/common/performance/
are left in place as forwarding headers to minimize conflicts with
outstanding patches. They'll be removed once all patches land and
callers using the old headers are cleaned up.
Bug: 365586676
Change-Id: Iacc9efb9ecc01ed5a0dcacd7157b62870417e4de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6217760
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1416341}
The public API to query performance scenarios is in
//third_party/blink/public/common/performance/. An upcoming patch will
move this into performance_manager so it can be used on iOS, which
can't include blink. To avoid confusion, this patch gets rid of
performance_manager/public/scenarios.
The only class that was actually used outside performance_manager was
ScopedGlobalScenarioMemory, used by embedders to set up the scenario
memory. Moves this to
performance_manager/embedder/scoped_global_scenario_memory.h.
The other classes and functions are used to manipulate scenarios in the
browser process, so they're moved to
performance_manager/scenarios/browser_performance_scenarios.h.
Bug: 365586676
Change-Id: I270bf9d3fee8150d217cbf9cf37724340bdd5be9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6217923
Commit-Queue: Joe Mason <joenotcharles@google.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1416191}
Every time a CPU measurement is received, this CL invokes for each page
a method with all the necessary information to emit the event described
in go/ukm-review-background-tab-freezing. We'll add the code to emit
the UKM event once it is approved.
Bug: 391646022
Change-Id: I758609fa78aa18dec644caf3fc187fcf4dffd5b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6208180
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413718}
This CL is the first in a series of CLs to implement a Default Search
Engine Keep Alive policy through the Performance Manager.
This CL connects the KeepAliveDSEPolicy to
ChromeBrowserMainExtraPartsPerformanceManager and retrieves the user's
default search engine.
No functional changes are expected in this CL.
Bug:365958798
Change-Id: I2894188b6d4117b606334413a66bd68422ceef9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6000476
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Alex Attar <aattar@google.com>
Cr-Commit-Position: refs/heads/main@{#1413219}
This CL replaces the boolean indicating whether a browsing instance
was "CPU intensive in background" with the highest CPU measurement
that occurred for a group of same-origin frames/workers within the
browsing instance while no CannotFreezeReason was applicable. This will
be used to build a UKM about freezing eligibility:
go/ukm-review-background-tab-freezing
Bug: 391646022
Change-Id: If6aed406f06b353a748e1280621183610f3cabb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6208868
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413195}
This CL replaces the boolean indicating whether any CannotFreezeReason
was applicable to a browsing instance at some point since the last
CPU measurement with a CannotFreezeReasonSet. This will be used to
build a UKM about freezing eligibility:
go/ukm-review-background-tab-freezing
Bug: 391646022
Change-Id: I235fc780f7d896ae5df84dce9e65035451a31ba2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6208269
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413193}
Now that the performance manager lives on the UI thread, any work
that must be done as soon as the frame node is created can be done
synchronously after calling CreateFrameNode().
Bug: 40755583
Change-Id: I47c99419ba06ea5e80ac80ce88cb85b53510dfff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6207991
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1413175}
In a content::ContentBrowserTest, SetUp() is responsible for running
the entire test. This means that after
content::ContentBrowserTest::SetUp() is called. The test has already
ran to completion. Doing a wait there to ensure the graph callback
was called is unnecessary and would not ensure that the callback was
called in time for the test anyways.
Change-Id: I4585a601985a28a5f3057a63b02967e1ebca6637
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6214090
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413149}
When the test suite was created, some facilities didn't exist, like
PerformanceManager::GetProcessNodeForRenderProcessHost() or
PerformanceManagerRegistryImpl::GetWorkerWatcherForTesting(). To work
around it, ProcessNodeSource and FrameNodeSource were added.
This change refactors WorkerWatcherTest to use those facilities. This
allows the removal of the ProcessNodeSource class. Additionally, now
nodes are held using WeakPtr, which is easier to work with (Can use
EXPECT_FALSE(node) to check if the node was really destroyed).
The end results is the same tests with less code.
Also get rid of RunOnGraph() usage now that the performance manager
lives on the UI thread.
Bug: 40755583
Change-Id: I579c06cd11e2f1b7ac1cc81470f50bef93aebfda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180100
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411968}
This change also fixes the battery discharge rate metric on ChromeOS,
since the new implementation accounts for the samples coming in every
30 seconds.
Change-Id: I12f2929d2b898d0e793d3a81770366d9c8134176
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6169264
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1410658}
This CL adds checks to validate that WasDiscarded isn't set correctly,
in preparation for removing it. The checks also serve as documentation
for anyone who looks at code that accesses the property.
Bug: 391179510
Change-Id: I9330a143098c4cabf49661abd460a6e638125205
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6185545
Auto-Submit: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1409268}
Now that the performance manager graph lives on the main thread, code
can simply be invoked synchronously instead of using RunInGraph().
Bug: 40755583
Change-Id: Iebe1dd0e01c0a1215903b9ce7f7093256044fb87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6171834
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1405703}