OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/subframe_navigation_filt
ering_throttle.h" | 5 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "components/subresource_filter/core/common/time_measurements.h" |
9 #include "content/public/browser/navigation_handle.h" | 11 #include "content/public/browser/navigation_handle.h" |
10 | 12 |
11 namespace subresource_filter { | 13 namespace subresource_filter { |
12 | 14 |
13 SubframeNavigationFilteringThrottle::SubframeNavigationFilteringThrottle( | 15 SubframeNavigationFilteringThrottle::SubframeNavigationFilteringThrottle( |
14 content::NavigationHandle* handle, | 16 content::NavigationHandle* handle, |
15 AsyncDocumentSubresourceFilter* parent_frame_filter) | 17 AsyncDocumentSubresourceFilter* parent_frame_filter) |
16 : content::NavigationThrottle(handle), | 18 : content::NavigationThrottle(handle), |
17 parent_frame_filter_(parent_frame_filter), | 19 parent_frame_filter_(parent_frame_filter), |
18 weak_ptr_factory_(this) { | 20 weak_ptr_factory_(this) { |
19 DCHECK(!handle->IsInMainFrame()); | 21 DCHECK(!handle->IsInMainFrame()); |
20 DCHECK(parent_frame_filter_); | 22 DCHECK(parent_frame_filter_); |
21 } | 23 } |
22 | 24 |
23 SubframeNavigationFilteringThrottle::~SubframeNavigationFilteringThrottle() {} | 25 SubframeNavigationFilteringThrottle::~SubframeNavigationFilteringThrottle() { |
| 26 if (disallowed_) { |
| 27 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| 28 "SubresourceFilter.DocumentLoad.SubframeFilteringDelay.Disallowed", |
| 29 total_defer_time_, base::TimeDelta::FromMicroseconds(1), |
| 30 base::TimeDelta::FromSeconds(10), 50); |
| 31 } else { |
| 32 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| 33 "SubresourceFilter.DocumentLoad.SubframeFilteringDelay.Allowed", |
| 34 total_defer_time_, base::TimeDelta::FromMicroseconds(1), |
| 35 base::TimeDelta::FromSeconds(10), 50); |
| 36 } |
| 37 } |
24 | 38 |
25 content::NavigationThrottle::ThrottleCheckResult | 39 content::NavigationThrottle::ThrottleCheckResult |
26 SubframeNavigationFilteringThrottle::WillStartRequest() { | 40 SubframeNavigationFilteringThrottle::WillStartRequest() { |
27 return DeferToCalculateLoadPolicy(); | 41 return DeferToCalculateLoadPolicy(); |
28 } | 42 } |
29 | 43 |
30 content::NavigationThrottle::ThrottleCheckResult | 44 content::NavigationThrottle::ThrottleCheckResult |
31 SubframeNavigationFilteringThrottle::WillRedirectRequest() { | 45 SubframeNavigationFilteringThrottle::WillRedirectRequest() { |
32 return DeferToCalculateLoadPolicy(); | 46 return DeferToCalculateLoadPolicy(); |
33 } | 47 } |
34 | 48 |
35 const char* SubframeNavigationFilteringThrottle::GetNameForLogging() { | 49 const char* SubframeNavigationFilteringThrottle::GetNameForLogging() { |
36 return "SubframeNavigationFilteringThrottle"; | 50 return "SubframeNavigationFilteringThrottle"; |
37 } | 51 } |
38 | 52 |
39 content::NavigationThrottle::ThrottleCheckResult | 53 content::NavigationThrottle::ThrottleCheckResult |
40 SubframeNavigationFilteringThrottle::DeferToCalculateLoadPolicy() { | 54 SubframeNavigationFilteringThrottle::DeferToCalculateLoadPolicy() { |
41 parent_frame_filter_->GetLoadPolicyForSubdocument( | 55 parent_frame_filter_->GetLoadPolicyForSubdocument( |
42 navigation_handle()->GetURL(), | 56 navigation_handle()->GetURL(), |
43 base::Bind(&SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy, | 57 base::Bind(&SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy, |
44 weak_ptr_factory_.GetWeakPtr())); | 58 weak_ptr_factory_.GetWeakPtr())); |
| 59 last_defer_timestamp_ = base::TimeTicks::Now(); |
45 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | 60 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
46 } | 61 } |
47 | 62 |
48 void SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy( | 63 void SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy( |
49 LoadPolicy policy) { | 64 LoadPolicy policy) { |
| 65 DCHECK(!last_defer_timestamp_.is_null()); |
| 66 total_defer_time_ += base::TimeTicks::Now() - last_defer_timestamp_; |
50 // TODO(csharrison): Support WouldDisallow pattern and expose the policy for | 67 // TODO(csharrison): Support WouldDisallow pattern and expose the policy for |
51 // metrics. Also, cancel with BLOCK_AND_COLLAPSE when it is implemented. | 68 // metrics. Also, cancel with BLOCK_AND_COLLAPSE when it is implemented. |
52 if (policy == LoadPolicy::DISALLOW) { | 69 if (policy == LoadPolicy::DISALLOW) { |
| 70 disallowed_ = true; |
53 parent_frame_filter_->ReportDisallowedLoad(); | 71 parent_frame_filter_->ReportDisallowedLoad(); |
54 navigation_handle()->CancelDeferredNavigation( | 72 navigation_handle()->CancelDeferredNavigation( |
55 content::NavigationThrottle::CANCEL); | 73 content::NavigationThrottle::CANCEL); |
56 } else { | 74 } else { |
57 navigation_handle()->Resume(); | 75 navigation_handle()->Resume(); |
58 } | 76 } |
59 } | 77 } |
60 | 78 |
61 } // namespace subresource_filter | 79 } // namespace subresource_filter |
OLD | NEW |