[bedrock] Migrate chrome_visibility_observer.cc away from BrowserListObserver. [chromium/src : main]

0 views
Skip to first unread message

Glenn Hartmann (Gerrit)

unread,
Dec 19, 2025, 9:43:39 AM12/19/25
to Chromium Metrics Reviews, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com

New activity on the change

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
Gerrit-Change-Number: 7112165
Gerrit-PatchSet: 29
Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
Gerrit-Reviewer: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
Gerrit-Comment-Date: Fri, 19 Dec 2025 14:43:32 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

gwsq (Gerrit)

unread,
Dec 19, 2025, 9:48:56 AM12/19/25
to Glenn Hartmann, Chromium Metrics Reviews, Luc Nguyen, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com
Attention needed from Luc Nguyen

Message from gwsq

Reviewer source(s):
lucn...@google.com is from context(analysis/uma/chrome-metrics.gwsq)

Open in Gerrit

Related details

Attention is currently required from:
  • Luc Nguyen
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
Gerrit-Change-Number: 7112165
Gerrit-PatchSet: 29
Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: gwsq
Gerrit-Attention: Luc Nguyen <lucn...@google.com>
Gerrit-Comment-Date: Fri, 19 Dec 2025 14:48:45 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Luc Nguyen (Gerrit)

unread,
Jan 6, 2026, 9:35:32 PM (11 days ago) Jan 6
to Glenn Hartmann, Chromium Metrics Reviews, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com
Attention needed from Glenn Hartmann

Luc Nguyen added 2 comments

File chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h
Line 38, Patchset 29 (Latest): void OnBrowserActivated(BrowserWindowInterface* browser) override;
void OnBrowserDeactivated(BrowserWindowInterface* browser) override;
void OnBrowserClosed(BrowserWindowInterface* browser) override;
Luc Nguyen . unresolved

sanity check: i'm not exactly familiar with the migration from `BrowserListObserver` to `BrowserCollectionObserver` -- is the latter intended to be the exact same behaviour as the former? i'm looking at when the `BrowserListObserver` functions are called vs `BrowserCollectionObserver` and i can't seem to find any trivial link between the two

if possible, could you possibly share code pointers on how exactly those two are linked?

for context, this class (`ChromeVisibilityObserver`) backs one of our most crucial metric (`Session.TotalDuration`) on Desktop so any behaviour change (however small it may seem, especially one that might not get picked up by our existing tests) would need to be vetted first

File chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer_interactive_uitest.cc
Line 96, Patchset 29 (Latest): // process. (Ideally we would want the observer to start after
// g_browser_process is initialized, but before a browser instance is created
// - but this is difficult or impossible with the way InProcessBrowserTest
// currently works). So we start by closing that browser and replacing it with
// one of our own, which the observer will know about.
Luc Nguyen . unresolved

hmm... so IIUC, `BrowserCollectionObserver` currently doesn't have support for observing the actual/first browser in a browsertest? that feels like a pretty big hole in terms of test coverage... is there any work being done to support this?

Open in Gerrit

Related details

Attention is currently required from:
  • Glenn Hartmann
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Gerrit-Change-Number: 7112165
    Gerrit-PatchSet: 29
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
    Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
    Gerrit-CC: gwsq
    Gerrit-Attention: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Comment-Date: Wed, 07 Jan 2026 02:35:27 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Glenn Hartmann (Gerrit)

    unread,
    Jan 9, 2026, 4:09:49 PM (8 days ago) Jan 9
    to Chromium Metrics Reviews, Luc Nguyen, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com
    Attention needed from Luc Nguyen

    Glenn Hartmann added 2 comments

    File chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h
    Line 38, Patchset 29: void OnBrowserActivated(BrowserWindowInterface* browser) override;

    void OnBrowserDeactivated(BrowserWindowInterface* browser) override;
    void OnBrowserClosed(BrowserWindowInterface* browser) override;
    Luc Nguyen . unresolved

    sanity check: i'm not exactly familiar with the migration from `BrowserListObserver` to `BrowserCollectionObserver` -- is the latter intended to be the exact same behaviour as the former? i'm looking at when the `BrowserListObserver` functions are called vs `BrowserCollectionObserver` and i can't seem to find any trivial link between the two

    if possible, could you possibly share code pointers on how exactly those two are linked?

    for context, this class (`ChromeVisibilityObserver`) backs one of our most crucial metric (`Session.TotalDuration`) on Desktop so any behaviour change (however small it may seem, especially one that might not get picked up by our existing tests) would need to be vetted first

    Glenn Hartmann

    sanity check: i'm not exactly familiar with the migration from `BrowserListObserver` to `BrowserCollectionObserver` -- is the latter intended to be the exact same behaviour as the former?

    They are intended to be equivalent, yes.

    i'm looking at when the `BrowserListObserver` functions are called vs `BrowserCollectionObserver` and i can't seem to find any trivial link between the two

    if possible, could you possibly share code pointers on how exactly those two are linked?

    Yeah, the relationship is not trivial. In the old world, BrowserList was the only list of browsers, and it was globally-scoped.

    However, there are many cases when we only need to observe browsers of a given profile rather than all browsers. So in the new world, each profile owns its own browsers, via BrowserManagerService (https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/browser_manager_service.h). Each BrowserManagerService implements ProfileBrowserCollection, which, as the name implies, is an observable collection of browsers in that profile.

    GlobalBrowserCollection observes every ProfileBrowserCollection to combine all the browsers into a global list which should be equivalent to the original BrowserList concept. That means there's a bit of extra indirection, hence why it's not immediately obvious that BrowserList and GlobalBrowserCollection behave the same.

    I think the situation is most easily conveyed with diagrams, so here you go: https://drive.google.com/drive/folders/1UmTddiO5sNe-ABbUrua9HieShdscVWcO?usp=sharing

    File chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer_interactive_uitest.cc
    Line 96, Patchset 29: // process. (Ideally we would want the observer to start after

    // g_browser_process is initialized, but before a browser instance is created
    // - but this is difficult or impossible with the way InProcessBrowserTest
    // currently works). So we start by closing that browser and replacing it with
    // one of our own, which the observer will know about.
    Luc Nguyen . resolved

    hmm... so IIUC, `BrowserCollectionObserver` currently doesn't have support for observing the actual/first browser in a browsertest? that feels like a pretty big hole in terms of test coverage... is there any work being done to support this?

    Glenn Hartmann

    I did some more research, and did manage to find a way to make this work. It's not too pretty, though.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Luc Nguyen
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Gerrit-Change-Number: 7112165
    Gerrit-PatchSet: 30
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
    Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
    Gerrit-CC: gwsq
    Gerrit-Attention: Luc Nguyen <lucn...@google.com>
    Gerrit-Comment-Date: Fri, 09 Jan 2026 21:09:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Luc Nguyen <lucn...@google.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Luc Nguyen (Gerrit)

    unread,
    Jan 12, 2026, 1:41:29 PM (5 days ago) Jan 12
    to Glenn Hartmann, Chromium Metrics Reviews, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com
    Attention needed from Glenn Hartmann

    Luc Nguyen voted and added 2 comments

    Votes added by Luc Nguyen

    Code-Review+1

    2 comments

    Patchset-level comments
    File-level comment, Patchset 30 (Latest):
    Luc Nguyen . resolved

    thanks a lot and sorry for the delay!

    File chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h
    Line 38, Patchset 29: void OnBrowserActivated(BrowserWindowInterface* browser) override;
    void OnBrowserDeactivated(BrowserWindowInterface* browser) override;
    void OnBrowserClosed(BrowserWindowInterface* browser) override;
    Luc Nguyen . resolved

    sanity check: i'm not exactly familiar with the migration from `BrowserListObserver` to `BrowserCollectionObserver` -- is the latter intended to be the exact same behaviour as the former? i'm looking at when the `BrowserListObserver` functions are called vs `BrowserCollectionObserver` and i can't seem to find any trivial link between the two

    if possible, could you possibly share code pointers on how exactly those two are linked?

    for context, this class (`ChromeVisibilityObserver`) backs one of our most crucial metric (`Session.TotalDuration`) on Desktop so any behaviour change (however small it may seem, especially one that might not get picked up by our existing tests) would need to be vetted first

    Glenn Hartmann

    sanity check: i'm not exactly familiar with the migration from `BrowserListObserver` to `BrowserCollectionObserver` -- is the latter intended to be the exact same behaviour as the former?

    They are intended to be equivalent, yes.

    i'm looking at when the `BrowserListObserver` functions are called vs `BrowserCollectionObserver` and i can't seem to find any trivial link between the two

    if possible, could you possibly share code pointers on how exactly those two are linked?

    Yeah, the relationship is not trivial. In the old world, BrowserList was the only list of browsers, and it was globally-scoped.

    However, there are many cases when we only need to observe browsers of a given profile rather than all browsers. So in the new world, each profile owns its own browsers, via BrowserManagerService (https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/browser_manager_service.h). Each BrowserManagerService implements ProfileBrowserCollection, which, as the name implies, is an observable collection of browsers in that profile.

    GlobalBrowserCollection observes every ProfileBrowserCollection to combine all the browsers into a global list which should be equivalent to the original BrowserList concept. That means there's a bit of extra indirection, hence why it's not immediately obvious that BrowserList and GlobalBrowserCollection behave the same.

    I think the situation is most easily conveyed with diagrams, so here you go: https://drive.google.com/drive/folders/1UmTddiO5sNe-ABbUrua9HieShdscVWcO?usp=sharing

    Luc Nguyen

    thanks a lot for the indepth explanation and context!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Glenn Hartmann
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Gerrit-Change-Number: 7112165
    Gerrit-PatchSet: 30
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
    Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
    Gerrit-CC: gwsq
    Gerrit-Attention: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Comment-Date: Mon, 12 Jan 2026 18:41:20 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Luc Nguyen <lucn...@google.com>
    Comment-In-Reply-To: Glenn Hartmann <hart...@chromium.org>
    satisfied_requirement
    open
    diffy

    Glenn Hartmann (Gerrit)

    unread,
    Jan 12, 2026, 1:48:31 PM (5 days ago) Jan 12
    to Luc Nguyen, Chromium Metrics Reviews, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com

    Glenn Hartmann voted Commit-Queue+2

    Commit-Queue+2
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Gerrit-Change-Number: 7112165
    Gerrit-PatchSet: 30
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
    Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
    Gerrit-CC: gwsq
    Gerrit-Comment-Date: Mon, 12 Jan 2026 18:48:23 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Chromium LUCI CQ (Gerrit)

    unread,
    Jan 12, 2026, 2:40:09 PM (5 days ago) Jan 12
    to Glenn Hartmann, Luc Nguyen, Chromium Metrics Reviews, AyeAye, chromium...@chromium.org, zackha...@chromium.org, vakh+safe_br...@chromium.org, xinghui...@chromium.org, druber...@chromium.org, nwoked...@chromium.org, andysjl...@chromium.org, asvitki...@chromium.org, chrome-gr...@chromium.org, chromium-a...@chromium.org, chromiumme...@microsoft.com, dmurph+watchin...@chromium.org, dmurph+wat...@chromium.org, grt+...@chromium.org, jatapiaro+wat...@google.com, loyso...@chromium.org, lwinston+watc...@google.com, mac-r...@chromium.org, mgiuca...@chromium.org, rginda...@chromium.org, trewin...@google.com, webap...@microsoft.com

    Chromium LUCI CQ submitted the change

    Change information

    Commit message:
    [bedrock] Migrate chrome_visibility_observer.cc away from BrowserListObserver.

    This migration is part of project bedrock to reduce the dependencies on
    Browser and BrowserList. See https://crbug.com/431671320 for more info.
    Bug: 459777668
    Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Commit-Queue: Glenn Hartmann <hart...@chromium.org>
    Reviewed-by: Luc Nguyen <lucn...@google.com>
    Cr-Commit-Position: refs/heads/main@{#1567946}
    Files:
    • M chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.cc
    • M chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h
    • M chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer_interactive_uitest.cc
    • M chrome/browser/metrics/desktop_session_duration/touch_ui_controller_stats_tracker_unittest.cc
    Change size: M
    Delta: 4 files changed, 117 insertions(+), 33 deletions(-)
    Branch: refs/heads/main
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by Luc Nguyen
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I0eabcd05a631916243b347fef9a2e1636a6a6964
    Gerrit-Change-Number: 7112165
    Gerrit-PatchSet: 31
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Luc Nguyen <lucn...@google.com>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages