Skip to content

Commit

Permalink
Adding app backgrounded result to rule compilation (#3533)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1204556816597738/1208691511506504/f
Tech Design URL:
CC:

**Description**:

<!--
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**:
1.
2.

<!--
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)?

**Copy Testing**:

* [ ] Use of correct apostrophes in new copy, ie `’` rather than `'`

**Orientation Testing**:

* [ ] Portrait
* [ ] Landscape

**Device Testing**:

* [ ] iPhone SE (1st Gen)
* [ ] iPhone 8
* [ ] iPhone X
* [ ] iPhone 14 Pro
* [ ] iPad

**OS Testing**:

* [ ] iOS 15
* [ ] iOS 16
* [ ] iOS 17

**Theme Testing**:

* [ ] Light theme
* [ ] Dark theme

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
studiosutara authored Nov 5, 2024
1 parent 1a978c2 commit 779b5bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ extension Pixel.Event {

case tabClosed = "tab_closed"
case appQuit = "app_quit"
case appBackgrounded = "app_backgrounded"
case success

}
Expand Down
17 changes: 17 additions & 0 deletions DuckDuckGo/RulesCompilationMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class RulesCompilationMonitor {
selector: #selector(applicationWillTerminate(_:)),
name: UIApplication.willTerminateNotification,
object: nil)

NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidEnterBackground),
name: UIApplication.didEnterBackgroundNotification,
object: nil)
}

/// Called when a Tab is going to wait for Content Blocking Rules compilation
Expand Down Expand Up @@ -88,6 +93,18 @@ final class RulesCompilationMonitor {

reportWaitTime(CACurrentMediaTime() - waitStart, result: .appQuit)
}

/// If App is going into the background while the rules are still being compiled, report the time so that we
/// do not continue to count the time in background
@objc func applicationDidEnterBackground() {
guard !didReport,
!waiters.isEmpty,
let waitStart = waitStart
else { return }

reportWaitTime(CACurrentMediaTime() - waitStart, result: .appBackgrounded)
}


private func reportWaitTime(_ waitTime: TimeInterval, result: Pixel.Event.CompileRulesResult) {
didReport = true
Expand Down

0 comments on commit 779b5bb

Please sign in to comment.