Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: components/subresource_filter/content/renderer/subresource_filter_agent.cc

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

Powered by Google App Engine
This is Rietveld 408576698