Commit 5365b5a1 authored by Charles Harrison's avatar Charles Harrison Committed by Commit Bot

[subresource_filter] Account for mmap failures in subresource filter agent

This CL also refactors the DidCommitProvisionalLoad method to be "flat"
using an early-return pattern vs deep conditional nesting

Bug: 734102
Change-Id: I59f42bba911307d124953f8b82d43ca4862eba59
Reviewed-on: https://chromium-review.googlesource.com/586638
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarShivani Sharma <shivanisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491019}
parent 16850550
...@@ -80,15 +80,15 @@ ActivationState SubresourceFilterAgent::GetParentActivationState( ...@@ -80,15 +80,15 @@ ActivationState SubresourceFilterAgent::GetParentActivationState(
} }
void SubresourceFilterAgent::OnActivateForNextCommittedLoad( void SubresourceFilterAgent::OnActivateForNextCommittedLoad(
ActivationState activation_state) { const ActivationState& activation_state) {
activation_state_for_next_commit_ = activation_state; activation_state_for_next_commit_ = activation_state;
} }
void SubresourceFilterAgent::RecordHistogramsOnLoadCommitted() { void SubresourceFilterAgent::RecordHistogramsOnLoadCommitted(
const ActivationState& activation_state) {
// Note: ActivationLevel used to be called ActivationState, the legacy name is // Note: ActivationLevel used to be called ActivationState, the legacy name is
// kept for the histogram. // kept for the histogram.
ActivationLevel activation_level = ActivationLevel activation_level = activation_state.activation_level;
activation_state_for_next_commit_.activation_level;
UMA_HISTOGRAM_ENUMERATION("SubresourceFilter.DocumentLoad.ActivationState", UMA_HISTOGRAM_ENUMERATION("SubresourceFilter.DocumentLoad.ActivationState",
static_cast<int>(activation_level), static_cast<int>(activation_level),
static_cast<int>(ActivationLevel::LAST) + 1); static_cast<int>(ActivationLevel::LAST) + 1);
...@@ -164,37 +164,36 @@ void SubresourceFilterAgent::DidCommitProvisionalLoad( ...@@ -164,37 +164,36 @@ void SubresourceFilterAgent::DidCommitProvisionalLoad(
const GURL& url = GetDocumentURL(); const GURL& url = GetDocumentURL();
bool use_parent_activation = ShouldUseParentActivation(url); bool use_parent_activation = ShouldUseParentActivation(url);
if (use_parent_activation) { const ActivationState activation_state =
activation_state_for_next_commit_ = use_parent_activation ? GetParentActivationState(render_frame())
GetParentActivationState(render_frame()); : activation_state_for_next_commit_;
} ResetActivatonStateForNextCommit();
if (!url.SchemeIsHTTPOrHTTPS() && !url.SchemeIsFile() &&
!use_parent_activation)
return;
if (url.SchemeIsHTTPOrHTTPS() || url.SchemeIsFile() || RecordHistogramsOnLoadCommitted(activation_state);
use_parent_activation) { if (activation_state.activation_level == ActivationLevel::DISABLED ||
RecordHistogramsOnLoadCommitted(); !ruleset_dealer_->IsRulesetFileAvailable())
if (activation_state_for_next_commit_.activation_level != return;
ActivationLevel::DISABLED &&
ruleset_dealer_->IsRulesetFileAvailable()) {
base::OnceClosure first_disallowed_load_callback(
base::BindOnce(&SubresourceFilterAgent::
SignalFirstSubresourceDisallowedForCommittedLoad,
AsWeakPtr()));
auto ruleset = ruleset_dealer_->GetRuleset();
// TODO(csharrison): Replace with DCHECK when crbug.com/734102 is
// resolved.
CHECK(ruleset);
CHECK(ruleset->data());
auto filter = base::MakeUnique<WebDocumentSubresourceFilterImpl>(
url::Origin(url), activation_state_for_next_commit_,
std::move(ruleset), std::move(first_disallowed_load_callback));
filter_for_last_committed_load_ = filter->AsWeakPtr();
SetSubresourceFilterForCommittedLoad(std::move(filter));
}
}
ResetActivatonStateForNextCommit(); scoped_refptr<const MemoryMappedRuleset> ruleset =
ruleset_dealer_->GetRuleset();
DCHECK(ruleset);
// Data can be null even if the original file is valid, if there is a
// memory mapping issue.
if (!ruleset->data())
return;
base::OnceClosure first_disallowed_load_callback(base::BindOnce(
&SubresourceFilterAgent::SignalFirstSubresourceDisallowedForCommittedLoad,
AsWeakPtr()));
auto filter = base::MakeUnique<WebDocumentSubresourceFilterImpl>(
url::Origin(url), activation_state, std::move(ruleset),
std::move(first_disallowed_load_callback));
filter_for_last_committed_load_ = filter->AsWeakPtr();
SetSubresourceFilterForCommittedLoad(std::move(filter));
} }
void SubresourceFilterAgent::DidFailProvisionalLoad( void SubresourceFilterAgent::DidFailProvisionalLoad(
......
...@@ -64,8 +64,8 @@ class SubresourceFilterAgent ...@@ -64,8 +64,8 @@ class SubresourceFilterAgent
static ActivationState GetParentActivationState( static ActivationState GetParentActivationState(
content::RenderFrame* render_frame); content::RenderFrame* render_frame);
void OnActivateForNextCommittedLoad(ActivationState activation_state); void OnActivateForNextCommittedLoad(const ActivationState& activation_state);
void RecordHistogramsOnLoadCommitted(); void RecordHistogramsOnLoadCommitted(const ActivationState& activation_state);
void RecordHistogramsOnLoadFinished(); void RecordHistogramsOnLoadFinished();
void ResetActivatonStateForNextCommit(); void ResetActivatonStateForNextCommit();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment