Commit aa17b101 authored by Jered Gray's avatar Jered Gray Committed by Commit Bot

Remove legacy support for top-level hint optimizations

Clients, starting at M-72, no longer support top-level hint
optimizations for the existing optimization types, so the code
supporting them is being removed.

The server may add new top-level optimization types in the future,
so the proto field is not being deprecated.

Bug: 917189

Change-Id: Ib6a1bb96958ff96dfd65921d9afd4b8bac8bf39c
Reviewed-on: https://chromium-review.googlesource.com/c/1387950
Commit-Queue: Jered Gray <jegray@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618585}
parent 4dcb10c9
......@@ -133,12 +133,8 @@ message Hint {
// The key that applies to this hint. The key_representation field describes
// the form in which this key takes. Guaranteed to be non-empty.
optional string key = 2;
// An unordered set of optimizations that should be whitelisted for this
// hint.
// If empty, then no optimizations should be whitelisted (this allows for an
// earlier hint entry to act as an exception to a subsequently matching hint
// whitelist entry). If multiple optimizations or page_hints are provided, the
// client will decide which one to act on.
// Top-level optimizations are currently unused on the client as of M-72. This
// may change in the future as new optimization types are added.
repeated Optimization whitelisted_optimizations = 3;
// An ordered set of per-page hints. Only the first PageHint record
// that matches a committed page URL should be used for that page load.
......
......@@ -315,13 +315,6 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
std::unique_ptr<PreviewsHints> hints(new PreviewsHints());
HintCache::Data hint_cache_data;
// The condition set ID is a simple increasing counter that matches the
// order of hints in the config (where earlier hints in the config take
// precedence over later hints in the config if there are multiple matches).
url_matcher::URLMatcherConditionSet::ID id = 0;
url_matcher::URLMatcherConditionFactory* condition_factory =
hints->url_matcher_.condition_factory();
url_matcher::URLMatcherConditionSet::Vector all_conditions;
std::set<std::string> seen_host_suffixes;
size_t total_page_patterns_with_resource_loading_hints_received = 0;
......@@ -350,38 +343,6 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
}
seen_host_suffixes.insert(hint_key);
// Only process legacy top level hints if specifically enabled.
if (previews::params::NoScriptPreviewsUsesTopLevelHints()) {
// Create whitelist condition set out of the optimizations that are
// whitelisted for the host suffix at the top level (i.e., not within
// PageHints).
std::set<std::pair<PreviewsType, int>> whitelisted_optimizations;
for (const auto& optimization : hint.whitelisted_optimizations()) {
if (IsDisabledExperimentalOptimization(optimization)) {
continue;
}
base::Optional<PreviewsType> previews_type =
ConvertProtoOptimizationTypeToPreviewsType(
optimization.optimization_type());
if (!previews_type.has_value()) {
continue;
}
// Resource loading hints should always be page hints; if they appear as
// top-level whitelisted optimizations, then it indicates a bug.
DCHECK(previews_type != PreviewsType::RESOURCE_LOADING_HINTS);
whitelisted_optimizations.insert(std::make_pair(
previews_type.value(), optimization.inflation_percent()));
}
url_matcher::URLMatcherCondition condition =
condition_factory->CreateHostSuffixCondition(hint_key);
all_conditions.push_back(new url_matcher::URLMatcherConditionSet(
id, std::set<url_matcher::URLMatcherCondition>{condition}));
hints->whitelist_[id] = whitelisted_optimizations;
id++;
}
// If this hint contains page hints, then add a pared down version of the
// hint to the initial hints that are used to populate the hint cache,
// removing all of the hint's top-level optimizations and only retaining the
......@@ -401,10 +362,6 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
total_resource_loading_hints_received);
}
if (!all_conditions.empty()) {
hints->url_matcher_.AddConditionSets(all_conditions);
}
if (hint_cache_data.HasHints()) {
hints->hint_cache_ =
std::make_unique<HintCache>(std::move(hint_cache_data));
......@@ -416,7 +373,7 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
// Completed processing hints data without crashing so clear sentinel.
DeleteSentinelFile(sentinel_path);
RecordProcessHintsResult(
all_conditions.empty() && !hints->hint_cache_
!hints->hint_cache_
? PreviewsProcessHintsResult::kProcessedNoPreviewsHints
: PreviewsProcessHintsResult::kProcessedPreviewsHints);
return hints;
......@@ -507,64 +464,11 @@ bool PreviewsHints::IsWhitelisted(
net::EffectiveConnectionType* out_ect_threshold) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!url.has_host()) {
return false;
}
return IsWhitelistedAtTopLevel(url, type, out_inflation_percent) ||
IsWhitelistedInPageHints(url, type, out_inflation_percent,
out_ect_threshold);
}
bool PreviewsHints::IsWhitelistedAtTopLevel(const GURL& url,
PreviewsType type,
int* out_inflation_percent) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Top level hints are deprecated so only check here if specifically enabled
// for NoScript.
if (!previews::params::NoScriptPreviewsUsesTopLevelHints()) {
return false;
}
// Resource loading hints are not processed in the top-level whitelist.
if (type == PreviewsType::RESOURCE_LOADING_HINTS) {
if (!hint_cache_) {
return false;
}
std::set<url_matcher::URLMatcherConditionSet::ID> matches =
url_matcher_.MatchURL(url);
// Only consider the first match in iteration order as it takes precedence
// if there are multiple matches for the top-level whitelist.
const auto& first_match = matches.begin();
if (first_match != matches.end()) {
const auto whitelist_iter = whitelist_.find(*first_match);
if (whitelist_iter != whitelist_.end()) {
const auto& whitelisted_optimizations = whitelist_iter->second;
for (auto optimization_iter = whitelisted_optimizations.begin();
optimization_iter != whitelisted_optimizations.end();
++optimization_iter) {
if (optimization_iter->first == type) {
*out_inflation_percent = optimization_iter->second;
// Whitelisted on top level whitelist.
return true;
}
}
}
}
return false;
}
bool PreviewsHints::IsWhitelistedInPageHints(
const GURL& url,
PreviewsType type,
int* out_inflation_percent,
net::EffectiveConnectionType* out_ect_threshold) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!hint_cache_) {
if (!url.has_host()) {
return false;
}
......
......@@ -5,7 +5,6 @@
#ifndef COMPONENTS_PREVIEWS_CONTENT_PREVIEWS_HINTS_H_
#define COMPONENTS_PREVIEWS_CONTENT_PREVIEWS_HINTS_H_
#include <map>
#include <memory>
#include <set>
#include <utility>
......@@ -18,7 +17,6 @@
#include "components/previews/content/previews_hints.h"
#include "components/previews/content/previews_user_data.h"
#include "components/previews/core/host_filter.h"
#include "components/url_matcher/url_matcher.h"
#include "net/nqe/effective_connection_type.h"
class GURL;
......@@ -48,9 +46,7 @@ class PreviewsHints {
// Whether the URL is whitelisted for the given previews type. If so,
// |out_inflation_percent| and |out_ect_threshold| will be populated if
// metadata is available for them. This first checks the top-level whitelist
// and, if not whitelisted there, it will check the HintCache for having a
// loaded, matching PageHint that whitelists it.
// metadata is available for them.
bool IsWhitelisted(const GURL& url,
PreviewsType type,
int* out_inflation_percent,
......@@ -83,40 +79,14 @@ class PreviewsHints {
PreviewsHints();
// Returns whether |url| is whitelisted in |whitelist_|. If it is, then
// |out_inflation_percent| will be populated if metadata is available for it.
// NOTE: PreviewsType::RESOURCE_LOADING_HINTS cannot be whitelisted at the
// top-level.
bool IsWhitelistedAtTopLevel(const GURL& url,
PreviewsType type,
int* out_inflation_percent) const;
// Returns whether |url| is whitelisted in the page hints contained within
// |hint_cache_|. If it is, then |out_inflation_percent| and
// |out_ect_threshold| will be populated if metadata is available for them.
bool IsWhitelistedInPageHints(
const GURL& url,
PreviewsType type,
int* out_inflation_percent,
net::EffectiveConnectionType* out_ect_threshold) const;
// Parses optimization filters from |config| and populates corresponding
// supported blacklists in this object.
void ParseOptimizationFilters(
const optimization_guide::proto::Configuration& config);
// The URLMatcher used to match whether a URL has any hints associated with
// it.
url_matcher::URLMatcher url_matcher_;
// Holds the hint cache (if any optimizations using it are enabled).
std::unique_ptr<HintCache> hint_cache_;
// A map from the condition set ID to associated whitelist Optimization
// details.
std::map<url_matcher::URLMatcherConditionSet::ID,
std::set<std::pair<PreviewsType, int>>>
whitelist_;
// Blacklist of host suffixes for LITE_PAGE_REDIRECT Previews.
std::unique_ptr<HostFilter> lite_page_redirect_blacklist_;
......
......@@ -335,11 +335,6 @@ int NoScriptPreviewsInflationBytes() {
kNoScriptInflationBytes, 0);
}
bool NoScriptPreviewsUsesTopLevelHints() {
return base::FeatureList::IsEnabled(
features::kNoScriptPreviewsUsesTopLevelHints);
}
int ResourceLoadingHintsPreviewsInflationPercent() {
return GetFieldTrialParamByFeatureAsInt(features::kResourceLoadingHints,
kResourceLoadingHintsInflationPercent,
......
......@@ -171,11 +171,6 @@ int NoScriptPreviewsInflationPercent();
// for inflating the original_bytes count.
int NoScriptPreviewsInflationBytes();
// Whether to use top level optimization hints for NoScript instead of
// page hints. This is to allow for reverting to original behavior until
// page hints for NoScript is successfully launched.
bool NoScriptPreviewsUsesTopLevelHints();
// For estimating ResourceLoadingHints data savings, this is the percentage
// factor to multiple by the network bytes for inflating the original_bytes
// count.
......
......@@ -46,10 +46,6 @@ const base::Feature kNoScriptPreviews {
#endif // defined(OS_ANDROID)
};
// Enables using (legacy) top level optimization hints to whitelist NoScript.
const base::Feature kNoScriptPreviewsUsesTopLevelHints{
"NoScriptPreviewsUsesTopLevelHints", base::FEATURE_DISABLED_BY_DEFAULT};
// Enables the Stale Previews timestamp on Previews infobars.
const base::Feature kStalePreviewsTimestamp{"StalePreviewsTimestamp",
base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -14,7 +14,6 @@ extern const base::Feature kPreviews;
extern const base::Feature kOfflinePreviews;
extern const base::Feature kClientLoFi;
extern const base::Feature kNoScriptPreviews;
extern const base::Feature kNoScriptPreviewsUsesTopLevelHints;
extern const base::Feature kStalePreviewsTimestamp;
extern const base::Feature kOptimizationHints;
extern const base::Feature kOptimizationHintsExperiments;
......
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