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/activation_state_computi
ng_navigation_throttle.h" | 5 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" |
12 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 13 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
| 14 #include "components/subresource_filter/core/common/time_measurements.h" |
13 #include "content/public/browser/navigation_handle.h" | 15 #include "content/public/browser/navigation_handle.h" |
14 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
16 | 18 |
17 namespace subresource_filter { | 19 namespace subresource_filter { |
18 | 20 |
19 // static | 21 // static |
20 std::unique_ptr<ActivationStateComputingNavigationThrottle> | 22 std::unique_ptr<ActivationStateComputingNavigationThrottle> |
21 ActivationStateComputingNavigationThrottle::CreateForMainFrame( | 23 ActivationStateComputingNavigationThrottle::CreateForMainFrame( |
22 content::NavigationHandle* navigation_handle) { | 24 content::NavigationHandle* navigation_handle) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); | 87 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); |
86 DCHECK(parent); | 88 DCHECK(parent); |
87 params.parent_document_origin = parent->GetLastCommittedOrigin(); | 89 params.parent_document_origin = parent->GetLastCommittedOrigin(); |
88 } | 90 } |
89 | 91 |
90 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( | 92 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( |
91 ruleset_handle_, std::move(params), | 93 ruleset_handle_, std::move(params), |
92 base::Bind(&ActivationStateComputingNavigationThrottle:: | 94 base::Bind(&ActivationStateComputingNavigationThrottle:: |
93 OnActivationStateComputed, | 95 OnActivationStateComputed, |
94 weak_ptr_factory_.GetWeakPtr())); | 96 weak_ptr_factory_.GetWeakPtr())); |
| 97 |
| 98 defer_timestamp_ = base::TimeTicks::Now(); |
95 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | 99 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
96 } | 100 } |
97 | 101 |
98 const char* ActivationStateComputingNavigationThrottle::GetNameForLogging() { | 102 const char* ActivationStateComputingNavigationThrottle::GetNameForLogging() { |
99 return "ActivationStateComputingNavigationThrottle"; | 103 return "ActivationStateComputingNavigationThrottle"; |
100 } | 104 } |
101 | 105 |
102 void ActivationStateComputingNavigationThrottle::OnActivationStateComputed( | 106 void ActivationStateComputingNavigationThrottle::OnActivationStateComputed( |
103 ActivationState state) { | 107 ActivationState state) { |
| 108 DCHECK(!defer_timestamp_.is_null()); |
| 109 base::TimeDelta delay = base::TimeTicks::Now() - defer_timestamp_; |
| 110 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| 111 "SubresourceFilter.DocumentLoad.ActivationComputingDelay", delay, |
| 112 base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(10), |
| 113 50); |
| 114 if (navigation_handle()->IsInMainFrame()) { |
| 115 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| 116 "SubresourceFilter.DocumentLoad.ActivationComputingDelay.MainFrame", |
| 117 delay, base::TimeDelta::FromMicroseconds(1), |
| 118 base::TimeDelta::FromSeconds(10), 50); |
| 119 } |
104 navigation_handle()->Resume(); | 120 navigation_handle()->Resume(); |
105 } | 121 } |
106 | 122 |
107 // Ensure the caller cannot take ownership of a subresource filter for cases | 123 // Ensure the caller cannot take ownership of a subresource filter for cases |
108 // when activation IPCs are not sent to the render process. | 124 // when activation IPCs are not sent to the render process. |
109 std::unique_ptr<AsyncDocumentSubresourceFilter> | 125 std::unique_ptr<AsyncDocumentSubresourceFilter> |
110 ActivationStateComputingNavigationThrottle::ReleaseFilter() { | 126 ActivationStateComputingNavigationThrottle::ReleaseFilter() { |
111 return will_send_activation_to_renderer_ ? std::move(async_filter_) : nullptr; | 127 return will_send_activation_to_renderer_ ? std::move(async_filter_) : nullptr; |
112 } | 128 } |
113 | 129 |
114 void ActivationStateComputingNavigationThrottle:: | 130 void ActivationStateComputingNavigationThrottle:: |
115 WillSendActivationToRenderer() { | 131 WillSendActivationToRenderer() { |
116 DCHECK(async_filter_); | 132 DCHECK(async_filter_); |
117 will_send_activation_to_renderer_ = true; | 133 will_send_activation_to_renderer_ = true; |
118 } | 134 } |
119 | 135 |
120 } // namespace subresource_filter | 136 } // namespace subresource_filter |
OLD | NEW |