Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "components/subresource_filter/core/common/activation_level.h" | 11 #include "components/subresource_filter/core/common/activation_level.h" |
| 12 #include "components/subresource_filter/core/common/activation_list.h" | 12 #include "components/subresource_filter/core/common/activation_list.h" |
| 13 #include "components/subresource_filter/core/common/activation_scope.h" | 13 #include "components/subresource_filter/core/common/activation_scope.h" |
| 14 | 14 |
| 15 namespace subresource_filter { | 15 namespace subresource_filter { |
| 16 | 16 |
| 17 // Encapsulates all parameters that define how the subresource filter feature | 17 // Encapsulates all parameters that define how the subresource filter feature |
| 18 // should operate. | 18 // should operate. |
| 19 struct Configuration { | 19 struct Configuration { |
| 20 Configuration(); | 20 Configuration(); |
| 21 Configuration(ActivationLevel activation_level, | |
| 22 ActivationScope activation_scope, | |
| 23 ActivationList activation_list = ActivationList::NONE); | |
| 24 Configuration(Configuration&&); | |
| 21 ~Configuration(); | 25 ~Configuration(); |
| 22 Configuration(Configuration&&); | |
| 23 Configuration& operator=(Configuration&&); | 26 Configuration& operator=(Configuration&&); |
| 24 | 27 |
| 25 // The maximum degree to which subresource filtering should be activated on | 28 // The maximum degree to which subresource filtering should be activated on |
| 26 // any RenderFrame. This will be ActivationLevel::DISABLED unless the feature | 29 // any RenderFrame. This will be ActivationLevel::DISABLED unless the feature |
| 27 // is enabled and variation parameters prescribe a higher activation level. | 30 // is enabled and variation parameters prescribe a higher activation level. |
| 28 ActivationLevel activation_level = ActivationLevel::DISABLED; | 31 ActivationLevel activation_level = ActivationLevel::DISABLED; |
| 29 | 32 |
| 30 // The activation scope. That is, the subset of page loads where subresource | 33 // The activation scope. That is, the subset of page loads where subresource |
| 31 // filtering should be activated. This will be ActivationScope::NO_SITES | 34 // filtering should be activated. This will be ActivationScope::NO_SITES |
| 32 // unless the feature is =enabled and variation parameters prescribe a wider | 35 // unless the feature is =enabled and variation parameters prescribe a wider |
| 33 // activation scope. | 36 // activation scope. |
| 34 ActivationScope activation_scope = ActivationScope::NO_SITES; | 37 ActivationScope activation_scope = ActivationScope::NO_SITES; |
| 35 | 38 |
| 36 // The activation list to use when the |activation_scope| is ACTIVATION_LIST. | 39 // The activation list to use when the |activation_scope| is ACTIVATION_LIST. |
| 37 // This will be ActivationList::NONE unless variation parameters prescribe a | 40 // This will be ActivationList::NONE unless variation parameters prescribe a |
| 38 // recognized list. | 41 // recognized list. |
| 39 ActivationList activation_list = ActivationList::NONE; | 42 ActivationList activation_list = ActivationList::NONE; |
| 40 | 43 |
| 41 // A number in the range [0, 1], indicating the fraction of page loads that | 44 // A number in the range [0, 1], indicating the fraction of page loads that |
| 42 // should have extended performance measurements enabled. The rate will | 45 // should have extended performance measurements enabled. The rate will |
| 43 // be 0 unless a greater frequency is specified by variation parameters. | 46 // be 0 unless a greater frequency is specified by variation parameters. |
| 44 double performance_measurement_rate = 0.0; | 47 double performance_measurement_rate = 0.0; |
| 45 | 48 |
| 46 // Whether notifications indicating that a subresource was disallowed should | 49 // Whether notifications indicating that a subresource was disallowed should |
| 47 // be suppressed in the UI. | 50 // be suppressed in the UI. |
| 48 bool should_suppress_notifications = false; | 51 bool should_suppress_notifications = false; |
| 49 | 52 |
| 50 // The ruleset flavor to download through the component updater, or the empty | 53 // The ruleset flavor to download through the component updater. This or the |
| 51 // string if the default ruleset should be used. | 54 // empty string if the default ruleset should be used. |
| 52 std::string ruleset_flavor; | 55 std::string ruleset_flavor; |
| 53 | 56 |
| 54 // Whether to whitelist a site when a page loaded from that site is reloaded. | 57 // Whether to whitelist a site when a page loaded from that site is reloaded. |
| 55 bool should_whitelist_site_on_reload = false; | 58 bool should_whitelist_site_on_reload = false; |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 // TODO(engedy): Make this an actual list once all call sites are prepared to | 61 // TODO(engedy): Make this an actual list once all call sites are prepared to |
| 59 // handle multiple simultaneous configurations. | 62 // handle multiple simultaneous configurations. |
| 60 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> { | 63 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> { |
| 61 public: | 64 public: |
| 62 explicit ConfigurationList(Configuration config); | 65 explicit ConfigurationList(Configuration config); |
| 63 | 66 |
| 64 const Configuration& the_one_and_only() const { return config_; } | 67 const Configuration& the_one_and_only() const { return config_; } |
| 65 | 68 |
| 66 private: | 69 private: |
| 67 friend class base::RefCountedThreadSafe<ConfigurationList>; | 70 friend class base::RefCountedThreadSafe<ConfigurationList>; |
| 68 ~ConfigurationList(); | 71 ~ConfigurationList(); |
| 69 | 72 |
| 70 const Configuration config_; | 73 const Configuration config_; |
| 71 | 74 |
| 72 DISALLOW_COPY_AND_ASSIGN(ConfigurationList); | 75 DISALLOW_COPY_AND_ASSIGN(ConfigurationList); |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 // Retrieves all currently enabled subresource filtering configurations. The | 78 // Retrieves all currently enabled subresource filtering configurations. The |
| 76 // configurations are parsed on first access and then the result is cached. | 79 // configurations are parsed on first access and then the result is cached. |
| 77 // | 80 // |
| 78 // In tests, however, the config may change in-between navigations, so callers | 81 // In tests, however, the config may be altered in-between navigations, so |
| 79 // should not hold on to the result for long. | 82 // callers should not hold on to the result for long. |
| 80 scoped_refptr<ConfigurationList> GetActiveConfigurations(); | 83 scoped_refptr<ConfigurationList> GetActiveConfigurations(); |
| 81 | 84 |
| 82 namespace testing { | 85 namespace testing { |
| 83 | 86 |
| 84 // Clears the cached active ConfigurationList so that it will be recomputed on | 87 // Returns the currently cached active ConfigurationList, if any, and replaces |
| 85 // next access. Used in tests when the variation parameters are altered. | 88 // it with |configs|, which may be nullptr to clear the cache. |
| 86 void ClearCachedActiveConfigurations(); | 89 scoped_refptr<ConfigurationList> ReplaceCachedActiveConfigurations( |
|
Charlie Harrison
2017/04/25 19:36:21
This is like a get-and-set right? Maybe GetAndSetA
engedy
2017/04/25 20:13:24
Done.
| |
| 90 scoped_refptr<ConfigurationList> configs); | |
| 87 | 91 |
| 88 } // namespace testing | 92 } // namespace testing |
| 89 | 93 |
| 90 // Feature and variation parameter definitions ------------------------------- | 94 // Feature and variation parameter definitions ------------------------------- |
| 91 | 95 |
| 92 // The master toggle to enable/disable the Safe Browsing Subresource Filter. | 96 // The master toggle to enable/disable the Safe Browsing Subresource Filter. |
| 93 extern const base::Feature kSafeBrowsingSubresourceFilter; | 97 extern const base::Feature kSafeBrowsingSubresourceFilter; |
| 94 | 98 |
| 95 // Enables the new experimental UI for the Subresource Filter. | 99 // Enables the new experimental UI for the Subresource Filter. |
| 96 extern const base::Feature kSafeBrowsingSubresourceFilterExperimentalUI; | 100 extern const base::Feature kSafeBrowsingSubresourceFilterExperimentalUI; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 115 | 119 |
| 116 extern const char kPerformanceMeasurementRateParameterName[]; | 120 extern const char kPerformanceMeasurementRateParameterName[]; |
| 117 | 121 |
| 118 extern const char kSuppressNotificationsParameterName[]; | 122 extern const char kSuppressNotificationsParameterName[]; |
| 119 | 123 |
| 120 extern const char kWhitelistSiteOnReloadParameterName[]; | 124 extern const char kWhitelistSiteOnReloadParameterName[]; |
| 121 | 125 |
| 122 } // namespace subresource_filter | 126 } // namespace subresource_filter |
| 123 | 127 |
| 124 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_ | 128 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_ |
| OLD | NEW |