1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_
6 #define COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_
8 #include "base/containers/flat_set.h"
9 #include "components/browsing_topics/common/common_types.h"
10 #include "content/public/browser/page_user_data.h"
14 } // namespace history
16 namespace browsing_topics {
18 // Tracks page-level (i.e. primary main frame document) signals to determine
19 // whether the page is eligible to be included in browsing topics calculation.
20 // Also tracks the context domains that have used the Topics API in the page.
21 class BrowsingTopicsPageLoadDataTracker
22 : public content::PageUserData<BrowsingTopicsPageLoadDataTracker> {
24 BrowsingTopicsPageLoadDataTracker(const BrowsingTopicsPageLoadDataTracker&) =
26 BrowsingTopicsPageLoadDataTracker& operator=(
27 const BrowsingTopicsPageLoadDataTracker&) = delete;
29 ~BrowsingTopicsPageLoadDataTracker() override;
31 // Called when the document.browsingTopics() API is used in the page.
32 void OnBrowsingTopicsApiUsed(const HashedDomain& hashed_context_domain,
33 const std::string& context_domain,
34 history::HistoryService* history_service);
37 friend class PageUserData;
39 explicit BrowsingTopicsPageLoadDataTracker(content::Page& page);
41 // |eligible_to_commit_| means all the commit time prerequisites are met
42 // (i.e. IP was publicly routable AND permissions policy is "allow").
43 bool eligible_to_commit_ = false;
45 HashedHost hashed_main_frame_host_;
47 ukm::SourceId source_id_;
49 base::flat_set<HashedDomain> observed_hashed_context_domains_;
51 PAGE_USER_DATA_KEY_DECL();
54 } // namespace browsing_topics
56 #endif // COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_