Commit e1deeafb authored by Connie Wan's avatar Connie Wan Committed by Commit Bot

Make profile optional when searching for Tab Groups across browsers

Followup to crrev.com/c/2326632 and some comments there.

For the Tab Groups Extensions API, it's useful to be able to query all browsers for the one containing a TabGroupId, without needing to know the profile up-front. There are separate checks for ensuring that a group doesn't move across profiles. This is still assuming it's unlikely for group IDs to clash across profiles.

If there's a better way to approach this I'm happy to adjust!

Bug: 1098439
Change-Id: I71bd07f5d00fad74ee5aa02d1a62feb4883e3819
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339341
Commit-Queue: Connie Wan <connily@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795549}
parent e361b676
......@@ -75,7 +75,7 @@ ChromeTabRestoreServiceClient::FindLiveTabContextWithGroup(
#if defined(OS_ANDROID)
return nullptr;
#else
return BrowserLiveTabContext::FindContextWithGroup(profile_, group);
return BrowserLiveTabContext::FindContextWithGroup(group, profile_);
#endif
}
......
......@@ -234,11 +234,13 @@ Browser* FindBrowserWithWebContents(const WebContents* web_contents) {
return (it == all_tabs.end()) ? nullptr : it.browser();
}
Browser* FindBrowserWithGroup(Profile* profile, tab_groups::TabGroupId group) {
Browser* FindBrowserWithGroup(tab_groups::TabGroupId group, Profile* profile) {
for (auto* browser : *BrowserList::GetInstance()) {
if (browser->profile() == profile && browser->tab_strip_model() &&
browser->tab_strip_model()->group_model()->ContainsTabGroup(group))
if ((!profile || browser->profile() == profile) &&
browser->tab_strip_model() &&
browser->tab_strip_model()->group_model()->ContainsTabGroup(group)) {
return browser;
}
}
return nullptr;
}
......
......@@ -63,8 +63,9 @@ Browser* FindBrowserWithActiveWindow();
Browser* FindBrowserWithWebContents(const content::WebContents* web_contents);
// Find the browser containing the group with ID |group| or nullptr if none is
// found within the given |profile|.
Browser* FindBrowserWithGroup(Profile* profile, tab_groups::TabGroupId group);
// found within the given |profile|. If the profile is not specified, find any
// browser containing the group.
Browser* FindBrowserWithGroup(tab_groups::TabGroupId group, Profile* profile);
// Returns the Browser object owned by |profile| whose window was most recently
// active. If no such Browsers exist, returns NULL.
......
......@@ -255,8 +255,8 @@ sessions::LiveTabContext* BrowserLiveTabContext::FindContextWithID(
// static
sessions::LiveTabContext* BrowserLiveTabContext::FindContextWithGroup(
Profile* profile,
tab_groups::TabGroupId group) {
Browser* browser = chrome::FindBrowserWithGroup(profile, group);
tab_groups::TabGroupId group,
Profile* profile) {
Browser* browser = chrome::FindBrowserWithGroup(group, profile);
return browser ? browser->live_tab_context() : nullptr;
}
......@@ -97,8 +97,8 @@ class BrowserLiveTabContext : public sessions::LiveTabContext {
// Returns the LiveTabContext of the Browser containing the group with ID
// |group| if such a Browser exists within the given |profile|.
static sessions::LiveTabContext* FindContextWithGroup(
Profile* profile,
tab_groups::TabGroupId group);
tab_groups::TabGroupId group,
Profile* profile);
private:
Browser* const browser_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment