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

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

Issue 2798953002: [PageLoadMetrics] Keep track of Ad Sizes on Pages (Closed)
Patch Set: Address comments from PS17 Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
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_
7
8 #include <list>
9 #include <memory>
10 #include <unordered_map>
11
12 #include "base/macros.h"
13 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
14 #include "net/http/http_response_info.h"
15
16 class AdsPageLoadMetricsObserver
17 : public page_load_metrics::PageLoadMetricsObserver {
18 public:
19 // Returns a new AdsPageLoadMetricObserver. If the feature is disabled it
20 // returns nullptr.
21 static std::unique_ptr<AdsPageLoadMetricsObserver> CreateIfNeeded();
22
23 AdsPageLoadMetricsObserver();
24 ~AdsPageLoadMetricsObserver() override;
25
26 // page_load_metrics::PageLoadMetricsObserver
27 ObservePolicy OnCommit(content::NavigationHandle* navigation_handle) override;
28 ObservePolicy OnDidFinishSubFrameNavigation(
29 content::NavigationHandle* navigation_handle) override;
30 ObservePolicy FlushMetricsOnAppEnterBackground(
31 const page_load_metrics::PageLoadTiming& timing,
32 const page_load_metrics::PageLoadExtraInfo& extra_info) override;
33 void OnLoadedResource(
34 const page_load_metrics::ExtraRequestInfo& extra_request_info) override;
35 void OnComplete(const page_load_metrics::PageLoadTiming& timing,
36 const page_load_metrics::PageLoadExtraInfo& info) override;
37
38 private:
39 using FrameTreeNodeId = int;
40
41 struct AdFrameData {
42 explicit AdFrameData(FrameTreeNodeId frame_tree_node_id);
43 size_t frame_bytes;
44 size_t frame_bytes_uncached;
45 FrameTreeNodeId frame_tree_node_id;
Bryan McQuade 2017/04/25 16:36:44 can we make this member const, given that it is se
jkarlin 2017/04/25 16:42:51 Done.
46 };
47
48 void ProcessLoadedResource(
49 const page_load_metrics::ExtraRequestInfo& extra_request_info);
50 void RecordHistograms();
51
52 // Checks to see if a resource is waiting for a navigation with the given
53 // |frame_tree_node_id| to commit before it can be processed. If so, call
54 // OnLoadedResource for the delayed resource.
55 void ProcessOngoingNavigationResource(FrameTreeNodeId frame_tree_node_id);
56
57 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a
58 // data structure that won't move the data around.
59 std::list<AdFrameData> ad_frames_data_storage_;
60
61 // Maps a frame (by id) to the AdFrameData responsible for the frame.
62 // Multiple frame ids can point to the same AdFrameData. The responsible
63 // frame is the top-most frame labeled as an ad in the frame's ancestry,
64 // which may be itself. If no responsible frame is found, the data is
65 // nullptr.
66 std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_;
67
68 // When the observer receives report of a document resource loading for a
69 // sub-frame before the sub-frame commit occurs, hold onto the resource
70 // request info (delay it) until the sub-frame commits.
71 std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo>
72 ongoing_navigation_resources_;
73
74 size_t page_bytes_ = 0u;
75 size_t uncached_page_bytes_ = 0u;
76 int top_level_subframe_count_ = 0;
77 int top_level_ad_frame_count_ = 0;
78
79 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver);
80 };
81
82 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698