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 <unordered_map> | |
10 | |
11 #include "base/macros.h" | |
12 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | |
13 #include "net/http/http_response_info.h" | |
14 | |
15 class AdsPageLoadMetricsObserver | |
16 : public page_load_metrics::PageLoadMetricsObserver { | |
17 public: | |
18 AdsPageLoadMetricsObserver(); | |
19 ~AdsPageLoadMetricsObserver() override; | |
20 | |
21 // page_load_metrics::PageLoadMetricsObserver:s | |
22 ObservePolicy OnCommit(content::NavigationHandle* navigation_handle) override; | |
23 ObservePolicy OnCommitSubFrame( | |
24 content::NavigationHandle* navigation_handle) override; | |
25 ObservePolicy FlushMetricsOnAppEnterBackground( | |
26 const page_load_metrics::PageLoadTiming& timing, | |
27 const page_load_metrics::PageLoadExtraInfo& extra_info) override; | |
28 void OnLoadedResource( | |
29 const page_load_metrics::ExtraRequestInfo& extra_request_info) override; | |
30 void OnComplete(const page_load_metrics::PageLoadTiming& timing, | |
31 const page_load_metrics::PageLoadExtraInfo& info) override; | |
32 | |
33 private: | |
34 struct AdFrameData { | |
35 size_t frame_bytes; | |
36 size_t frame_bytes_uncached; | |
37 }; | |
38 | |
39 using FrameTreeNodeId = int; | |
40 | |
41 friend class AdsPageLoadMetricsObserverTest; | |
42 | |
43 void RecordHistograms(); | |
44 AdFrameData* FindAdAncestor(content::NavigationHandle* navigation_handle); | |
45 | |
46 // Checks to see if a resource is waiting for |frame_tree_node_id| to commit | |
47 // before it can be processed. If so, call OnLoadedResource for the delayed | |
48 // resource. | |
49 void ProcessDelayedResources(FrameTreeNodeId frame_tree_node_id); | |
50 | |
51 // Stores the size data of each ad frame. Pointed to by ad_frames_ so use a | |
52 // data structure that won't move the data around. | |
53 std::list<AdFrameData> ad_frames_data_storage_; | |
Charlie Harrison
2017/04/11 17:30:06
It is append-only. Why not use std::vector?
jkarlin
2017/04/13 17:25:30
Because I'm taking pointers to its elements. When
| |
54 | |
55 // Maps a frame (by id) to the AdFraneData responsible for the frame. The | |
Charlie Harrison
2017/04/11 17:30:06
s/AdFraneData/AdFrameData
jkarlin
2017/04/13 17:25:30
Done.
| |
56 // responsible frame is the top-most frame labeled as an ad in the frame's | |
57 // ancestry, which may be itself. If no responsible frame is found, the data | |
58 // is nullptr. | |
59 std::unordered_map<FrameTreeNodeId, AdFrameData*> ad_frames_data_; | |
60 | |
61 // When the observer receives report of a document resource loading for a | |
62 // sub-frame before the sub-frame commit occurs, hold onto the resource | |
63 // request info (delay it) until the sub-frame commits. | |
64 std::unordered_map<FrameTreeNodeId, page_load_metrics::ExtraRequestInfo> | |
65 delayed_resources_; | |
66 | |
67 size_t page_bytes_ = 0; | |
68 size_t uncached_page_bytes_ = 0; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserver); | |
71 }; | |
72 | |
73 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_ADS_PAGE_LOAD_METRICS_OBSE RVER_H_ | |
OLD | NEW |