Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc

Issue 2578363002: Wire up download attribution enable finch experiment (Closed)
Patch Set: Remove unnecessary includes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/sessions/session_tab_helper.h" 17 #include "chrome/browser/sessions/session_tab_helper.h"
15 #include "chrome/browser/tab_contents/retargeting_details.h" 18 #include "chrome/browser/tab_contents/retargeting_details.h"
19 #include "chrome/common/pref_names.h"
20 #include "components/prefs/pref_service.h"
16 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
22 27
23 using content::WebContents; 28 using content::WebContents;
24 29
25 namespace safe_browsing { 30 namespace safe_browsing {
(...skipping 14 matching lines...) Expand all
40 } // namespace 45 } // namespace
41 46
42 // The expiration period of a user gesture. Any user gesture that happened 1.0 47 // The expiration period of a user gesture. Any user gesture that happened 1.0
43 // second ago is considered as expired and not relevant to upcoming navigation 48 // second ago is considered as expired and not relevant to upcoming navigation
44 // events. 49 // events.
45 static const double kUserGestureTTLInSecond = 1.0; 50 static const double kUserGestureTTLInSecond = 1.0;
46 // The expiration period of navigation events and resolved IP addresses. Any 51 // The expiration period of navigation events and resolved IP addresses. Any
47 // navigation related records that happened 2 minutes ago are considered as 52 // navigation related records that happened 2 minutes ago are considered as
48 // expired. So we clean up these navigation footprints every 2 minutes. 53 // expired. So we clean up these navigation footprints every 2 minutes.
49 static const double kNavigationFootprintTTLInSecond = 120.0; 54 static const double kNavigationFootprintTTLInSecond = 120.0;
50 // The number of user gestures we trace back for download attribution.
51 static const int kDownloadAttributionUserGestureLimit = 2;
52 55
53 // static 56 // static
57 const base::Feature
58 SafeBrowsingNavigationObserverManager::kDownloadAttribution {
59 "DownloadAttribution", base::FEATURE_DISABLED_BY_DEFAULT
60 };
61 // static
54 bool SafeBrowsingNavigationObserverManager::IsUserGestureExpired( 62 bool SafeBrowsingNavigationObserverManager::IsUserGestureExpired(
55 const base::Time& timestamp) { 63 const base::Time& timestamp) {
56 return IsEventExpired(timestamp, kUserGestureTTLInSecond); 64 return IsEventExpired(timestamp, kUserGestureTTLInSecond);
57 } 65 }
58 66
59 // static 67 // static
60 GURL SafeBrowsingNavigationObserverManager::ClearEmptyRef(const GURL& url) { 68 GURL SafeBrowsingNavigationObserverManager::ClearEmptyRef(const GURL& url) {
61 if (url.has_ref() && url.ref().empty()) { 69 if (url.has_ref() && url.ref().empty()) {
62 url::Replacements<char> replacements; 70 url::Replacements<char> replacements;
63 replacements.ClearRef(); 71 replacements.ClearRef();
64 return url.ReplaceComponents(replacements); 72 return url.ReplaceComponents(replacements);
65 } 73 }
66 return url; 74 return url;
67 } 75 }
68 76
77 // static
78 bool SafeBrowsingNavigationObserverManager::IsEnabledAndReady(
79 Profile* profile) {
80 return base::FeatureList::IsEnabled(
81 SafeBrowsingNavigationObserverManager::kDownloadAttribution) &&
82 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
83 g_browser_process->safe_browsing_service() &&
84 g_browser_process->safe_browsing_service()->navigation_observer_manager();
85 }
86
69 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() { 87 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() {
70 registrar_.Add(this, chrome::NOTIFICATION_RETARGETING, 88 registrar_.Add(this, chrome::NOTIFICATION_RETARGETING,
71 content::NotificationService::AllSources()); 89 content::NotificationService::AllSources());
72 90
73 // TODO(jialiul): call ScheduleNextCleanUpAfterInterval() when this class is 91 // Schedule clean up in 2 minutes.
74 // ready to be hooked into SafeBrowsingService. 92 ScheduleNextCleanUpAfterInterval(
93 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond));
75 } 94 }
76 95
77 void SafeBrowsingNavigationObserverManager::RecordNavigationEvent( 96 void SafeBrowsingNavigationObserverManager::RecordNavigationEvent(
78 const GURL& nav_event_key, 97 const GURL& nav_event_key,
79 NavigationEvent* nav_event) { 98 NavigationEvent* nav_event) {
80 auto insertion_result = navigation_map_.insert( 99 auto insertion_result = navigation_map_.insert(
81 std::make_pair(nav_event_key, std::vector<NavigationEvent>())); 100 std::make_pair(nav_event_key, std::vector<NavigationEvent>()));
82 101
83 insertion_result.first->second.push_back(std::move(*nav_event)); 102 insertion_result.first->second.push_back(std::move(*nav_event));
84 } 103 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 AddToReferrerChain(out_referrer_chain, nav_event, 220 AddToReferrerChain(out_referrer_chain, nav_event,
202 ReferrerChainEntry::LANDING_REFERRER); 221 ReferrerChainEntry::LANDING_REFERRER);
203 result = SUCCESS_LANDING_REFERRER; 222 result = SUCCESS_LANDING_REFERRER;
204 } else { 223 } else {
205 NOTREACHED(); 224 NOTREACHED();
206 } 225 }
207 } 226 }
208 return result; 227 return result;
209 } 228 }
210 229
211 void SafeBrowsingNavigationObserverManager::
212 AddReferrerChainToClientDownloadRequest(
213 const GURL& download_url,
214 content::WebContents* source_contents,
215 ClientDownloadRequest* out_request) {
216 int download_tab_id = SessionTabHelper::IdForTab(source_contents);
217 UMA_HISTOGRAM_BOOLEAN(
218 "SafeBrowsing.ReferrerHasInvalidTabID.DownloadAttribution",
219 download_tab_id == -1);
220 std::vector<ReferrerChainEntry> attribution_chain;
221 AttributionResult result = IdentifyReferrerChain(
222 download_url, download_tab_id, kDownloadAttributionUserGestureLimit,
223 &attribution_chain);
224 UMA_HISTOGRAM_COUNTS_100(
225 "SafeBrowsing.ReferrerURLChainSize.DownloadAttribution",
226 attribution_chain.size());
227 UMA_HISTOGRAM_ENUMERATION(
228 "SafeBrowsing.ReferrerAttributionResult.DownloadAttribution", result,
229 SafeBrowsingNavigationObserverManager::ATTRIBUTION_FAILURE_TYPE_MAX);
230 for (auto entry : attribution_chain)
231 *out_request->add_referrer_chain() = entry;
232 }
233
234 SafeBrowsingNavigationObserverManager:: 230 SafeBrowsingNavigationObserverManager::
235 ~SafeBrowsingNavigationObserverManager() {} 231 ~SafeBrowsingNavigationObserverManager() {}
236 232
237 void SafeBrowsingNavigationObserverManager::Observe( 233 void SafeBrowsingNavigationObserverManager::Observe(
238 int type, 234 int type,
239 const content::NotificationSource& source, 235 const content::NotificationSource& source,
240 const content::NotificationDetails& details) { 236 const content::NotificationDetails& details) {
241 if (type == chrome::NOTIFICATION_RETARGETING) 237 if (type == chrome::NOTIFICATION_RETARGETING)
242 RecordRetargeting(details); 238 RecordRetargeting(details);
243 } 239 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 nav_event->source_main_frame_url.spec()); 391 nav_event->source_main_frame_url.spec());
396 } 392 }
397 referrer_chain_entry.set_is_retargeting(nav_event->source_tab_id != 393 referrer_chain_entry.set_is_retargeting(nav_event->source_tab_id !=
398 nav_event->target_tab_id); 394 nav_event->target_tab_id);
399 referrer_chain_entry.set_navigation_time_msec( 395 referrer_chain_entry.set_navigation_time_msec(
400 nav_event->last_updated.ToJavaTime()); 396 nav_event->last_updated.ToJavaTime());
401 referrer_chain->push_back(referrer_chain_entry); 397 referrer_chain->push_back(referrer_chain_entry);
402 } 398 }
403 399
404 } // namespace safe_browsing 400 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698