DevTools/Android: Honor browserContextId in createTarget [chromium/src : main]

0 views
Skip to first unread message

Dmitry Gozman (Gerrit)

unread,
Jul 1, 2026, 7:45:16 AM (5 days ago) Jul 1
to Julio Piubello, Alex Rudenko, Chromium LUCI CQ, chromium...@chromium.org, blink-...@chromium.org, devtools...@chromium.org
Attention needed from Alex Rudenko and Julio Piubello

Dmitry Gozman added 3 comments

File chrome/browser/devtools/devtools_browser_context_manager.cc
Line 123, Patchset 6 (Latest): DestroyOTRProfileWhenAppropriate(profile->GetWeakPtr());
Dmitry Gozman . unresolved

Since we are no longer waiting for all tabs to be closed, does that mean `CloseTabAt()` does the job synchronously?

File chrome/browser/devtools/protocol/target_handler_android.cc
Line 118, Patchset 6 (Latest): GURL gurl = NormalizeTargetUrl(url);
Dmitry Gozman . unresolved

I wonder why extract a method? Not that I am really against it, but seems unnecessary 😊

Line 157, Patchset 6 (Latest): DevToolsManagerDelegateAndroid::MarkCreatedByDevTools(*web_contents);

if (for_tab.value_or(false)) {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateForTab(web_contents)->GetId();
} else {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateFor(web_contents)->GetId();
}

return protocol::Response::Success();
}
Dmitry Gozman . unresolved

Can we reuse this code between browser_context_id vs default branches?

Open in Gerrit

Related details

Attention is currently required from:
  • Alex Rudenko
  • Julio Piubello
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: I7ec4dd6efef35e45f7a7756155fbc43c7ccf8f6f
Gerrit-Change-Number: 7870944
Gerrit-PatchSet: 6
Gerrit-Owner: Julio Piubello <ju...@gitstart.com>
Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
Gerrit-Reviewer: Julio Piubello <ju...@gitstart.com>
Gerrit-Attention: Alex Rudenko <alexr...@chromium.org>
Gerrit-Attention: Julio Piubello <ju...@gitstart.com>
Gerrit-Comment-Date: Wed, 01 Jul 2026 11:44:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alex Rudenko (Gerrit)

unread,
Jul 1, 2026, 9:05:14 AM (5 days ago) Jul 1
to Julio Piubello, Dmitry Gozman, Chromium LUCI CQ, chromium...@chromium.org, blink-...@chromium.org, devtools...@chromium.org
Attention needed from Julio Piubello

Alex Rudenko added 2 comments

File chrome/browser/devtools/devtools_browser_context_manager.cc
Line 124, Patchset 6 (Latest): std::move(callback).Run(true, "");
Alex Rudenko . unresolved

Since you updated `DisposeBrowserContext` to use `TabModelList` on Android because `BrowserWindowInterface` doesn't work for Android tabs, shouldn't `OnProfileWillBeDestroyed` be updated as well?

If `OnProfileWillBeDestroyed` continues to use `ForEachCurrentBrowserWindowInterfaceOrderedByActivation`, it won't close tabs with the destroyed profile on Android, which could lead to a use-after-free when the profile is destroyed?

File chrome/browser/devtools/protocol/target_handler_android.cc
Line 152, Patchset 6 (Latest): WebContents* web_contents = CreateTabInBrowserContext(profile, gurl);
Alex Rudenko . unresolved

The logic for marking the tab and getting the target ID here is identical to the fallback case on lines 170-186. You can deduplicate this by assigning `web_contents` in an `if/else` block and then running the common logic once.

```cpp
WebContents* web_contents = nullptr;
if (browser_context_id.has_value()) {
Profile* profile =
DevToolsBrowserContextManager::GetInstance().GetProfileById(
*browser_context_id);
if (!profile) {
return protocol::Response::ServerError(
"Failed to find browser context with id " + *browser_context_id);
}
web_contents = CreateTabInBrowserContext(profile, gurl);
} else {
web_contents =
tab_model->CreateNewTabForDevTools(gurl, new_window.value_or(false));
}
  if (!web_contents) {
return protocol::Response::ServerError("Could not create a Tab");
}
  DevToolsManagerDelegateAndroid::MarkCreatedByDevTools(*web_contents);
  if (for_tab.value_or(false)) {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateForTab(web_contents)->GetId();
} else {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateFor(web_contents)->GetId();
}
  return protocol::Response::Success();
```
Open in Gerrit

Related details

Attention is currently required from:
  • Julio Piubello
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: I7ec4dd6efef35e45f7a7756155fbc43c7ccf8f6f
Gerrit-Change-Number: 7870944
Gerrit-PatchSet: 6
Gerrit-Owner: Julio Piubello <ju...@gitstart.com>
Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
Gerrit-Reviewer: Julio Piubello <ju...@gitstart.com>
Gerrit-Attention: Julio Piubello <ju...@gitstart.com>
Gerrit-Comment-Date: Wed, 01 Jul 2026 13:04:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Julio Piubello (Gerrit)

unread,
10:07 AM (6 hours ago) 10:07 AM
to Alex Rudenko, Dmitry Gozman, Chromium LUCI CQ, chromium...@chromium.org, blink-...@chromium.org, devtools...@chromium.org
Attention needed from Alex Rudenko and Dmitry Gozman

Julio Piubello added 5 comments

File chrome/browser/devtools/devtools_browser_context_manager.cc
Line 123, Patchset 6: DestroyOTRProfileWhenAppropriate(profile->GetWeakPtr());
Dmitry Gozman . resolved

Since we are no longer waiting for all tabs to be closed, does that mean `CloseTabAt()` does the job synchronously?

Julio Piubello

yes, that path does not enqueue a pending closure, and TabCollectionTabModelImpl.closeTabsInternal() removes and finalizes the tab before returning.

do you think I should add a small comment?

Line 124, Patchset 6: std::move(callback).Run(true, "");
Alex Rudenko . resolved

Since you updated `DisposeBrowserContext` to use `TabModelList` on Android because `BrowserWindowInterface` doesn't work for Android tabs, shouldn't `OnProfileWillBeDestroyed` be updated as well?

If `OnProfileWillBeDestroyed` continues to use `ForEachCurrentBrowserWindowInterfaceOrderedByActivation`, it won't close tabs with the destroyed profile on Android, which could lead to a use-after-free when the profile is destroyed?

Julio Piubello

that makes sense, thanks. changed to use the same Android TabModelList-based cleanup

File chrome/browser/devtools/protocol/target_handler_android.cc
Line 118, Patchset 6: GURL gurl = NormalizeTargetUrl(url);
Dmitry Gozman . resolved

I wonder why extract a method? Not that I am really against it, but seems unnecessary 😊

Julio Piubello

removed!

Line 152, Patchset 6: WebContents* web_contents = CreateTabInBrowserContext(profile, gurl);
Alex Rudenko . resolved

The logic for marking the tab and getting the target ID here is identical to the fallback case on lines 170-186. You can deduplicate this by assigning `web_contents` in an `if/else` block and then running the common logic once.

```cpp
WebContents* web_contents = nullptr;
if (browser_context_id.has_value()) {
Profile* profile =
DevToolsBrowserContextManager::GetInstance().GetProfileById(
*browser_context_id);
if (!profile) {
return protocol::Response::ServerError(
"Failed to find browser context with id " + *browser_context_id);
}
web_contents = CreateTabInBrowserContext(profile, gurl);
} else {
web_contents =
tab_model->CreateNewTabForDevTools(gurl, new_window.value_or(false));
}
  if (!web_contents) {
return protocol::Response::ServerError("Could not create a Tab");
}
  DevToolsManagerDelegateAndroid::MarkCreatedByDevTools(*web_contents);
  if (for_tab.value_or(false)) {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateForTab(web_contents)->GetId();
} else {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateFor(web_contents)->GetId();
}
  return protocol::Response::Success();
```
Julio Piubello

sure thing, done

Line 157, Patchset 6: DevToolsManagerDelegateAndroid::MarkCreatedByDevTools(*web_contents);


if (for_tab.value_or(false)) {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateForTab(web_contents)->GetId();
} else {
*out_target_id =
content::DevToolsAgentHost::GetOrCreateFor(web_contents)->GetId();
}

return protocol::Response::Success();
}
Dmitry Gozman . resolved

Can we reuse this code between browser_context_id vs default branches?

Julio Piubello

done!

Open in Gerrit

Related details

Attention is currently required from:
  • Alex Rudenko
  • Dmitry Gozman
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: I7ec4dd6efef35e45f7a7756155fbc43c7ccf8f6f
    Gerrit-Change-Number: 7870944
    Gerrit-PatchSet: 7
    Gerrit-Owner: Julio Piubello <ju...@gitstart.com>
    Gerrit-Reviewer: Alex Rudenko <alexr...@chromium.org>
    Gerrit-Reviewer: Dmitry Gozman <dgo...@chromium.org>
    Gerrit-Reviewer: Julio Piubello <ju...@gitstart.com>
    Gerrit-Attention: Dmitry Gozman <dgo...@chromium.org>
    Gerrit-Attention: Alex Rudenko <alexr...@chromium.org>
    Gerrit-Comment-Date: Mon, 06 Jul 2026 14:07:33 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Dmitry Gozman <dgo...@chromium.org>
    Comment-In-Reply-To: Alex Rudenko <alexr...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages