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

Side by Side Diff: components/subresource_filter/core/browser/subresource_filter_features.h

Issue 2844063002: Add support for multiple simultaneous subresource_filter::Configurations. (Closed)
Patch Set: Rebase. Created 3 years, 7 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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _
6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _
7 7
8 #include <iosfwd>
9 #include <vector>
10
8 #include "base/feature_list.h" 11 #include "base/feature_list.h"
9 #include "base/macros.h" 12 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/strings/string_piece.h"
11 #include "components/subresource_filter/core/common/activation_level.h" 15 #include "components/subresource_filter/core/common/activation_level.h"
12 #include "components/subresource_filter/core/common/activation_list.h" 16 #include "components/subresource_filter/core/common/activation_list.h"
13 #include "components/subresource_filter/core/common/activation_scope.h" 17 #include "components/subresource_filter/core/common/activation_scope.h"
14 18
15 namespace subresource_filter { 19 namespace subresource_filter {
16 20
17 // Encapsulates all parameters that define how the subresource filter feature 21 // Encapsulates a set of parameters that define how the subresource filter
18 // should operate. 22 // feature should operate. Each configuration consists of three parts as
23 // described in detail below.
24 //
25 // There can be multiple configuration enabled at the same time. For each
26 // navigation, however, subresource filtering will be activated according to
27 // exactly one of these enabled configuration, if any. Namely, the configuration
28 // with the highest |priority| among those whose |activation_conditions| are
29 // otherwise satisfied for the navigation.
30 //
31 // Even when there are multiple enabled configurations, the RulesetService is
32 // currently only capable of fetching and indexing a single |ruleset_flavor|,
33 // which will be used for all navigations with subresource filtering activated,
34 // regardless of which configuration prescribed filtering for that navigation.
35 // This shared ruleset flavor will be the one lexicographically greatest.
36 //
37 // Experimenters wishing to use customized rulesets therefore must ensure that
38 // they set up the experimental state so that the ruleset chosen through this
39 // mechanism is compatible with all the enabled configurations (or disable some
40 // as needed).
19 struct Configuration { 41 struct Configuration {
42 // The conditions that determine whether subresource filtering should be
43 // activated for a given main frame navigation using this configuration.
44 struct ActivationConditions {
45 // The activation scope. That is, the subset of page loads where subresource
46 // filtering should be activated according to this configuration. When set
47 // to NO_SITES, this configuration will never be active.
48 ActivationScope activation_scope = ActivationScope::NO_SITES;
49
50 // The activation list to use when the |activation_scope| is
51 // ACTIVATION_LIST, ignored otherwise.
52 ActivationList activation_list = ActivationList::NONE;
53
54 // The activation priority of this configuration. Used to break ties when
55 // there are multiple configurations whose activation conditions are
56 // otherwise satisfied. A greater value indicates higher priority.
57 int priority = 0;
58 };
59
60 // The details of how subresource filtering should operate for a given main
61 // frame navigation when it is activated using this configuration.
62 struct ActivationOptions {
63 // The maximum degree to which subresource filtering should be activated on
64 // any RenderFrame. When set to DISABLED, this configuration will cause
65 // subresource filtering to be de-activated for a navigation if this is the
66 // highest priority configuration with its activation conditions met.
67 ActivationLevel activation_level = ActivationLevel::DISABLED;
68
69 // A number in the range [0, 1], indicating the fraction of page loads that
70 // should have extended performance measurements enabled.
71 double performance_measurement_rate = 0.0;
72
73 // Whether notifications indicating that a subresource was disallowed should
74 // be suppressed in the UI.
75 bool should_suppress_notifications = false;
76
77 // Whether to whitelist a site when a page loaded from that site is
78 // reloaded.
79 bool should_whitelist_site_on_reload = false;
80 };
81
82 // General settings that apply outside of the scope of a navigation.
83 struct GeneralSettings {
84 // The ruleset flavor to download through the component updater. The empty
85 // string indicates that the default ruleset should be used.
86 std::string ruleset_flavor;
87 };
88
89 // Do not forget updating operator==, operator<<, and any other necessary
90 // methods when adding new fields here!
91
20 Configuration(); 92 Configuration();
21 Configuration(ActivationLevel activation_level, 93 Configuration(ActivationLevel activation_level,
22 ActivationScope activation_scope, 94 ActivationScope activation_scope,
23 ActivationList activation_list = ActivationList::NONE); 95 ActivationList activation_list = ActivationList::NONE);
96 Configuration(const Configuration&);
24 Configuration(Configuration&&); 97 Configuration(Configuration&&);
25 ~Configuration(); 98 ~Configuration();
99 Configuration& operator=(const Configuration&);
26 Configuration& operator=(Configuration&&); 100 Configuration& operator=(Configuration&&);
27 101
28 // The maximum degree to which subresource filtering should be activated on 102 bool operator==(const Configuration& rhs) const;
29 // any RenderFrame. This will be ActivationLevel::DISABLED unless the feature 103 bool operator!=(const Configuration& rhs) const;
30 // is enabled and variation parameters prescribe a higher activation level.
31 ActivationLevel activation_level = ActivationLevel::DISABLED;
32 104
33 // The activation scope. That is, the subset of page loads where subresource 105 // Factory methods for preset configurations.
34 // filtering should be activated. This will be ActivationScope::NO_SITES 106 //
35 // unless the feature is =enabled and variation parameters prescribe a wider 107 // To add a new preset:
36 // activation scope. 108 // 1.) Define a named factory method here.
37 ActivationScope activation_scope = ActivationScope::NO_SITES; 109 // 2.) Define a name for the configuration to be used in variation params.
110 // 3.) Register it into |kAvailablePresetConfigurations| in the .cc file.
111 // 4.) Update unittests to cover the new preset.
112 static Configuration MakePresetForLiveRunOnPhishingSites();
113 static Configuration MakePresetForPerformanceTestingDryRunOnAllSites();
38 114
39 // The activation list to use when the |activation_scope| is ACTIVATION_LIST. 115 ActivationConditions activation_conditions;
40 // This will be ActivationList::NONE unless variation parameters prescribe a 116 ActivationOptions activation_options;
41 // recognized list. 117 GeneralSettings general_settings;
42 ActivationList activation_list = ActivationList::NONE;
43
44 // A number in the range [0, 1], indicating the fraction of page loads that
45 // should have extended performance measurements enabled. The rate will
46 // be 0 unless a greater frequency is specified by variation parameters.
47 double performance_measurement_rate = 0.0;
48
49 // Whether notifications indicating that a subresource was disallowed should
50 // be suppressed in the UI.
51 bool should_suppress_notifications = false;
52
53 // The ruleset flavor to download through the component updater. This or the
54 // empty string if the default ruleset should be used.
55 std::string ruleset_flavor;
56
57 // Whether to whitelist a site when a page loaded from that site is reloaded.
58 bool should_whitelist_site_on_reload = false;
59 }; 118 };
60 119
61 // TODO(engedy): Make this an actual list once all call sites are prepared to 120 // For logging in tests.
62 // handle multiple simultaneous configurations. 121 std::ostream& operator<<(std::ostream& os, const Configuration& config);
122
123 // Thread-safe, ref-counted wrapper around an immutable list of configurations.
63 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> { 124 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> {
64 public: 125 public:
65 explicit ConfigurationList(Configuration config); 126 explicit ConfigurationList(std::vector<Configuration> configs);
66 127
67 const Configuration& the_one_and_only() const { return config_; } 128 // Returns the lexicographically greatest flavor string that is prescribed by
129 // any of the configurations. The caller must hold a reference to this
130 // instance while using the returned string piece.
131 base::StringPiece lexicographically_greatest_ruleset_flavor() const {
132 return lexicographically_greatest_ruleset_flavor_;
133 }
134
135 // Retrieves the configurations pre-sorted in decreasing order of their
136 // |activation_condition.priority|.
137 const std::vector<Configuration>& configs_by_decreasing_priority() const {
138 return configs_by_decreasing_priority_;
139 }
68 140
69 private: 141 private:
70 friend class base::RefCountedThreadSafe<ConfigurationList>; 142 friend class base::RefCountedThreadSafe<ConfigurationList>;
71 ~ConfigurationList(); 143 ~ConfigurationList();
72 144
73 const Configuration config_; 145 const std::vector<Configuration> configs_by_decreasing_priority_;
146 const base::StringPiece lexicographically_greatest_ruleset_flavor_;
74 147
75 DISALLOW_COPY_AND_ASSIGN(ConfigurationList); 148 DISALLOW_COPY_AND_ASSIGN(ConfigurationList);
76 }; 149 };
77 150
78 // Retrieves all currently enabled subresource filtering configurations. The 151 // Retrieves all currently enabled subresource filtering configurations. The
79 // configurations are parsed on first access and then the result is cached. 152 // configurations are parsed on first access and then the result is cached.
80 // 153 //
81 // In tests, however, the config may be altered in-between navigations, so 154 // In tests, however, the config may be changed in-between navigations, so
82 // callers should not hold on to the result for long. 155 // callers should not hold on to the result for long.
83 scoped_refptr<ConfigurationList> GetActiveConfigurations(); 156 scoped_refptr<ConfigurationList> GetEnabledConfigurations();
84 157
85 namespace testing { 158 namespace testing {
86 159
87 // Returns the currently cached active ConfigurationList, if any, and replaces 160 // Returns the currently cached enabled ConfigurationList, if any, and replaces
88 // it with |new_configs|, which may be nullptr to clear the cache. 161 // it with |new_configs|, which may be nullptr to clear the cache.
89 scoped_refptr<ConfigurationList> GetAndSetActivateConfigurations( 162 scoped_refptr<ConfigurationList> GetAndSetActivateConfigurations(
90 scoped_refptr<ConfigurationList> new_configs); 163 scoped_refptr<ConfigurationList> new_configs);
91 164
92 } // namespace testing 165 } // namespace testing
93 166
94 // Feature and variation parameter definitions ------------------------------- 167 // Feature and variation parameter definitions -------------------------------
95 168
96 // The master toggle to enable/disable the Safe Browsing Subresource Filter. 169 // The master toggle to enable/disable the Safe Browsing Subresource Filter.
97 extern const base::Feature kSafeBrowsingSubresourceFilter; 170 extern const base::Feature kSafeBrowsingSubresourceFilter;
(...skipping 10 matching lines...) Expand all
108 extern const char kActivationScopeParameterName[]; 181 extern const char kActivationScopeParameterName[];
109 extern const char kActivationScopeAllSites[]; 182 extern const char kActivationScopeAllSites[];
110 extern const char kActivationScopeActivationList[]; 183 extern const char kActivationScopeActivationList[];
111 extern const char kActivationScopeNoSites[]; 184 extern const char kActivationScopeNoSites[];
112 185
113 extern const char kActivationListsParameterName[]; 186 extern const char kActivationListsParameterName[];
114 extern const char kActivationListSocialEngineeringAdsInterstitial[]; 187 extern const char kActivationListSocialEngineeringAdsInterstitial[];
115 extern const char kActivationListPhishingInterstitial[]; 188 extern const char kActivationListPhishingInterstitial[];
116 extern const char kActivationListSubresourceFilter[]; 189 extern const char kActivationListSubresourceFilter[];
117 190
118 extern const char kRulesetFlavorParameterName[]; 191 extern const char kActivationPriorityParameterName[];
119 192
120 extern const char kPerformanceMeasurementRateParameterName[]; 193 extern const char kPerformanceMeasurementRateParameterName[];
121 194
122 extern const char kSuppressNotificationsParameterName[]; 195 extern const char kSuppressNotificationsParameterName[];
123 196
124 extern const char kWhitelistSiteOnReloadParameterName[]; 197 extern const char kWhitelistSiteOnReloadParameterName[];
125 198
199 extern const char kRulesetFlavorParameterName[];
200
201 extern const char kEnablePresetsParameterName[];
202 extern const char kDisablePresetsParameterName[];
203 extern const char kPresetLiveRunOnPhishingSites[];
204 extern const char kPresetPerformanceTestingDryRunOnAllSites[];
205
126 } // namespace subresource_filter 206 } // namespace subresource_filter
127 207
128 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_ 208 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698