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