Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 22 matching lines...) Expand all Loading... | |
| 33 // Returns true with a probability given by |performance_measurement_rate| if | 33 // Returns true with a probability given by |performance_measurement_rate| if |
| 34 // ThreadTicks is supported, otherwise returns false. | 34 // ThreadTicks is supported, otherwise returns false. |
| 35 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { | 35 bool ShouldMeasurePerformanceForPageLoad(double performance_measurement_rate) { |
| 36 if (!base::ThreadTicks::IsSupported()) | 36 if (!base::ThreadTicks::IsSupported()) |
| 37 return false; | 37 return false; |
| 38 return performance_measurement_rate == 1 || | 38 return performance_measurement_rate == 1 || |
| 39 (performance_measurement_rate > 0 && | 39 (performance_measurement_rate > 0 && |
| 40 base::RandDouble() < performance_measurement_rate); | 40 base::RandDouble() < performance_measurement_rate); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Records histograms about the length of redirect chains, and about the pattern | 43 // Records histograms about the length of redirect chains, and about the pattern |
|
engedy
2017/04/26 13:47:09
nit: s/about the pattern of//
melandory
2017/04/26 15:02:20
Done.
| |
| 44 // of whether each URL in the chain matched the activation list. | 44 // of whether each URL in the chain matched the activation list. |
|
engedy
2017/04/26 13:47:09
nit: s/each/the last/
melandory
2017/04/26 15:02:20
Done.
| |
| 45 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, hits_pattern, chain_size) \ | 45 #define REPORT_REDIRECT_PATTERN_FOR_SUFFIX(suffix, match_pattern, chain_size) \ |
|
engedy
2017/04/26 13:47:09
nit: s/match_pattern/did_match|is_match|matched/,
melandory
2017/04/26 15:02:20
Done.
| |
| 46 do { \ | 46 do { \ |
| 47 UMA_HISTOGRAM_ENUMERATION( \ | 47 UMA_HISTOGRAM_BOOLEAN("SubresourecFilter.PageLoad.FinalURLMatch." suffix, \ |
| 48 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." suffix, \ | 48 match_pattern); \ |
| 49 hits_pattern, 0x10); \ | 49 if (match_pattern) { \ |
| 50 UMA_HISTOGRAM_COUNTS( \ | 50 UMA_HISTOGRAM_COUNTS( \ |
| 51 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, chain_size); \ | 51 "SubresourceFilter.PageLoad.RedirectChainLength." suffix, \ |
| 52 chain_size); \ | |
| 53 }; \ | |
| 52 } while (0) | 54 } while (0) |
| 53 | 55 |
| 54 } // namespace | 56 } // namespace |
| 55 | 57 |
| 56 // static | 58 // static |
| 57 void ContentSubresourceFilterDriverFactory::CreateForWebContents( | 59 void ContentSubresourceFilterDriverFactory::CreateForWebContents( |
| 58 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
| 59 std::unique_ptr<SubresourceFilterClient> client) { | 61 std::unique_ptr<SubresourceFilterClient> client) { |
| 60 if (FromWebContents(web_contents)) | 62 if (FromWebContents(web_contents)) |
| 61 return; | 63 return; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 266 |
| 265 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( | 267 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( |
| 266 const GURL& url, | 268 const GURL& url, |
| 267 ActivationList match_type) { | 269 ActivationList match_type) { |
| 268 if (match_type == ActivationList::NONE) | 270 if (match_type == ActivationList::NONE) |
| 269 return; | 271 return; |
| 270 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) | 272 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) |
| 271 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); | 273 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); |
| 272 } | 274 } |
| 273 | 275 |
| 274 int ContentSubresourceFilterDriverFactory::CalculateHitPatternForActivationList( | |
| 275 ActivationList activation_list) const { | |
| 276 int hits_pattern = 0; | |
| 277 const int kInitialURLHitMask = 0x4; | |
| 278 const int kRedirectURLHitMask = 0x2; | |
| 279 const int kFinalURLHitMask = 0x1; | |
| 280 | |
| 281 if (navigation_chain_.size() > 1) { | |
| 282 if (DidURLMatchActivationList(navigation_chain_.back(), activation_list)) | |
| 283 hits_pattern |= kFinalURLHitMask; | |
| 284 if (DidURLMatchActivationList(navigation_chain_.front(), activation_list)) | |
| 285 hits_pattern |= kInitialURLHitMask; | |
| 286 | |
| 287 // Examine redirects. | |
| 288 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) { | |
| 289 if (DidURLMatchActivationList(navigation_chain_[i], activation_list)) { | |
| 290 hits_pattern |= kRedirectURLHitMask; | |
| 291 break; | |
| 292 } | |
| 293 } | |
| 294 } else { | |
| 295 if (navigation_chain_.size() && | |
| 296 DidURLMatchActivationList(navigation_chain_.front(), activation_list)) { | |
| 297 hits_pattern = 0x8; // One url hit. | |
| 298 } | |
| 299 } | |
| 300 return hits_pattern; | |
| 301 } | |
| 302 | |
| 303 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() | 276 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() |
| 304 const { | 277 const { |
| 305 RecordRedirectChainMatchPatternForList( | 278 RecordRedirectChainMatchPatternForList( |
| 306 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 279 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 307 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL); | 280 RecordRedirectChainMatchPatternForList(ActivationList::PHISHING_INTERSTITIAL); |
| 308 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER); | 281 RecordRedirectChainMatchPatternForList(ActivationList::SUBRESOURCE_FILTER); |
| 309 } | 282 } |
| 310 | 283 |
| 311 void ContentSubresourceFilterDriverFactory:: | 284 void ContentSubresourceFilterDriverFactory:: |
| 312 RecordRedirectChainMatchPatternForList( | 285 RecordRedirectChainMatchPatternForList( |
| 313 ActivationList activation_list) const { | 286 ActivationList activation_list) const { |
| 314 int hits_pattern = CalculateHitPatternForActivationList(activation_list); | 287 if (!navigation_chain_.back().has_host() || |
|
engedy
2017/04/26 13:47:09
nit: Add DCHECK(!navigation_chain_.empty()); befor
melandory
2017/04/26 15:02:20
Done.
| |
| 315 if (!hits_pattern) | 288 !navigation_chain_.back().SchemeIsHTTPOrHTTPS()) { |
| 316 return; | 289 return; |
| 290 } | |
| 291 bool match_pattern = | |
| 292 DidURLMatchActivationList(navigation_chain_.back(), activation_list); | |
| 317 size_t chain_size = navigation_chain_.size(); | 293 size_t chain_size = navigation_chain_.size(); |
| 318 switch (activation_list) { | 294 switch (activation_list) { |
| 319 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: | 295 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: |
| 320 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial", | 296 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SocialEngineeringAdsInterstitial", |
| 321 hits_pattern, chain_size); | 297 match_pattern, chain_size); |
| 322 break; | 298 break; |
| 323 case ActivationList::PHISHING_INTERSTITIAL: | 299 case ActivationList::PHISHING_INTERSTITIAL: |
| 324 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", hits_pattern, | 300 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("PhishingInterstital", match_pattern, |
| 325 chain_size); | 301 chain_size); |
| 326 break; | 302 break; |
| 327 case ActivationList::SUBRESOURCE_FILTER: | 303 case ActivationList::SUBRESOURCE_FILTER: |
| 328 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, | 304 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", match_pattern, |
| 329 chain_size); | 305 chain_size); |
| 330 break; | 306 break; |
| 331 default: | 307 default: |
| 332 NOTREACHED(); | 308 NOTREACHED(); |
| 333 break; | 309 break; |
| 334 } | 310 } |
| 335 } | 311 } |
| 336 | 312 |
| 337 } // namespace subresource_filter | 313 } // namespace subresource_filter |
| OLD | NEW |