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 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions firefox-ios/Client/Application/DependencyHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class DependencyHelper {
let profile: Profile = appDelegate.profile
AppContainer.shared.register(service: profile)

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

let searchEnginesManagerProvider: SearchEnginesManagerProvider = searchEnginesManager
AppContainer.shared.register(service: searchEnginesManagerProvider)

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
17 changes: 14 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 @@ -365,7 +372,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 @@ -11,11 +11,11 @@ final class SearchEngineSelectionMiddleware {
private let searchEnginesManager: SearchEnginesManagerProvider

init(profile: Profile = AppContainer.shared.resolve(),
searchEnginesManager: SearchEnginesManagerProvider? = nil,
searchEnginesManager: SearchEnginesManagerProvider = 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TopSitesDataAdaptorImplementation: TopSitesDataAdaptor, FeatureFlaggable {
private let contileProvider: ContileProviderInterface
private let unifiedAdsProvider: UnifiedAdsProviderInterface
private let dispatchGroup: DispatchGroupInterface
private let searchEnginesManager: SearchEnginesManager

// Pre-loading the data with a default number of tiles so we always show section when needed
// If this isn't done, then no data will be found from the view model and section won't show
Expand All @@ -52,6 +53,7 @@ class TopSitesDataAdaptorImplementation: TopSitesDataAdaptor, FeatureFlaggable {
contileProvider: ContileProviderInterface = ContileProvider(),
unifiedAdsProvider: UnifiedAdsProviderInterface = UnifiedAdsProvider(),
notificationCenter: NotificationProtocol = NotificationCenter.default,
searchEnginesManager: SearchEnginesManager = AppContainer.shared.resolve(),
dispatchGroup: DispatchGroupInterface = DispatchGroup()
) {
self.profile = profile
Expand All @@ -60,6 +62,7 @@ class TopSitesDataAdaptorImplementation: TopSitesDataAdaptor, FeatureFlaggable {
self.contileProvider = contileProvider
self.unifiedAdsProvider = unifiedAdsProvider
self.notificationCenter = notificationCenter
self.searchEnginesManager = searchEnginesManager
self.dispatchGroup = dispatchGroup
topSiteHistoryManager.delegate = self

Expand Down Expand Up @@ -194,7 +197,7 @@ class TopSitesDataAdaptorImplementation: TopSitesDataAdaptor, FeatureFlaggable {
if sponsoredTileSpaces > 0 {
sites.addSponsoredTiles(sponsoredTileSpaces: sponsoredTileSpaces,
contiles: contiles,
defaultSearchEngine: profile.searchEnginesManager.defaultEngine)
defaultSearchEngine: searchEnginesManager.defaultEngine)
}
}

Expand Down
Loading