From cd78b3a9d8a839951ef533dad53a5325b7597997 Mon Sep 17 00:00:00 2001 From: Nancy Wang Date: Thu, 19 Jan 2023 23:11:30 +0000 Subject: [PATCH] M110 merge: Modify website usage UKM to use the NAVIGATION_ID and CHROMEOS_WEBSITE_ID source type. Modify WebsiteMetrics: 1. For the urls saved in the user pref, since we can't get the web_contents from the previous user session, call GetSourceIdForChromeOSWebsiteURL to generate the source id. 2. For the realtime url, since we can get web_contents, call GetPageUkmSourceId to get the source id from web_contents with the NAVIGATION_ID source type. Remove UrlContent, because we don't report scope and only report the full url. Modify test cases to align with the change: 1. Remove UrlContent. 2. Record the full url, not the scope for the website with manifest. BUG=1401207, b:254508887 (cherry picked from commit e7a16c1ea6fc8a518037b71e141e1c6e7be41a41) Change-Id: Ifda002acb93893650f592a8dc361d7dc1aa698fd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112860 Reviewed-by: Robert Kaplow Reviewed-by: Yue Ru Sun Commit-Queue: Nancy Wang Reviewed-by: Dominick Ng Cr-Original-Commit-Position: refs/heads/main@{#1091617} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4179390 Cr-Commit-Position: refs/branch-heads/5481@{#474} Cr-Branched-From: 130f3e4d850f4bc7387cfb8d08aa993d288a67a9-refs/heads/main@{#1084008} --- .../app_service/metrics/website_metrics.cc | 107 +++----- .../app_service/metrics/website_metrics.h | 29 +- .../metrics/website_metrics_browsertest.cc | 250 ++++++++---------- services/metrics/public/cpp/ukm_recorder.cc | 10 +- services/metrics/public/cpp/ukm_recorder.h | 7 +- tools/metrics/ukm/ukm.xml | 3 + 6 files changed, 160 insertions(+), 246 deletions(-) diff --git a/chrome/browser/apps/app_service/metrics/website_metrics.cc b/chrome/browser/apps/app_service/metrics/website_metrics.cc index b83d71a2aec208..ffe8abc34ab61f 100644 --- a/chrome/browser/apps/app_service/metrics/website_metrics.cc +++ b/chrome/browser/apps/app_service/metrics/website_metrics.cc @@ -87,7 +87,6 @@ namespace apps { constexpr char kWebsiteUsageTime[] = "app_platform_metrics.website_usage_time"; constexpr char kRunningTimeKey[] = "time"; -constexpr char kUrlContentKey[] = "url_content"; constexpr char kPromotableKey[] = "promotable"; WebsiteMetrics::ActiveTabWebContentsObserver::ActiveTabWebContentsObserver( @@ -139,18 +138,12 @@ WebsiteMetrics::UrlInfo::UrlInfo(const base::Value& value) { return; } - auto url_content_value = data_dict->FindInt(kUrlContentKey); - if (!url_content_value.has_value()) { - return; - } - auto promotable_value = data_dict->FindBool(kPromotableKey); if (!promotable_value.has_value()) { return; } running_time_in_two_hours = running_time_value.value(); - url_content = static_cast(url_content_value.value()); promotable = promotable_value.value(); } @@ -158,7 +151,6 @@ base::Value WebsiteMetrics::UrlInfo::ConvertToValue() const { base::Value usage_time_dict(base::Value::Type::DICTIONARY); usage_time_dict.SetPath(kRunningTimeKey, base::TimeDeltaToValue(running_time_in_two_hours)); - usage_time_dict.SetIntKey(kUrlContentKey, static_cast(url_content)); usage_time_dict.SetBoolKey(kPromotableKey, promotable); return usage_time_dict; } @@ -442,9 +434,9 @@ void WebsiteMetrics::OnWebContentsUpdated(content::WebContents* web_contents) { bool is_activated = wm::IsActiveWindow(window) && it != window_to_web_contents_.end() && it->second == web_contents; - AddUrlInfo(web_contents->GetVisibleURL(), base::TimeTicks::Now(), - UrlContent::kFullUrl, is_activated, - /*promotable=*/false); + AddUrlInfo(web_contents->GetVisibleURL(), + web_contents->GetPrimaryMainFrame()->GetPageUkmSourceId(), + base::TimeTicks::Now(), is_activated, /*promotable=*/false); } void WebsiteMetrics::OnInstallableWebAppStatusUpdated( @@ -465,64 +457,31 @@ void WebsiteMetrics::OnInstallableWebAppStatusUpdated( // In some test cases, AppBannerManager might be null. if (!app_banner_manager || - blink::IsEmptyManifest(app_banner_manager->manifest())) { - return; - } - - auto* window = - GetWindowWithBrowser(chrome::FindBrowserWithWebContents(web_contents)); - if (!window) { + blink::IsEmptyManifest(app_banner_manager->manifest()) || + app_banner_manager->manifest().scope.is_empty()) { return; } - DCHECK(!app_banner_manager->manifest().scope.is_empty()); - auto window_it = window_to_web_contents_.find(window); - bool is_activated = wm::IsActiveWindow(window) && - window_it != window_to_web_contents_.end() && - window_it->second == web_contents; - UpdateUrlInfo(it->second, app_banner_manager->manifest().scope, - UrlContent::kScope, is_activated, - /*promotable=*/true); - it->second = app_banner_manager->manifest().scope; + UpdateUrlInfo(it->second, /*promotable=*/true); } void WebsiteMetrics::AddUrlInfo(const GURL& url, + ukm::SourceId source_id, const base::TimeTicks& start_time, - UrlContent url_content, bool is_activated, bool promotable) { auto& url_info = url_infos_[url]; + url_info.source_id = source_id; url_info.start_time = start_time; - url_info.url_content = url_content; url_info.is_activated = is_activated; url_info.promotable = promotable; } -void WebsiteMetrics::UpdateUrlInfo(const GURL& old_url, - const GURL& new_url, - UrlContent url_content, - bool is_activated, - bool promotable) { - base::TimeTicks start_time = base::TimeTicks::Now(); - base::TimeDelta running_time_in_five_minutes; - base::TimeDelta running_time_in_two_hours; - - auto it = url_infos_.find(old_url); +void WebsiteMetrics::UpdateUrlInfo(const GURL& url, bool promotable) { + auto it = url_infos_.find(url); if (it != url_infos_.end()) { - running_time_in_five_minutes = it->second.running_time_in_five_minutes; - running_time_in_two_hours = it->second.running_time_in_two_hours; - start_time = it->second.start_time; - url_infos_.erase(old_url); - } - - if (new_url.is_empty() || !new_url.SchemeIsHTTPOrHTTPS()) { - return; + it->second.promotable = promotable; } - - AddUrlInfo(new_url, start_time, url_content, is_activated, promotable); - url_infos_[new_url].running_time_in_five_minutes = - running_time_in_five_minutes; - url_infos_[new_url].running_time_in_two_hours = running_time_in_two_hours; } void WebsiteMetrics::SetWindowActivated(aura::Window* window) { @@ -603,8 +562,9 @@ void WebsiteMetrics::SaveUsageTime() { void WebsiteMetrics::RecordUsageTime() { for (auto& it : url_infos_) { if (!it.second.running_time_in_two_hours.is_zero()) { - EmitUkm(it.first, it.second.running_time_in_two_hours.InMilliseconds(), - it.second.url_content, it.second.promotable, + EmitUkm(it.second.source_id, + it.second.running_time_in_two_hours.InMilliseconds(), + it.second.promotable, /*is_from_last_login=*/false); it.second.running_time_in_two_hours = base::TimeDelta(); } @@ -629,39 +589,36 @@ void WebsiteMetrics::RecordUsageTimeFromPref() { } auto url_info = std::make_unique(url_info_value); if (!url_info->running_time_in_two_hours.is_zero()) { - EmitUkm(url, url_info->running_time_in_two_hours.InMilliseconds(), - url_info->url_content, url_info->promotable, + // For the URL records dump from the user pref, since the web_contents + // doesn't exist due to logout/login, we can't call GetPageUkmSourceId to + // get the source id with the web_contents. So call + // GetSourceIdForChromeOSWebsiteURL to generate the UKM source id to log + // saved URLs from the last login session. + auto source_id = ukm::UkmRecorder::GetSourceIdForChromeOSWebsiteURL( + base::PassKey(), url); + EmitUkm(source_id, url_info->running_time_in_two_hours.InMilliseconds(), + url_info->promotable, /*is_from_last_login=*/true); } } } -void WebsiteMetrics::EmitUkm(const GURL& url, +void WebsiteMetrics::EmitUkm(ukm::SourceId source_id, int64_t usage_time, - UrlContent url_content, bool promotable, bool is_from_last_login) { - auto source_id = ukm::UkmRecorder::GetSourceIdForWebsiteUrl( - base::PassKey(), url); - if (url.is_empty() || !url.SchemeIsHTTPOrHTTPS() || - ukm::SourceIdObj::FromInt64(source_id).GetType() != - ukm::SourceIdType::DESKTOP_WEB_APP_ID) { - LOG(ERROR) << "WebsiteMetrics::EmitUkm url is " << url.spec() - << ", source id type is " - << (int)ukm::SourceIdObj::FromInt64(source_id).GetType(); + if (source_id == ukm::kInvalidSourceId) { + DVLOG(1) << "WebsiteMetrics::EmitUkm source id is invalid."; base::debug::DumpWithoutCrashing(); return; } - if (source_id != ukm::kInvalidSourceId) { - ukm::builders::ChromeOS_WebsiteUsageTime builder(source_id); - builder.SetDuration(usage_time) - .SetUrlContent(static_cast(url_content)) - .SetIsFromLastLogin(is_from_last_login) - .SetPromotable(promotable) - .SetUserDeviceMatrix(user_type_by_device_type_) - .Record(ukm::UkmRecorder::Get()); - } + ukm::builders::ChromeOS_WebsiteUsageTime builder(source_id); + builder.SetDuration(usage_time) + .SetIsFromLastLogin(is_from_last_login) + .SetPromotable(promotable) + .SetUserDeviceMatrix(user_type_by_device_type_) + .Record(ukm::UkmRecorder::Get()); } } // namespace apps diff --git a/chrome/browser/apps/app_service/metrics/website_metrics.h b/chrome/browser/apps/app_service/metrics/website_metrics.h index 6a23fcd6b54d7c..c601986ea8dfd1 100644 --- a/chrome/browser/apps/app_service/metrics/website_metrics.h +++ b/chrome/browser/apps/app_service/metrics/website_metrics.h @@ -22,6 +22,7 @@ #include "content/public/browser/page.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" +#include "services/metrics/public/cpp/ukm_source_id.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" #include "ui/wm/public/activation_change_observer.h" @@ -36,17 +37,6 @@ namespace apps { class WebsiteMetricsBrowserTest; class TestWebsiteMetrics; -// This is used for logging, so do not remove or reorder existing entries. -enum class UrlContent { - kUnknown = 0, - kFullUrl = 1, - kScope = 2, - - // Add any new values above this one, and update kMaxValue to the highest - // enumerator value. - kMaxValue = kScope, -}; - extern const char kWebsiteUsageTime[]; extern const char kRunningTimeKey[]; extern const char kUrlContentKey[]; @@ -134,6 +124,7 @@ class WebsiteMetrics : public BrowserListObserver, struct UrlInfo { UrlInfo() = default; explicit UrlInfo(const base::Value& value); + ukm::SourceId source_id = ukm::kInvalidSourceId; base::TimeTicks start_time; // Running time in the past 5 minutes without noise. base::TimeDelta running_time_in_five_minutes; @@ -141,7 +132,6 @@ class WebsiteMetrics : public BrowserListObserver, // time1 * noise1 + time2 * noise2 + time3 * noise3.... base::TimeDelta running_time_in_two_hours; - UrlContent url_content = UrlContent::kUnknown; bool is_activated = false; bool promotable = false; @@ -184,18 +174,14 @@ class WebsiteMetrics : public BrowserListObserver, // Adds the url info to `url_infos_`. void AddUrlInfo(const GURL& url, + ukm::SourceId source_id, const base::TimeTicks& start_time, - UrlContent url_content, bool is_activated, bool promotable); - // Modifies `old_url` to `new_url` in `url_infos_`, when the website manifest - // is updated. - void UpdateUrlInfo(const GURL& old_url, - const GURL& new_url, - UrlContent url_content, - bool is_activated, - bool promotable); + // Modifies `url_infos_` to set whether the website can be promoted to PWA, + // when the website manifest is updated. + void UpdateUrlInfo(const GURL& old_url, bool promotable); void SetWindowActivated(aura::Window* window); @@ -216,9 +202,8 @@ class WebsiteMetrics : public BrowserListObserver, // after the user logs in. void RecordUsageTimeFromPref(); - void EmitUkm(const GURL& url, + void EmitUkm(ukm::SourceId source_id, int64_t usage_time, - UrlContent url_content, bool promotable, bool is_from_last_login); diff --git a/chrome/browser/apps/app_service/metrics/website_metrics_browsertest.cc b/chrome/browser/apps/app_service/metrics/website_metrics_browsertest.cc index 923fed2980958c..61fb1ef16e4e9d 100644 --- a/chrome/browser/apps/app_service/metrics/website_metrics_browsertest.cc +++ b/chrome/browser/apps/app_service/metrics/website_metrics_browsertest.cc @@ -198,27 +198,18 @@ class WebsiteMetricsBrowserTest : public InProcessBrowserTest { return InstallWebApp(start_url, web_app::UserDisplayMode::kStandalone); } - void VerifyUrlInfo(const GURL& url, - UrlContent url_content, - bool is_activated, - bool promotable) { - EXPECT_EQ(url_content, url_infos()[url].url_content); + void VerifyUrlInfo(const GURL& url, bool is_activated, bool promotable) { EXPECT_EQ(is_activated, url_infos()[url].is_activated); EXPECT_EQ(promotable, url_infos()[url].promotable); } - void VerifyUrlInfoInPref(const GURL& url, - UrlContent url_content, - bool promotable) { + void VerifyUrlInfoInPref(const GURL& url, bool promotable) { const auto& dict = ProfileManager::GetPrimaryUserProfile()->GetPrefs()->GetDict( kWebsiteUsageTime); const auto* url_info = dict.FindDict(url.spec()); ASSERT_TRUE(url_info); - auto url_content_value = url_info->FindInt(kUrlContentKey); - ASSERT_TRUE(url_content_value.has_value()); - EXPECT_EQ(static_cast(url_content), url_content_value.value()); auto promotable_value = url_info->FindBool(kPromotableKey); ASSERT_TRUE(promotable_value.has_value()); @@ -249,9 +240,7 @@ class WebsiteMetricsBrowserTest : public InProcessBrowserTest { ASSERT_EQ(0, count); } - void VerifyUsageTimeUkm(const GURL& url, - UrlContent url_content, - bool promotable) { + void VerifyUsageTimeUkm(const GURL& url, bool promotable) { const auto entries = test_ukm_recorder()->GetEntriesByName("ChromeOS.WebsiteUsageTime"); int count = 0; @@ -262,8 +251,6 @@ class WebsiteMetricsBrowserTest : public InProcessBrowserTest { continue; } ++count; - test_ukm_recorder()->ExpectEntryMetric(entry, "UrlContent", - (int)url_content); test_ukm_recorder()->ExpectEntryMetric(entry, "Promotable", promotable); } ASSERT_EQ(1, count); @@ -347,7 +334,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, InsertAndCloseTabs) { GURL("https://b.example.org")); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app1], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); // Open two more tabs in foreground and close them. @@ -363,9 +350,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, InsertAndCloseTabs) { EXPECT_EQ(3u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app3], GURL("https://c.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab_app4], GURL("https://d.example.org")); - VerifyUrlInfo(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://c.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/true, /*promotable=*/false); // Close in reverse order. @@ -374,7 +361,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, InsertAndCloseTabs) { i, TabCloseTypes::CLOSE_USER_GESTURE); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_FALSE(base::Contains(webcontents_to_ukm_key(), tab_app4)); - VerifyUrlInfo(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://c.example.org"), /*is_activated=*/true, /*promotable=*/false); i = browser->tab_strip_model()->GetIndexOfWebContents(tab_app3); @@ -387,7 +374,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, InsertAndCloseTabs) { GURL("https://b.example.org")); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_FALSE(base::Contains(webcontents_to_ukm_key(), tab_app3)); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); browser->tab_strip_model()->CloseAllTabs(); @@ -395,25 +382,25 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, InsertAndCloseTabs) { EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); EXPECT_EQ(3u, url_infos().size()); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); website_metrics()->OnFiveMinutes(); VerifyNoUrlInfoInPref(GURL("https://a.example.org")); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://c.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://d.example.org"), /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); VerifyNoUsageTimeUkm(GURL("https://a.example.org")); - VerifyUsageTimeUkm(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://b.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://c.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://d.example.org"), /*promotable=*/false); EXPECT_TRUE(url_infos().empty()); } @@ -432,7 +419,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ForegroundTabNavigate) { GURL("https://a.example.org")); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app], GURL("https://a.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/true, /*promotable=*/false); // Navigate the foreground tab to a different url. @@ -446,9 +433,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ForegroundTabNavigate) { GURL("https://b.example.org")); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); website_metrics()->OnFiveMinutes(); @@ -456,20 +443,20 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ForegroundTabNavigate) { EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://b.example.org"), /*promotable=*/false); EXPECT_TRUE(url_infos().empty()); } @@ -493,24 +480,23 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, NavigateToBackgroundTab) { EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url1); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab1], url1); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/false); // Navigate the background tab to a url with a manifest. GURL url2 = embedded_test_server()->GetURL("/banners/manifest_test_page.html"); - auto ukm_key = url2.GetWithoutFilename(); auto* tab2 = InsertBackgroundTab(browser, url2.spec()); - metrics->AwaitForInstallableWebAppCheck(ukm_key); + metrics->AwaitForInstallableWebAppCheck(url2); EXPECT_EQ(2u, webcontents_to_observer_map().size()); EXPECT_TRUE(base::Contains(webcontents_to_observer_map(), tab2)); EXPECT_EQ(1u, window_to_web_contents().size()); EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url1); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); - EXPECT_EQ(webcontents_to_ukm_key()[tab2], ukm_key); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + EXPECT_EQ(webcontents_to_ukm_key()[tab2], url2); + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/true); website_metrics()->OnFiveMinutes(); @@ -518,19 +504,19 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, NavigateToBackgroundTab) { EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/true); - VerifyUrlInfoInPref(url1, UrlContent::kFullUrl, + VerifyUrlInfoInPref(url1, /*promotable=*/false); - VerifyNoUrlInfoInPref(ukm_key); + VerifyNoUrlInfoInPref(url2); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(url1, UrlContent::kFullUrl, + VerifyUsageTimeUkm(url1, /*promotable=*/false); - VerifyNoUsageTimeUkm(ukm_key); + VerifyNoUsageTimeUkm(url2); EXPECT_TRUE(url_infos().empty()); } @@ -553,24 +539,23 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ActiveBackgroundTab) { EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url1); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab1], url1); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/false); // Navigate the background tab to a url with a manifest. GURL url2 = embedded_test_server()->GetURL("/banners/manifest_test_page.html"); - auto ukm_key = url2.GetWithoutFilename(); auto* tab2 = InsertBackgroundTab(browser, url2.spec()); - metrics->AwaitForInstallableWebAppCheck(ukm_key); + metrics->AwaitForInstallableWebAppCheck(url2); EXPECT_EQ(2u, webcontents_to_observer_map().size()); EXPECT_TRUE(base::Contains(webcontents_to_observer_map(), tab2)); EXPECT_EQ(1u, window_to_web_contents().size()); EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url1); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); - EXPECT_EQ(webcontents_to_ukm_key()[tab2], ukm_key); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + EXPECT_EQ(webcontents_to_ukm_key()[tab2], url2); + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/true); website_metrics()->OnFiveMinutes(); @@ -579,9 +564,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ActiveBackgroundTab) { EXPECT_EQ(1u, window_to_web_contents().size()); EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url2); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/true, /*promotable=*/true); website_metrics()->OnFiveMinutes(); @@ -589,21 +574,21 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, ActiveBackgroundTab) { EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/true); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(url1, UrlContent::kFullUrl, + VerifyUrlInfoInPref(url1, /*promotable=*/false); - VerifyUrlInfoInPref(ukm_key, UrlContent::kScope, + VerifyUrlInfoInPref(url2, /*promotable=*/true); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(url1, UrlContent::kFullUrl, + VerifyUsageTimeUkm(url1, /*promotable=*/false); - VerifyUsageTimeUkm(ukm_key, UrlContent::kScope, + VerifyUsageTimeUkm(url2, /*promotable=*/true); EXPECT_TRUE(url_infos().empty()); } @@ -628,46 +613,45 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, NavigateToUrlWithManifest) { EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url1); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app], url1); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/false); // Navigate the foreground tab to a url with a manifest. GURL url2 = embedded_test_server()->GetURL("/banners/manifest_test_page.html"); - auto ukm_key = url2.GetWithoutFilename(); NavigateActiveTab(browser, url2.spec()); - metrics->AwaitForInstallableWebAppCheck(ukm_key); + metrics->AwaitForInstallableWebAppCheck(url2); EXPECT_EQ(1u, webcontents_to_observer_map().size()); EXPECT_EQ(1u, window_to_web_contents().size()); EXPECT_TRUE(base::Contains(webcontents_to_observer_map(), window_to_web_contents()[window])); EXPECT_EQ(window_to_web_contents()[window]->GetVisibleURL(), url2); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); - EXPECT_EQ(webcontents_to_ukm_key()[tab_app], ukm_key); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + EXPECT_EQ(webcontents_to_ukm_key()[tab_app], url2); + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/true, /*promotable=*/true); browser->tab_strip_model()->CloseAllTabs(); EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(url1, UrlContent::kFullUrl, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/true); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(url1, UrlContent::kFullUrl, + VerifyUrlInfoInPref(url1, /*promotable=*/false); - VerifyUrlInfoInPref(ukm_key, UrlContent::kScope, + VerifyUrlInfoInPref(url2, /*promotable=*/true); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(url1, UrlContent::kFullUrl, + VerifyUsageTimeUkm(url1, /*promotable=*/false); - VerifyUsageTimeUkm(ukm_key, UrlContent::kScope, + VerifyUsageTimeUkm(url2, /*promotable=*/true); EXPECT_TRUE(url_infos().empty()); } @@ -688,9 +672,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app1], GURL("https://a.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab_app2], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); auto* browser2 = CreateBrowser(); @@ -708,11 +692,11 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { EXPECT_EQ(4u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app3], GURL("https://c.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab_app4], GURL("https://d.example.org")); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://c.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/true, /*promotable=*/false); // Close tabs. @@ -725,7 +709,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { GURL("https://b.example.org")); EXPECT_EQ(3u, webcontents_to_ukm_key().size()); EXPECT_FALSE(base::Contains(webcontents_to_ukm_key(), tab_app1)); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/true, /*promotable=*/false); i = browser2->tab_strip_model()->GetIndexOfWebContents(tab_app3); @@ -737,9 +721,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { GURL("https://d.example.org")); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_FALSE(base::Contains(webcontents_to_ukm_key(), tab_app3)); - VerifyUrlInfo(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://c.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/true, /*promotable=*/false); i = browser2->tab_strip_model()->GetIndexOfWebContents(tab_app4); @@ -752,17 +736,17 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { window_to_web_contents()[window1])); EXPECT_EQ(1u, webcontents_to_ukm_key().size()); EXPECT_FALSE(base::Contains(webcontents_to_ukm_key(), tab_app4)); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/false, /*promotable=*/false); i = browser1->tab_strip_model()->GetIndexOfWebContents(tab_app2); browser1->tab_strip_model()->CloseWebContentsAt( i, TabCloseTypes::CLOSE_USER_GESTURE); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); EXPECT_TRUE(window_to_web_contents().empty()); @@ -770,24 +754,24 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, MultipleBrowser) { EXPECT_TRUE(webcontents_to_ukm_key().empty()); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://c.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://d.example.org"), /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://b.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://c.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://d.example.org"), /*promotable=*/false); EXPECT_TRUE(url_infos().empty()); } @@ -806,9 +790,8 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, // Open a tab in foreground with a manifest. GURL url1 = embedded_test_server()->GetURL("/banners/manifest_test_page.html"); - auto ukm_key = url1.GetWithoutFilename(); auto* tab1 = InsertForegroundTab(browser1, url1.spec()); - metrics->AwaitForInstallableWebAppCheck(ukm_key); + metrics->AwaitForInstallableWebAppCheck(url1); // Open a background tab to a url. GURL url2 = embedded_test_server()->GetURL("/banners/no_manifest_test_page.html"); @@ -819,17 +802,16 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, window_to_web_contents()[window1])); EXPECT_EQ(window_to_web_contents()[window1]->GetVisibleURL(), url1); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); - EXPECT_EQ(webcontents_to_ukm_key()[tab1], ukm_key); + EXPECT_EQ(webcontents_to_ukm_key()[tab1], url1); EXPECT_EQ(webcontents_to_ukm_key()[tab2], url2); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/true); - VerifyUrlInfo(url2, UrlContent::kFullUrl, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/false); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(ukm_key, UrlContent::kScope, + VerifyUrlInfoInPref(url1, /*promotable=*/true); - VerifyNoUrlInfoInPref(url1); // Create the second browser, and move the activated tab to the new browser. auto* browser2 = CreateBrowser(); @@ -851,15 +833,15 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, window_to_web_contents()[window2])); EXPECT_EQ(window_to_web_contents()[window2]->GetVisibleURL(), url1); EXPECT_EQ(2u, webcontents_to_ukm_key().size()); - EXPECT_EQ(webcontents_to_ukm_key()[tab3], ukm_key); + EXPECT_EQ(webcontents_to_ukm_key()[tab3], url1); EXPECT_EQ(webcontents_to_ukm_key()[tab2], url2); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url1, /*is_activated=*/true, /*promotable=*/true); - VerifyUrlInfo(url2, UrlContent::kFullUrl, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/false); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(ukm_key, UrlContent::kScope, + VerifyUrlInfoInPref(url1, /*promotable=*/true); VerifyNoUrlInfoInPref(url2); @@ -872,11 +854,11 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, GURL("https://a.example.org")); EXPECT_EQ(3u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab4], GURL("https://a.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/true, /*promotable=*/false); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/true); - VerifyUrlInfo(url2, UrlContent::kFullUrl, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/false); auto i = browser2->tab_strip_model()->GetIndexOfWebContents(tab4); @@ -886,9 +868,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnFiveMinutes(); website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUsageTimeUkm(ukm_key, UrlContent::kScope, + VerifyUsageTimeUkm(url1, /*promotable=*/true); VerifyNoUsageTimeUkm(url2); @@ -905,9 +887,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(ukm_key, UrlContent::kScope, + VerifyUrlInfo(url1, /*is_activated=*/false, /*promotable=*/true); - VerifyUrlInfo(url2, UrlContent::kFullUrl, + VerifyUrlInfo(url2, /*is_activated=*/false, /*promotable=*/false); EXPECT_TRUE(window_to_web_contents().empty()); @@ -915,9 +897,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, EXPECT_TRUE(webcontents_to_ukm_key().empty()); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(ukm_key, UrlContent::kScope, + VerifyUrlInfoInPref(url1, /*promotable=*/true); - VerifyUrlInfoInPref(url2, UrlContent::kFullUrl, + VerifyUrlInfoInPref(url2, /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. @@ -942,19 +924,19 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab1], GURL("https://a.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab2], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/true, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://a.example.org"), /*promotable=*/false); VerifyNoUrlInfoInPref(GURL("https://b.example.org")); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://a.example.org"), /*promotable=*/false); VerifyNoUsageTimeUkm(GURL("https://b.example.org")); @@ -981,18 +963,18 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab1], GURL("https://a.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab3], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. website_metrics()->OnTwoHours(); - VerifyUsageTimeUkm(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://b.example.org"), /*promotable=*/false); browser1->tab_strip_model()->CloseAllTabs(); @@ -1007,9 +989,9 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, EXPECT_TRUE(window_to_web_contents().empty()); EXPECT_TRUE(webcontents_to_observer_map().empty()); EXPECT_TRUE(webcontents_to_ukm_key().empty()); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/false, /*promotable=*/false); EXPECT_TRUE(window_to_web_contents().empty()); @@ -1018,7 +1000,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, website_metrics()->OnFiveMinutes(); VerifyNoUrlInfoInPref(GURL("https://a.example.org")); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); // Simulate recording the UKMs to clear the local usage time records. @@ -1071,14 +1053,14 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, OnURLsDeleted) { EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app1], GURL("https://a.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab_app2], GURL("https://b.example.org")); - VerifyUrlInfo(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://a.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://b.example.org"), /*is_activated=*/true, /*promotable=*/false); website_metrics()->OnFiveMinutes(); - VerifyUrlInfoInPref(GURL("https://a.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://a.example.org"), /*promotable=*/false); - VerifyUrlInfoInPref(GURL("https://b.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://b.example.org"), /*promotable=*/false); // Simulate OnURLsDeleted is called. @@ -1104,15 +1086,15 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, OnURLsDeleted) { EXPECT_EQ(2u, webcontents_to_ukm_key().size()); EXPECT_EQ(webcontents_to_ukm_key()[tab_app3], GURL("https://c.example.org")); EXPECT_EQ(webcontents_to_ukm_key()[tab_app4], GURL("https://d.example.org")); - VerifyUrlInfo(GURL("https://c.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://c.example.org"), /*is_activated=*/false, /*promotable=*/false); - VerifyUrlInfo(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfo(GURL("https://d.example.org"), /*is_activated=*/true, /*promotable=*/false); website_metrics()->OnFiveMinutes(); // "https://c.example.org" is inactivated, and the running time is zero, so it // won't be saved in the user pref. VerifyNoUrlInfoInPref(GURL("https://c.example.org")); - VerifyUrlInfoInPref(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUrlInfoInPref(GURL("https://d.example.org"), /*promotable=*/false); // Close the browsers. @@ -1128,7 +1110,7 @@ IN_PROC_BROWSER_TEST_F(WebsiteMetricsBrowserTest, OnURLsDeleted) { VerifyNoUsageTimeUkm(GURL("https://a.example.org")); VerifyNoUsageTimeUkm(GURL("https://b.example.org")); VerifyNoUsageTimeUkm(GURL("https://c.example.org")); - VerifyUsageTimeUkm(GURL("https://d.example.org"), UrlContent::kFullUrl, + VerifyUsageTimeUkm(GURL("https://d.example.org"), /*promotable=*/false); EXPECT_TRUE(url_infos().empty()); } diff --git a/services/metrics/public/cpp/ukm_recorder.cc b/services/metrics/public/cpp/ukm_recorder.cc index 9fdecac79d4178..66c6f10944c78d 100644 --- a/services/metrics/public/cpp/ukm_recorder.cc +++ b/services/metrics/public/cpp/ukm_recorder.cc @@ -56,14 +56,6 @@ ukm::SourceId UkmRecorder::GetSourceIdForDesktopWebAppStartUrl( start_url, SourceIdType::DESKTOP_WEB_APP_ID); } -// static -ukm::SourceId UkmRecorder::GetSourceIdForWebsiteUrl( - base::PassKey, - const GURL& start_url) { - return UkmRecorder::GetSourceIdFromScopeImpl( - start_url, SourceIdType::DESKTOP_WEB_APP_ID); -} - // static ukm::SourceId UkmRecorder::GetSourceIdForWebIdentityFromScope( base::PassKey, @@ -82,7 +74,7 @@ ukm::SourceId UkmRecorder::GetSourceIdForRedirectUrl( // static ukm::SourceId UkmRecorder::GetSourceIdForChromeOSWebsiteURL( - base::PassKey, + base::PassKey, const GURL& redirect_url) { return UkmRecorder::GetSourceIdFromScopeImpl( redirect_url, SourceIdType::CHROMEOS_WEBSITE_ID); diff --git a/services/metrics/public/cpp/ukm_recorder.h b/services/metrics/public/cpp/ukm_recorder.h index e29cb341607826..ebd9d62884bd9b 100644 --- a/services/metrics/public/cpp/ukm_recorder.h +++ b/services/metrics/public/cpp/ukm_recorder.h @@ -95,11 +95,6 @@ class METRICS_EXPORT UkmRecorder { base::PassKey, const GURL& start_url); - // Gets new SourceId for a website Url. This method should only be called by - // WebsiteMetrics. - static SourceId GetSourceIdForWebsiteUrl(base::PassKey, - const GURL& website_url); - // Gets new source Id for PAYMENT_APP_ID type and updates the source url to // the scope of the app. This method should only be called by // PaymentAppProviderUtil class when the payment app window is opened. @@ -123,7 +118,7 @@ class METRICS_EXPORT UkmRecorder { // Gets a new SourceId of CHROMEOS_WEBSITE_ID type. This should be only // used for recording ChromeOS website stats. static SourceId GetSourceIdForChromeOSWebsiteURL( - base::PassKey, + base::PassKey, const GURL& chromeos_website_url); // Add an entry to the UkmEntry list. diff --git a/tools/metrics/ukm/ukm.xml b/tools/metrics/ukm/ukm.xml index e92c972c502912..b68a46e29c3218 100644 --- a/tools/metrics/ukm/ukm.xml +++ b/tools/metrics/ukm/ukm.xml @@ -5171,6 +5171,9 @@ be describing additional metrics about the same event. + + Deprecated as of 01/2023. + The url content, e.g. full url, scope.