OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/renderer/subresource_filter_agen t.h" | 5 #include "components/subresource_filter/content/renderer/subresource_filter_agen t.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ptr_util.h" |
engedy
2017/02/17 16:44:04
nit: Should we keep this for |ruleset|? Strictly s
pkalinnikov
2017/02/17 17:16:48
Done.
| |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "components/subresource_filter/content/common/document_subresource_filt er.h" | |
12 #include "components/subresource_filter/content/common/subresource_filter_messag es.h" | 11 #include "components/subresource_filter/content/common/subresource_filter_messag es.h" |
13 #include "components/subresource_filter/content/renderer/unverified_ruleset_deal er.h" | 12 #include "components/subresource_filter/content/renderer/unverified_ruleset_deal er.h" |
13 #include "components/subresource_filter/content/renderer/web_document_subresourc e_filter_impl.h" | |
14 #include "components/subresource_filter/core/common/document_load_statistics.h" | |
15 #include "components/subresource_filter/core/common/document_subresource_filter. h" | |
14 #include "components/subresource_filter/core/common/memory_mapped_ruleset.h" | 16 #include "components/subresource_filter/core/common/memory_mapped_ruleset.h" |
15 #include "components/subresource_filter/core/common/scoped_timers.h" | 17 #include "components/subresource_filter/core/common/scoped_timers.h" |
16 #include "components/subresource_filter/core/common/time_measurements.h" | 18 #include "components/subresource_filter/core/common/time_measurements.h" |
17 #include "content/public/common/browser_side_navigation_policy.h" | |
18 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
19 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
20 #include "third_party/WebKit/public/web/WebDataSource.h" | 21 #include "third_party/WebKit/public/web/WebDataSource.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
23 #include "url/gurl.h" | |
24 | 24 |
25 namespace subresource_filter { | 25 namespace subresource_filter { |
26 | 26 |
27 SubresourceFilterAgent::SubresourceFilterAgent( | 27 SubresourceFilterAgent::SubresourceFilterAgent( |
28 content::RenderFrame* render_frame, | 28 content::RenderFrame* render_frame, |
29 UnverifiedRulesetDealer* ruleset_dealer) | 29 UnverifiedRulesetDealer* ruleset_dealer) |
30 : content::RenderFrameObserver(render_frame), | 30 : content::RenderFrameObserver(render_frame), |
31 ruleset_dealer_(ruleset_dealer) { | 31 ruleset_dealer_(ruleset_dealer) { |
32 DCHECK(ruleset_dealer); | 32 DCHECK(ruleset_dealer); |
33 } | 33 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 static_cast<int>(ActivationLevel::LAST) + 1); | 81 static_cast<int>(ActivationLevel::LAST) + 1); |
82 | 82 |
83 if (activation_level_for_next_commit_ != ActivationLevel::DISABLED) { | 83 if (activation_level_for_next_commit_ != ActivationLevel::DISABLED) { |
84 UMA_HISTOGRAM_BOOLEAN("SubresourceFilter.DocumentLoad.RulesetIsAvailable", | 84 UMA_HISTOGRAM_BOOLEAN("SubresourceFilter.DocumentLoad.RulesetIsAvailable", |
85 ruleset_dealer_->IsRulesetFileAvailable()); | 85 ruleset_dealer_->IsRulesetFileAvailable()); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 void SubresourceFilterAgent::RecordHistogramsOnLoadFinished() { | 89 void SubresourceFilterAgent::RecordHistogramsOnLoadFinished() { |
90 DCHECK(filter_for_last_committed_load_); | 90 DCHECK(filter_for_last_committed_load_); |
91 const auto& statistics = filter_for_last_committed_load_->statistics(); | 91 const auto& statistics = |
92 filter_for_last_committed_load_->filter().statistics(); | |
92 | 93 |
93 UMA_HISTOGRAM_COUNTS_1000( | 94 UMA_HISTOGRAM_COUNTS_1000( |
94 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total", | 95 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total", |
95 statistics.num_loads_total); | 96 statistics.num_loads_total); |
96 UMA_HISTOGRAM_COUNTS_1000( | 97 UMA_HISTOGRAM_COUNTS_1000( |
97 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated", | 98 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated", |
98 statistics.num_loads_evaluated); | 99 statistics.num_loads_evaluated); |
99 UMA_HISTOGRAM_COUNTS_1000( | 100 UMA_HISTOGRAM_COUNTS_1000( |
100 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules", | 101 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules", |
101 statistics.num_loads_matching_rules); | 102 statistics.num_loads_matching_rules); |
102 UMA_HISTOGRAM_COUNTS_1000( | 103 UMA_HISTOGRAM_COUNTS_1000( |
103 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Disallowed", | 104 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Disallowed", |
104 statistics.num_loads_disallowed); | 105 statistics.num_loads_disallowed); |
105 | 106 |
106 // If ThreadTicks is not supported or performance measuring is switched off, | 107 // If ThreadTicks is not supported or performance measuring is switched off, |
107 // then no time measurements have been collected. | 108 // then no time measurements have been collected. |
108 if (ScopedThreadTimers::IsSupported() && | 109 if (ScopedThreadTimers::IsSupported() && |
109 filter_for_last_committed_load_->is_performance_measuring_enabled()) { | 110 filter_for_last_committed_load_->filter() |
111 .activation_state() | |
112 .measure_performance) { | |
110 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( | 113 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
111 "SubresourceFilter.DocumentLoad.SubresourceEvaluation." | 114 "SubresourceFilter.DocumentLoad.SubresourceEvaluation." |
112 "TotalWallDuration", | 115 "TotalWallDuration", |
113 statistics.evaluation_total_wall_duration, | 116 statistics.evaluation_total_wall_duration, |
114 base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(10), | 117 base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(10), |
115 50); | 118 50); |
116 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( | 119 UMA_HISTOGRAM_CUSTOM_MICRO_TIMES( |
117 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration", | 120 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration", |
118 statistics.evaluation_total_cpu_duration, | 121 statistics.evaluation_total_cpu_duration, |
119 base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(10), | 122 base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(10), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 SignalFirstSubresourceDisallowedForCommittedLoad, | 157 SignalFirstSubresourceDisallowedForCommittedLoad, |
155 AsWeakPtr())); | 158 AsWeakPtr())); |
156 | 159 |
157 auto ruleset = ruleset_dealer_->GetRuleset(); | 160 auto ruleset = ruleset_dealer_->GetRuleset(); |
158 DCHECK(ruleset); | 161 DCHECK(ruleset); |
159 ActivationState activation_state = | 162 ActivationState activation_state = |
160 ComputeActivationState(activation_level_for_next_commit_, | 163 ComputeActivationState(activation_level_for_next_commit_, |
161 measure_performance_for_next_commit_, | 164 measure_performance_for_next_commit_, |
162 ancestor_document_urls, ruleset.get()); | 165 ancestor_document_urls, ruleset.get()); |
163 DCHECK(!ancestor_document_urls.empty()); | 166 DCHECK(!ancestor_document_urls.empty()); |
164 std::unique_ptr<DocumentSubresourceFilter> filter( | 167 auto filter = base::MakeUnique<WebDocumentSubresourceFilterImpl>( |
165 new DocumentSubresourceFilter( | 168 url::Origin(ancestor_document_urls[0]), activation_state, |
166 url::Origin(ancestor_document_urls[0]), activation_state, | 169 std::move(ruleset), std::move(first_disallowed_load_callback)); |
167 std::move(ruleset), std::move(first_disallowed_load_callback))); | |
168 | 170 |
169 filter_for_last_committed_load_ = filter->AsWeakPtr(); | 171 filter_for_last_committed_load_ = filter->AsWeakPtr(); |
170 SetSubresourceFilterForCommittedLoad(std::move(filter)); | 172 SetSubresourceFilterForCommittedLoad(std::move(filter)); |
171 } | 173 } |
172 } | 174 } |
173 | 175 |
174 ResetActivatonStateForNextCommit(); | 176 ResetActivatonStateForNextCommit(); |
175 } | 177 } |
176 | 178 |
177 void SubresourceFilterAgent::DidFailProvisionalLoad( | 179 void SubresourceFilterAgent::DidFailProvisionalLoad( |
178 const blink::WebURLError& error) { | 180 const blink::WebURLError& error) { |
179 // TODO(engedy): Add a test with `frame-ancestor` violation to exercise this. | 181 // TODO(engedy): Add a test with `frame-ancestor` violation to exercise this. |
180 ResetActivatonStateForNextCommit(); | 182 ResetActivatonStateForNextCommit(); |
181 } | 183 } |
182 | 184 |
183 void SubresourceFilterAgent::DidFinishLoad() { | 185 void SubresourceFilterAgent::DidFinishLoad() { |
184 if (!filter_for_last_committed_load_) | 186 if (!filter_for_last_committed_load_) |
185 return; | 187 return; |
186 | |
187 RecordHistogramsOnLoadFinished(); | 188 RecordHistogramsOnLoadFinished(); |
188 } | 189 } |
189 | 190 |
190 bool SubresourceFilterAgent::OnMessageReceived(const IPC::Message& message) { | 191 bool SubresourceFilterAgent::OnMessageReceived(const IPC::Message& message) { |
191 bool handled = true; | 192 bool handled = true; |
192 IPC_BEGIN_MESSAGE_MAP(SubresourceFilterAgent, message) | 193 IPC_BEGIN_MESSAGE_MAP(SubresourceFilterAgent, message) |
193 IPC_MESSAGE_HANDLER(SubresourceFilterMsg_ActivateForNextCommittedLoad, | 194 IPC_MESSAGE_HANDLER(SubresourceFilterMsg_ActivateForNextCommittedLoad, |
194 OnActivateForNextCommittedLoad) | 195 OnActivateForNextCommittedLoad) |
195 IPC_MESSAGE_UNHANDLED(handled = false) | 196 IPC_MESSAGE_UNHANDLED(handled = false) |
196 IPC_END_MESSAGE_MAP() | 197 IPC_END_MESSAGE_MAP() |
197 return handled; | 198 return handled; |
198 } | 199 } |
199 | 200 |
200 } // namespace subresource_filter | 201 } // namespace subresource_filter |
OLD | NEW |