| Index: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
|
| diff --git a/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
|
| index 108e9675f795786df409231320c6082f9ebc28d8..b48fb409bbffa4d14f1cbacb07e321c1d3565d0f 100644
|
| --- a/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
|
| +++ b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h
|
| @@ -5,13 +5,13 @@
|
| #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVER_H_
|
| #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVER_H_
|
|
|
| +#include <bitset>
|
| #include <list>
|
| #include <map>
|
| #include <memory>
|
|
|
| #include "base/macros.h"
|
| #include "base/scoped_observer.h"
|
| -#include "chrome/browser/page_load_metrics/ads_detection.h"
|
| #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
|
| #include "components/subresource_filter/content/browser/subresource_filter_observer.h"
|
| #include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
|
| @@ -25,6 +25,16 @@
|
| : public page_load_metrics::PageLoadMetricsObserver,
|
| public subresource_filter::SubresourceFilterObserver {
|
| public:
|
| + // The types of ads that one can filter on.
|
| + enum AdType {
|
| + AD_TYPE_GOOGLE = 0,
|
| + AD_TYPE_SUBRESOURCE_FILTER = 1,
|
| + AD_TYPE_ALL = 2,
|
| + AD_TYPE_MAX = AD_TYPE_ALL
|
| + };
|
| +
|
| + using AdTypes = std::bitset<AD_TYPE_MAX>;
|
| +
|
| // Returns a new AdsPageLoadMetricObserver. If the feature is disabled it
|
| // returns nullptr.
|
| static std::unique_ptr<AdsPageLoadMetricsObserver> CreateIfNeeded();
|
| @@ -50,12 +60,11 @@
|
|
|
| private:
|
| struct AdFrameData {
|
| - AdFrameData(FrameTreeNodeId frame_tree_node_id,
|
| - page_load_metrics::AdTypes ad_types);
|
| + AdFrameData(FrameTreeNodeId frame_tree_node_id, AdTypes ad_types);
|
| size_t frame_bytes;
|
| size_t frame_bytes_uncached;
|
| const FrameTreeNodeId frame_tree_node_id;
|
| - page_load_metrics::AdTypes ad_types;
|
| + AdTypes ad_types;
|
| };
|
|
|
| // subresource_filter::SubresourceFilterObserver:
|
| @@ -63,6 +72,15 @@
|
| content::NavigationHandle* navigation_handle,
|
| subresource_filter::LoadPolicy load_policy) override;
|
| void OnSubresourceFilterGoingAway() override;
|
| +
|
| + // Determines if the URL of a frame matches the SubresourceFilter block
|
| + // list. Should only be called once per frame navigation.
|
| + bool DetectSubresourceFilterAd(FrameTreeNodeId frame_tree_node_id);
|
| +
|
| + // This should only be called once per frame navigation, as the
|
| + // SubresourceFilter detector clears its state about detected frames after
|
| + // each call in order to free up memory.
|
| + AdTypes DetectAds(content::NavigationHandle* navigation_handle);
|
|
|
| void ProcessLoadedResource(
|
| const page_load_metrics::ExtraRequestCompleteInfo& extra_request_info);
|
| @@ -86,6 +104,11 @@
|
| // nullptr.
|
| std::map<FrameTreeNodeId, AdFrameData*> ad_frames_data_;
|
|
|
| + // The set of frames that have yet to finish but that the SubresourceFilter
|
| + // has reported are ads. Once DetectSubresourceFilterAd is called the id is
|
| + // removed from the set.
|
| + std::set<FrameTreeNodeId> unfinished_subresource_ad_frames_;
|
| +
|
| // When the observer receives report of a document resource loading for a
|
| // sub-frame before the sub-frame commit occurs, hold onto the resource
|
| // request info (delay it) until the sub-frame commits.
|
|
|