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

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc

Issue 2814733002: Add the SocEng as a type for checking in CheckUrlForSubresourceFilter. (Closed)
Patch Set: . Created 3 years, 7 months 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 "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 5 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 23 matching lines...) Expand all
34 // Returns true with a probability given by |performance_measurement_rate| if 34 // Returns true with a probability given by |performance_measurement_rate| if
35 // ThreadTicks is supported, otherwise returns false. 35 // ThreadTicks is supported, otherwise returns false.
36 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { 36 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) {
37 if (!base::ThreadTicks::IsSupported()) 37 if (!base::ThreadTicks::IsSupported())
38 return false; 38 return false;
39 return performance_measurement_rate == 1 || 39 return performance_measurement_rate == 1 ||
40 (performance_measurement_rate > 0 && 40 (performance_measurement_rate > 0 &&
41 base::RandDouble() < performance_measurement_rate); 41 base::RandDouble() < performance_measurement_rate);
42 } 42 }
43 43
44 // Records histograms about the length of redirect chains, and about the pattern 44 // Records histograms about the pattern of redirect chains, and about the
45 // of whether each URL in the chain matched the activation list. 45 // pattern of whether the last URL in the chain matched the activation list.
46 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, hits_pattern, chain_size) \ 46 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, is_matched, chain_size) \
47 do { \ 47 do { \
48 UMA_HISTOGRAM_ENUMERATION( \ 48 UMA_HISTOGRAM_BOOLEAN("SubresourceFilter.PageLoad.FinalURLMatch." suffix, \
49 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." suffix, \ 49 is_matched); \
50 hits_pattern, 0x10); \ 50 if (is_matched) { \
51 UMA_HISTOGRAM_COUNTS( \ 51 UMA_HISTOGRAM_COUNTS( \
52 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \ 52 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, \
53 chain_size); \
54 }; \
53 } while (0) 55 } while (0)
54 56
55 } // namespace 57 } // namespace
56 58
57 // static 59 // static
58 void ContentSubresourceFilterDriverFactory::CreateForWebContents( 60 void ContentSubresourceFilterDriverFactory::CreateForWebContents(
59 content::WebContents* web_contents, 61 content::WebContents* web_contents,
60 SubresourceFilterClient* client) { 62 SubresourceFilterClient* client) {
61 if (FromWebContents(web_contents)) 63 if (FromWebContents(web_contents))
62 return; 64 return;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 273
272 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( 274 void ContentSubresourceFilterDriverFactory::AddActivationListMatch(
273 const GURL& url, 275 const GURL& url,
274 ActivationList match_type) { 276 ActivationList match_type) {
275 if (match_type == ActivationList::NONE) 277 if (match_type == ActivationList::NONE)
276 return; 278 return;
277 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) 279 if (url.has_host() && url.SchemeIsHTTPOrHTTPS())
278 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); 280 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type);
279 } 281 }
280 282
281 int ContentSubresourceFilterDriverFactory::CalculateHitPatternForActivationList(
282 ActivationList activation_list) const {
283 int hits_pattern = 0;
284 const int kInitialURLHitMask = 0x4;
285 const int kRedirectURLHitMask = 0x2;
286 const int kFinalURLHitMask = 0x1;
287
288 if (navigation_chain_.size() > 1) {
289 if (DidURLMatchActivationList(navigation_chain_.back(), activation_list))
290 hits_pattern |= kFinalURLHitMask;
291 if (DidURLMatchActivationList(navigation_chain_.front(), activation_list))
292 hits_pattern |= kInitialURLHitMask;
293
294 // Examine redirects.
295 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) {
296 if (DidURLMatchActivationList(navigation_chain_[i], activation_list)) {
297 hits_pattern |= kRedirectURLHitMask;
298 break;
299 }
300 }
301 } else {
302 if (navigation_chain_.size() &&
303 DidURLMatchActivationList(navigation_chain_.front(), activation_list)) {
304 hits_pattern = 0x8; // One url hit.
305 }
306 }
307 return hits_pattern;
308 }
309
310 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() 283 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern()
311 const { 284 const {
312 RecordRedirectChainMatchPatternForList( 285 RecordRedirectChainMatchPatternForList(
313 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); 286 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL);
314 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL); 287 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL);
315 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER); 288 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER);
316 } 289 }
317 290
318 void ContentSubresourceFilterDriverFactory:: 291 void ContentSubresourceFilterDriverFactory::
319 RecordRedirectChainMatchPatternForList( 292 RecordRedirectChainMatchPatternForList(
320 ActivationList activation_list) const { 293 ActivationList activation_list) const {
321 int hits_pattern = CalculateHitPatternForActivationList(activation_list); 294 DCHECK(!navigation_chain_.empty());
322 if (!hits_pattern) 295 if (!navigation_chain_.back().has_host() ||
296 !navigation_chain_.back().SchemeIsHTTPOrHTTPS()) {
323 return; 297 return;
298 }
299 bool is_matched =
300 DidURLMatchActivationList(navigation_chain_.back(), activation_list);
324 size_t chain_size = navigation_chain_.size(); 301 size_t chain_size = navigation_chain_.size();
325 switch (activation_list) { 302 switch (activation_list) {
326 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: 303 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL:
327 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial", 304 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial",
328 hits_pattern, chain_size); 305 is_matched, chain_size);
329 break; 306 break;
330 case ActivationList::PHISHING_INTERSTITIAL: 307 case ActivationList::PHISHING_INTERSTITIAL:
331 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", hits_pattern, 308 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", is_matched,
332 chain_size); 309 chain_size);
333 break; 310 break;
334 case ActivationList::SUBRESOURCE_FILTER: 311 case ActivationList::SUBRESOURCE_FILTER:
335 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, 312 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", is_matched,
336 chain_size); 313 chain_size);
337 break; 314 break;
338 default: 315 default:
339 NOTREACHED(); 316 NOTREACHED();
340 break; 317 break;
341 } 318 }
342 } 319 }
343 320
344 } // namespace subresource_filter 321 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698