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

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: remove tests which are not neede anymore Created 3 years, 8 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/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 28 matching lines...) Expand all
39 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { 39 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) {
40 if (!base::ThreadTicks::IsSupported()) 40 if (!base::ThreadTicks::IsSupported())
41 return false; 41 return false;
42 return performance_measurement_rate == 1 || 42 return performance_measurement_rate == 1 ||
43 (performance_measurement_rate > 0 && 43 (performance_measurement_rate > 0 &&
44 base::RandDouble() < performance_measurement_rate); 44 base::RandDouble() < performance_measurement_rate);
45 } 45 }
46 46
47 // Records histograms about the length of redirect chains, and about the pattern 47 // Records histograms about the length of redirect chains, and about the pattern
48 // of whether each URL in the chain matched the activation list. 48 // of whether each URL in the chain matched the activation list.
49 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, hits_pattern, chain_size) \ 49 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, match_pattern, chain_size) \
50 do { \ 50 do { \
51 UMA_HISTOGRAM_ENUMERATION( \ 51 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.Match." suffix, \
engedy 2017/04/20 11:16:11 Have you considered making this UMA_HISTOGRAM_BOOL
melandory 2017/04/25 13:48:13 Done.
52 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." suffix, \ 52 match_pattern); \
53 hits_pattern, 0x10); \
54 UMA_HISTOGRAM_COUNTS( \ 53 UMA_HISTOGRAM_COUNTS( \
55 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \ 54 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \
56 } while (0) 55 } while (0)
57 56
58 } // namespace 57 } // namespace
59 58
60 // static 59 // static
61 void ContentSubresourceFilterDriverFactory::CreateForWebContents( 60 void ContentSubresourceFilterDriverFactory::CreateForWebContents(
62 content::WebContents* web_contents, 61 content::WebContents* web_contents,
63 std::unique_ptr<SubresourceFilterClient> client) { 62 std::unique_ptr<SubresourceFilterClient> client) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 339
341 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( 340 void ContentSubresourceFilterDriverFactory::AddActivationListMatch(
342 const GURL& url, 341 const GURL& url,
343 ActivationList match_type) { 342 ActivationList match_type) {
344 if (match_type == ActivationList::NONE) 343 if (match_type == ActivationList::NONE)
345 return; 344 return;
346 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) 345 if (url.has_host() && url.SchemeIsHTTPOrHTTPS())
347 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); 346 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type);
348 } 347 }
349 348
350 int ContentSubresourceFilterDriverFactory::CalculateHitPatternForActivationList( 349 bool ContentSubresourceFilterDriverFactory::CalculateMatchForActivationList(
engedy 2017/04/20 11:16:11 nit: Let's just inline this method now that it bec
melandory 2017/04/25 13:48:13 Done.
351 ActivationList activation_list) const { 350 ActivationList activation_list) const {
352 int hits_pattern = 0; 351 return navigation_chain_.size() &&
engedy 2017/04/20 11:16:11 nit: Can |navigation_chain_| ever be empty here?
melandory 2017/04/25 13:48:13 Done.
353 const int kInitialURLHitMask = 0x4; 352 DidURLMatchActivationList(navigation_chain_.back(), activation_list);
354 const int kRedirectURLHitMask = 0x2;
355 const int kFinalURLHitMask = 0x1;
356
357 if (navigation_chain_.size() > 1) {
358 if (DidURLMatchActivationList(navigation_chain_.back(), activation_list))
359 hits_pattern |= kFinalURLHitMask;
360 if (DidURLMatchActivationList(navigation_chain_.front(), activation_list))
361 hits_pattern |= kInitialURLHitMask;
362
363 // Examine redirects.
364 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) {
365 if (DidURLMatchActivationList(navigation_chain_[i], activation_list)) {
366 hits_pattern |= kRedirectURLHitMask;
367 break;
368 }
369 }
370 } else {
371 if (navigation_chain_.size() &&
372 DidURLMatchActivationList(navigation_chain_.front(), activation_list)) {
373 hits_pattern = 0x8; // One url hit.
374 }
375 }
376 return hits_pattern;
377 } 353 }
378 354
379 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() 355 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern()
380 const { 356 const {
381 RecordRedirectChainMatchPatternForList( 357 RecordRedirectChainMatchPatternForList(
382 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); 358 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL);
383 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL); 359 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL);
384 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER); 360 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER);
385 } 361 }
386 362
387 void ContentSubresourceFilterDriverFactory:: 363 void ContentSubresourceFilterDriverFactory::
388 RecordRedirectChainMatchPatternForList( 364 RecordRedirectChainMatchPatternForList(
389 ActivationList activation_list) const { 365 ActivationList activation_list) const {
390 int hits_pattern = CalculateHitPatternForActivationList(activation_list); 366 int match_pattern = CalculateMatchForActivationList(activation_list);
391 if (!hits_pattern) 367 if (!match_pattern)
392 return; 368 return;
393 size_t chain_size = navigation_chain_.size(); 369 size_t chain_size = navigation_chain_.size();
394 switch (activation_list) { 370 switch (activation_list) {
395 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: 371 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL:
396 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial", 372 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial",
397 hits_pattern, chain_size); 373 match_pattern, chain_size);
398 break; 374 break;
399 case ActivationList::PHISHING_INTERSTITIAL: 375 case ActivationList::PHISHING_INTERSTITIAL:
400 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", hits_pattern, 376 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", match_pattern,
401 chain_size); 377 chain_size);
402 break; 378 break;
403 case ActivationList::SUBRESOURCE_FILTER: 379 case ActivationList::SUBRESOURCE_FILTER:
404 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, 380 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", match_pattern,
405 chain_size); 381 chain_size);
406 break; 382 break;
407 default: 383 default:
408 NOTREACHED(); 384 NOTREACHED();
409 break; 385 break;
410 } 386 }
411 } 387 }
412 388
413 } // namespace subresource_filter 389 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698