-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor FXIOS-11147 [Tab Optomization Phase 1] Additional Tab Manager cleanup #24560
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,8 +238,10 @@ class TabManagerImplementation: NSObject, TabManager, FeatureFlaggable, TabEvent | |
) | ||
} | ||
|
||
func removeTab(_ tab: Tab, completion: (() -> Void)? = nil) { | ||
guard let index = tabs.firstIndex(where: { $0 === tab }) else { return } | ||
func removeTabWithCompletion(_ tabUUID: TabUUID, completion: (() -> Void)? = nil) { | ||
guard let index = tabs.firstIndex(where: { $0.tabUUID == tabUUID }) else { return } | ||
let tab = tabs[index] | ||
|
||
DispatchQueue.main.async { [weak self] in | ||
self?.removeTab(tab, flushToDisk: true) | ||
self?.updateSelectedTabAfterRemovalOf(tab, deletedIndex: index) | ||
|
@@ -269,9 +271,7 @@ class TabManagerImplementation: NSObject, TabManager, FeatureFlaggable, TabEvent | |
return urls.contains(url) | ||
} | ||
for tab in tabsToRemove { | ||
await withCheckedContinuation { continuation in | ||
removeTab(tab) { continuation.resume() } | ||
} | ||
await removeTab(tab.tabUUID) | ||
} | ||
} | ||
|
||
|
@@ -1016,19 +1016,12 @@ class TabManagerImplementation: NSObject, TabManager, FeatureFlaggable, TabEvent | |
tabToSelect = addTab(request, afterTab: selectedTab, isPrivate: selectedTab.isPrivate) | ||
} | ||
selectTab(tabToSelect) | ||
removeTab(selectedTab) | ||
Task { | ||
await removeTab(selectedTab.tabUUID) | ||
await tabSessionStore.deleteUnusedTabSessionData(keeping: []) | ||
Comment on lines
-1019
to
1021
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Cramsden Doesn't this create a potential race condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattreaganmozilla it is very possible. Help me understand what the race condition you would expect would be? Like you go to clear your tabs history and the tab is not removed immediately? The other implementation of this same function dispatches the call to the main thread asynchronously as well so it might also not execute right away? My hope here with this work was to at least minimize the places where we are calling async/await and gcd. Clearly I didn't actually accomplish this because the call site of My naive strategy has been if we are already using async/await to try to bubble it up as far as possible so that we can insure an isolated context or at least make the places where we are wrapping work in tasks as visible as possible. So maybe here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Quick disclaimer that I am not a Swift concurrency expert so I could be totally mistaken on some of this. 😅 But AFAIU the
If the former code is
Yeah this is all fantastic and I'm glad we're digging more into this. 👍 I am a little concerned that the way we're using Tasks is potentially unsafe and might be contributing to weird/rare edge case bugs. |
||
} | ||
} | ||
|
||
func closeTab(by url: URL) { | ||
// Find the tab with the specified URL | ||
if let tabToClose = tabs.first(where: { $0.url == url }) { | ||
self.removeTab(tabToClose) | ||
} | ||
} | ||
|
||
func reorderTabs(isPrivate privateMode: Bool, fromIndex visibleFromIndex: Int, toIndex visibleToIndex: Int) { | ||
let currentTabs = privateMode ? privateTabs : normalActiveTabs | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to test this because I am not sure how to get this function to fire https://mozilla.slack.com/archives/C05C9RET70F/p1738709743883439