Skip to content

Commit

Permalink
[Topics] Organize Taxonomy v1 as a Semantic Tree
Browse files Browse the repository at this point in the history
Use this tree to filter topics by observers who viewed topic descendants instead of using a child-to-parent map. Use this tree as the source of truth for a topic's name.

This change will support adding new taxonomies.

Binary-Size: Size increase is unavoidable
Change-Id: I9991053a8a0f8d5ed6f3974a46e6d10c2d6cbb75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4330034
Reviewed-by: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: Josh Karlin <jkarlin@chromium.org>
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1119815}
  • Loading branch information
Abigail Katcoff authored and Chromium LUCI CQ committed Mar 21, 2023
1 parent ee9ea07 commit fef6dce
Show file tree
Hide file tree
Showing 12 changed files with 2,010 additions and 680 deletions.
1 change: 1 addition & 0 deletions components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ test("components_unittests") {
"//components/blocked_content:unit_tests",
"//components/browsing_data/content:unit_tests",
"//components/browsing_topics:unit_tests",
"//components/browsing_topics/common:unit_tests",
"//components/captive_portal/content:unit_tests",
"//components/cast_receiver:unit_tests",
"//components/cast_streaming:unit_tests",
Expand Down
1 change: 0 additions & 1 deletion components/browsing_topics/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ source_set("unit_tests") {
"browsing_topics_state_unittest.cc",
"epoch_topics_unittest.cc",
"topic_and_domains_unittest.cc",
"util_unittest.cc",
]

deps = [
Expand Down
7 changes: 3 additions & 4 deletions components/browsing_topics/browsing_topics_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "components/browsing_topics/util.h"
#include "components/browsing_topics/common/semantic_tree.h"
#include "components/history/core/browser/history_service.h"
#include "components/optimization_guide/content/browser/page_content_annotations_service.h"
#include "components/privacy_sandbox/canonical_topic.h"
Expand Down Expand Up @@ -444,8 +444,7 @@ void BrowsingTopicsCalculator::OnGetTopicsForHostsCompleted(
// For each top topic, derive the context domains that observed it
std::vector<TopicAndDomains> top_topics_and_observing_domains;

const std::map<Topic, std::vector<Topic>> parent_to_child_topic_map =
GetParentToChildTopicMap();
SemanticTree semantic_tree;

for (const Topic& topic : top_topics) {
if (!privacy_sandbox_settings_->IsTopicAllowed(
Expand All @@ -462,7 +461,7 @@ void BrowsingTopicsCalculator::OnGetTopicsForHostsCompleted(

// Calculate descendant topics + their observing context domains
std::set<Topic> descendant_topics =
GetDescendantTopics(topic, parent_to_child_topic_map);
semantic_tree.GetDescendantTopics(topic);
for (const Topic& descendant_topic : descendant_topics) {
std::set<HashedDomain> descendant_topic_observation_domains =
GetTopicObservationDomains(descendant_topic, topic_hosts_map,
Expand Down
18 changes: 17 additions & 1 deletion components/browsing_topics/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ component("common") {
sources = [
"common_types.cc",
"common_types.h",
"semantic_tree.cc",
"semantic_tree.h",
]

deps = [ "//base" ]
deps = [
"//base",
"//components/strings:components_strings_grit",
]
}

source_set("unit_tests") {
testonly = true
sources = [ "semantic_tree_unittest.cc" ]

deps = [
":common",
"//base/test:test_support",
"//components/strings:components_strings_grit",
]
}
3 changes: 3 additions & 0 deletions components/browsing_topics/common/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+components/strings/grit/components_strings.h",
]

0 comments on commit fef6dce

Please sign in to comment.