Skip to content

Commit f00aeb8

Browse files
committed
remove unneeded main actor isolation
1 parent 396d351 commit f00aeb8

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

firefox-ios/Client/TabManagement/TabManagerImplementation.swift

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class TabManagerImplementation: NSObject,
6262
return tabs[selectedIndex]
6363
}
6464

65-
@MainActor
6665
var normalActiveTabs: [Tab] {
6766
let inactiveTabs = getInactiveTabs()
6867
let activeTabs = tabs.filter { $0.isPrivate == false && !inactiveTabs.contains($0) }
@@ -81,7 +80,6 @@ class TabManagerImplementation: NSObject,
8180
return tabs.filter { $0.isPrivate }
8281
}
8382

84-
@MainActor
8583
var recentlyAccessedNormalTabs: [Tab] {
8684
// If inactive tabs are enabled, do not include inactive tabs, as they are not "recently" accessed
8785
var eligibleTabs = isInactiveTabsEnabled ? normalActiveTabs : normalTabs
@@ -121,7 +119,7 @@ class TabManagerImplementation: NSObject,
121119
var tabRestoreHasFinished = false
122120
private(set) var selectedIndex: Int = -1
123121

124-
@MainActor private lazy var tabConfigurationProvider = {
122+
private lazy var tabConfigurationProvider = {
125123
return TabConfigurationProvider(prefs: profile.prefs)
126124
}()
127125

@@ -193,7 +191,6 @@ class TabManagerImplementation: NSObject,
193191
}
194192

195193
// MARK: - Add/Remove Delegate
196-
@MainActor
197194
func removeDelegate(_ delegate: any TabManagerDelegate, completion: (() -> Void)?) {
198195
for index in 0 ..< delegates.count {
199196
let del = delegates[index]
@@ -387,7 +384,6 @@ class TabManagerImplementation: NSObject,
387384
commitChanges()
388385
}
389386

390-
@MainActor
391387
private func addTab(_ request: URLRequest? = nil,
392388
afterTab: Tab? = nil,
393389
flushToDisk: Bool,
@@ -407,13 +403,11 @@ class TabManagerImplementation: NSObject,
407403
return filterdTabs.first
408404
}
409405

410-
@MainActor
411406
func getTabForURL(_ url: URL) -> Tab? {
412407
return tabs.first(where: { $0.webView?.url == url })
413408
}
414409

415410
// MARK: - Undo Close Tab
416-
@MainActor
417411
func undoCloseTab() {
418412
assert(Thread.isMainThread)
419413
guard let backupCloseTab = self.backupCloseTab else { return }
@@ -435,7 +429,6 @@ class TabManagerImplementation: NSObject,
435429
commitChanges()
436430
}
437431

438-
@MainActor
439432
func undoCloseAllTabs() {
440433
assert(Thread.isMainThread)
441434
guard !backupCloseTabs.isEmpty else { return }
@@ -450,7 +443,6 @@ class TabManagerImplementation: NSObject,
450443

451444
// MARK: - Restore tabs
452445

453-
@MainActor
454446
func restoreTabs(_ forced: Bool = false) {
455447
assert(Thread.isMainThread)
456448
if isDeeplinkOptimizationRefactorEnabled {
@@ -488,7 +480,6 @@ class TabManagerImplementation: NSObject,
488480
restoreTabs()
489481
}
490482

491-
@MainActor
492483
private func updateSelectedTabAfterRemovalOf(_ removedTab: Tab, deletedIndex: Int) {
493484
assert(Thread.isMainThread)
494485
// If the currently selected tab has been deleted, try to select the next most reasonable tab.
@@ -547,7 +538,6 @@ class TabManagerImplementation: NSObject,
547538
}
548539
}
549540

550-
@MainActor
551541
private func blockPopUpDidChange() {
552542
assert(Thread.isMainThread)
553543
let allowPopups = !(profile.prefs.boolForKey(PrefsKeys.KeyBlockPopups) ?? true)
@@ -559,7 +549,6 @@ class TabManagerImplementation: NSObject,
559549
tabConfigurationProvider.updateAllowsPopups(allowPopups)
560550
}
561551

562-
@MainActor
563552
private func autoPlayDidChange() {
564553
assert(Thread.isMainThread)
565554
let mediaType = AutoplayAccessors.getMediaTypesRequiringUserActionForPlayback(profile.prefs)
@@ -569,7 +558,6 @@ class TabManagerImplementation: NSObject,
569558
tabConfigurationProvider.updateMediaTypesRequiringUserActionForPlayback(mediaType)
570559
}
571560

572-
@MainActor
573561
private func buildTabRestore(window: WindowData?) {
574562
defer {
575563
isRestoringTabs = false
@@ -625,7 +613,6 @@ class TabManagerImplementation: NSObject,
625613
}
626614

627615
/// Creates the webview so needs to live on the main thread
628-
@MainActor
629616
private func generateTabs(from windowData: WindowData) {
630617
let filteredTabs = filterPrivateTabs(from: windowData,
631618
clearPrivateTabs: shouldClearPrivateTabs())
@@ -650,7 +637,6 @@ class TabManagerImplementation: NSObject,
650637
handleTabSelectionAfterRestore(tabToSelect: tabToSelect)
651638
}
652639

653-
@MainActor
654640
private func configureNewTab(with tabData: TabData) -> Tab? {
655641
let newTab: Tab
656642

@@ -700,7 +686,6 @@ class TabManagerImplementation: NSObject,
700686
return newTab
701687
}
702688

703-
@MainActor
704689
private func handleTabSelectionAfterRestore(tabToSelect: Tab?) {
705690
assert(Thread.isMainThread)
706691
if isDeeplinkOptimizationRefactorEnabled, let deeplinkTab {
@@ -737,7 +722,6 @@ class TabManagerImplementation: NSObject,
737722
}
738723

739724
/// Creates the webview so needs to live on the main thread
740-
@MainActor
741725
private func generateEmptyTab() {
742726
let newTab = addTab()
743727
selectTab(newTab)
@@ -815,20 +799,17 @@ class TabManagerImplementation: NSObject,
815799
return tabData
816800
}
817801

818-
@MainActor
819802
func commitChanges() {
820803
preserveTabs()
821804
saveSessionData(forTab: selectedTab)
822805
}
823806

824-
@MainActor
825807
func notifyCurrentTabDidFinishLoading() {
826808
delegates.forEach {
827809
$0.get()?.tabManagerTabDidFinishLoading()
828810
}
829811
}
830812

831-
@MainActor
832813
private func saveSessionData(forTab tab: Tab?) {
833814
guard let tab = tab,
834815
let tabSession = tab.webView?.interactionState as? Data,
@@ -838,7 +819,6 @@ class TabManagerImplementation: NSObject,
838819
self.tabSessionStore.saveTabSession(tabID: tabID, sessionData: tabSession)
839820
}
840821

841-
@MainActor
842822
private func saveAllTabData() {
843823
// Only preserve tabs after the restore has finished
844824
guard tabRestoreHasFinished, let url = selectedTab?.url, !url.isFxHomeUrl else { return }
@@ -852,7 +832,6 @@ class TabManagerImplementation: NSObject,
852832
/// This function updates the selectedIndex.
853833
/// Note: it is safe to call this with `tab` and `previous` as the same tab, for use in the case
854834
/// where the index of the tab has changed (such as after deletion).
855-
@MainActor
856835
func selectTab(_ tab: Tab?, previous: Tab? = nil) {
857836
assert(Thread.isMainThread)
858837
// Fallback everywhere to selectedTab if no previous tab
@@ -934,7 +913,6 @@ class TabManagerImplementation: NSObject,
934913
forKey: PrefsKeys.LastSessionWasPrivate)
935914
}
936915

937-
@MainActor
938916
private func removeAllPrivateTabs() {
939917
// reset the selectedTabIndex if we are on a private tab because we will be removing it.
940918
if selectedTab?.isPrivate ?? false {
@@ -969,7 +947,6 @@ class TabManagerImplementation: NSObject,
969947
store.dispatchLegacy(action)
970948
}
971949

972-
@MainActor
973950
private func selectTabWithSession(tab: Tab, sessionData: Data?) {
974951
MainActor.assertIsolated("Expected to be called only on main actor.")
975952
let configuration: WKWebViewConfiguration = tabConfigurationProvider.configuration(
@@ -1027,15 +1004,13 @@ class TabManagerImplementation: NSObject,
10271004
}
10281005

10291006
// MARK: - Inactive tabs
1030-
@MainActor
10311007
func getInactiveTabs() -> [Tab] {
10321008
let inactiveTabsPrefEnabled = profile.prefs.boolForKey(PrefsKeys.FeatureFlags.InactiveTabs) ?? true
10331009
let inactiveTabsEnabled = inactiveTabsPrefEnabled && !isTabTrayUIExperimentsEnabled
10341010
guard inactiveTabsEnabled else { return [] }
10351011
return inactiveTabsManager.getInactiveTabs(tabs: tabs)
10361012
}
10371013

1038-
@MainActor
10391014
func removeAllInactiveTabs() {
10401015
let currentModeTabs = getInactiveTabs()
10411016
backupCloseTabs = currentModeTabs
@@ -1045,14 +1020,12 @@ class TabManagerImplementation: NSObject,
10451020
commitChanges()
10461021
}
10471022

1048-
@MainActor
10491023
func undoCloseInactiveTabs() {
10501024
tabs.append(contentsOf: backupCloseTabs)
10511025
commitChanges()
10521026
backupCloseTabs = [Tab]()
10531027
}
10541028

1055-
@MainActor
10561029
func clearAllTabsHistory() {
10571030
assert(Thread.isMainThread)
10581031
guard let selectedTab = selectedTab, let url = selectedTab.url else { return }
@@ -1076,7 +1049,6 @@ class TabManagerImplementation: NSObject,
10761049
}
10771050
}
10781051

1079-
@MainActor
10801052
func reorderTabs(isPrivate privateMode: Bool, fromIndex visibleFromIndex: Int, toIndex visibleToIndex: Int) {
10811053
let currentTabs = privateMode ? privateTabs : normalActiveTabs
10821054

@@ -1103,7 +1075,6 @@ class TabManagerImplementation: NSObject,
11031075
}
11041076
}
11051077

1106-
@MainActor
11071078
func switchPrivacyMode() -> SwitchPrivacyModeResult {
11081079
assert(Thread.isMainThread)
11091080
var result = SwitchPrivacyModeResult.usedExistingTab
@@ -1128,7 +1099,6 @@ class TabManagerImplementation: NSObject,
11281099
return result
11291100
}
11301101

1131-
@MainActor
11321102
func addPopupForParentTab(profile: any Profile, parentTab: Tab, configuration: WKWebViewConfiguration) -> Tab {
11331103
assert(Thread.isMainThread)
11341104
let popup = Tab(profile: profile,
@@ -1156,7 +1126,6 @@ class TabManagerImplementation: NSObject,
11561126
}
11571127

11581128
/// Note: Inserts AND configures the given tab.
1159-
@MainActor
11601129
private func configureTab(
11611130
_ tab: Tab,
11621131
request: URLRequest?,
@@ -1260,7 +1229,6 @@ class TabManagerImplementation: NSObject,
12601229
}
12611230

12621231
// MARK: - Update Menu Items
1263-
@MainActor
12641232
private func updateMenuItemsForSelectedTab() {
12651233
guard let selectedTab,
12661234
var menuItems = UIMenuController.shared.menuItems
@@ -1292,7 +1260,6 @@ class TabManagerImplementation: NSObject,
12921260
}
12931261

12941262
// MARK: - SessionCreator
1295-
@MainActor
12961263
func createPopupSession(configuration: WKWebViewConfiguration, parent: WKWebView) -> WKWebView? {
12971264
guard let parentTab = self[parent] else { return nil }
12981265
return addPopupForParentTab(profile: profile, parentTab: parentTab, configuration: configuration).webView
@@ -1304,17 +1271,17 @@ extension TabManagerImplementation: Notifiable {
13041271
func handleNotifications(_ notification: Notification) {
13051272
let name = notification.name
13061273
let notificationWindowUUID = notification.windowUUID
1307-
Task { @MainActor in
1274+
ensureMainThread {
13081275
switch name {
13091276
case UIApplication.willResignActiveNotification:
1310-
saveAllTabData()
1277+
self.saveAllTabData()
13111278
case .TabMimeTypeDidSet:
1312-
guard windowUUID == notificationWindowUUID else { return }
1313-
updateMenuItemsForSelectedTab()
1279+
guard self.windowUUID == notificationWindowUUID else { return }
1280+
self.updateMenuItemsForSelectedTab()
13141281
case .BlockPopup:
1315-
blockPopUpDidChange()
1282+
self.blockPopUpDidChange()
13161283
case .AutoPlayChanged:
1317-
autoPlayDidChange()
1284+
self.autoPlayDidChange()
13181285
default:
13191286
break
13201287
}

0 commit comments

Comments
 (0)