Skip to content
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

DBP: Restructure AgentManager and scheduler and add tests #2777

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8457fae
Rebase merge
aataraxiaa May 8, 2024
7f6234a
Rebase merge
aataraxiaa May 8, 2024
d4386f4
Rebase merge
aataraxiaa May 8, 2024
bd76677
Rebase merge
aataraxiaa May 8, 2024
4c555b1
Refactor DataBrokerOperation dependency definition, usage
aataraxiaa May 6, 2024
926b53e
Update Builder test post-refactor
aataraxiaa May 6, 2024
2170a1d
Rebase merge
aataraxiaa May 8, 2024
f3468a6
Initial implementation of `DataBrokerProtectionQueueManager` & `DataB…
aataraxiaa May 8, 2024
35aef1c
Post-rebase manual fixes
aataraxiaa May 8, 2024
699ff01
Rebase merge: Scheduler
aataraxiaa May 10, 2024
13c1ae1
Add tests & mocks
aataraxiaa May 9, 2024
6f19c1e
Remove debug command enum, protocol, and usage
aataraxiaa May 9, 2024
76dabb9
Correct log message
aataraxiaa May 9, 2024
6c4a23b
Post-rebase updates/fixes
aataraxiaa May 10, 2024
5de0f3c
PR Feedback Part 1
aataraxiaa May 12, 2024
ec93899
PR Feedback: Fire pixels in queue manager, clear errors on completion…
aataraxiaa May 13, 2024
74b6cc2
PR Feedback: Rename `provide` method
aataraxiaa May 13, 2024
a1283af
PR Feedback: Avoid side-effects, rename errorCollection, and add test
aataraxiaa May 13, 2024
a995cb3
Swiftlint
aataraxiaa May 13, 2024
f7909d6
Merge agentManager and scheduler
THISISDINOSAUR May 13, 2024
e72e05b
Refactor AgentManager to enable testability
THISISDINOSAUR May 13, 2024
be40496
Make IPC server testable
THISISDINOSAUR May 14, 2024
e227ed6
Add mocks for tests and rename MockUserNotification to MockUserNotifi…
THISISDINOSAUR May 14, 2024
b19d9e3
Add AgentManager tests
THISISDINOSAUR May 14, 2024
0698622
Update agent manager log statements
THISISDINOSAUR May 14, 2024
1f80248
Remove out of date comment
THISISDINOSAUR May 14, 2024
8f10093
Merge branch 'feature/pir-stabilization' into elle/dbp-agentmanager-a…
THISISDINOSAUR May 14, 2024
99ea6aa
Integrate new and renamed debug commands
THISISDINOSAUR May 14, 2024
901bf4f
Add debug running status string back
THISISDINOSAUR May 14, 2024
2b5e863
Update references to manual and restore debug run state
THISISDINOSAUR May 14, 2024
e2f29a5
Fix another reference to manual
THISISDINOSAUR May 14, 2024
1bb4a1f
Move scheduler config into config struct
THISISDINOSAUR May 14, 2024
eddab4b
Fix agent manager not being persisted in memory
THISISDINOSAUR May 15, 2024
a00aeea
Fix not calling app launched
THISISDINOSAUR May 15, 2024
028d561
Add interrupted error to queueManager
THISISDINOSAUR May 15, 2024
24a43ae
Add delay to profile saved call to make sure agent has started
THISISDINOSAUR May 15, 2024
c1c2ebd
Add pixels
THISISDINOSAUR May 15, 2024
9b5940a
Fix interrupt error
THISISDINOSAUR May 15, 2024
7a753dc
Add interrupt to unit tests
THISISDINOSAUR May 15, 2024
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
18 changes: 0 additions & 18 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1461,14 +1461,12 @@
56D145F229E6F06D00E3488A /* MockBookmarkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D145F029E6F06D00E3488A /* MockBookmarkManager.swift */; };
56D6A3D629DB2BAB0055215A /* ContinueSetUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D6A3D529DB2BAB0055215A /* ContinueSetUpView.swift */; };
56D6A3D729DB2BAB0055215A /* ContinueSetUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D6A3D529DB2BAB0055215A /* ContinueSetUpView.swift */; };
7B0099792B65013800FE7C31 /* BrowserWindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0099782B65013800FE7C31 /* BrowserWindowManager.swift */; };
7B00997D2B6508B700FE7C31 /* NetworkProtectionProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 7B00997C2B6508B700FE7C31 /* NetworkProtectionProxy */; };
7B00997F2B6508C200FE7C31 /* NetworkProtectionProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 7B00997E2B6508C200FE7C31 /* NetworkProtectionProxy */; };
7B0099822B65C6B300FE7C31 /* MacTransparentProxyProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0099802B65C6B300FE7C31 /* MacTransparentProxyProvider.swift */; };
7B0694982B6E980F00FA4DBA /* VPNProxyLauncher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0694972B6E980F00FA4DBA /* VPNProxyLauncher.swift */; };
7B09CBA92BA4BE8100CF245B /* NetworkProtectionPixelEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B09CBA72BA4BE7000CF245B /* NetworkProtectionPixelEventTests.swift */; };
7B09CBAA2BA4BE8200CF245B /* NetworkProtectionPixelEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B09CBA72BA4BE7000CF245B /* NetworkProtectionPixelEventTests.swift */; };
7B1459542B7D437200047F2C /* BrowserWindowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0099782B65013800FE7C31 /* BrowserWindowManager.swift */; };
7B1459552B7D438F00047F2C /* VPNProxyLauncher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0694972B6E980F00FA4DBA /* VPNProxyLauncher.swift */; };
7B1459572B7D43E500047F2C /* NetworkProtectionProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 7B1459562B7D43E500047F2C /* NetworkProtectionProxy */; };
7B1E819E27C8874900FF0E60 /* ContentOverlayPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1E819B27C8874900FF0E60 /* ContentOverlayPopover.swift */; };
Expand Down Expand Up @@ -1689,10 +1687,6 @@
9D9AE9202AAA3B450026E7DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9D9AE9162AAA3B450026E7DC /* Assets.xcassets */; };
9D9AE9212AAA3B450026E7DC /* UserText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE9172AAA3B450026E7DC /* UserText.swift */; };
9D9AE9222AAA3B450026E7DC /* UserText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE9172AAA3B450026E7DC /* UserText.swift */; };
9D9AE9292AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE9282AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift */; };
9D9AE92A2AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE9282AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift */; };
9D9AE92C2AAB84FF0026E7DC /* DBPMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE92B2AAB84FF0026E7DC /* DBPMocks.swift */; };
9D9AE92D2AAB84FF0026E7DC /* DBPMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9AE92B2AAB84FF0026E7DC /* DBPMocks.swift */; };
9DC70B1A2AA1FA5B005A844B /* LoginItems in Frameworks */ = {isa = PBXBuildFile; productRef = 9DC70B192AA1FA5B005A844B /* LoginItems */; };
9DEF97E12B06C4EE00764F03 /* Networking in Frameworks */ = {isa = PBXBuildFile; productRef = 9DEF97E02B06C4EE00764F03 /* Networking */; };
9F0A2CF82B96A58600C5B8C0 /* BaseBookmarkEntityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F0A2CF72B96A58600C5B8C0 /* BaseBookmarkEntityTests.swift */; };
Expand Down Expand Up @@ -3276,7 +3270,6 @@
56D145ED29E6DAD900E3488A /* DataImportProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataImportProviderTests.swift; sourceTree = "<group>"; };
56D145F029E6F06D00E3488A /* MockBookmarkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBookmarkManager.swift; sourceTree = "<group>"; };
56D6A3D529DB2BAB0055215A /* ContinueSetUpView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContinueSetUpView.swift; sourceTree = "<group>"; };
7B0099782B65013800FE7C31 /* BrowserWindowManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserWindowManager.swift; sourceTree = "<group>"; };
7B0099802B65C6B300FE7C31 /* MacTransparentProxyProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacTransparentProxyProvider.swift; sourceTree = "<group>"; };
7B05829D2A812AC000AC3F7C /* NetworkProtectionOnboardingMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkProtectionOnboardingMenu.swift; sourceTree = "<group>"; };
7B0694972B6E980F00FA4DBA /* VPNProxyLauncher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNProxyLauncher.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3444,8 +3437,6 @@
9D9AE9182AAA3B450026E7DC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9D9AE9192AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgentAppStore.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = DuckDuckGoDBPBackgroundAgentAppStore.entitlements; sourceTree = "<group>"; };
9D9AE91A2AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgent.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = DuckDuckGoDBPBackgroundAgent.entitlements; sourceTree = "<group>"; };
9D9AE9282AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionAgentManager.swift; sourceTree = "<group>"; };
9D9AE92B2AAB84FF0026E7DC /* DBPMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBPMocks.swift; sourceTree = "<group>"; };
9DB6E7222AA0DA7A00A17F3C /* LoginItems */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = LoginItems; sourceTree = "<group>"; };
9F0A2CF72B96A58600C5B8C0 /* BaseBookmarkEntityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseBookmarkEntityTests.swift; sourceTree = "<group>"; };
9F0FFFB32BCCAE37007C87DD /* BookmarkAllTabsDialogCoordinatorViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkAllTabsDialogCoordinatorViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6238,9 +6229,6 @@
isa = PBXGroup;
children = (
9D9AE9152AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgentAppDelegate.swift */,
9D9AE9282AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift */,
7B0099782B65013800FE7C31 /* BrowserWindowManager.swift */,
9D9AE92B2AAB84FF0026E7DC /* DBPMocks.swift */,
9D9AE9172AAA3B450026E7DC /* UserText.swift */,
9D9AE9162AAA3B450026E7DC /* Assets.xcassets */,
9D9AE91A2AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgent.entitlements */,
Expand Down Expand Up @@ -10713,9 +10701,6 @@
buildActionMask = 2147483647;
files = (
31A83FB72BE28D8A00F74E67 /* UserText+DBP.swift in Sources */,
9D9AE92C2AAB84FF0026E7DC /* DBPMocks.swift in Sources */,
7B0099792B65013800FE7C31 /* BrowserWindowManager.swift in Sources */,
9D9AE9292AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift in Sources */,
9D9AE91D2AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgentAppDelegate.swift in Sources */,
9D9AE9212AAA3B450026E7DC /* UserText.swift in Sources */,
);
Expand All @@ -10726,9 +10711,6 @@
buildActionMask = 2147483647;
files = (
31A83FB82BE28D8A00F74E67 /* UserText+DBP.swift in Sources */,
7B1459542B7D437200047F2C /* BrowserWindowManager.swift in Sources */,
9D9AE92D2AAB84FF0026E7DC /* DBPMocks.swift in Sources */,
9D9AE92A2AAA43EB0026E7DC /* DataBrokerProtectionAgentManager.swift in Sources */,
9D9AE91E2AAA3B450026E7DC /* DuckDuckGoDBPBackgroundAgentAppDelegate.swift in Sources */,
9D9AE9222AAA3B450026E7DC /* UserText.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ struct DataBrokerProtectionFeatureDisabler: DataBrokerProtectionFeatureDisabling

func disableAndDelete() {
if !DefaultDataBrokerProtectionFeatureVisibility.bypassWaitlist {
loginItemInterface.disableLoginItem()

do {
try dataManager.removeAllData()
// the dataManagers delegate handles login item disabling
} catch {
os_log("DataBrokerProtectionFeatureDisabler error: disableAndDelete, error: %{public}@", log: .error, error.localizedDescription)
}
Expand Down
23 changes: 11 additions & 12 deletions DuckDuckGo/DBP/DataBrokerProtectionLoginItemInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import DataBrokerProtection
import Common

protocol DataBrokerProtectionLoginItemInterface: DataBrokerProtectionAgentInterface {
func disableLoginItem()
func enableLoginItem()
protocol DataBrokerProtectionLoginItemInterface: DataBrokerProtectionAppToAgentInterface {
func dataDeleted()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

}

/// Launches a login item and then communicates with it through IPC
Expand All @@ -43,35 +42,35 @@

// MARK: - Login Item Management

func disableLoginItem() {
private func disableLoginItem() {
DataBrokerProtectionLoginItemPixels.fire(pixel: GeneralPixel.dataBrokerDisableLoginItemDaily, frequency: .daily)
loginItemsManager.disableLoginItems([.dbpBackgroundAgent])
}

func enableLoginItem() {
private func enableLoginItem() {
DataBrokerProtectionLoginItemPixels.fire(pixel: GeneralPixel.dataBrokerEnableLoginItemDaily, frequency: .daily)
loginItemsManager.enableLoginItems([.dbpBackgroundAgent], log: .dbp)
}

// MARK: - DataBrokerProtectionAgentInterface
// MARK: - DataBrokerProtectionLoginItemInterface

func dataDeleted() {
disableLoginItem()
}

// MARK: - DataBrokerProtectionAppToAgentInterface
// MARK: - DataBrokerProtectionAgentAppEvents

func profileSaved() {
enableLoginItem()
ipcClient.profileSaved { error in

Check failure on line 66 in DuckDuckGo/DBP/DataBrokerProtectionLoginItemInterface.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Unused parameter in a closure should be replaced with _ (unused_closure_parameter)
// TODO

Check failure on line 67 in DuckDuckGo/DBP/DataBrokerProtectionLoginItemInterface.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

TODOs should be resolved (todo)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the pixels that are pending

}

func dataDeleted() {
ipcClient.dataDeleted { error in
// TODO
}
}

func appLaunched() {
ipcClient.appLaunched { error in

Check failure on line 72 in DuckDuckGo/DBP/DataBrokerProtectionLoginItemInterface.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Unused parameter in a closure should be replaced with _ (unused_closure_parameter)
// TODO

Check failure on line 73 in DuckDuckGo/DBP/DataBrokerProtectionLoginItemInterface.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

TODOs should be resolved (todo)
}
}

Expand Down
165 changes: 0 additions & 165 deletions DuckDuckGoDBPBackgroundAgent/DataBrokerProtectionAgentManager.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class DuckDuckGoDBPBackgroundAgentAppDelegate: NSObject, NSApplicationDele
func applicationDidFinishLaunching(_ aNotification: Notification) {
os_log("DuckDuckGoAgent started", log: .dbpBackgroundAgent, type: .info)

let manager = DataBrokerProtectionAgentManager.shared
let manager = DataBrokerProtectionAgentManagerProvider.agentManager()
manager.agentFinishedLaunching()

setupStatusBarMenu()
Expand Down
Loading
Loading