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

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

Powered by Google App Engine
This is Rietveld 408576698