Commit 0efba143 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Extend referrer chain for SBER users to 5 gestures

Based on some example campaigns for which chrome sync history won't be
useful, extend the maximum number of gestures in a referrer chain to
5 gestures. We can then evaluate how useful the extra data is, and
possible extend the maximum gestures for all users.

Bug: 864266
Change-Id: Idbcc2e07f7593a90f05ba07a2e1ef0c2a1be757b
Reviewed-on: https://chromium-review.googlesource.com/c/1287041
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarJialiu Lin <jialiul@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600883}
parent 6e195006
...@@ -44,6 +44,7 @@ const double kWhitelistDownloadSampleRate = 0.01; ...@@ -44,6 +44,7 @@ const double kWhitelistDownloadSampleRate = 0.01;
// The number of user gestures we trace back for download attribution. // The number of user gestures we trace back for download attribution.
const int kDownloadAttributionUserGestureLimit = 2; const int kDownloadAttributionUserGestureLimit = 2;
const int kDownloadAttributionUserGestureLimitForExtendedReporting = 5;
void AddEventUrlToReferrerChain(const download::DownloadItem& item, void AddEventUrlToReferrerChain(const download::DownloadItem& item,
ReferrerChain* out_referrer_chain) { ReferrerChain* out_referrer_chain) {
...@@ -74,6 +75,26 @@ bool MatchesEnterpriseWhitelist(const Profile* profile, ...@@ -74,6 +75,26 @@ bool MatchesEnterpriseWhitelist(const Profile* profile,
return false; return false;
} }
int GetDownloadAttributionUserGestureLimit(const download::DownloadItem& item) {
content::WebContents* web_contents =
content::DownloadItemUtils::GetWebContents(
const_cast<download::DownloadItem*>(&item));
if (!web_contents)
return kDownloadAttributionUserGestureLimit;
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (!profile)
return kDownloadAttributionUserGestureLimit;
const PrefService* prefs = profile->GetPrefs();
if (!prefs)
return kDownloadAttributionUserGestureLimit;
if (!IsExtendedReportingEnabled(*prefs))
return kDownloadAttributionUserGestureLimit;
return kDownloadAttributionUserGestureLimitForExtendedReporting;
}
} // namespace } // namespace
const void* const DownloadProtectionService::kDownloadPingTokenKey = const void* const DownloadProtectionService::kDownloadPingTokenKey =
...@@ -426,8 +447,8 @@ DownloadProtectionService::IdentifyReferrerChain( ...@@ -426,8 +447,8 @@ DownloadProtectionService::IdentifyReferrerChain(
// We look for the referrer chain that leads to the download url first. // We look for the referrer chain that leads to the download url first.
SafeBrowsingNavigationObserverManager::AttributionResult result = SafeBrowsingNavigationObserverManager::AttributionResult result =
navigation_observer_manager_->IdentifyReferrerChainByEventURL( navigation_observer_manager_->IdentifyReferrerChainByEventURL(
item.GetURL(), download_tab_id, kDownloadAttributionUserGestureLimit, item.GetURL(), download_tab_id,
referrer_chain.get()); GetDownloadAttributionUserGestureLimit(item), referrer_chain.get());
// If no navigation event is found, this download is not triggered by regular // If no navigation event is found, this download is not triggered by regular
// navigation (e.g. html5 file apis, etc). We look for the referrer chain // navigation (e.g. html5 file apis, etc). We look for the referrer chain
...@@ -437,7 +458,7 @@ DownloadProtectionService::IdentifyReferrerChain( ...@@ -437,7 +458,7 @@ DownloadProtectionService::IdentifyReferrerChain(
web_contents && web_contents->GetLastCommittedURL().is_valid()) { web_contents && web_contents->GetLastCommittedURL().is_valid()) {
AddEventUrlToReferrerChain(item, referrer_chain.get()); AddEventUrlToReferrerChain(item, referrer_chain.get());
result = navigation_observer_manager_->IdentifyReferrerChainByWebContents( result = navigation_observer_manager_->IdentifyReferrerChainByWebContents(
web_contents, kDownloadAttributionUserGestureLimit, web_contents, GetDownloadAttributionUserGestureLimit(item),
referrer_chain.get()); referrer_chain.get());
} }
......
...@@ -194,12 +194,14 @@ class DownloadProtectionService { ...@@ -194,12 +194,14 @@ class DownloadProtectionService {
PPAPIDownloadRequest_InvalidResponse); PPAPIDownloadRequest_InvalidResponse);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
PPAPIDownloadRequest_Timeout); PPAPIDownloadRequest_Timeout);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainWithEmptyNavigationHistory);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceFlagTest, FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceFlagTest,
CheckClientDownloadOverridenByFlag); CheckClientDownloadOverridenByFlag);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyMaybeSendDangerousDownloadOpenedReport); VerifyMaybeSendDangerousDownloadOpenedReport);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainWithEmptyNavigationHistory);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainLengthForExtendedReporting);
static const void* const kDownloadPingTokenKey; static const void* const kDownloadPingTokenKey;
......
...@@ -49,7 +49,7 @@ bool IsEventExpired(const base::Time& event_time, double ttl_in_second) { ...@@ -49,7 +49,7 @@ bool IsEventExpired(const base::Time& event_time, double ttl_in_second) {
// Helper function to determine if the URL type should be LANDING_REFERRER or // Helper function to determine if the URL type should be LANDING_REFERRER or
// LANDING_PAGE, and modify AttributionResult accordingly. // LANDING_PAGE, and modify AttributionResult accordingly.
ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult( ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult(
bool at_user_gesture_limit, size_t user_gesture_count,
SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { SafeBrowsingNavigationObserverManager::AttributionResult* out_result) {
// Landing page refers to the page user directly interacts with to trigger // Landing page refers to the page user directly interacts with to trigger
// this event (e.g. clicking on download button). Landing referrer page is the // this event (e.g. clicking on download button). Landing referrer page is the
...@@ -57,13 +57,19 @@ ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult( ...@@ -57,13 +57,19 @@ ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult(
// Since we are tracing navigations backwards, if we've reached // Since we are tracing navigations backwards, if we've reached
// user gesture limit before this navigation event, this is a navigation // user gesture limit before this navigation event, this is a navigation
// leading to the landing referrer page, otherwise it leads to landing page. // leading to the landing referrer page, otherwise it leads to landing page.
if (at_user_gesture_limit) { if (user_gesture_count == 0) {
*out_result = SafeBrowsingNavigationObserverManager::SUCCESS;
return ReferrerChainEntry::EVENT_URL;
} else if (user_gesture_count == 2) {
*out_result = *out_result =
SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_REFERRER; SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_REFERRER;
return ReferrerChainEntry::LANDING_REFERRER; return ReferrerChainEntry::LANDING_REFERRER;
} else { } else if (user_gesture_count == 1) {
*out_result = SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_PAGE; *out_result = SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_PAGE;
return ReferrerChainEntry::LANDING_PAGE; return ReferrerChainEntry::LANDING_PAGE;
} else {
*out_result = SafeBrowsingNavigationObserverManager::SUCCESS_REFERRER;
return ReferrerChainEntry::REFERRER;
} }
} }
...@@ -424,8 +430,7 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByHostingPage( ...@@ -424,8 +430,7 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByHostingPage(
user_gesture_count = 1; user_gesture_count = 1;
AddToReferrerChain( AddToReferrerChain(
out_referrer_chain, nav_event, initiating_main_frame_url, out_referrer_chain, nav_event, initiating_main_frame_url,
GetURLTypeAndAdjustAttributionResult( GetURLTypeAndAdjustAttributionResult(user_gesture_count, &result));
user_gesture_count == user_gesture_count_limit, &result));
} else { } else {
AddToReferrerChain(out_referrer_chain, nav_event, initiating_main_frame_url, AddToReferrerChain(out_referrer_chain, nav_event, initiating_main_frame_url,
ReferrerChainEntry::CLIENT_REDIRECT); ReferrerChainEntry::CLIENT_REDIRECT);
...@@ -667,11 +672,10 @@ void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain( ...@@ -667,11 +672,10 @@ void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain(
if (!last_nav_event_traced) if (!last_nav_event_traced)
return; return;
AddToReferrerChain( AddToReferrerChain(out_referrer_chain, last_nav_event_traced,
out_referrer_chain, last_nav_event_traced, last_main_frame_url_traced, last_main_frame_url_traced,
GetURLTypeAndAdjustAttributionResult( GetURLTypeAndAdjustAttributionResult(
current_user_gesture_count == user_gesture_count_limit, current_user_gesture_count, out_result));
out_result));
// Stop searching if the size of out_referrer_chain already reached its // Stop searching if the size of out_referrer_chain already reached its
// limit. // limit.
if (out_referrer_chain->size() == kReferrerChainMaxLength) if (out_referrer_chain->size() == kReferrerChainMaxLength)
......
...@@ -26,6 +26,8 @@ class ReferrerChainProvider { ...@@ -26,6 +26,8 @@ class ReferrerChainProvider {
SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer. SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer.
INVALID_URL = 4, INVALID_URL = 4,
NAVIGATION_EVENT_NOT_FOUND = 5, NAVIGATION_EVENT_NOT_FOUND = 5,
SUCCESS_REFERRER = 6, // Successfully identified extra referrers beyond the
// landing referrer.
// Always at the end. // Always at the end.
ATTRIBUTION_FAILURE_TYPE_MAX ATTRIBUTION_FAILURE_TYPE_MAX
......
...@@ -660,6 +660,11 @@ message ReferrerChainEntry { ...@@ -660,6 +660,11 @@ message ReferrerChainEntry {
// chain is empty or partially missing, we will add/append recent navigation // chain is empty or partially missing, we will add/append recent navigation
// events to this list. RECENT_NAVIGATION type is set for these cases. // events to this list. RECENT_NAVIGATION type is set for these cases.
RECENT_NAVIGATION = 6; RECENT_NAVIGATION = 6;
// The REFERRER type is used for entries that recede the LANDING_REFERRER in
// the referrer chain, when more than two gestures are included in the
// referrer chain.
REFERRER = 7;
} }
enum NavigationInitiation { enum NavigationInitiation {
......
...@@ -376,6 +376,9 @@ base::Value SerializeReferrer(const ReferrerChainEntry& referrer) { ...@@ -376,6 +376,9 @@ base::Value SerializeReferrer(const ReferrerChainEntry& referrer) {
case ReferrerChainEntry::RECENT_NAVIGATION: case ReferrerChainEntry::RECENT_NAVIGATION:
url_type = "RECENT_NAVIGATION"; url_type = "RECENT_NAVIGATION";
break; break;
case ReferrerChainEntry::REFERRER:
url_type = "REFERRER";
break;
} }
referrer_dict.SetKey("type", base::Value(url_type)); referrer_dict.SetKey("type", base::Value(url_type));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment