Closed Bug 2030052 Opened 3 months ago Closed 1 month ago

Update Anti Tracking Database to Ingest Real Time Tracking Data

Categories

(Core :: Privacy: Anti-Tracking, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: jhan, Assigned: jhan)

References

Details

Attachments

(2 files)

The anti-tracking database (protections.sqlite, backed by TrackingDBService) today is only written to when a WindowGlobalParent is destroyed: i.e. when a page unloads or a tab closes (dom/ipc/WindowGlobalParent.cpp). Long-lived tabs (Gmail, YouTube, Discord, etc.) accumulate blocking events in ContentBlockingLog for hours or days and never flush them, so anything reading the database: the Protection Dashboard, milestone messaging, and the upcoming Android Global Protections Dashboard (Bug 2016140, Bug 2030080), sees stale data.

We need to ingest tracking events from browser content in real time instead of waiting for page destruction.
Proposed approach:

  • Add a periodic flush from ContentBlockingLog to TrackingDBService while the window is alive (timer-based, interval configurable via pref).
  • Also flush on visibility change (tab hidden / pagehide) so dashboards are fresh when the user switches away.
  • Make ContentBlockingLog::ReportLog() incremental — track a "last reported" cursor per LogEntry so repeated flushes don't double-count. Today Stringify() serializes the entire mLog.
  • Preserve existing exclusions: private browsing, non-top-level documents, and the browser.contentblocking.database.enabled pref.
Severity: -- → N/A
See Also: → 2016140
See Also: → protection-panel

TrackingDBService previously only wrote to protections.sqlite when a
WindowGlobalParent was destroyed, so long-lived top-level tabs never
contributed their blocking events until the tab closed. Consumers like the
Protection Dashboard and milestone messaging saw stale data.

This change adds a flush-on-query barrier: before each read, TrackingDBService
forces every live top-level WindowGlobalParent to flush its in-memory log
to the database, then awaits the pending DeferredTask writes.

To keep repeated flushes from double-counting against the daily aggregated
counters, ContentBlockingLog::Stringify() gains a delta mode that emits
only entries added since the last MarkAsReported() call, and ReportLog()
skips the IPC round-trip when the delta is empty.

Gated behind browser.contentblocking.database.flushOnQuery.enabled (default
true). Preserves the existing private-browsing, out-of-process, and
top-level-content gates by routing both the teardown and query-time flushes
through a shared WindowGlobalParent::MaybeReportContentBlockingLog helper.

Opens a tab with a blocked tracker and, without closing the tab, queries
TrackingDBService.getEventsByDateRange. The event count must be nonzero —
verifying the query-time flush barrier routed the live ContentBlockingLog
through to the database.

Also covers the idempotency path: a second query returns the same count
(per-origin Stringify cursor prevents re-emitting entries), and closing the
tab afterwards triggers the teardown flush without increasing the count.

A separate sub-test flips browser.contentblocking.database.flushOnQuery.enabled
off and verifies the live events do NOT appear — the pref gates the barrier.

Attachment #9571483 - Attachment description: Bug 2030052 - Part 2: Browser test for anti-tracking DB flush-on-query r?timhuang → Bug 2030052 - Browser test for anti-tracking DB flush-on-query r?timhuang
Attachment #9571483 - Attachment description: Bug 2030052 - Browser test for anti-tracking DB flush-on-query r?timhuang → Bug 2030052 - Part 2: Browser test for anti-tracking DB flush-on-query r?timhuang
Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
QA Whiteboard: [qa-triage-done-c153/b152]
See Also: → 2043202
See Also: → 2044300
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: