Chromium Code Reviews| Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
| diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
| index dbb8f3a5918a9cbba2421ab24925f5035f118b7d..748ec82e9315a6082764ed524cfbf9193e1bff8f 100644 |
| --- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
| +++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
| @@ -6,11 +6,13 @@ |
| #include "base/metrics/histogram_macros.h" |
| #include "base/rand_util.h" |
| +#include "base/time/time.h" |
| #include "components/subresource_filter/content/browser/content_subresource_filter_driver.h" |
| #include "components/subresource_filter/content/common/subresource_filter_messages.h" |
| #include "components/subresource_filter/core/browser/subresource_filter_client.h" |
| #include "components/subresource_filter/core/browser/subresource_filter_features.h" |
| #include "components/subresource_filter/core/common/activation_list.h" |
| +#include "components/subresource_filter/core/common/time_measurements.h" |
| #include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -28,8 +30,15 @@ std::string DistillURLToHostAndPath(const GURL& url) { |
| return url.host() + url.path(); |
| } |
| -bool ShouldMeasurePerformance(double rate) { |
| - return base::RandDouble() < rate; |
| +// Returns true with a probability of GetPerformanceMeasurementRate() if |
| +// ThreadTicks is supported, otherwise returns false. |
| +bool ShouldMeasurePerformanceForPageLoad() { |
| + if (!base::ThreadTicks::IsSupported()) |
| + return false; |
| + // TODO(pkalinnikov): Cache |rate| and other variation params in |
| + // ContentSubresourceFilterDriverFactory. |
| + const double rate = GetPerformanceMeasurementRate(); |
| + return rate == 1 || (rate > 0 && base::RandDouble() < rate); |
| } |
| } // namespace |
| @@ -83,6 +92,13 @@ void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { |
| ActivationState::ENABLED); |
| } |
| +void ContentSubresourceFilterDriverFactory::OnEvaluationDurationAggregated( |
| + base::TimeDelta evaluation_total_wall_duration, |
| + base::TimeDelta evaluation_total_cpu_duration) { |
| + evaluation_total_wall_duration_ += evaluation_total_wall_duration; |
| + evaluation_total_cpu_duration_ += evaluation_total_cpu_duration; |
| +} |
| + |
| bool ContentSubresourceFilterDriverFactory::IsWhitelisted( |
| const GURL& url) const { |
| return whitelisted_hosts_.find(url.host()) != whitelisted_hosts_.end(); |
| @@ -169,6 +185,8 @@ void ContentSubresourceFilterDriverFactory::DidStartNavigation( |
| client_->ToggleNotificationVisibility(false); |
| activation_state_ = ActivationState::DISABLED; |
| measure_performance_ = false; |
| + evaluation_total_wall_duration_ = base::TimeDelta(); |
| + evaluation_total_cpu_duration_ = base::TimeDelta(); |
| } |
| } |
| @@ -198,6 +216,26 @@ void ContentSubresourceFilterDriverFactory::ReadyToCommitNavigation( |
| ReadyToCommitNavigationInternal(render_frame_host, url); |
| } |
| +void ContentSubresourceFilterDriverFactory::DidFinishLoad( |
| + content::RenderFrameHost* render_frame_host, |
| + const GURL& validated_url) { |
| + if (render_frame_host->GetParent()) |
| + return; |
| + |
| + if (measure_performance_) { |
| + DCHECK(activation_state_ != ActivationState::DISABLED); |
| + UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| + "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalWallDuration", |
| + evaluation_total_wall_duration_, base::TimeDelta::FromMicroseconds(1), |
| + base::TimeDelta::FromSeconds(10), 50); |
| + |
| + UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
| + "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration", |
| + evaluation_total_cpu_duration_, base::TimeDelta::FromMicroseconds(1), |
| + base::TimeDelta::FromSeconds(10), 50); |
| + } |
| +} |
| + |
| bool ContentSubresourceFilterDriverFactory::OnMessageReceived( |
| const IPC::Message& message, |
| content::RenderFrameHost* render_frame_host) { |
| @@ -205,6 +243,8 @@ bool ContentSubresourceFilterDriverFactory::OnMessageReceived( |
| IPC_BEGIN_MESSAGE_MAP(ContentSubresourceFilterDriverFactory, message) |
| IPC_MESSAGE_HANDLER(SubresourceFilterHostMsg_DidDisallowFirstSubresource, |
| OnFirstSubresourceLoadDisallowed) |
| + IPC_MESSAGE_HANDLER(SubresourceFilterHostMsg_DocumentLoadStatistics, |
| + OnEvaluationDurationAggregated) |
|
engedy
2016/12/21 19:10:28
nit: Update method name.
pkalinnikov
2016/12/22 16:53:04
Done.
|
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -217,12 +257,14 @@ void ContentSubresourceFilterDriverFactory::ReadyToCommitNavigationInternal( |
| RecordRedirectChainMatchPattern(); |
| if (ShouldActivateForMainFrameURL(url)) { |
| activation_state_ = GetMaximumActivationState(); |
| - measure_performance_ = |
| - ShouldMeasurePerformance(GetPerformanceMeasurementRate()); |
| + measure_performance_ = activation_state_ != ActivationState::DISABLED && |
| + ShouldMeasurePerformanceForPageLoad(); |
| ActivateForFrameHostIfNeeded(render_frame_host, url); |
| } else { |
| activation_state_ = ActivationState::DISABLED; |
| measure_performance_ = false; |
| + evaluation_total_wall_duration_ = base::TimeDelta(); |
| + evaluation_total_cpu_duration_ = base::TimeDelta(); |
| } |
| } else { |
| ActivateForFrameHostIfNeeded(render_frame_host, url); |