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