Chromium Code Reviews| 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" |
| 13 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 | 17 |
| 17 namespace subresource_filter { | 18 namespace subresource_filter { |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 std::unique_ptr<ActivationStateComputingNavigationThrottle> | 21 std::unique_ptr<ActivationStateComputingNavigationThrottle> |
| 21 ActivationStateComputingNavigationThrottle::CreateForMainFrame( | 22 ActivationStateComputingNavigationThrottle::CreateForMainFrame( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); | 86 content::RenderFrameHost* parent = navigation_handle()->GetParentFrame(); |
| 86 DCHECK(parent); | 87 DCHECK(parent); |
| 87 params.parent_document_origin = parent->GetLastCommittedOrigin(); | 88 params.parent_document_origin = parent->GetLastCommittedOrigin(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( | 91 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( |
| 91 ruleset_handle_, std::move(params), | 92 ruleset_handle_, std::move(params), |
| 92 base::Bind(&ActivationStateComputingNavigationThrottle:: | 93 base::Bind(&ActivationStateComputingNavigationThrottle:: |
| 93 OnActivationStateComputed, | 94 OnActivationStateComputed, |
| 94 weak_ptr_factory_.GetWeakPtr())); | 95 weak_ptr_factory_.GetWeakPtr())); |
| 96 | |
| 97 defer_timestamp_ = base::TimeTicks::Now(); | |
| 95 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | 98 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
| 96 } | 99 } |
| 97 | 100 |
| 98 const char* ActivationStateComputingNavigationThrottle::GetNameForLogging() { | 101 const char* ActivationStateComputingNavigationThrottle::GetNameForLogging() { |
| 99 return "ActivationStateComputingNavigationThrottle"; | 102 return "ActivationStateComputingNavigationThrottle"; |
| 100 } | 103 } |
| 101 | 104 |
| 102 void ActivationStateComputingNavigationThrottle::OnActivationStateComputed( | 105 void ActivationStateComputingNavigationThrottle::OnActivationStateComputed( |
| 103 ActivationState state) { | 106 ActivationState state) { |
| 107 DCHECK(!defer_timestamp_.is_null()); | |
| 108 base::TimeDelta delay = base::TimeTicks::Now() - defer_timestamp_; | |
| 109 UMA_HISTOGRAM_TIMES("SubresourceFilter.DocumentLoad.ActivationComputingDelay", | |
|
pkalinnikov
2017/05/08 12:00:05
Do you expect it to be mostly >= 1 ms?
We also ha
Charlie Harrison
2017/05/08 12:53:33
Yeah we can us microseconds for these metrics (may
| |
| 110 delay); | |
| 111 if (navigation_handle()->IsInMainFrame()) { | |
| 112 UMA_HISTOGRAM_TIMES( | |
| 113 "SubresourceFilter.DocumentLoad.ActivationComputingDelay.MainFrame", | |
| 114 delay); | |
| 115 } | |
| 104 navigation_handle()->Resume(); | 116 navigation_handle()->Resume(); |
| 105 } | 117 } |
| 106 | 118 |
| 107 // Ensure the caller cannot take ownership of a subresource filter for cases | 119 // Ensure the caller cannot take ownership of a subresource filter for cases |
| 108 // when activation IPCs are not sent to the render process. | 120 // when activation IPCs are not sent to the render process. |
| 109 std::unique_ptr<AsyncDocumentSubresourceFilter> | 121 std::unique_ptr<AsyncDocumentSubresourceFilter> |
| 110 ActivationStateComputingNavigationThrottle::ReleaseFilter() { | 122 ActivationStateComputingNavigationThrottle::ReleaseFilter() { |
| 111 return will_send_activation_to_renderer_ ? std::move(async_filter_) : nullptr; | 123 return will_send_activation_to_renderer_ ? std::move(async_filter_) : nullptr; |
| 112 } | 124 } |
| 113 | 125 |
| 114 void ActivationStateComputingNavigationThrottle:: | 126 void ActivationStateComputingNavigationThrottle:: |
| 115 WillSendActivationToRenderer() { | 127 WillSendActivationToRenderer() { |
| 116 DCHECK(async_filter_); | 128 DCHECK(async_filter_); |
| 117 will_send_activation_to_renderer_ = true; | 129 will_send_activation_to_renderer_ = true; |
| 118 } | 130 } |
| 119 | 131 |
| 120 } // namespace subresource_filter | 132 } // namespace subresource_filter |
| OLD | NEW |