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

Side by Side Diff: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.h

Issue 2946113002: Use FrameIsAd to decide whether to isolate a frame in TopDocumentIsolation mode. (Closed)
Patch Set: Addressing 2 more CR comments from csharrison@. Created 3 years, 5 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE R_H_ 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE R_H_
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE R_H_ 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSERVE R_H_
7 7
8 #include <bitset>
9 #include <list> 8 #include <list>
10 #include <map> 9 #include <map>
11 #include <memory> 10 #include <memory>
12 11
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "chrome/browser/page_load_metrics/ads_detection.h"
15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" 15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
16 #include "components/subresource_filter/content/browser/subresource_filter_obser ver.h" 16 #include "components/subresource_filter/content/browser/subresource_filter_obser ver.h"
17 #include "components/subresource_filter/content/browser/subresource_filter_obser ver_manager.h" 17 #include "components/subresource_filter/content/browser/subresource_filter_obser ver_manager.h"
18 #include "components/subresource_filter/core/common/load_policy.h" 18 #include "components/subresource_filter/core/common/load_policy.h"
19 #include "components/ukm/ukm_source.h" 19 #include "components/ukm/ukm_source.h"
20 #include "net/http/http_response_info.h" 20 #include "net/http/http_response_info.h"
21 21
22 // This observer labels each sub-frame as an ad or not, and keeps track of 22 // This observer labels each sub-frame as an ad or not, and keeps track of
23 // relevant per-frame and whole-page byte statistics. 23 // relevant per-frame and whole-page byte statistics.
24 class AdsPageLoadMetricsObserver 24 class AdsPageLoadMetricsObserver
25 : public page_load_metrics::PageLoadMetricsObserver, 25 : public page_load_metrics::PageLoadMetricsObserver,
26 public subresource_filter::SubresourceFilterObserver { 26 public subresource_filter::SubresourceFilterObserver {
27 public: 27 public:
28 // The types of ads that one can filter on.
29 enum AdType {
30 AD_TYPE_GOOGLE = 0,
31 AD_TYPE_SUBRESOURCE_FILTER = 1,
32 AD_TYPE_ALL = 2,
33 AD_TYPE_MAX = AD_TYPE_ALL
34 };
35
36 using AdTypes = std::bitset<AD_TYPE_MAX>;
37
38 // Returns a new AdsPageLoadMetricObserver. If the feature is disabled it 28 // Returns a new AdsPageLoadMetricObserver. If the feature is disabled it
39 // returns nullptr. 29 // returns nullptr.
40 static std::unique_ptr<AdsPageLoadMetricsObserver> CreateIfNeeded(); 30 static std::unique_ptr<AdsPageLoadMetricsObserver> CreateIfNeeded();
41 31
42 AdsPageLoadMetricsObserver(); 32 AdsPageLoadMetricsObserver();
43 ~AdsPageLoadMetricsObserver() override; 33 ~AdsPageLoadMetricsObserver() override;
44 34
45 // page_load_metrics::PageLoadMetricsObserver 35 // page_load_metrics::PageLoadMetricsObserver
46 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, 36 ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
47 const GURL& currently_committed_url, 37 const GURL& currently_committed_url,
(...skipping 18 matching lines...) Expand all
66 const FrameTreeNodeId frame_tree_node_id; 56 const FrameTreeNodeId frame_tree_node_id;
67 AdTypes ad_types; 57 AdTypes ad_types;
68 }; 58 };
69 59
70 // subresource_filter::SubresourceFilterObserver: 60 // subresource_filter::SubresourceFilterObserver:
71 void OnSubframeNavigationEvaluated( 61 void OnSubframeNavigationEvaluated(
72 content::NavigationHandle* navigation_handle, 62 content::NavigationHandle* navigation_handle,
73 subresource_filter::LoadPolicy load_policy) override; 63 subresource_filter::LoadPolicy load_policy) override;
74 void OnSubresourceFilterGoingAway() override; 64 void OnSubresourceFilterGoingAway() override;
75 65
76 // Determines if the URL of a frame matches the SubresourceFilter block
77 // list. Should only be called once per frame navigation.
78 bool DetectSubresourceFilterAd(FrameTreeNodeId frame_tree_node_id);
79
80 // This should only be called once per frame navigation, as the
81 // SubresourceFilter detector clears its state about detected frames after
82 // each call in order to free up memory.
83 AdTypes DetectAds(content::NavigationHandle* navigation_handle);
84
85 void ProcessLoadedResource( 66 void ProcessLoadedResource(
86 const page_load_metrics::ExtraRequestCompleteInfo& extra_request_info); 67 const page_load_metrics::ExtraRequestCompleteInfo& extra_request_info);
87 68
88 void RecordHistograms(); 69 void RecordHistograms();
89 void RecordHistogramsForType(int ad_type); 70 void RecordHistogramsForType(int ad_type);
90 71
91 // Checks to see if a resource is waiting for a navigation with the given 72 // Checks to see if a resource is waiting for a navigation with the given
92 // |frame_tree_node_id| to commit before it can be processed. If so, call 73 // |frame_tree_node_id| to commit before it can be processed. If so, call
93 // OnLoadedResource for the delayed resource. 74 // OnLoadedResource for the delayed resource.
94 void ProcessOngoingNavigationResource(FrameTreeNodeId frame_tree_node_id); 75 void ProcessOngoingNavigationResource(FrameTreeNodeId frame_tree_node_id);
95 76
96 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a 77 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a
97 // data structure that won't move the data around. 78 // data structure that won't move the data around.
98 std::list<AdFrameData> ad_frames_data_storage_; 79 std::list<AdFrameData> ad_frames_data_storage_;
99 80
100 // Maps a frame (by id) to the AdFrameData responsible for the frame. 81 // Maps a frame (by id) to the AdFrameData responsible for the frame.
101 // Multiple frame ids can point to the same AdFrameData. The responsible 82 // Multiple frame ids can point to the same AdFrameData. The responsible
102 // frame is the top-most frame labeled as an ad in the frame's ancestry, 83 // frame is the top-most frame labeled as an ad in the frame's ancestry,
103 // which may be itself. If no responsible frame is found, the data is 84 // which may be itself. If no responsible frame is found, the data is
104 // nullptr. 85 // nullptr.
105 std::map<FrameTreeNodeId, AdFrameData*> ad_frames_data_; 86 std::map<FrameTreeNodeId, AdFrameData*> ad_frames_data_;
106 87
107 // The set of frames that have yet to finish but that the SubresourceFilter
108 // has reported are ads. Once DetectSubresourceFilterAd is called the id is
109 // removed from the set.
110 std::set<FrameTreeNodeId> unfinished_subresource_ad_frames_;
111
112 // When the observer receives report of a document resource loading for a 88 // When the observer receives report of a document resource loading for a
113 // sub-frame before the sub-frame commit occurs, hold onto the resource 89 // sub-frame before the sub-frame commit occurs, hold onto the resource
114 // request info (delay it) until the sub-frame commits. 90 // request info (delay it) until the sub-frame commits.
115 std::map<FrameTreeNodeId, page_load_metrics::ExtraRequestCompleteInfo> 91 std::map<FrameTreeNodeId, page_load_metrics::ExtraRequestCompleteInfo>
116 ongoing_navigation_resources_; 92 ongoing_navigation_resources_;
117 93
118 size_t page_bytes_ = 0u; 94 size_t page_bytes_ = 0u;
119 size_t uncached_page_bytes_ = 0u; 95 size_t uncached_page_bytes_ = 0u;
120 bool committed_ = false; 96 bool committed_ = false;
121 97
122 ScopedObserver<subresource_filter::SubresourceFilterObserverManager, 98 ScopedObserver<subresource_filter::SubresourceFilterObserverManager,
123 subresource_filter::SubresourceFilterObserver> 99 subresource_filter::SubresourceFilterObserver>
124 subresource_observer_; 100 subresource_observer_;
125 101
126 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver); 102 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver);
127 }; 103 };
128 104
129 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_ 105 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698