Skip to content

Refactor FXIOS-11799 [Profile] Decouple SearchEnginesManager from Profile #26203

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion firefox-ios/Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, FeatureFlaggable {
rustKeychainEnabled: rustKeychainEnabled,
loginsVerificationEnabled: loginsVerificationEnabled)

lazy var searchEnginesManager = SearchEnginesManager(
prefs: profile.prefs,
files: profile.files
)

lazy var themeManager: ThemeManager = DefaultThemeManager(
sharedContainerIdentifier: AppInfo.sharedContainerIdentifier,
isNewAppearanceMenuOnClosure: { self.featureFlags.isFeatureEnabled(.appearanceMenu, checking: .buildOnly) }
Expand Down Expand Up @@ -99,7 +104,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, FeatureFlaggable {
// Then setup dependency container as it's needed for everything else
DependencyHelper().bootstrapDependencies()

appLaunchUtil = AppLaunchUtil(profile: profile)
appLaunchUtil = AppLaunchUtil(profile: profile, searchEnginesManager: searchEnginesManager)
appLaunchUtil?.setUpPreLaunchDependencies()

// Set up a web server that serves us static content.
Expand Down
9 changes: 6 additions & 3 deletions firefox-ios/Client/Application/AppLaunchUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ class AppLaunchUtil {
private var logger: Logger
// private var adjustHelper: AdjustHelper
private var profile: Profile
private let searchEnginesManager: SearchEnginesManager
private let introScreenManager: IntroScreenManager
private let termsOfServiceManager: TermsOfServiceManager

init(
logger: Logger = DefaultLogger.shared,
profile: Profile
profile: Profile,
searchEnginesManager: SearchEnginesManager
) {
self.logger = logger
self.profile = profile
self.searchEnginesManager = searchEnginesManager
// self.adjustHelper = AdjustHelper(profile: profile)
self.introScreenManager = IntroScreenManager(prefs: profile.prefs)
self.termsOfServiceManager = TermsOfServiceManager(prefs: profile.prefs)
Expand Down Expand Up @@ -52,7 +55,7 @@ class AppLaunchUtil {
let isTermsOfServiceAccepted = termsOfServiceManager.isAccepted || !introScreenManager.shouldShowIntroScreen
logger.setup(sendCrashReports: sendCrashReports && isTermsOfServiceAccepted)
if isTermsOfServiceAccepted {
TelemetryWrapper.shared.setup(profile: profile)
TelemetryWrapper.shared.setup(profile: profile, searchEnginesManager: searchEnginesManager)
TelemetryWrapper.shared.recordStartUpTelemetry()
} else {
// If ToS are not accepted, we still need to setup the Contextual Identifier for
Expand All @@ -61,7 +64,7 @@ class AppLaunchUtil {
}
} else {
logger.setup(sendCrashReports: sendCrashReports)
TelemetryWrapper.shared.setup(profile: profile)
TelemetryWrapper.shared.setup(profile: profile, searchEnginesManager: searchEnginesManager)
TelemetryWrapper.shared.recordStartUpTelemetry()
}

Expand Down
3 changes: 3 additions & 0 deletions firefox-ios/Client/Application/DependencyHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class DependencyHelper {
let profile: Profile = appDelegate.profile
AppContainer.shared.register(service: profile)

let searchEnginesManager = appDelegate.searchEnginesManager
AppContainer.shared.register(service: searchEnginesManager)

let diskImageStore: DiskImageStore =
DefaultDiskImageStore(files: profile.files,
namespace: TabManagerConstants.tabScreenshotNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ class LaunchCoordinator: BaseCoordinator,
QRCodeNavigationHandler,
ParentCoordinatorDelegate {
private let profile: Profile
private let searchEnginesManager: SearchEnginesManager
private let isIphone: Bool
let windowUUID: WindowUUID
weak var parentCoordinator: LaunchCoordinatorDelegate?

init(router: Router,
windowUUID: WindowUUID,
profile: Profile = AppContainer.shared.resolve(),
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve(),
isIphone: Bool = UIDevice.current.userInterfaceIdiom == .phone) {
self.profile = profile
self.isIphone = isIphone
self.windowUUID = windowUUID
self.searchEnginesManager = searchEnginesManager
super.init(router: router)
}

Expand Down Expand Up @@ -65,7 +68,7 @@ class LaunchCoordinator: BaseCoordinator,
self.profile.prefs.setBool(sendCrashReports, forKey: AppConstants.prefSendCrashReports)
self.logger.setup(sendCrashReports: sendCrashReports)

TelemetryWrapper.shared.setup(profile: profile)
TelemetryWrapper.shared.setup(profile: profile, searchEnginesManager: searchEnginesManager)
TelemetryWrapper.shared.recordStartUpTelemetry()

self.parentCoordinator?.didFinishTermsOfService(from: self)
Expand Down
19 changes: 16 additions & 3 deletions firefox-ios/Client/Coordinators/SettingsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SettingsCoordinator: BaseCoordinator,
private let tabManager: TabManager
private let themeManager: ThemeManager
private let gleanUsageReportingMetricsService: GleanUsageReportingMetricsService
private let searchEnginesManager: SearchEnginesManager
weak var parentCoordinator: SettingsCoordinatorDelegate?
private var windowUUID: WindowUUID { return tabManager.windowUUID }
private let settingsTelemetry: SettingsTelemetry
Expand All @@ -41,14 +42,16 @@ class SettingsCoordinator: BaseCoordinator,
tabManager: TabManager,
themeManager: ThemeManager = AppContainer.shared.resolve(),
gleanUsageReportingMetricsService: GleanUsageReportingMetricsService = AppContainer.shared.resolve(),
gleanWrapper: GleanWrapper = DefaultGleanWrapper()
gleanWrapper: GleanWrapper = DefaultGleanWrapper(),
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve()
) {
self.wallpaperManager = wallpaperManager
self.profile = profile
self.tabManager = tabManager
self.themeManager = themeManager
self.gleanUsageReportingMetricsService = gleanUsageReportingMetricsService
self.settingsTelemetry = SettingsTelemetry(gleanWrapper: gleanWrapper)
self.searchEnginesManager = searchEnginesManager
super.init(router: router)

// It's important we initialize AppSettingsTableViewController with a settingsDelegate and parentCoordinator
Expand Down Expand Up @@ -130,7 +133,11 @@ class SettingsCoordinator: BaseCoordinator,
return viewController

case .search:
let viewController = SearchSettingsTableViewController(profile: profile, windowUUID: windowUUID)
let viewController = SearchSettingsTableViewController(
profile: profile,
searchEnginesManager: searchEnginesManager,
windowUUID: windowUUID
)
return viewController

case .clearPrivateData:
Expand Down Expand Up @@ -176,6 +183,7 @@ class SettingsCoordinator: BaseCoordinator,
contentBlockerVC.settingsDelegate = self
contentBlockerVC.profile = profile
contentBlockerVC.tabManager = tabManager
contentBlockerVC.searchEnginesManager = searchEnginesManager
return contentBlockerVC

case .browser:
Expand Down Expand Up @@ -314,6 +322,7 @@ class SettingsCoordinator: BaseCoordinator,
viewController.settingsDelegate = self
viewController.profile = profile
viewController.tabManager = tabManager
viewController.searchEnginesManager = searchEnginesManager
router.push(viewController)
}

Expand Down Expand Up @@ -365,7 +374,11 @@ class SettingsCoordinator: BaseCoordinator,
}

func pressedSearchEngine() {
let viewController = SearchSettingsTableViewController(profile: profile, windowUUID: windowUUID)
let viewController = SearchSettingsTableViewController(
profile: profile,
searchEnginesManager: searchEnginesManager,
windowUUID: windowUUID
)
router.push(viewController)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension BrowserViewController: URLBarDelegate {
if let url = searchURL, InternalURL.isValid(url: url) {
searchURL = url
}
if let query = profile.searchEnginesManager.queryForSearchURL(searchURL as URL?) {
if let query = searchEnginesManager.queryForSearchURL(searchURL as URL?) {
return (query, true)
} else {
return (url?.absoluteString, false)
Expand Down Expand Up @@ -138,7 +138,7 @@ extension BrowserViewController: URLBarDelegate {
}

func submitSearchText(_ text: String, forTab tab: Tab) {
guard let engine = profile.searchEnginesManager.defaultEngine,
guard let engine = searchEnginesManager.defaultEngine,
let searchURL = engine.searchURLForQuery(text)
else {
DefaultLogger.shared.log("Error handling URL entry: \"\(text)\".", level: .warning, category: .tabs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class BrowserViewController: UIViewController,
let ratingPromptManager: RatingPromptManager
private var browserViewControllerState: BrowserViewControllerState?
var appAuthenticator: AppAuthenticationProtocol
let searchEnginesManager: SearchEnginesManager
private var keyboardState: KeyboardState?

// Tracking navigation items to record history types.
Expand Down Expand Up @@ -324,7 +325,8 @@ class BrowserViewController: UIViewController,
notificationCenter: NotificationProtocol = NotificationCenter.default,
downloadQueue: DownloadQueue = AppContainer.shared.resolve(),
logger: Logger = DefaultLogger.shared,
appAuthenticator: AppAuthenticationProtocol = AppAuthenticator()
appAuthenticator: AppAuthenticationProtocol = AppAuthenticator(),
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve()
) {
self.profile = profile
self.tabManager = tabManager
Expand All @@ -335,6 +337,7 @@ class BrowserViewController: UIViewController,
self.downloadQueue = downloadQueue
self.logger = logger
self.appAuthenticator = appAuthenticator
self.searchEnginesManager = searchEnginesManager
self.bookmarksSaver = DefaultBookmarksSaver(profile: profile)
self.bookmarksHandler = profile.places

Expand Down Expand Up @@ -969,7 +972,7 @@ class BrowserViewController: UIViewController,
private func createLegacyUrlBar() {
guard !isToolbarRefactorEnabled else { return }

let urlBar = URLBarView(profile: profile, windowUUID: windowUUID)
let urlBar = URLBarView(profile: profile, searchEnginesManager: searchEnginesManager, windowUUID: windowUUID)
urlBar.translatesAutoresizingMaskIntoConstraints = false
urlBar.delegate = self
urlBar.tabToolbarDelegate = self
Expand All @@ -987,6 +990,7 @@ class BrowserViewController: UIViewController,
addressToolbarContainer.configure(
windowUUID: windowUUID,
profile: profile,
searchEnginesManager: searchEnginesManager,
delegate: self,
isUnifiedSearchEnabled: isUnifiedSearchEnabled
)
Expand Down Expand Up @@ -1675,12 +1679,12 @@ class BrowserViewController: UIViewController,
let searchViewModel = SearchViewModel(isPrivate: isPrivate,
isBottomSearchBar: isBottomSearchBar,
profile: profile,
model: profile.searchEnginesManager,
model: searchEnginesManager,
tabManager: tabManager)
let searchController = SearchViewController(profile: profile,
viewModel: searchViewModel,
tabManager: tabManager)
searchViewModel.searchEnginesManager = profile.searchEnginesManager
searchViewModel.searchEnginesManager = searchEnginesManager
searchController.searchDelegate = self

let searchLoader = SearchLoader(
Expand Down Expand Up @@ -2856,7 +2860,7 @@ class BrowserViewController: UIViewController,
func openSearchNewTab(isPrivate: Bool = false, _ text: String) {
popToBVC()

guard let engine = profile.searchEnginesManager.defaultEngine,
guard let engine = searchEnginesManager.defaultEngine,
let searchURL = engine.searchURLForQuery(text)
else {
DefaultLogger.shared.log("Error handling URL entry: \"\(text)\".", level: .warning, category: .tabs)
Expand Down Expand Up @@ -3203,7 +3207,7 @@ class BrowserViewController: UIViewController,
.searchScreenState
.showSearchSugestionsView ?? false

let isSettingEnabled = profile.searchEnginesManager.shouldShowPrivateModeSearchSuggestions
let isSettingEnabled = searchEnginesManager.shouldShowPrivateModeSearchSuggestions

return featureFlagEnabled && !alwaysShowSearchSuggestionsView && !isSettingEnabled
}
Expand Down Expand Up @@ -3870,7 +3874,11 @@ extension BrowserViewController: SearchViewControllerDelegate {
}

func presentSearchSettingsController() {
let searchSettingsTableViewController = SearchSettingsTableViewController(profile: profile, windowUUID: windowUUID)
let searchSettingsTableViewController = SearchSettingsTableViewController(
profile: profile,
searchEnginesManager: searchEnginesManager,
windowUUID: windowUUID
)
let navController = ModalSettingsNavigationController(rootViewController: searchSettingsTableViewController)
self.present(navController, animated: true, completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Redux
final class SearchEngineSelectionMiddleware {
private let profile: Profile
private let logger: Logger
private let searchEnginesManager: SearchEnginesManagerProvider
private let searchEnginesManager: SearchEnginesManager

init(profile: Profile = AppContainer.shared.resolve(),
searchEnginesManager: SearchEnginesManagerProvider? = nil,
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve(),
logger: Logger = DefaultLogger.shared) {
self.profile = profile
self.logger = logger
self.searchEnginesManager = searchEnginesManager ?? profile.searchEnginesManager
self.searchEnginesManager = searchEnginesManager
}

lazy var searchEngineSelectionProvider: Middleware<AppState> = { [self] state, action in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class AddressToolbarContainer: UIView,

private var windowUUID: WindowUUID?
private var profile: Profile?
private var searchEnginesManager: SearchEnginesManager?
private var model: AddressToolbarContainerModel?
private(set) weak var delegate: AddressToolbarContainerDelegate?

Expand Down Expand Up @@ -124,11 +125,13 @@ final class AddressToolbarContainer: UIView,
func configure(
windowUUID: WindowUUID,
profile: Profile,
searchEnginesManager: SearchEnginesManager,
delegate: AddressToolbarContainerDelegate,
isUnifiedSearchEnabled: Bool
) {
self.windowUUID = windowUUID
self.profile = profile
self.searchEnginesManager = searchEnginesManager
self.delegate = delegate
self.isUnifiedSearchEnabled = isUnifiedSearchEnabled
subscribeToRedux()
Expand Down Expand Up @@ -198,9 +201,10 @@ final class AddressToolbarContainer: UIView,
}

private func updateModel(toolbarState: ToolbarState) {
guard let windowUUID, let profile else { return }
guard let windowUUID, let profile, let searchEnginesManager else { return }
let newModel = AddressToolbarContainerModel(state: toolbarState,
profile: profile,
searchEnginesManager: searchEnginesManager,
windowUUID: windowUUID)

shouldDisplayCompact = newModel.shouldDisplayCompact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final class AddressToolbarContainerModel: Equatable {
shouldAnimate: shouldAnimate)
}

init(state: ToolbarState, profile: Profile, windowUUID: UUID) {
init(state: ToolbarState, profile: Profile, searchEnginesManager: SearchEnginesManager, windowUUID: UUID) {
self.borderPosition = state.addressToolbar.borderPosition
self.navigationActions = AddressToolbarContainerModel.mapActions(state.addressToolbar.navigationActions,
isShowingTopTabs: state.isShowingTopTabs,
Expand All @@ -109,12 +109,12 @@ final class AddressToolbarContainerModel: Equatable {

// If the user has selected an alternative search engine, use that. Otherwise, use the default engine.
let searchEngineModel = state.addressToolbar.alternativeSearchEngine
?? profile.searchEnginesManager.defaultEngine?.generateModel()
?? searchEnginesManager.defaultEngine?.generateModel()

self.windowUUID = windowUUID
self.searchEngineName = searchEngineModel?.name ?? ""
self.searchEngineImage = searchEngineModel?.image ?? UIImage()
self.searchEnginesManager = profile.searchEnginesManager
self.searchEnginesManager = searchEnginesManager
self.lockIconImageName = state.addressToolbar.lockIconImageName
self.lockIconNeedsTheming = state.addressToolbar.lockIconNeedsTheming
self.safeListedURLImageName = state.addressToolbar.safeListedURLImageName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class TopSitesMiddleware: FeatureFlaggable {
bookmarksTelemetry: BookmarksTelemetry = BookmarksTelemetry(),
unifiedAdsTelemetry: UnifiedAdsCallbackTelemetry = DefaultUnifiedAdsCallbackTelemetry(),
sponsoredTileTelemetry: SponsoredTileTelemetry = DefaultSponsoredTileTelemetry(),
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve(),
logger: Logger = DefaultLogger.shared
) {
self.topSitesManager = topSitesManager ?? TopSitesManager(
Expand All @@ -37,7 +38,7 @@ final class TopSitesMiddleware: FeatureFlaggable {
prefs: profile.prefs
),
topSiteHistoryManager: TopSiteHistoryManager(profile: profile),
searchEnginesManager: profile.searchEnginesManager
searchEnginesManager: searchEnginesManager
)
self.homepageTelemetry = homepageTelemetry
self.bookmarksTelemetry = bookmarksTelemetry
Expand Down
Loading