| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ | |
| 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/optional.h" | |
| 10 #include "components/page_load_metrics/common/page_load_timing.h" | |
| 11 #include "content/public/browser/navigation_handle.h" | |
| 12 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace page_load_metrics { | |
| 16 | |
| 17 // This enum represents how a page load ends. If the action occurs before the | |
| 18 // page load finishes (or reaches some point like first paint), then we consider | |
| 19 // the load to be aborted. | |
| 20 enum UserAbortType { | |
| 21 // Represents no abort. | |
| 22 ABORT_NONE, | |
| 23 | |
| 24 // If the user presses reload or shift-reload. | |
| 25 ABORT_RELOAD, | |
| 26 | |
| 27 // The user presses the back/forward button. | |
| 28 ABORT_FORWARD_BACK, | |
| 29 | |
| 30 // If the navigation is replaced by a new navigation. This includes link | |
| 31 // clicks, typing in the omnibox (not a reload), and form submissions. | |
| 32 ABORT_NEW_NAVIGATION, | |
| 33 | |
| 34 // If the user presses the stop X button. | |
| 35 ABORT_STOP, | |
| 36 | |
| 37 // If the navigation is aborted by closing the tab or browser. | |
| 38 ABORT_CLOSE, | |
| 39 | |
| 40 // We don't know why the navigation aborted. This is the value we assign to an | |
| 41 // aborted load if the only signal we get is a provisional load finishing | |
| 42 // without committing, either without error or with net::ERR_ABORTED. | |
| 43 ABORT_OTHER, | |
| 44 | |
| 45 // The load aborted due to another navigation, but it isn't clear what type of | |
| 46 // navigation it was. | |
| 47 ABORT_UNKNOWN_NAVIGATION, | |
| 48 | |
| 49 // Add values before this final count. | |
| 50 ABORT_LAST_ENTRY | |
| 51 }; | |
| 52 | |
| 53 // Information related to failed provisional loads. | |
| 54 struct FailedProvisionalLoadInfo { | |
| 55 FailedProvisionalLoadInfo(base::TimeDelta interval, net::Error error); | |
| 56 ~FailedProvisionalLoadInfo(); | |
| 57 | |
| 58 base::TimeDelta time_to_failed_provisional_load; | |
| 59 net::Error error; | |
| 60 }; | |
| 61 | |
| 62 struct PageLoadExtraInfo { | |
| 63 PageLoadExtraInfo( | |
| 64 const base::Optional<base::TimeDelta>& first_background_time, | |
| 65 const base::Optional<base::TimeDelta>& first_foreground_time, | |
| 66 bool started_in_foreground, | |
| 67 const GURL& committed_url, | |
| 68 const base::Optional<base::TimeDelta>& time_to_commit, | |
| 69 UserAbortType abort_type, | |
| 70 const base::Optional<base::TimeDelta>& time_to_abort, | |
| 71 const PageLoadMetadata& metadata); | |
| 72 | |
| 73 PageLoadExtraInfo(const PageLoadExtraInfo& other); | |
| 74 | |
| 75 ~PageLoadExtraInfo(); | |
| 76 | |
| 77 // The first time that the page was backgrounded since the navigation started. | |
| 78 const base::Optional<base::TimeDelta> first_background_time; | |
| 79 | |
| 80 // The first time that the page was foregrounded since the navigation started. | |
| 81 const base::Optional<base::TimeDelta> first_foreground_time; | |
| 82 | |
| 83 // True if the page load started in the foreground. | |
| 84 const bool started_in_foreground; | |
| 85 | |
| 86 // Committed URL. If the page load did not commit, |committed_url| will be | |
| 87 // empty. | |
| 88 const GURL committed_url; | |
| 89 | |
| 90 // Time from navigation start until commit. | |
| 91 const base::Optional<base::TimeDelta> time_to_commit; | |
| 92 | |
| 93 // The abort time and time to abort for this page load. If the page was not | |
| 94 // aborted, |abort_type| will be |ABORT_NONE|. | |
| 95 const UserAbortType abort_type; | |
| 96 const base::Optional<base::TimeDelta> time_to_abort; | |
| 97 | |
| 98 // Extra information supplied to the page load metrics system from the | |
| 99 // renderer. | |
| 100 const PageLoadMetadata metadata; | |
| 101 }; | |
| 102 | |
| 103 // Interface for PageLoadMetrics observers. All instances of this class are | |
| 104 // owned by the PageLoadTracker tracking a page load. | |
| 105 class PageLoadMetricsObserver { | |
| 106 public: | |
| 107 virtual ~PageLoadMetricsObserver() {} | |
| 108 | |
| 109 // The page load started, with the given navigation handle. Note that OnStart | |
| 110 // is called for same-page navigations. Implementers of OnStart that only want | |
| 111 // to process non-same-page navigations should also check to see that the page | |
| 112 // load committed via OnCommit or committed_url in | |
| 113 // PageLoadExtraInfo. currently_committed_url contains the URL of the | |
| 114 // committed page load at the time the navigation for navigation_handle was | |
| 115 // initiated, or the empty URL if there was no committed page load at the time | |
| 116 // the navigation was initiated. | |
| 117 virtual void OnStart(content::NavigationHandle* navigation_handle, | |
| 118 const GURL& currently_committed_url, | |
| 119 bool started_in_foreground) {} | |
| 120 | |
| 121 // OnRedirect is triggered when a page load redirects to another URL. | |
| 122 // The navigation handle holds relevant data for the navigation, but will | |
| 123 // be destroyed soon after this call. Don't hold a reference to it. This can | |
| 124 // be called multiple times. | |
| 125 virtual void OnRedirect(content::NavigationHandle* navigation_handle) {} | |
| 126 | |
| 127 // OnCommit is triggered when a page load commits, i.e. when we receive the | |
| 128 // first data for the request. The navigation handle holds relevant data for | |
| 129 // the navigation, but will be destroyed soon after this call. Don't hold a | |
| 130 // reference to it. | |
| 131 // Note that this does not get called for same page navigations. | |
| 132 virtual void OnCommit(content::NavigationHandle* navigation_handle) {} | |
| 133 | |
| 134 // OnHidden is triggered when a page leaves the foreground. It does not fire | |
| 135 // when a foreground page is permanently closed; for that, listen to | |
| 136 // OnComplete instead. | |
| 137 virtual void OnHidden() {} | |
| 138 | |
| 139 // OnShown is triggered when a page is brought to the foreground. It does not | |
| 140 // fire when the page first loads; for that, listen for OnStart instead. | |
| 141 virtual void OnShown() {} | |
| 142 | |
| 143 // The callbacks below are only invoked after a navigation commits, for | |
| 144 // tracked page loads. Page loads that don't meet the criteria for being | |
| 145 // tracked at the time a navigation commits will not receive any of the | |
| 146 // callbacks below. | |
| 147 | |
| 148 // OnTimingUpdate is triggered when an updated PageLoadTiming is | |
| 149 // available. This method may be called multiple times over the course of the | |
| 150 // page load. This method is currently only intended for use in testing. Most | |
| 151 // implementers should implement one of the On* callbacks, such as | |
| 152 // OnFirstContentfulPaint or OnDomContentLoadedEventStart. Please email | |
| 153 // loading-dev@chromium.org if you intend to override this method. | |
| 154 virtual void OnTimingUpdate(const PageLoadTiming& timing, | |
| 155 const PageLoadExtraInfo& extra_info) {} | |
| 156 // OnUserInput is triggered when a new user input is passed in to | |
| 157 // web_contents. Contains a TimeDelta from navigation start. | |
| 158 virtual void OnUserInput(const blink::WebInputEvent& event) {} | |
| 159 | |
| 160 // The following methods are invoked at most once, when the timing for the | |
| 161 // associated event first becomes available. | |
| 162 virtual void OnDomContentLoadedEventStart( | |
| 163 const PageLoadTiming& timing, | |
| 164 const PageLoadExtraInfo& extra_info) {} | |
| 165 virtual void OnLoadEventStart(const PageLoadTiming& timing, | |
| 166 const PageLoadExtraInfo& extra_info) {} | |
| 167 virtual void OnFirstLayout(const PageLoadTiming& timing, | |
| 168 const PageLoadExtraInfo& extra_info) {} | |
| 169 virtual void OnFirstPaint(const PageLoadTiming& timing, | |
| 170 const PageLoadExtraInfo& extra_info) {} | |
| 171 virtual void OnFirstTextPaint(const PageLoadTiming& timing, | |
| 172 const PageLoadExtraInfo& extra_info) {} | |
| 173 virtual void OnFirstImagePaint(const PageLoadTiming& timing, | |
| 174 const PageLoadExtraInfo& extra_info) {} | |
| 175 virtual void OnFirstContentfulPaint(const PageLoadTiming& timing, | |
| 176 const PageLoadExtraInfo& extra_info) {} | |
| 177 virtual void OnParseStart(const PageLoadTiming& timing, | |
| 178 const PageLoadExtraInfo& extra_info) {} | |
| 179 virtual void OnParseStop(const PageLoadTiming& timing, | |
| 180 const PageLoadExtraInfo& extra_info) {} | |
| 181 | |
| 182 // Observer method to be invoked when there is a change in PageLoadMetadata's | |
| 183 // behavior_flags. | |
| 184 virtual void OnLoadingBehaviorObserved( | |
| 185 const page_load_metrics::PageLoadExtraInfo& extra_info) {} | |
| 186 | |
| 187 // One of OnComplete or OnFailedProvisionalLoad is invoked for tracked page | |
| 188 // loads, immediately before the observer is deleted. These callbacks will not | |
| 189 // be invoked for page loads that did not meet the criteria for being tracked | |
| 190 // at the time the navigation completed. The PageLoadTiming struct contains | |
| 191 // timing data and the PageLoadExtraInfo struct contains other useful data | |
| 192 // collected over the course of the page load. Most observers should not need | |
| 193 // to implement these callbacks, and should implement the On* timing callbacks | |
| 194 // instead. | |
| 195 | |
| 196 // OnComplete is invoked for tracked page loads that committed, immediately | |
| 197 // before the observer is deleted. | |
| 198 virtual void OnComplete(const PageLoadTiming& timing, | |
| 199 const PageLoadExtraInfo& extra_info) {} | |
| 200 | |
| 201 // OnFailedProvisionalLoad is invoked for tracked page loads that did not | |
| 202 // commit, immediately before the observer is deleted. Note that provisional | |
| 203 // loads that result in downloads or 204s are aborted by the system, and are | |
| 204 // also included as failed provisional loads. | |
| 205 virtual void OnFailedProvisionalLoad( | |
| 206 const FailedProvisionalLoadInfo& failed_provisional_load_info, | |
| 207 const PageLoadExtraInfo& extra_info) {} | |
| 208 }; | |
| 209 | |
| 210 } // namespace page_load_metrics | |
| 211 | |
| 212 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_OBSERVER_H_ | |
| OLD | NEW |