1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_
#define COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_
#include "base/containers/flat_set.h"
#include "components/browsing_topics/common/common_types.h"
#include "content/public/browser/page_user_data.h"
namespace history {
class HistoryService;
} // namespace history
namespace browsing_topics {
// Tracks several page-level (i.e. primary main frame document) Topics signals,
// such as whether the page is eligible to be included in topics calculation
// (i.e. to "observe" topics), the context domains that have requested to
// observe topics, the client side redirect chain's status, etc.
class BrowsingTopicsPageLoadDataTracker
: public content::PageUserData<BrowsingTopicsPageLoadDataTracker> {
public:
BrowsingTopicsPageLoadDataTracker(const BrowsingTopicsPageLoadDataTracker&) =
delete;
BrowsingTopicsPageLoadDataTracker& operator=(
const BrowsingTopicsPageLoadDataTracker&) = delete;
~BrowsingTopicsPageLoadDataTracker() override;
// Called when the document.browsingTopics() API is used in the page.
void OnBrowsingTopicsApiUsed(const HashedDomain& hashed_context_domain,
const std::string& context_domain,
history::HistoryService* history_service,
bool observe);
const std::set<HashedHost>& redirect_hosts_with_topics_invoked() const {
return redirect_hosts_with_topics_invoked_;
}
HashedHost hashed_main_frame_host() const { return hashed_main_frame_host_; }
ukm::SourceId source_id_before_redirects() const {
return source_id_before_redirects_;
}
bool topics_invoked() const { return topics_invoked_; }
private:
friend class PageUserData;
explicit BrowsingTopicsPageLoadDataTracker(content::Page& page);
BrowsingTopicsPageLoadDataTracker(
content::Page& page,
std::set<HashedHost> redirect_hosts_with_topics_invoked,
ukm::SourceId source_id_before_redirects);
// Whether this page is eligible to observe topics (i.e. IP was publicly
// routable AND permissions policy is "allow").
bool eligible_to_observe_ = false;
HashedHost hashed_main_frame_host_;
// Main frame hosts from the redirect chain that invoked the Topics API.
// Initialized with the *previous* redirect chain's hosts, and may be
// expanded to include the current host when Topics is called. The size is
// limited to 5 to prevent unbounded growth.
std::set<HashedHost> redirect_hosts_with_topics_invoked_;
ukm::SourceId source_id_;
base::flat_set<HashedDomain> observed_hashed_context_domains_;
// The UKM source ID of the page before the client-side redirects.
ukm::SourceId source_id_before_redirects_;
bool topics_invoked_ = false;
PAGE_USER_DATA_KEY_DECL();
};
} // namespace browsing_topics
#endif // COMPONENTS_BROWSING_TOPICS_BROWSING_TOPICS_PAGE_LOAD_DATA_TRACKER_H_
|