Skip to content
This repository has been archived by the owner on Feb 24, 2025. It is now read-only.

Display Privacy Stats on HTML New Tab Page #3611

Merged
merged 23 commits into from
Nov 29, 2024
Merged

Display Privacy Stats on HTML New Tab Page #3611

merged 23 commits into from
Nov 29, 2024

Conversation

ayoy
Copy link
Collaborator

@ayoy ayoy commented Nov 28, 2024

Task/Issue URL: https://app.asana.com/0/72649045549333/1208246350498754/f
Tech Design URL: https://app.asana.com/0/481882893211075/1208848285586302

Description:
This change adds support for displaying Privacy Stats on New Tab Page.

Steps to test this PR:

  1. Clean app data and launch the app from Xcode, set internal user state and enable HTML NTP via Debug Menu -> Feature Flag Overrides.
  2. Optionally import bookmarks to have some easily accessible websites for visiting quickly.
  3. Open a new window to have NTP in one window and do web browsing in another.
  4. Visit a website and watch the NTP privacy stats widget reporting blocked trackers.
  5. Expand the widget to see the breakdown of blocked trackers.

Test that reporting multiple blocked trackers concurrently works well:

  1. This is simple because we have a second implementation in place (for the old Privacy Feed) which we can use as a benchmark.
  2. Open multiple websites at the same time (tip: I use right click on bookmarks folder - open in new tabs) and watch the stats get populated.
  3. Use Debug Menu to switch back to native NTP and verify that the number of reported trackers is the same.

Test evicting old stats:

  1. Pro tip: close Outlook app prior to changing system date or it will go crazy with notifications.
  2. Move system date to + 1 day torward.
  3. Visit a website, verify that stats are bumped.
  4. Move system date to +6 days forward (so +7 days in total from now - extra tip: make sure you update month to December or you'll actually move back by 4 weeks 😂). This will cause the first day stats to get deleted.
  5. Visit a website and verify that stats are updated to lower values.
  6. Reset the system date to current.
  7. Visit some websites to populate the stats.
  8. Press fire button and verify that stats are cleared.

Definition of Done:


Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

Copy link
Contributor

github-actions bot commented Nov 28, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against 89d9ed9

@ayoy ayoy requested a review from aataraxiaa November 29, 2024 09:02
@ayoy ayoy marked this pull request as ready for review November 29, 2024 09:02
@ayoy ayoy requested review from aataraxiaa and removed request for aataraxiaa November 29, 2024 09:03
@ayoy ayoy requested a review from aataraxiaa November 29, 2024 09:10
Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Nice one @ayoy, only a few minor comments here. 👍🏼

let count: Int64
let displayName: String

static func otherCompanies(count: Int64) -> TrackerCompany {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: should be called otherCompany as the return is singular

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the sum of all other companies (the non-top-100 companies), so I'd rather keep it plural if that makes sense.

}

private enum Const {
static let maxTopCompaniesCount: Int = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Maybe add documentation explaining why 100 is the max here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure thing 👍

public static func make(location: URL) -> CoreDataDatabase {
let bundle = PrivacyStats.bundle
guard let model = CoreDataDatabase.loadModel(from: bundle, named: "PrivacyStats") else {
fatalError("Failed to load model")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a fatalError? Could we gracefully handle privacy stats not working as expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could throw an error and handle it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I've clearly taken the shortcut here. All other database stacks use fatalError here but it's a weak justification, as users could probably live without privacy stats, rather than without Bookmarks. Let me try to do something about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, now I know what's up. I've been here already, trying to make it not crash with a fatal error, but unfortunately this initialization is asynchronous and while we have the database object ready, we can only learn that it's unusable in an asynchronous callback. Reworking privacy stats to be asynchronous would require major changes to entire NTP loading mechanism. I will add it to the project to consider adding privacy stats module to NTP after a delay, but given it requires extra work I'd skip it for now.

After all, if the database crashes here, it's either:

  • the user doesn't have space on disk, which is recoverable and they should take care of it anyway
  • we messed up database migration which should really be caught earlier during the release process (and also doesn't have a chance of happening for the v1 ;))

Copy link
Contributor

Choose a reason for hiding this comment

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

Reasonable justification.

@aataraxiaa
Copy link
Contributor

Ran through tests @ayoy and it works great, nice work! 👍🏼

Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Thanks @ayoy, LGTM!

@ayoy ayoy assigned ayoy and unassigned aataraxiaa Nov 29, 2024
@ayoy ayoy merged commit 9134ba2 into main Nov 29, 2024
18 of 20 checks passed
@ayoy ayoy deleted the dominik/privacy-stats branch November 29, 2024 14:54
samsymons added a commit that referenced this pull request Nov 29, 2024
# By Anka (2) and others
# Via GitHub (2) and Michal Smaga (1)
* main:
  Revert to empty RMF config for debug builds (#3616)
  Fix test
  Display Privacy Stats on HTML New Tab Page (#3611)
  point to BSK branch and updates (#3606)
  Bump version to 1.116.0 (319)
  Client displays correct subscription (#3581)
  Bump version to 1.116.0 (318)
  [Release PR] Add StoreKit debugging menu options (#3607)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
samsymons added a commit that referenced this pull request Nov 30, 2024
# By Anka (2) and others
# Via GitHub (2) and Michal Smaga (1)
* main:
  Add support for RMF survey `locale` parameter (#3613)
  Revert to empty RMF config for debug builds (#3616)
  Fix test
  Display Privacy Stats on HTML New Tab Page (#3611)
  point to BSK branch and updates (#3606)
  Bump version to 1.116.0 (319)
  Client displays correct subscription (#3581)
  Bump version to 1.116.0 (318)
  [Release PR] Add StoreKit debugging menu options (#3607)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants