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;
// The number of user gestures we trace back for download attribution.
const int kDownloadAttributionUserGestureLimit = 2;
const int kDownloadAttributionUserGestureLimitForExtendedReporting = 5;
void AddEventUrlToReferrerChain(const download::DownloadItem& item,
ReferrerChain* out_referrer_chain) {
......@@ -74,6 +75,26 @@ bool MatchesEnterpriseWhitelist(const Profile* profile,
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
const void* const DownloadProtectionService::kDownloadPingTokenKey =
......@@ -426,8 +447,8 @@ DownloadProtectionService::IdentifyReferrerChain(
// We look for the referrer chain that leads to the download url first.
SafeBrowsingNavigationObserverManager::AttributionResult result =
navigation_observer_manager_->IdentifyReferrerChainByEventURL(
item.GetURL(), download_tab_id, kDownloadAttributionUserGestureLimit,
referrer_chain.get());
item.GetURL(), download_tab_id,
GetDownloadAttributionUserGestureLimit(item), referrer_chain.get());
// 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
......@@ -437,7 +458,7 @@ DownloadProtectionService::IdentifyReferrerChain(
web_contents && web_contents->GetLastCommittedURL().is_valid()) {
AddEventUrlToReferrerChain(item, referrer_chain.get());
result = navigation_observer_manager_->IdentifyReferrerChainByWebContents(
web_contents, kDownloadAttributionUserGestureLimit,
web_contents, GetDownloadAttributionUserGestureLimit(item),
referrer_chain.get());
}
......
......@@ -194,12 +194,14 @@ class DownloadProtectionService {
PPAPIDownloadRequest_InvalidResponse);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
PPAPIDownloadRequest_Timeout);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainWithEmptyNavigationHistory);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceFlagTest,
CheckClientDownloadOverridenByFlag);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyMaybeSendDangerousDownloadOpenedReport);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainWithEmptyNavigationHistory);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
VerifyReferrerChainLengthForExtendedReporting);
static const void* const kDownloadPingTokenKey;
......
......@@ -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
// LANDING_PAGE, and modify AttributionResult accordingly.
ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult(
bool at_user_gesture_limit,
size_t user_gesture_count,
SafeBrowsingNavigationObserverManager::AttributionResult* out_result) {
// 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
......@@ -57,13 +57,19 @@ ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult(
// Since we are tracing navigations backwards, if we've reached
// user gesture limit before this navigation event, this is a navigation
// 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 =
SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_REFERRER;
return ReferrerChainEntry::LANDING_REFERRER;
} else {
} else if (user_gesture_count == 1) {
*out_result = SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_PAGE;
return ReferrerChainEntry::LANDING_PAGE;
} else {
*out_result = SafeBrowsingNavigationObserverManager::SUCCESS_REFERRER;
return ReferrerChainEntry::REFERRER;
}
}
......@@ -424,8 +430,7 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByHostingPage(
user_gesture_count = 1;
AddToReferrerChain(
out_referrer_chain, nav_event, initiating_main_frame_url,
GetURLTypeAndAdjustAttributionResult(
user_gesture_count == user_gesture_count_limit, &result));
GetURLTypeAndAdjustAttributionResult(user_gesture_count, &result));
} else {
AddToReferrerChain(out_referrer_chain, nav_event, initiating_main_frame_url,
ReferrerChainEntry::CLIENT_REDIRECT);
......@@ -667,11 +672,10 @@ void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain(
if (!last_nav_event_traced)
return;
AddToReferrerChain(
out_referrer_chain, last_nav_event_traced, last_main_frame_url_traced,
GetURLTypeAndAdjustAttributionResult(
current_user_gesture_count == user_gesture_count_limit,
out_result));
AddToReferrerChain(out_referrer_chain, last_nav_event_traced,
last_main_frame_url_traced,
GetURLTypeAndAdjustAttributionResult(
current_user_gesture_count, out_result));
// Stop searching if the size of out_referrer_chain already reached its
// limit.
if (out_referrer_chain->size() == kReferrerChainMaxLength)
......
......@@ -26,6 +26,8 @@ class ReferrerChainProvider {
SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer.
INVALID_URL = 4,
NAVIGATION_EVENT_NOT_FOUND = 5,
SUCCESS_REFERRER = 6, // Successfully identified extra referrers beyond the
// landing referrer.
// Always at the end.
ATTRIBUTION_FAILURE_TYPE_MAX
......
......@@ -660,6 +660,11 @@ message ReferrerChainEntry {
// chain is empty or partially missing, we will add/append recent navigation
// events to this list. RECENT_NAVIGATION type is set for these cases.
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 {
......
......@@ -376,6 +376,9 @@ base::Value SerializeReferrer(const ReferrerChainEntry& referrer) {
case ReferrerChainEntry::RECENT_NAVIGATION:
url_type = "RECENT_NAVIGATION";
break;
case ReferrerChainEntry::REFERRER:
url_type = "REFERRER";
break;
}
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