OLD | NEW |
---|---|
(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:s | |
Charlie Harrison
2017/04/14 20:16:26
nit: remove the s.
jkarlin
2017/04/24 17:27:59
Done.
| |
27 ObservePolicy OnCommit(content::NavigationHandle* navigation_handle) override; | |
28 ObservePolicy OnCommitSubFrame( | |
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 struct AdFrameData { | |
40 size_t frame_bytes; | |
41 size_t frame_bytes_uncached; | |
42 }; | |
43 | |
44 using FrameTreeNodeId = int; | |
45 | |
46 void RecordHistograms(); | |
47 | |
48 // Checks to see if a resource is waiting for |frame_tree_node_id| to commit | |
Charlie Harrison
2017/04/14 20:16:26
for a navigation with the given |frame_tree_node_i
jkarlin
2017/04/24 17:27:59
Done.
| |
49 // before it can be processed. If so, call OnLoadedResource for the delayed | |
50 // resource. | |
51 void ProcessOngoingNavigationResources(FrameTreeNodeId frame_tree_node_id); | |
Bryan McQuade
2017/04/17 22:00:04
nit: when i read this name, which has Resources pl
jkarlin
2017/04/24 17:27:59
Done.
| |
52 | |
53 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a | |
54 // data structure that won't move the data around. | |
55 std::list<AdFrameData> ad_frames_data_storage_; | |
Bryan McQuade
2017/04/17 22:00:04
My sense is that ad_frames_data_storage_ and ad_fr
jkarlin
2017/04/24 17:27:59
I think pretty much all of the logic would wind up
Bryan McQuade
2017/04/24 19:28:22
Sure - I'm fine with that.
| |
56 | |
57 // Maps a frame (by id) to the AdFrameData responsible for the frame. The | |
58 // responsible frame is the top-most frame labeled as an ad in the frame's | |
Bryan McQuade
2017/04/14 19:19:23
it sounds like it's possible for multiple FrameTre
jkarlin
2017/04/24 17:27:59
Done.
| |
59 // ancestry, which may be itself. If no responsible frame is found, the data | |
60 // is nullptr. | |
61 std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_; | |
62 | |
63 // When the observer receives report of a document resource loading for a | |
64 // sub-frame before the sub-frame commit occurs, hold onto the resource | |
65 // request info (delay it) until the sub-frame commits. | |
66 std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo> | |
67 ongoing_navigation_resources_; | |
68 | |
69 size_t page_bytes_ = 0u; | |
70 size_t uncached_page_bytes_ = 0u; | |
71 int top_level_subframe_count_ = 0; | |
72 int top_level_ad_frame_count_ = 0; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver); | |
75 }; | |
76 | |
77 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_ | |
OLD | NEW |