| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ | 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ | 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // cc file for details). We use this error counter to understand how often it | 80 // cc file for details). We use this error counter to understand how often it |
| 81 // happens. | 81 // happens. |
| 82 ERR_ABORT_BEFORE_NAVIGATION_START, | 82 ERR_ABORT_BEFORE_NAVIGATION_START, |
| 83 | 83 |
| 84 // A new navigation triggers abort updates in multiple trackers in | 84 // A new navigation triggers abort updates in multiple trackers in |
| 85 // |aborted_provisional_loads_|, when usually there should only be one (the | 85 // |aborted_provisional_loads_|, when usually there should only be one (the |
| 86 // navigation that just aborted because of this one). If this happens, the | 86 // navigation that just aborted because of this one). If this happens, the |
| 87 // latest aborted load is used to track the chain size. | 87 // latest aborted load is used to track the chain size. |
| 88 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS, | 88 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS, |
| 89 | 89 |
| 90 // A TimeTicks value in the browser process has value less than |
| 91 // navigation_start_. This could happen if navigation_start_ was computed in |
| 92 // renderer process and the system clock has inter process time tick skew. |
| 93 ERR_INTER_PROCESS_TIME_TICK_SKEW, |
| 94 |
| 90 // Add values before this final count. | 95 // Add values before this final count. |
| 91 ERR_LAST_ENTRY | 96 ERR_LAST_ENTRY |
| 92 }; | 97 }; |
| 93 | 98 |
| 94 // This class serves as a functional interface to various chrome// features. | 99 // This class serves as a functional interface to various chrome// features. |
| 95 // Impl version is defined in chrome/browser/page_load_metrics. | 100 // Impl version is defined in chrome/browser/page_load_metrics. |
| 96 class PageLoadMetricsEmbedderInterface { | 101 class PageLoadMetricsEmbedderInterface { |
| 97 public: | 102 public: |
| 98 virtual ~PageLoadMetricsEmbedderInterface() {} | 103 virtual ~PageLoadMetricsEmbedderInterface() {} |
| 99 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; | 104 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 141 } |
| 137 | 142 |
| 138 UserAbortType abort_type() const { return abort_type_; } | 143 UserAbortType abort_type() const { return abort_type_; } |
| 139 base::TimeTicks abort_time() const { return abort_time_; } | 144 base::TimeTicks abort_time() const { return abort_time_; } |
| 140 | 145 |
| 141 void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer); | 146 void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer); |
| 142 | 147 |
| 143 // If the user performs some abort-like action while we are tracking this page | 148 // If the user performs some abort-like action while we are tracking this page |
| 144 // load, notify the tracker. Note that we may not classify this as an abort if | 149 // load, notify the tracker. Note that we may not classify this as an abort if |
| 145 // we've already performed a first paint. | 150 // we've already performed a first paint. |
| 146 void NotifyAbort(UserAbortType abort_type, base::TimeTicks timestamp); | 151 // is_browser_timestamp signifies if the timestamp passed is taken in the |
| 147 void UpdateAbort(UserAbortType abort_type, base::TimeTicks timestamp); | 152 // browser process or not. We need this to possibly clamp browser timestamp on |
| 153 // a machine with inter process time tick skew. |
| 154 void NotifyAbort(UserAbortType abort_type, |
| 155 base::TimeTicks timestamp, |
| 156 bool is_browser_timestamp); |
| 157 void UpdateAbort(UserAbortType abort_type, |
| 158 base::TimeTicks timestamp, |
| 159 bool is_browser_timestamp); |
| 148 | 160 |
| 149 // This method returns true if this page load has been aborted with type of | 161 // This method returns true if this page load has been aborted with type of |
| 150 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close | 162 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close |
| 151 // delta to when it was aborted. Note that only provisional loads can be | 163 // delta to when it was aborted. Note that only provisional loads can be |
| 152 // aborted with ABORT_OTHER. While this heuristic is coarse, it works better | 164 // aborted with ABORT_OTHER. While this heuristic is coarse, it works better |
| 153 // and is simpler than other feasible methods. See https://goo.gl/WKRG98. | 165 // and is simpler than other feasible methods. See https://goo.gl/WKRG98. |
| 154 bool IsLikelyProvisionalAbort(base::TimeTicks abort_cause_time); | 166 bool IsLikelyProvisionalAbort(base::TimeTicks abort_cause_time); |
| 155 | 167 |
| 156 bool MatchesOriginalNavigation(content::NavigationHandle* navigation_handle); | 168 bool MatchesOriginalNavigation(content::NavigationHandle* navigation_handle); |
| 157 | 169 |
| 158 // Only valid to call post-commit. | 170 // Only valid to call post-commit. |
| 159 const GURL& committed_url() const { | 171 const GURL& committed_url() const { |
| 160 DCHECK(!commit_time_.is_null()); | 172 DCHECK(!commit_time_.is_null()); |
| 161 return url_; | 173 return url_; |
| 162 } | 174 } |
| 163 | 175 |
| 176 PageLoadExtraInfo ComputePageLoadExtraInfo(); |
| 177 |
| 164 private: | 178 private: |
| 165 PageLoadExtraInfo GetPageLoadMetricsInfo(); | 179 // This function converts a TimeTicks value taken in the browser process |
| 180 // to navigation_start_ if: |
| 181 // - base::TimeTicks is not comparable across processes because the clock |
| 182 // is not system wide monotonic. |
| 183 // - *event_time < navigation_start_ |
| 184 void ClampBrowserTimestampIfInterProcessTimeTickSkew( |
| 185 base::TimeTicks* event_time); |
| 166 | 186 |
| 167 void UpdateAbortInternal(UserAbortType abort_type, | 187 void UpdateAbortInternal(UserAbortType abort_type, |
| 168 base::TimeTicks timestamp); | 188 base::TimeTicks timestamp, |
| 189 bool is_browser_timestamp); |
| 169 | 190 |
| 170 // If |final_navigation| is null, then this is an "unparented" abort chain, | 191 // If |final_navigation| is null, then this is an "unparented" abort chain, |
| 171 // and represents a sequence of provisional aborts that never ends with a | 192 // and represents a sequence of provisional aborts that never ends with a |
| 172 // committed load. | 193 // committed load. |
| 173 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); | 194 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); |
| 174 | 195 |
| 175 // Whether the renderer should be sending timing IPCs to this page load. | 196 // Whether the renderer should be sending timing IPCs to this page load. |
| 176 bool renderer_tracked_; | 197 bool renderer_tracked_; |
| 177 | 198 |
| 178 // The navigation start in TimeTicks, not the wall time reported by Blink. | 199 // The navigation start in TimeTicks, not the wall time reported by Blink. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 content::NavigationHandle* navigation_handle) override; | 265 content::NavigationHandle* navigation_handle) override; |
| 245 void DidFinishNavigation( | 266 void DidFinishNavigation( |
| 246 content::NavigationHandle* navigation_handle) override; | 267 content::NavigationHandle* navigation_handle) override; |
| 247 void DidRedirectNavigation( | 268 void DidRedirectNavigation( |
| 248 content::NavigationHandle* navigation_handle) override; | 269 content::NavigationHandle* navigation_handle) override; |
| 249 void NavigationStopped() override; | 270 void NavigationStopped() override; |
| 250 void WasShown() override; | 271 void WasShown() override; |
| 251 void WasHidden() override; | 272 void WasHidden() override; |
| 252 void RenderProcessGone(base::TerminationStatus status) override; | 273 void RenderProcessGone(base::TerminationStatus status) override; |
| 253 | 274 |
| 275 // This getter function is required for testing. |
| 276 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); |
| 277 |
| 254 private: | 278 private: |
| 255 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 279 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
| 256 | 280 |
| 257 // Notify all loads, provisional and committed, that we performed an action | 281 // Notify all loads, provisional and committed, that we performed an action |
| 258 // that might abort them. | 282 // that might abort them. |
| 259 void NotifyAbortAllLoads(UserAbortType abort_type); | 283 void NotifyAbortAllLoads(UserAbortType abort_type); |
| 260 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, | 284 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, |
| 261 base::TimeTicks timestamp); | 285 base::TimeTicks timestamp, |
| 286 bool is_browser_timestamp); |
| 262 // Notify aborted provisional loads that a new navigation occurred. This is | 287 // Notify aborted provisional loads that a new navigation occurred. This is |
| 263 // used for more consistent attribution tracking for aborted provisional | 288 // used for more consistent attribution tracking for aborted provisional |
| 264 // loads. This method returns the provisional load that was likely aborted by | 289 // loads. This method returns the provisional load that was likely aborted by |
| 265 // this navigation, to help instantiate the new PageLoadTracker. | 290 // this navigation, to help instantiate the new PageLoadTracker. |
| 266 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( | 291 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( |
| 267 content::NavigationHandle* new_navigation); | 292 content::NavigationHandle* new_navigation); |
| 268 | 293 |
| 269 void OnTimingUpdated(content::RenderFrameHost*, | 294 void OnTimingUpdated(content::RenderFrameHost*, |
| 270 const PageLoadTiming& timing, | 295 const PageLoadTiming& timing, |
| 271 const PageLoadMetadata& metadata); | 296 const PageLoadMetadata& metadata); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 295 | 320 |
| 296 // Has the MWCO observed at least one navigation? | 321 // Has the MWCO observed at least one navigation? |
| 297 bool has_navigated_; | 322 bool has_navigated_; |
| 298 | 323 |
| 299 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 324 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
| 300 }; | 325 }; |
| 301 | 326 |
| 302 } // namespace page_load_metrics | 327 } // namespace page_load_metrics |
| 303 | 328 |
| 304 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ | 329 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| OLD | NEW |