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