Implement BrowserCollectionObserver and ProfileBrowsers. [chromium/src : main]

0 views
Skip to first unread message

Glenn Hartmann (Gerrit)

unread,
Nov 5, 2025, 2:09:58 PMNov 5
to Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
Attention needed from Tom Lukaszewicz

Glenn Hartmann voted and added 1 comment

Votes added by Glenn Hartmann

Commit-Queue+1

1 comment

Patchset-level comments
Open in Gerrit

Related details

Attention is currently required from:
  • Tom Lukaszewicz
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: I985ca0ceb68c72d97ea5721951fcc81d6a6a6964
Gerrit-Change-Number: 7088443
Gerrit-PatchSet: 15
Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Comment-Date: Wed, 05 Nov 2025 19:09:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Tom Lukaszewicz (Gerrit)

unread,
Nov 6, 2025, 4:48:22 AMNov 6
to Glenn Hartmann, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
Attention needed from Glenn Hartmann

Tom Lukaszewicz added 7 comments

Patchset-level comments
Tom Lukaszewicz . resolved

Overall looks great!

File chrome/browser/ui/browser.cc
Line 1287, Patchset 15 (Latest): BrowserManagerServiceFactory::GetForProfile(GetProfile())
->OnBrowserDidBecomeActive(this);
Tom Lukaszewicz . unresolved

Since `BrowserManagerService` owns `BrowserWindowInterface` instances would it work to register listeners on the specific instances each service is responsible for to avoid relying on `Browser` to deliver these updates?

Dealing with the callback subscription handles seems like it might be annoying but the upside is we wouldn't need to expose `BrowserManagerService::OnBrowserDidBecomeActive/Inactive()`

File chrome/browser/ui/browser_manager_service.h
Line 46, Patchset 15 (Latest): // ProfileBrowsers
Tom Lukaszewicz . unresolved

trivial nit: We typically add a trailing colon by convention

File chrome/browser/ui/browser_manager_service_browsertest.cc
Line 44, Patchset 15 (Latest): void CloseBrowser(Profile* profile, Browser* browser) {
BrowserManagerServiceFactory::GetForProfile(profile)->DeleteBrowser(
browser);
}
Tom Lukaszewicz . unresolved

nit: We should be able to use `InProcessBrowserTest::CloseBrowserSynchronously()`

Line 49, Patchset 15 (Latest): void ActivatePrimaryBrowser(Browser* const secondary_browser) {
Tom Lukaszewicz . unresolved

I wonder if we should attempt to activate browsers using the [`BrowserActivationWaiter`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/interactive_test_utils.h;l=42;drc=e44b92356d4568bf5f3d7a78ed75d2356b3d2871) (this does mean it would need to be an interactive_ui_test however).

File chrome/browser/ui/browser_window/public/profile_browsers.h
Line 15, Patchset 15 (Latest): static ProfileBrowsers* GetForProfile(Profile* profile);
Tom Lukaszewicz . unresolved

nit: We should add a virtual defaulted destructor also.

Line 13, Patchset 15 (Latest):class ProfileBrowsers {
Tom Lukaszewicz . unresolved

nit: Could we add a brief comment describing the responsibility / functionality of ProfileBrowsers?

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: I985ca0ceb68c72d97ea5721951fcc81d6a6a6964
    Gerrit-Change-Number: 7088443
    Gerrit-PatchSet: 15
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Comment-Date: Thu, 06 Nov 2025 09:47:51 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Glenn Hartmann (Gerrit)

    unread,
    Nov 6, 2025, 3:15:53 PMNov 6
    to Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
    Attention needed from Tom Lukaszewicz

    Glenn Hartmann added 7 comments

    File chrome/browser/ui/browser.cc
    Line 1287, Patchset 15: BrowserManagerServiceFactory::GetForProfile(GetProfile())
    ->OnBrowserDidBecomeActive(this);
    Tom Lukaszewicz . unresolved

    Since `BrowserManagerService` owns `BrowserWindowInterface` instances would it work to register listeners on the specific instances each service is responsible for to avoid relying on `Browser` to deliver these updates?

    Dealing with the callback subscription handles seems like it might be annoying but the upside is we wouldn't need to expose `BrowserManagerService::OnBrowserDidBecomeActive/Inactive()`

    Glenn Hartmann

    hmm, good point. It is a bit of a pain to manage the subscriptions, but I gave it a go.

    btw, why does BrowserManagerService never remove anything from its `browsers_` vector? Just because we don't expect it to ever grow very big?

    File chrome/browser/ui/browser_manager_service.h
    Line 46, Patchset 15: // ProfileBrowsers
    Tom Lukaszewicz . resolved

    trivial nit: We typically add a trailing colon by convention

    Glenn Hartmann

    Done

    File chrome/browser/ui/browser_manager_service.cc
    Line 23, Patchset 15: // TODO: is it possible for |browser_ptr| to get deleted part-way through?
    Glenn Hartmann . unresolved

    any thoughts on this in particular?

    File chrome/browser/ui/browser_manager_service_browsertest.cc
    Line 44, Patchset 15: void CloseBrowser(Profile* profile, Browser* browser) {
    BrowserManagerServiceFactory::GetForProfile(profile)->DeleteBrowser(
    browser);
    }
    Tom Lukaszewicz . resolved

    nit: We should be able to use `InProcessBrowserTest::CloseBrowserSynchronously()`

    Glenn Hartmann

    Done

    Line 49, Patchset 15: void ActivatePrimaryBrowser(Browser* const secondary_browser) {
    Tom Lukaszewicz . unresolved

    I wonder if we should attempt to activate browsers using the [`BrowserActivationWaiter`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/interactive_test_utils.h;l=42;drc=e44b92356d4568bf5f3d7a78ed75d2356b3d2871) (this does mean it would need to be an interactive_ui_test however).

    Glenn Hartmann

    I tried, but couldn't get it working. Maybe I'm doing something wrong, but here's a minimal repro of my issue: https://chromium-review.googlesource.com/c/chromium/src/+/7127225

    That consistently times out on my machine.

    File chrome/browser/ui/browser_window/public/profile_browsers.h
    Line 15, Patchset 15: static ProfileBrowsers* GetForProfile(Profile* profile);
    Tom Lukaszewicz . resolved

    nit: We should add a virtual defaulted destructor also.

    Glenn Hartmann

    Done

    Line 13, Patchset 15:class ProfileBrowsers {
    Tom Lukaszewicz . resolved

    nit: Could we add a brief comment describing the responsibility / functionality of ProfileBrowsers?

    Glenn Hartmann

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Tom Lukaszewicz
    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: I985ca0ceb68c72d97ea5721951fcc81d6a6a6964
    Gerrit-Change-Number: 7088443
    Gerrit-PatchSet: 16
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Comment-Date: Thu, 06 Nov 2025 20:15:48 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Tom Lukaszewicz <tl...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Tom Lukaszewicz (Gerrit)

    unread,
    Nov 7, 2025, 12:19:37 AMNov 7
    to Glenn Hartmann, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
    Attention needed from Glenn Hartmann

    Tom Lukaszewicz voted and added 4 comments

    Votes added by Tom Lukaszewicz

    Code-Review+1

    4 comments

    Patchset-level comments
    File-level comment, Patchset 16 (Latest):
    Tom Lukaszewicz . resolved

    Still looks good - just a few nits

    File chrome/browser/ui/browser_manager_service.h
    Line 41, Patchset 16 (Latest): struct BrowserAndSubscriptions {
    Tom Lukaszewicz . unresolved

    nit: It's probably sufficient to have this be a pair of `std::pair<std::unique_ptr<Browser>, std::vector<base::CallbackListSubscription>>` instead (since we don't really care about differentiating between the subscriptions, we just need to hang onto the handles).

    File chrome/browser/ui/browser_manager_service.cc
    Line 23, Patchset 15: // TODO: is it possible for |browser_ptr| to get deleted part-way through?
    Glenn Hartmann . unresolved

    any thoughts on this in particular?

    Tom Lukaszewicz

    It's technically possible though should be very unlikely (there aren't any actions I'm aware of that would reasonably lead to the destruction of that same browser being created).

    If we wanted to be extra careful though we could get a WeakPtr to the BWI before notifying and check this before notifying any clients if its end up going away.

    File chrome/browser/ui/browser_manager_service_browsertest.cc
    Line 49, Patchset 15: void ActivatePrimaryBrowser(Browser* const secondary_browser) {
    Tom Lukaszewicz . unresolved

    I wonder if we should attempt to activate browsers using the [`BrowserActivationWaiter`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/interactive_test_utils.h;l=42;drc=e44b92356d4568bf5f3d7a78ed75d2356b3d2871) (this does mean it would need to be an interactive_ui_test however).

    Glenn Hartmann

    I tried, but couldn't get it working. Maybe I'm doing something wrong, but here's a minimal repro of my issue: https://chromium-review.googlesource.com/c/chromium/src/+/7127225

    That consistently times out on my machine.

    Tom Lukaszewicz

    Interesting - there does seem to be an issue with this on linux (see crbug.com/356183782). I'd add a TODO to this method to consider re-writing this as an interactive_ui_test once native window activation issues have been addressed (your current approach is great for now though)

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Glenn Hartmann
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • 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: I985ca0ceb68c72d97ea5721951fcc81d6a6a6964
    Gerrit-Change-Number: 7088443
    Gerrit-PatchSet: 16
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Comment-Date: Fri, 07 Nov 2025 05:19:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Glenn Hartmann <hart...@chromium.org>
    Comment-In-Reply-To: Tom Lukaszewicz <tl...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Glenn Hartmann (Gerrit)

    unread,
    Nov 7, 2025, 12:29:29 PMNov 7
    to Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
    Attention needed from Tom Lukaszewicz

    Glenn Hartmann voted and added 4 comments

    Votes added by Glenn Hartmann

    Commit-Queue+1

    4 comments

    Patchset-level comments
    File-level comment, Patchset 17 (Latest):
    Glenn Hartmann . unresolved

    Also did a few renames:

    • looks like we're agreed on the new class names (ProfileBrowserCollection, GlobalBrowserCollection, BrowserCollectionObserver) so I moved ProfileBrowsers -> ProfileBrowserCollection
    • also renamed some methods as Dana suggested: OnBrowserWasCreated -> OnBrowserCreated, OnBrowserWasClosed -> OnBrowserClosed, OnBrowserDidBecomeActive -> OnBrowserActivated, and OnBrowserDidBecomeInactive -> OnBrowserDeactivated
    File chrome/browser/ui/browser_manager_service.h
    Line 41, Patchset 16: struct BrowserAndSubscriptions {
    Tom Lukaszewicz . resolved

    nit: It's probably sufficient to have this be a pair of `std::pair<std::unique_ptr<Browser>, std::vector<base::CallbackListSubscription>>` instead (since we don't really care about differentiating between the subscriptions, we just need to hang onto the handles).

    Glenn Hartmann

    Done

    File chrome/browser/ui/browser_manager_service.cc
    Line 23, Patchset 15: // TODO: is it possible for |browser_ptr| to get deleted part-way through?
    Glenn Hartmann . resolved

    any thoughts on this in particular?

    Tom Lukaszewicz

    It's technically possible though should be very unlikely (there aren't any actions I'm aware of that would reasonably lead to the destruction of that same browser being created).

    If we wanted to be extra careful though we could get a WeakPtr to the BWI before notifying and check this before notifying any clients if its end up going away.

    Glenn Hartmann

    Done

    File chrome/browser/ui/browser_manager_service_browsertest.cc
    Line 49, Patchset 15: void ActivatePrimaryBrowser(Browser* const secondary_browser) {
    Tom Lukaszewicz . resolved

    I wonder if we should attempt to activate browsers using the [`BrowserActivationWaiter`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/base/interactive_test_utils.h;l=42;drc=e44b92356d4568bf5f3d7a78ed75d2356b3d2871) (this does mean it would need to be an interactive_ui_test however).

    Glenn Hartmann

    I tried, but couldn't get it working. Maybe I'm doing something wrong, but here's a minimal repro of my issue: https://chromium-review.googlesource.com/c/chromium/src/+/7127225

    That consistently times out on my machine.

    Tom Lukaszewicz

    Interesting - there does seem to be an issue with this on linux (see crbug.com/356183782). I'd add a TODO to this method to consider re-writing this as an interactive_ui_test once native window activation issues have been addressed (your current approach is great for now though)

    Glenn Hartmann

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Tom Lukaszewicz
    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: I985ca0ceb68c72d97ea5721951fcc81d6a6a6964
    Gerrit-Change-Number: 7088443
    Gerrit-PatchSet: 17
    Gerrit-Owner: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Glenn Hartmann <hart...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Comment-Date: Fri, 07 Nov 2025 17:29:24 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Glenn Hartmann (Gerrit)

    unread,
    Nov 7, 2025, 12:29:57 PMNov 7
    to Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org, dewitt...@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, loyso...@chromium.org, mac-r...@chromium.org, mgiuca...@chromium.org, webap...@microsoft.com, jatapiaro+wat...@google.com, lwinston+watc...@google.com, rginda...@chromium.org, trewin...@google.com
    Attention needed from Tom Lukaszewicz

    Glenn Hartmann added 1 comment

    File chrome/browser/ui/browser.cc
    Line 1287, Patchset 15: BrowserManagerServiceFactory::GetForProfile(GetProfile())
    ->OnBrowserDidBecomeActive(this);
    Tom Lukaszewicz . resolved

    Since `BrowserManagerService` owns `BrowserWindowInterface` instances would it work to register listeners on the specific instances each service is responsible for to avoid relying on `Browser` to deliver these updates?

    Dealing with the callback subscription handles seems like it might be annoying but the upside is we wouldn't need to expose `BrowserManagerService::OnBrowserDidBecomeActive/Inactive()`

    Glenn Hartmann

    hmm, good point. It is a bit of a pain to manage the subscriptions, but I gave it a go.

    btw, why does BrowserManagerService never remove anything from its `browsers_` vector? Just because we don't expect it to ever grow very big?

    Glenn Hartmann

    Done

    Gerrit-Comment-Date: Fri, 07 Nov 2025 17:29:52 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages