Skip to content

Commit

Permalink
Fix Network Controller leak and Dependency Provider usage (#3367)
Browse files Browse the repository at this point in the history
<!--
Note: This checklist is a reminder of our shared engineering
expectations. Feel free to change it, although assigning a GitHub
reviewer and the items in bold are required.

⚠️ If you're an external contributor, please file an issue first before
working on a PR, as we can't guarantee that we will accept your changes
if they haven't been discussed ahead of time. Thanks!
-->

Task/Issue URL:
https://app.asana.com/0/414235014887631/1208331423616717/f
Tech Design URL:
CC:

**Description**:

Fix Network Controller leak and Dependency Provider usage so it doesn't
generate multiple instances unnecessarily.

<!--
If at any point it isn't actively being worked on/ready for
review/otherwise moving forward strongly consider closing it (or not
opening it in the first place). If you decide not to close it, use Draft
PR while work is still in progress or use `DO NOT MERGE` label to
clarify the PRs state and comment with more information.
-->

**Steps to test this PR**:

Run app with allocations & leaks Instruments to ensure no extra
instances of Network related classes are created.

Smoke test app instantiation and lifecycle around DI changes.

<!--
Before submitting a PR, please ensure you have tested the combinations
you expect the reviewer to test, then delete configurations you *know*
do not need explicit testing.

Using a simulator where a physical device is unavailable is acceptable.
-->

**Definition of Done (Internal Only)**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?


---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)

---------

Co-authored-by: Chris Brind <[email protected]>
  • Loading branch information
bwaresiak and brindy authored Sep 18, 2024
1 parent 05718f9 commit 56cc6c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions DuckDuckGo/NetworkProtectionTunnelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
private func subscribeToConfigurationChanges() {
notificationCenter.publisher(for: .NEVPNConfigurationChange)
.receive(on: DispatchQueue.main)
.sink { _ in
.sink { [weak self] _ in
guard let self = self else { return }
Task { @MainActor in
guard let manager = self.internalManager else {
return
Expand All @@ -346,7 +347,9 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr

private func subscribeToStatusChanges() {
notificationCenter.publisher(for: .NEVPNStatusDidChange)
.sink(receiveValue: handleStatusChange(_:))
.sink { [weak self] value in
self?.handleStatusChange(value)
}
.store(in: &cancellables)
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/StubAutofillLoginImportStateProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ struct StubAutofillLoginImportStateProvider: AutofillLoginImportStateProvider {
var credentialsImportPromptPresentationCount: Int = 0

var isAutofillEnabled: Bool {
AppDependencyProvider().appSettings.autofillCredentialsEnabled
AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled
}

func hasNeverPromptWebsitesFor(_ domain: String) -> Bool {
AppDependencyProvider().autofillNeverPromptWebsitesManager.hasNeverPromptWebsitesFor(domain: domain)
AppDependencyProvider.shared.autofillNeverPromptWebsitesManager.hasNeverPromptWebsitesFor(domain: domain)
}
}
4 changes: 2 additions & 2 deletions DuckDuckGo/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TabManager {
contextualOnboardingPresenter: contextualOnboardingPresenter,
contextualOnboardingLogic: contextualOnboardingLogic,
onboardingPixelReporter: onboardingPixelReporter,
featureFlagger: AppDependencyProvider().featureFlagger)
featureFlagger: AppDependencyProvider.shared.featureFlagger)
controller.applyInheritedAttribution(inheritedAttribution)
controller.attachWebView(configuration: configuration,
andLoadRequest: url == nil ? nil : URLRequest.userInitiated(url!),
Expand Down Expand Up @@ -167,7 +167,7 @@ class TabManager {
contextualOnboardingPresenter: contextualOnboardingPresenter,
contextualOnboardingLogic: contextualOnboardingLogic,
onboardingPixelReporter: onboardingPixelReporter,
featureFlagger: AppDependencyProvider().featureFlagger)
featureFlagger: AppDependencyProvider.shared.featureFlagger)
controller.attachWebView(configuration: configCopy,
andLoadRequest: request,
consumeCookies: !model.hasActiveTabs,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/TabViewControllerLongPressMenuExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension TabViewController {
contextualOnboardingPresenter: contextualOnboardingPresenter,
contextualOnboardingLogic: contextualOnboardingLogic,
onboardingPixelReporter: onboardingPixelReporter,
featureFlagger: AppDependencyProvider().featureFlagger)
featureFlagger: AppDependencyProvider.shared.featureFlagger)
tabController.isLinkPreview = true
let configuration = WKWebViewConfiguration.nonPersistent()
tabController.attachWebView(configuration: configuration, andLoadRequest: URLRequest.userInitiated(url), consumeCookies: false)
Expand Down

0 comments on commit 56cc6c7

Please sign in to comment.