OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_H_ | 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_ | 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" |
12 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" | 14 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 class NavigationHandle; | 17 class NavigationHandle; |
16 class RenderFrameHost; | 18 class RenderFrameHost; |
17 } // namespace content | 19 } // namespace content |
18 | 20 |
19 namespace page_load_metrics { | 21 namespace page_load_metrics { |
20 | 22 |
21 class PageLoadMetricsEmbedderInterface; | 23 class PageLoadMetricsEmbedderInterface; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 INVALID_ORDER_FIRST_PAINT_FIRST_TEXT_PAINT, | 60 INVALID_ORDER_FIRST_PAINT_FIRST_TEXT_PAINT, |
59 INVALID_ORDER_FIRST_PAINT_FIRST_IMAGE_PAINT, | 61 INVALID_ORDER_FIRST_PAINT_FIRST_IMAGE_PAINT, |
60 INVALID_ORDER_FIRST_PAINT_FIRST_CONTENTFUL_PAINT, | 62 INVALID_ORDER_FIRST_PAINT_FIRST_CONTENTFUL_PAINT, |
61 INVALID_ORDER_FIRST_PAINT_FIRST_MEANINGFUL_PAINT, | 63 INVALID_ORDER_FIRST_PAINT_FIRST_MEANINGFUL_PAINT, |
62 | 64 |
63 // New values should be added before this final entry. | 65 // New values should be added before this final entry. |
64 LAST_PAGE_LOAD_TIMING_STATUS | 66 LAST_PAGE_LOAD_TIMING_STATUS |
65 }; | 67 }; |
66 | 68 |
67 extern const char kPageLoadTimingStatus[]; | 69 extern const char kPageLoadTimingStatus[]; |
| 70 extern const char kHistogramOutOfOrderTiming[]; |
| 71 extern const char kHistogramOutOfOrderTimingBuffered[]; |
68 | 72 |
69 } // namespace internal | 73 } // namespace internal |
70 | 74 |
71 // PageLoadMetricsUpdateDispatcher manages updates to page load metrics data, | 75 // PageLoadMetricsUpdateDispatcher manages updates to page load metrics data, |
72 // and dispatches them to the Client. PageLoadMetricsUpdateDispatcher may delay | 76 // and dispatches them to the Client. PageLoadMetricsUpdateDispatcher may delay |
73 // dispatching metrics updates to the Client in cases where metrics state hasn't | 77 // dispatching metrics updates to the Client in cases where metrics state hasn't |
74 // stabilized. | 78 // stabilized. |
75 class PageLoadMetricsUpdateDispatcher { | 79 class PageLoadMetricsUpdateDispatcher { |
76 public: | 80 public: |
77 // The Client class is updated when metrics managed by the dispatcher have | 81 // The Client class is updated when metrics managed by the dispatcher have |
(...skipping 16 matching lines...) Expand all Loading... |
94 PageLoadMetricsEmbedderInterface* embedder_interface); | 98 PageLoadMetricsEmbedderInterface* embedder_interface); |
95 ~PageLoadMetricsUpdateDispatcher(); | 99 ~PageLoadMetricsUpdateDispatcher(); |
96 | 100 |
97 void UpdateMetrics(content::RenderFrameHost* render_frame_host, | 101 void UpdateMetrics(content::RenderFrameHost* render_frame_host, |
98 const mojom::PageLoadTiming& new_timing, | 102 const mojom::PageLoadTiming& new_timing, |
99 const mojom::PageLoadMetadata& new_metadata); | 103 const mojom::PageLoadMetadata& new_metadata); |
100 | 104 |
101 void DidFinishSubFrameNavigation( | 105 void DidFinishSubFrameNavigation( |
102 content::NavigationHandle* navigation_handle); | 106 content::NavigationHandle* navigation_handle); |
103 | 107 |
| 108 void ShutDown(); |
| 109 |
104 const mojom::PageLoadTiming& timing() const { | 110 const mojom::PageLoadTiming& timing() const { |
105 return *(current_merged_page_timing_.get()); | 111 return *(current_merged_page_timing_.get()); |
106 } | 112 } |
107 | 113 |
108 const mojom::PageLoadMetadata& main_frame_metadata() const { | 114 const mojom::PageLoadMetadata& main_frame_metadata() const { |
109 return *(main_frame_metadata_.get()); | 115 return *(main_frame_metadata_.get()); |
110 } | 116 } |
111 const mojom::PageLoadMetadata& subframe_metadata() const { | 117 const mojom::PageLoadMetadata& subframe_metadata() const { |
112 return *(subframe_metadata_.get()); | 118 return *(subframe_metadata_.get()); |
113 } | 119 } |
114 | 120 |
115 private: | 121 private: |
116 using FrameTreeNodeId = int; | 122 using FrameTreeNodeId = int; |
117 | 123 |
118 void UpdateMainFrameTiming(const mojom::PageLoadTiming& new_timing); | 124 void UpdateMainFrameTiming(const mojom::PageLoadTiming& new_timing); |
119 void UpdateSubFrameTiming(content::RenderFrameHost* render_frame_host, | 125 void UpdateSubFrameTiming(content::RenderFrameHost* render_frame_host, |
120 const mojom::PageLoadTiming& new_timing); | 126 const mojom::PageLoadTiming& new_timing); |
121 | 127 |
122 void UpdateMainFrameMetadata(const mojom::PageLoadMetadata& new_metadata); | 128 void UpdateMainFrameMetadata(const mojom::PageLoadMetadata& new_metadata); |
123 void UpdateSubFrameMetadata(const mojom::PageLoadMetadata& subframe_metadata); | 129 void UpdateSubFrameMetadata(const mojom::PageLoadMetadata& subframe_metadata); |
124 | 130 |
125 // Merge values from |new_paint_timing| into |pending_merged_page_timing_|, | 131 void MaybeDispatchTimingUpdates(bool did_merge_new_timing_value); |
126 // offsetting any new timings by the |navigation_start_offset|. | |
127 void MergePaintTiming(base::TimeDelta navigation_start_offset, | |
128 const mojom::PaintTiming& new_paint_timing, | |
129 bool is_main_frame); | |
130 | |
131 void DispatchTimingUpdates(); | 132 void DispatchTimingUpdates(); |
132 | 133 |
133 // The client is guaranteed to outlive this object. | 134 // The client is guaranteed to outlive this object. |
134 Client* const client_; | 135 Client* const client_; |
135 | 136 |
136 // Interface to chrome features. Must outlive the class. | 137 // Interface to chrome features. Must outlive the class. |
137 PageLoadMetricsEmbedderInterface* const embedder_interface_; | 138 PageLoadMetricsEmbedderInterface* const embedder_interface_; |
138 | 139 |
| 140 std::unique_ptr<base::Timer> timer_; |
| 141 |
139 // Time the navigation for this page load was initiated. | 142 // Time the navigation for this page load was initiated. |
140 const base::TimeTicks navigation_start_; | 143 const base::TimeTicks navigation_start_; |
141 | 144 |
142 // PageLoadTiming for the currently tracked page. The fields in |paint_timing| | 145 // PageLoadTiming for the currently tracked page. The fields in |paint_timing| |
143 // are merged across all frames in the document. All other fields are from the | 146 // are merged across all frames in the document. All other fields are from the |
144 // main frame document. |current_merged_page_timing_| contains the most recent | 147 // main frame document. |current_merged_page_timing_| contains the most recent |
145 // valid page load timing data, while pending_merged_page_timing_ contains | 148 // valid page load timing data, while pending_merged_page_timing_ contains |
146 // pending updates received since |current_merged_page_timing_| was last | 149 // pending updates received since |current_merged_page_timing_| was last |
147 // dispatched to the client. pending_merged_page_timing_ will be copied to | 150 // dispatched to the client. pending_merged_page_timing_ will be copied to |
148 // |current_merged_page_timing_| once it is valid, at the time the | 151 // |current_merged_page_timing_| once it is valid, at the time the |
149 // Client::OnTimingChanged callback is invoked. | 152 // Client::OnTimingChanged callback is invoked. |
150 mojom::PageLoadTimingPtr current_merged_page_timing_; | 153 mojom::PageLoadTimingPtr current_merged_page_timing_; |
151 mojom::PageLoadTimingPtr pending_merged_page_timing_; | 154 mojom::PageLoadTimingPtr pending_merged_page_timing_; |
152 | 155 |
153 mojom::PageLoadMetadataPtr main_frame_metadata_; | 156 mojom::PageLoadMetadataPtr main_frame_metadata_; |
154 mojom::PageLoadMetadataPtr subframe_metadata_; | 157 mojom::PageLoadMetadataPtr subframe_metadata_; |
155 | 158 |
156 // Navigation start offsets for the most recently committed document in each | 159 // Navigation start offsets for the most recently committed document in each |
157 // frame. | 160 // frame. |
158 std::map<FrameTreeNodeId, base::TimeDelta> subframe_navigation_start_offset_; | 161 std::map<FrameTreeNodeId, base::TimeDelta> subframe_navigation_start_offset_; |
159 | 162 |
160 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsUpdateDispatcher); | 163 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsUpdateDispatcher); |
161 }; | 164 }; |
162 | 165 |
163 } // namespace page_load_metrics | 166 } // namespace page_load_metrics |
164 | 167 |
165 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_
H_ | 168 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_METRICS_UPDATE_DISPATCHER_
H_ |
OLD | NEW |