chrome/browser/privacy_sandbox/notice/docs/architecture.md
This document provides a detailed technical overview of the components within the Privacy Sandbox Notice Framework. It is intended for developers who need a deeper understanding of how the framework operates internally.
The framework is composed of several key C++ classes that work together to manage the notice lifecycle.
NoticeService (The Orchestrator)chrome/browser/privacy_sandbox/notice/notice_service.hProfileKeyedService that orchestrates the entire process of selecting and displaying a notice.Key Responsibilities:
GetRequiredNotices(SurfaceType surface). This method executes a selection algorithm to determine the precise sequence of notices to show:
NoticeApis that are currently enabled, eligible for the user, and have not already been fulfilled.Notices that are registered for the given SurfaceType, are enabled, have not been fulfilled, and can satisfy all of their target APIs' eligibility requirements (e.g., a Consent notice for an API requiring consent). Crucially, it only considers notices whose target APIs are all present in the filtered list from the previous step.NoticeViewGroup or as a group of one). It then uses a scoring algorithm (CompareNoticeGroups) to select the best group. The scoring prioritizes groups that fulfill the most APIs with the fewest number of separate UI interactions.ViewManager implementations for the different surfaces (e.g., DesktopViewManager) call the NoticeService to retrieve the list of required notices. The ViewManager is then responsible for initiating the display of the UI.EventOccurred method. ViewManagers call this to report user interactions, which the service then records in NoticeStorage and uses to update the fulfillment status of the relevant NoticeApis.NoticeCatalogchrome/browser/privacy_sandbox/notice/notice_catalog.hNoticeApis and Notices.Key Responsibilities:
NoticeCatalogImpl::Populate() method is where all NoticeApis and Notices are defined and their relationships are established. This includes setting target APIs, prerequisite APIs, base::Feature flags, and eligibility callbacks.NoticeService: It serves as the single source of truth for the NoticeService's decision-making process.NoticeStoragechrome/browser/privacy_sandbox/notice/notice_storage.hKey Responsibilities:
PrivacySandboxNoticeStorage implementation handles all reading and writing to the profile's PrefService under the privacy_sandbox.notices dictionary.ViewManagers (e.g., DesktopViewManager)chrome/browser/privacy_sandbox/notice/desktop_view_manager.hKey Responsibilities:
NoticeService provides the ViewManager with a list of required notices. The ViewManager is responsible for showing the first notice, and then advancing through the list as user actions are performed. It manages a pending_notices_to_show_ list to track the sequence.ViewManager owns handlers that detect when a notice flow should be initiated. For example, DesktopViewManager owns NavigationHandler, which monitors navigations to specific chrome-owned pages (like the New Tab Page or Settings) before triggering the notice flow.OnEventOccurred method that the UI code calls to report user interactions. The ViewManager forwards this event to the NoticeService. Based on the event (e.g., kAck, kOptIn), it will then advance its internal state and notify the active UI view to either display the next notice in the sequence or close itself. This notification is handled via an Observer pattern, where the UI views are the observers.A SurfaceType is a key concept that enables the framework to be platform-agnostic.
kDesktopNewTab).NoticeService takes a SurfaceType as a parameter when it starts its evaluation. The NoticeCatalog is then filtered to only consider Notices that are registered for that specific surface.SurfaceType enum.NavigationHandler) that can detect when that surface is active.ViewManager.Notices in the catalog for the new surface type.