0
Commit Graph

1298 Commits

Author SHA1 Message Date
Patrick Monette
2227fb5686 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I5edbcf62842397963cfc3f21d63a2343a9df7d99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284725
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1423967}
2025-02-24 09:55:07 -08:00
Patrick Monette
dbdbc1d2bc [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I08a251dd57c124928ebdb350ac752d01a9bcc3b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6299232
Commit-Queue: Joe Mason <joenotcharles@google.com>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1423965}
2025-02-24 09:42:20 -08:00
Patrick Monette
d95d38b005 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: Ia753a177008c462153b4212c5728d0c613696b25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284308
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1423113}
2025-02-21 07:07:39 -08:00
Patrick Monette
48df50471b [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I61bfb518db719c4da5c7b00926bb1754a824dd29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284686
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1423101}
2025-02-21 06:47:23 -08:00
Patrick Monette
6d7e7acf05 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: Icf42962096b9851289477f17a926bd0813d038a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284685
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1422934}
2025-02-20 20:53:25 -08:00
Patrick Monette
c6c524153e [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I45b1df2a932aa74105f90240b804f8cf7fd78e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284785
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1422854}
2025-02-20 15:44:47 -08:00
Patrick Monette
51f0397ffb [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I96e3cc44b1946e84605a3ec1f60041a435a05e0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284746
Reviewed-by: Joe Mason <joenotcharles@google.com>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1422847}
2025-02-20 15:33:33 -08:00
Patrick Monette
9928270d02 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I97400c4d0f796fe1eb265f66cda84b24619b770f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284705
Reviewed-by: Joe Mason <joenotcharles@google.com>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1422845}
2025-02-20 15:31:13 -08:00
Patrick Monette
908a725e17 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: Id00ef39f891380c54eca6227456923956d565a6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284745
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1422663}
2025-02-20 10:26:27 -08:00
Patrick Monette
2fe5d36b62 [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I1f6a798881b78f42e9b9bfe9420132dcba6cc59e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284306
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1422584}
2025-02-20 08:07:02 -08:00
Patrick Monette
109c01da3f [PM] Migrate uses of CallOnGraph/RunInGraph
The performance manager now lives on the UI thread, making
these functions obsolete.

The graph can be directly accessed through the
PerformanceManager::GetGraph() function.

This CL was uploaded by git cl split.

R=joenotcharles@google.com

Bug: 40755583
Change-Id: I24350e4d8f7a6bd1f4d610eb2acb796e4495d962
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6284547
Auto-Submit: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1422573}
2025-02-20 07:59:31 -08:00
Patrick Monette
9bbabd144e [PM] SetViewportIntersectionImpl: Use ReportBadMessage instead of CHECK
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}
2025-02-19 08:00:56 -08:00
David Sanders
4eb00ba902 Remove unused include in //base/values.h
Adds missing includes to other files as needed to fix the build.

Bug: 40318405
Change-Id: I86ad08f3d37a507fc7cf19fa48cb95b5fc73dff5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6255498
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1419873}
2025-02-13 07:02:39 -08:00
Jiahe Zhang
4e2e2e632a Detect typing scenario in Performance Manager
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}
2025-02-12 22:12:18 -08:00
Joe Mason
7c58bc4f54 Persist PageLiveStateDecoratorData::IsAutoDiscardable across discards
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}
2025-02-12 13:17:39 -08:00
Joe Mason
77c8dba64a Reland "Remove CallOnGraph calls from PageLiveStateDecorator and test"
This is a reland of commit f922d8c56f

It fixes a crash caused by state updated from observers while a node
is being torn down.

Original change's description:
> Remove CallOnGraph calls from PageLiveStateDecorator and test
>
> R=pmonette
>
> Bug: 40755583
> Change-Id: Id429c47f7a451cf4f148e62a39a40a9fc61bac1f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6248265
> 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@{#1418275}

Bug: 40755583
Change-Id: I01a46336ac8f68cc76edc95a4d0f25cf6fef34fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6250049
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1419510}
2025-02-12 13:14:42 -08:00
Joe Mason
588de76b0a Add tests of PerformanceManager node accessors during add/remove observers
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}
2025-02-12 13:11:28 -08:00
Joe Mason
b897743691 Move test worker factories into PerformanceManagerTestHarness
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}
2025-02-12 10:42:55 -08:00
David Sanders
958dcc154a Do IWYU for page_node.h
Also replaces some includes with forward declarations.

Bug: 40318405
Change-Id: I52855511b3358e0f790709a36f4712103f06f728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6251884
Commit-Queue: David Sanders <dsanders11@ucsbalum.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1418784}
2025-02-11 11:25:01 -08:00
Thomas Lukaszewicz
ad1a8ff38d Reland "[discard] Ensures FrameNodes transition lifecycle state correctly"
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}
2025-02-10 15:16:45 -08:00
Yue Zhang
a495a04910 Revert "Remove CallOnGraph calls from PageLiveStateDecorator and test"
This reverts commit f922d8c56f.

Reason for revert: Potential culprit for multiple failures on Clank. See b/395695315 for more details.

Original change's description:
> Remove CallOnGraph calls from PageLiveStateDecorator and test
>
> R=pmonette
>
> Bug: 40755583
> Change-Id: Id429c47f7a451cf4f148e62a39a40a9fc61bac1f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6248265
> 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@{#1418275}

Bug: 40755583
Change-Id: I91ce4ea0e9611ea723f531988a4ac94d26aff842
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6249599
Auto-Submit: Yue Zhang <yuezhanggg@chromium.org>
Owners-Override: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: Yue Zhang <yuezhanggg@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1418314}
2025-02-10 14:05:10 -08:00
Joe Mason
f922d8c56f Remove CallOnGraph calls from PageLiveStateDecorator and test
R=pmonette

Bug: 40755583
Change-Id: Id429c47f7a451cf4f148e62a39a40a9fc61bac1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6248265
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@{#1418275}
2025-02-10 11:08:48 -08:00
Jiacheng Guo
d7095ba560 Revert "[discard] Ensures FrameNodes transition lifecycle state correctly"
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}
2025-02-09 18:52:44 -08:00
Thomas Lukaszewicz
758f6c0a64 [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}
2025-02-09 15:58:08 -08:00
Joe Mason
48ac2fabb4 Add ScopedObservation traits for graph observers
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}
2025-02-08 21:03:36 -08:00
Joe Mason
92ccdc87df Move performance scenario headers out of blink
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}
2025-02-05 11:17:23 -08:00
Joe Mason
a23aedf6db Remove performance_manager/public/scenarios
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}
2025-02-05 08:28:52 -08:00
Joe Mason
35c94706cf [PM] Remove GetWeakPtrOnUIThread
Now that Performance Manager runs on the main thread, this is the same
as GetWeakPtr().

Bug: 40755583
Change-Id: I02a12759000fabb7a3fff903f52cb29a2a9ef8e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6216679
Auto-Submit: Joe Mason <joenotcharles@google.com>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415643}
2025-02-04 09:59:04 -08:00
François Doray
e189c469f3 [freezing] Rename browsing_instances_ -> browsing_instance_states_.
Change-Id: I3317b7c564cbb291a0c1b21b7990178b104a11fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6219349
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415573}
2025-02-04 07:57:25 -08:00
François Doray
ea20507163 [freezing] Emit the FreezingEligibility UKM event.
go/ukm-review-background-tab-freezing

Fixed: 391646022
Change-Id: I2bd2952b3436d605177e48658bffcf5bb3de5f8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6226359
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415170}
2025-02-03 13:34:37 -08:00
David Sanders
daf3ddcf39 Remove unused include in page_live_state_decorator.h
Also removes a forward declaration which has no effect since the header
is being included.

Bug: 40318405
Change-Id: I28503870cc3bebb671a57dd2bd7a2c931f8c5161
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6181693
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415131}
2025-02-03 12:40:37 -08:00
Greg Thompson
9ec0679024 [performance_manager] Remove dead code
- r1341581: Maintain a PageNode's AXMode in its LiveState
- r1341520: Add an operation for visiting a page and its embeds

Bug: 40925658
Change-Id: Ia534aaf3f7d26e5b46a70819d1ee2175f40ac23a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6216875
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Auto-Submit: Greg Thompson <grt@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1414089}
2025-01-31 06:52:15 -08:00
François Doray
d0feaee367 [freezing] Prepare for emitting freezing eligibility UKM event.
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}
2025-01-30 13:15:05 -08:00
Alex Attar
4c7f21fccc Add KeepAliveDSEPolicy to ChromeBrowserMainExtraPartsPerformanceManager.
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}
2025-01-29 15:41:23 -08:00
François Doray
5f0fec1eae [freezing] Track highest CPU measurement without a CannotFreezeReason.
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}
2025-01-29 14:58:58 -08:00
François Doray
08c1fc4552 [freezing] Track CannotFreezeReasons applicable since last CPU measurement.
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}
2025-01-29 14:57:47 -08:00
Patrick Monette
bfa541dc77 Remove FrameNodeCreationCallback
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}
2025-01-29 14:19:24 -08:00
Joe Mason
33ffdd6595 [PM] Fix threading description in README
R=pmonette

Bug: 40755583
Change-Id: I1c62db77a76973dfa164990246fa7ac39256d246
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6214332
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Auto-Submit: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1413162}
2025-01-29 13:55:32 -08:00
Patrick Monette
05cca03435 PerformanceManagerBrowserTestHarness::SetUp: Remove superfluous wait
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}
2025-01-29 13:41:07 -08:00
Tom Sepez
8726d30ed0 Suppress unsafe_libc_call warning for initial identified files.
See docs/unsafe_buffers.md for details. Enforcement is not yet
enabled, but this set of files are not in compliance with the
new warnings.

Bug: 390223051
Change-Id: I4e24c2141b9399f572678302c833947494098b29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6187925
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1412673}
2025-01-28 18:11:08 -08:00
Patrick Monette
1f3dc3cf2d Modernize WorkerWatcherTest
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}
2025-01-27 16:13:51 -08:00
Joe Laughlin
6d6b5f2d99 Remove unused performance manager policies
Change-Id: I29c1940f22d6cd150b6934c6eb49a6e5a4e6aaeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6199304
Commit-Queue: Joe Laughlin <joel@microsoft.com>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411843}
2025-01-27 12:55:41 -08:00
Thomas Lukaszewicz
088770a12a [discard] Prevent renderer events changing lifecycle state post discard
This CL ensures that FrameNodeImpl's DocumentCoordinationUnit receiver_
is reset immediately when a discard is initiated in the browser.

This is done to ensure messages queued by the discarded frame's
document before discard are dropped. The receiver is already reset for
similar reasons in FrameNodeImpl::OnNavigationCommitted() [1].

Practically there are reports of queued renderer-initiated page
lifecycle update events attempting invalid lifecycle state
transitions when they are processed following a discard in the
browser process (see bug for example crash reports).

[1] https://source.chromium.org/chromium/chromium/src/+/main:components/performance_manager/graph/frame_node_impl.cc;l=586;drc=6cf4c37f9d3ad30a2ed31e723a38a828655df165

Bug: 391723297
Change-Id: I3263f0642ad734046bbc39b8e205be5194309728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6193310
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411733}
2025-01-27 10:40:00 -08:00
Peter Kasting
ccea09835f [cleanup] Replace base::ranges with std::ranges: components/
Done entirely with `git grep` and `sed` + `git cl format`, no
hand-editing.

Bug: 386918226
Change-Id: I7377af2f9c3758c68a249b421d98bd3fd5c2c1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6201377
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411730}
2025-01-27 10:38:22 -08:00
Patrick Monette
48c9abef58 Refactor BatteryDischargeProvider
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}
2025-01-23 17:07:16 -08:00
Patrick Monette
15442a11e7 Avoid including web_contents.h in web_contents_observer.h
A previous change added the CapabilityType as an inner enum of
WebContents which forced the inclusion of web_contents.h in
web_contents_observer.h.
See https://chromium-review.googlesource.com/c/chromium/src/+/5938280

This change moves the enum to its own file to avoid this as
web_contents.h is a huge header, making it worth to avoid including
when not needed.

Change-Id: I37fdf6c5443c242557a5c1c32fa1a7688fde8738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180166
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Andy Paicu <andypaicu@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1409875}
2025-01-22 12:09:31 -08:00
François Doray
76652c380e [performance manager] Validate that WasDiscarded isn't set correctly.
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}
2025-01-21 13:59:18 -08:00
Patrick Monette
d41fd42d24 [PM] Remove usage of GetDeprecatedID()
Bug: 379869738
Change-Id: I8edf9b69089c0af8fd7608fdb6255b560e4854ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6173063
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1408680}
2025-01-20 07:46:33 -08:00
Evan Stade
7ed0da5777 Mechanical updates in support of rolling third_party/protobuf
refer to C++ built in types directly. Newer versions of protobuf don't
have google::protobuf aliases for them.

Bug: 328417294
Change-Id: I701a6301f4fabdf2ea09bfca9479a0e23bd92a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6180719
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1407906}
2025-01-17 07:23:23 -08:00
Patrick Monette
350030c052 [PM] Remove usage of RunInGraph (2/n)
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}
2025-01-13 13:05:24 -08:00