browsing_topics_page_load_data_tracker.h 1.9 KB

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