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

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: Clean up test 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 {
Bryan McQuade 2017/04/24 19:20:47 cam we specify sane default values for the members
jkarlin 2017/04/25 15:56:50 Thanks for the catch!
42 size_t frame_bytes;
43 size_t frame_bytes_uncached;
44 };
45
46 void ProcessLoadedResource(
47 const page_load_metrics::ExtraRequestInfo& extra_request_info);
48 void RecordHistograms();
49
50 // Checks to see if a resource is waiting for a navigation with the given
51 // |frame_tree_node_id| to commit before it can be processed. If so, call
52 // OnLoadedResource for the delayed resource.
53 void ProcessOngoingNavigationResource(FrameTreeNodeId frame_tree_node_id);
54
55 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a
56 // data structure that won't move the data around.
57 std::list<AdFrameData> ad_frames_data_storage_;
58
59 // Maps a frame (by id) to the AdFrameData responsible for the frame.
60 // Multiple frame ids can point to the same AdFrameData. The responsible
61 // frame is the top-most frame labeled as an ad in the frame's ancestry,
62 // which may be itself. If no responsible frame is found, the data is
63 // nullptr.
64 std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_;
65
66 // When the observer receives report of a document resource loading for a
67 // sub-frame before the sub-frame commit occurs, hold onto the resource
68 // request info (delay it) until the sub-frame commits.
69 std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo>
70 ongoing_navigation_resources_;
71
72 size_t page_bytes_ = 0u;
73 size_t uncached_page_bytes_ = 0u;
74 int top_level_subframe_count_ = 0;
75 int top_level_ad_frame_count_ = 0;
76
77 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver);
78 };
79
80 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698