Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #1938: Initialize P3A service and add P3A pref in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson authored and soner-yuksel committed Nov 9, 2022
1 parent 78fc6f6 commit 7158f98
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
9 changes: 9 additions & 0 deletions App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
.didFinishLaunching(options: launchOptions ?? [:])
)

// DAU may not have pinged on the first launch so weekOfInstallation pref may not be set yet
if let weekOfInstall = Preferences.DAU.weekOfInstallation.value ??
Preferences.DAU.installationDate.value?.mondayOfCurrentWeekFormatted {
braveCore.initializeP3AService(
forChannel: AppConstants.buildChannel.serverChannelParam,
weekOfInstall: weekOfInstall
)
}

return shouldPerformAdditionalDelegateHandling
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ extension BrowserViewController: TopToolbarDelegate {
profile: self.profile,
tabManager: self.tabManager,
feedDataSource: self.feedDataSource,
historyAPI: self.braveCore.historyAPI
historyAPI: self.braveCore.historyAPI,
p3aUtilities: self.braveCore.p3aUtils
)
let container = SettingsNavigationController(rootViewController: shieldsAndPrivacy)
container.isModalInPresentation = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
let tabManager: TabManager
let feedDataSource: FeedDataSource
let historyAPI: BraveHistoryAPI
let p3aUtilities: BraveP3AUtils

private let cookieConsentNoticesRowUUID = UUID()
private var filterListsSubscription: AnyCancellable?
private var currentCookieConsentNoticeBlockingState: Bool

init(profile: Profile, tabManager: TabManager, feedDataSource: FeedDataSource, historyAPI: BraveHistoryAPI) {
init(
profile: Profile,
tabManager: TabManager,
feedDataSource: FeedDataSource,
historyAPI: BraveHistoryAPI,
p3aUtilities: BraveP3AUtils
) {
self.profile = profile
self.tabManager = tabManager
self.feedDataSource = feedDataSource
self.historyAPI = historyAPI

self.p3aUtilities = p3aUtilities

self.currentCookieConsentNoticeBlockingState = FilterListResourceDownloader.shared.isEnabled(
for: FilterList.cookieConsentNoticesComponentID
)
Expand Down Expand Up @@ -264,6 +273,16 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
}()

private lazy var otherSettingsSection: Section = {
let p3aRow = Row.boolRow(
title: Strings.P3A.settingTitle,
detailText: Strings.P3A.settingSubtitle,
toggleValue: p3aUtilities.isP3AEnabled,
valueChange: { [unowned self] isOn in
p3aUtilities.isP3AEnabled = isOn
},
cellReuseId: "p3a"
)

var section = Section(
header: .title(Strings.otherPrivacySettingsSection),
rows: [
Expand All @@ -289,6 +308,7 @@ class BraveShieldsAndPrivacySettingsController: TableViewController {
)
)
}
section.rows.append(p3aRow)

return section
}()
Expand Down
6 changes: 5 additions & 1 deletion Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SettingsViewController: TableViewController {
private let passwordAPI: BravePasswordAPI
private let syncAPI: BraveSyncAPI
private let syncProfileServices: BraveSyncProfileServiceIOS
private let p3aUtilities: BraveP3AUtils
private let keyringStore: KeyringStore?
private let cryptoStore: CryptoStore?
private let windowProtection: WindowProtection?
Expand Down Expand Up @@ -74,6 +75,7 @@ class SettingsViewController: TableViewController {
self.passwordAPI = braveCore.passwordAPI
self.syncAPI = braveCore.syncAPI
self.syncProfileServices = braveCore.syncProfileService
self.p3aUtilities = braveCore.p3aUtils
self.keyringStore = keyringStore
self.cryptoStore = cryptoStore

Expand Down Expand Up @@ -205,7 +207,9 @@ class SettingsViewController: TableViewController {
profile: self.profile,
tabManager: self.tabManager,
feedDataSource: self.feedDataSource,
historyAPI: self.historyAPI)
historyAPI: self.historyAPI,
p3aUtilities: self.p3aUtilities
)
self.navigationController?.pushViewController(controller, animated: true)
}, image: UIImage(named: "settings-shields", in: .module, compatibleWith: nil)!, accessory: .disclosureIndicator)
],
Expand Down
15 changes: 14 additions & 1 deletion Sources/BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ extension Strings {
public static let HTTPSEverywhere = NSLocalizedString("HTTPSEverywhere", tableName: "BraveShared", bundle: .module, value: "Upgrade Connections to HTTPS", comment: "")
public static let HTTPSEverywhereDescription = NSLocalizedString("HTTPSEverywhereDescription", tableName: "BraveShared", bundle: .module, value: "Opens sites using secure HTTPS instead of HTTP when possible.", comment: "")
public static let blockPhishingAndMalware = NSLocalizedString("BlockPhishingAndMalware", tableName: "BraveShared", bundle: .module, value: "Block Phishing and Malware", comment: "")
public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .module, value: "Block dangerous sites", comment: "")
public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .module, value: "Block Dangerous Sites", comment: "")
public static let googleSafeBrowsingUsingWebKitDescription = NSLocalizedString("GoogleSafeBrowsingUsingWebKitDescription", tableName: "BraveShared", bundle: .module, value: "Sends obfuscated URLs of some pages you visit to the Google Safe Browsing service, when your security is at risk.", comment: "")
public static let contentFiltering = NSLocalizedString("ContentFiltering", tableName: "BraveShared", bundle: .module, value: "Content Filtering", comment: "A title to the content filtering page under global shield settings and the title on the Content filtering page")
public static let blockMobileAnnoyances = NSLocalizedString("blockMobileAnnoyances", tableName: "BraveShared", bundle: .module, value: "Block 'Switch to App' Notices", comment: "A title for setting which blocks 'switch to app' popups")
Expand Down Expand Up @@ -4093,6 +4093,19 @@ extension Strings {
}
}

// P3A
extension Strings {
public struct P3A {
public static let settingTitle = NSLocalizedString("p3a.settingTitle", tableName: "BraveShared", bundle: .module,
value: "Allow Privacy-Preserving Product Analytics (P3A)",
comment: "The title for the setting that will allow a user to toggle sending privacy preserving analytics to Brave. P3A is the name of a Brave Product")

public static let settingSubtitle = NSLocalizedString("p3a.settingSubtitle", tableName: "BraveShared", bundle: .module,
value: "Anonymized P3A info helps Brave estimate overall usage and ensure we're improving popular features",
comment: "A subtitle shown on the setting that toggles analytics on Brave. P3A is the name of a Brave Product")
}
}

// Page Zoom
extension Strings {
public struct PageZoom {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Growth/DAU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public class DAU {

extension Date {
/// Returns date of current week's monday in YYYY-MM-DD formatted String
var mondayOfCurrentWeekFormatted: String? {
public var mondayOfCurrentWeekFormatted: String? {
// We look for a previous monday because Sunday is considered a beggining of a new week using default gregorian calendar.
// For example if today is Sunday, the next Monday using Calendar would be the day after Sunday which is wrong.
// That's why backward search may sound counter intuitive.
Expand Down

0 comments on commit 7158f98

Please sign in to comment.