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_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_H_ | |
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
Charlie Harrison
2017/05/23 20:32:10
Is <memory> for the mojo ptrs?
Bryan McQuade
2017/05/23 20:51:09
This isn't needed. Removed.
| |
10 | |
11 #include "base/time/time.h" | |
12 #include "chrome/common/page_load_metrics/page_load_timing.h" | |
13 | |
14 namespace content { | |
15 class NavigationHandle; | |
16 class RenderFrameHost; | |
17 } // namespace content | |
18 | |
19 namespace page_load_metrics { | |
20 | |
21 class PageLoadMetricsEmbedderInterface; | |
22 | |
23 namespace internal { | |
24 | |
25 // Used to track the status of PageLoadTimings received from the render process. | |
26 // | |
27 // If you add elements to this enum, make sure you update the enum value in | |
28 // histograms.xml. Only add elements to the end to prevent inconsistencies | |
29 // between versions. | |
30 enum PageLoadTimingStatus { | |
31 // The PageLoadTiming is valid (all data within the PageLoadTiming is | |
32 // consistent with expectations). | |
33 VALID, | |
34 | |
35 // All remaining status codes are for invalid PageLoadTimings. | |
36 | |
37 // The PageLoadTiming was empty. | |
38 INVALID_EMPTY_TIMING, | |
39 | |
40 // The PageLoadTiming had a null navigation_start. | |
41 INVALID_NULL_NAVIGATION_START, | |
42 | |
43 // Script load or execution durations in the PageLoadTiming were too long. | |
44 INVALID_SCRIPT_LOAD_LONGER_THAN_PARSE, | |
45 INVALID_SCRIPT_EXEC_LONGER_THAN_PARSE, | |
46 INVALID_SCRIPT_LOAD_DOC_WRITE_LONGER_THAN_SCRIPT_LOAD, | |
47 INVALID_SCRIPT_EXEC_DOC_WRITE_LONGER_THAN_SCRIPT_EXEC, | |
48 | |
49 // The order of two events in the PageLoadTiming was invalid. Either the first | |
50 // wasn't present when the second was present, or the second was reported as | |
51 // happening before the first. | |
52 INVALID_ORDER_RESPONSE_START_PARSE_START, | |
53 INVALID_ORDER_PARSE_START_PARSE_STOP, | |
54 INVALID_ORDER_PARSE_STOP_DOM_CONTENT_LOADED, | |
55 INVALID_ORDER_DOM_CONTENT_LOADED_LOAD, | |
56 INVALID_ORDER_PARSE_START_FIRST_LAYOUT, | |
57 INVALID_ORDER_FIRST_LAYOUT_FIRST_PAINT, | |
58 INVALID_ORDER_FIRST_PAINT_FIRST_TEXT_PAINT, | |
59 INVALID_ORDER_FIRST_PAINT_FIRST_IMAGE_PAINT, | |
60 INVALID_ORDER_FIRST_PAINT_FIRST_CONTENTFUL_PAINT, | |
61 INVALID_ORDER_FIRST_PAINT_FIRST_MEANINGFUL_PAINT, | |
62 | |
63 // New values should be added before this final entry. | |
64 LAST_PAGE_LOAD_TIMING_STATUS | |
65 }; | |
66 | |
67 extern const char kPageLoadTimingStatus[]; | |
68 | |
69 } // namespace internal | |
70 | |
71 // PageLoadMetricsUpdateDispatcher manages updates to page load metrics data, | |
72 // and dispatches them to the Client. PageLoadMetricsUpdateDispatcher may delay | |
73 // dispatching metrics updates to the Client in cases where metrics state hasn't | |
74 // stabilized. | |
75 class PageLoadMetricsUpdateDispatcher { | |
76 public: | |
77 // The Client interface informs a client of the | |
Charlie Harrison
2017/05/23 20:32:10
This is awkwardly worded. Maybe something like: "T
Bryan McQuade
2017/05/23 20:50:36
Done
| |
78 // PageLoadMetricsUpdateDispatcher (typically the owner of the | |
79 // PageLoadMetricsUpdateDispatcher) when metrics managed by the | |
80 // PageLoadMetricsUpdateDispatcher object have changed. | |
81 class Client { | |
82 public: | |
83 virtual ~Client() {} | |
84 | |
85 virtual void OnTimingChanged() = 0; | |
86 virtual void OnMainFrameMetadataChanged() = 0; | |
87 virtual void OnSubframeMetadataChanged() = 0; | |
88 }; | |
89 | |
90 PageLoadMetricsUpdateDispatcher( | |
91 Client* client, | |
92 content::NavigationHandle* navigation_handle, | |
93 PageLoadMetricsEmbedderInterface* embedder_interface); | |
94 ~PageLoadMetricsUpdateDispatcher(); | |
95 | |
96 void UpdateMetrics(content::RenderFrameHost* render_frame_host, | |
97 const mojom::PageLoadTiming& new_timing, | |
98 const mojom::PageLoadMetadata& new_metadata); | |
99 | |
100 void DidFinishSubFrameNavigation( | |
101 content::NavigationHandle* navigation_handle); | |
102 | |
103 const mojom::PageLoadTiming& timing() const { | |
104 return *(current_merged_page_timing_.get()); | |
105 } | |
106 | |
107 const mojom::PageLoadMetadata& main_frame_metadata() const { | |
Charlie Harrison
2017/05/23 20:32:10
Does it need fwd declaration / #include?
Bryan McQuade
2017/05/23 20:50:35
I was including page_load_timing.h which includes
| |
108 return *(main_frame_metadata_.get()); | |
109 } | |
110 const mojom::PageLoadMetadata& subframe_metadata() const { | |
111 return *(subframe_metadata_.get()); | |
112 } | |
113 | |
114 private: | |
115 using FrameTreeNodeId = int; | |
116 | |
117 void UpdateMainFrameTiming(const mojom::PageLoadTiming& new_timing); | |
118 void UpdateSubFrameTiming(content::RenderFrameHost* render_frame_host, | |
119 const mojom::PageLoadTiming& new_timing); | |
120 | |
121 void UpdateMainFrameMetadata(const mojom::PageLoadMetadata& new_metadata); | |
122 void UpdateSubFrameMetadata(const mojom::PageLoadMetadata& subframe_metadata); | |
123 | |
124 // Merge values from |new_paint_timing| into |pending_merged_page_timing_|, | |
125 // offsetting any new timings by the |navigation_start_offset|. | |
126 void MergePaintTiming(base::TimeDelta navigation_start_offset, | |
127 const mojom::PaintTiming& new_paint_timing, | |
128 bool is_main_frame); | |
129 | |
130 void DispatchTimingUpdates(); | |
131 | |
132 Client* const client_; | |
Charlie Harrison
2017/05/23 20:32:10
Can you comment on the lifetime of client_?
Bryan McQuade
2017/05/23 20:50:36
Done
| |
133 | |
134 // Interface to chrome features. Must outlive the class. | |
135 PageLoadMetricsEmbedderInterface* const embedder_interface_; | |
136 | |
137 // Time the navigation for this page load was initiated. | |
138 const base::TimeTicks navigation_start_; | |
139 | |
140 // PageLoadTiming for the currently tracked page. The fields in |paint_timing| | |
141 // are merged across all frames in the document. All other fields are from the | |
142 // main frame document. | |
143 mojom::PageLoadTimingPtr current_merged_page_timing_; | |
Charlie Harrison
2017/05/23 20:32:10
Can you comment what is the difference between cur
Bryan McQuade
2017/05/23 20:50:36
Done
| |
144 mojom::PageLoadTimingPtr pending_merged_page_timing_; | |
145 | |
146 mojom::PageLoadMetadataPtr main_frame_metadata_; | |
147 mojom::PageLoadMetadataPtr subframe_metadata_; | |
148 | |
149 // Navigation start offsets for the most recently committed document in each | |
150 // frame. | |
151 std::map<FrameTreeNodeId, base::TimeDelta> subframe_navigation_start_offset_; | |
152 | |
153 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsUpdateDispatcher); | |
154 }; | |
155 | |
156 } // namespace page_load_metrics | |
157 | |
158 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_ H_ | |
OLD | NEW |