| 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_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE
RVER_H_ | 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE
RVER_H_ |
| 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE
RVER_H_ | 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE
RVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" | |
| 12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 13 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" | 12 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" |
| 14 #include "components/page_load_metrics/common/page_load_timing.h" | 13 #include "components/page_load_metrics/common/page_load_timing.h" |
| 15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 18 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 19 | 18 |
| 20 class PageLoadMetricsObserverTest; | 19 class PageLoadMetricsObserverTest; |
| 21 | 20 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const char kHistogramFirstContentfulPaintHigh[] = | 65 const char kHistogramFirstContentfulPaintHigh[] = |
| 67 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock"; | 66 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock"; |
| 68 const char kHistogramFirstContentfulPaintLow[] = | 67 const char kHistogramFirstContentfulPaintLow[] = |
| 69 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock"; | 68 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock"; |
| 70 | 69 |
| 71 const char kHistogramFirstBackground[] = | 70 const char kHistogramFirstBackground[] = |
| 72 "PageLoad.Timing2.NavigationToFirstBackground"; | 71 "PageLoad.Timing2.NavigationToFirstBackground"; |
| 73 const char kHistogramFirstForeground[] = | 72 const char kHistogramFirstForeground[] = |
| 74 "PageLoad.Timing2.NavigationToFirstForeground"; | 73 "PageLoad.Timing2.NavigationToFirstForeground"; |
| 75 | 74 |
| 75 const char kHistogramBackgroundBeforePaint[] = |
| 76 "PageLoad.Timing2.NavigationToFirstBackground.AfterCommit.BeforePaint"; |
| 77 const char kHistogramBackgroundBeforeCommit[] = |
| 78 "PageLoad.Timing2.NavigationToFirstBackground.BeforeCommit"; |
| 79 |
| 76 const char kProvisionalEvents[] = "PageLoad.Events.Provisional"; | 80 const char kProvisionalEvents[] = "PageLoad.Events.Provisional"; |
| 77 const char kCommittedEvents[] = "PageLoad.Events.Committed"; | 81 const char kCommittedEvents[] = "PageLoad.Events.Committed"; |
| 78 const char kBackgroundProvisionalEvents[] = | 82 const char kBackgroundProvisionalEvents[] = |
| 79 "PageLoad.Events.Provisional.Background"; | 83 "PageLoad.Events.Provisional.Background"; |
| 80 const char kBackgroundCommittedEvents[] = | 84 const char kBackgroundCommittedEvents[] = |
| 81 "PageLoad.Events.Committed.Background"; | 85 "PageLoad.Events.Committed.Background"; |
| 82 | 86 |
| 83 const char kErrorEvents[] = "PageLoad.Events.InternalError"; | 87 const char kErrorEvents[] = "PageLoad.Events.InternalError"; |
| 84 | 88 |
| 85 const char kRapporMetricsNameCoarseTiming[] = | 89 const char kRapporMetricsNameCoarseTiming[] = |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // Returns true if the timing was successfully updated. | 219 // Returns true if the timing was successfully updated. |
| 216 bool UpdateTiming(const PageLoadTiming& timing); | 220 bool UpdateTiming(const PageLoadTiming& timing); |
| 217 void RecordProvisionalEvent(ProvisionalLoadEvent event); | 221 void RecordProvisionalEvent(ProvisionalLoadEvent event); |
| 218 void RecordCommittedEvent(CommittedRelevantLoadEvent event, | 222 void RecordCommittedEvent(CommittedRelevantLoadEvent event, |
| 219 bool backgrounded); | 223 bool backgrounded); |
| 220 bool HasBackgrounded(); | 224 bool HasBackgrounded(); |
| 221 | 225 |
| 222 void set_renderer_tracked(bool renderer_tracked); | 226 void set_renderer_tracked(bool renderer_tracked); |
| 223 bool renderer_tracked() { return renderer_tracked_; } | 227 bool renderer_tracked() { return renderer_tracked_; } |
| 224 | 228 |
| 229 const base::TimeTicks& abort_time() { return abort_time_; } |
| 230 |
| 225 void AddObserver(scoped_ptr<PageLoadMetricsObserver> observer); | 231 void AddObserver(scoped_ptr<PageLoadMetricsObserver> observer); |
| 226 | 232 |
| 233 // If the user performs some abort-like action while we are tracking this page |
| 234 // load, notify the tracker. Note that we may not classify this as an abort if |
| 235 // we've already performed a first paint. |
| 236 void NotifyAbort(UserAbortType abort_type, const base::TimeTicks& timestamp); |
| 237 void UpdateAbort(UserAbortType abort_type, const base::TimeTicks& timestamp); |
| 238 |
| 227 private: | 239 private: |
| 228 PageLoadExtraInfo GetPageLoadMetricsInfo(); | 240 PageLoadExtraInfo GetPageLoadMetricsInfo(); |
| 229 // Only valid to call post-commit. | 241 // Only valid to call post-commit. |
| 230 const GURL& committed_url(); | 242 const GURL& committed_url(); |
| 231 | 243 |
| 232 base::TimeDelta GetBackgroundDelta(); | 244 void RecordTimingHistograms(const PageLoadExtraInfo& info); |
| 233 void RecordTimingHistograms(); | 245 void RecordRappor(const PageLoadExtraInfo& info); |
| 234 void RecordRappor(); | |
| 235 | 246 |
| 236 // Whether the renderer should be sending timing IPCs to this page load. | 247 // Whether the renderer should be sending timing IPCs to this page load. |
| 237 bool renderer_tracked_; | 248 bool renderer_tracked_; |
| 238 | 249 |
| 239 bool has_commit_; | 250 bool has_commit_; |
| 240 | 251 |
| 241 // The navigation start in TimeTicks, not the wall time reported by Blink. | 252 // The navigation start in TimeTicks, not the wall time reported by Blink. |
| 242 const base::TimeTicks navigation_start_; | 253 const base::TimeTicks navigation_start_; |
| 243 | 254 |
| 255 // Will be ABORT_NONE if we have not aborted this load yet. Otherwise will |
| 256 // be the first abort action the user performed. |
| 257 UserAbortType abort_type_; |
| 258 base::TimeTicks abort_time_; |
| 259 |
| 244 // We record separate metrics for events that occur after a background, | 260 // We record separate metrics for events that occur after a background, |
| 245 // because metrics like layout/paint are delayed artificially | 261 // because metrics like layout/paint are delayed artificially |
| 246 // when they occur in the background. | 262 // when they occur in the background. |
| 247 base::TimeTicks background_time_; | 263 base::TimeTicks background_time_; |
| 248 base::TimeTicks foreground_time_; | 264 base::TimeTicks foreground_time_; |
| 249 bool started_in_foreground_; | 265 bool started_in_foreground_; |
| 250 | 266 |
| 251 PageLoadTiming timing_; | 267 PageLoadTiming timing_; |
| 252 GURL url_; | 268 GURL url_; |
| 253 | 269 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 278 | 294 |
| 279 // content::WebContentsObserver implementation: | 295 // content::WebContentsObserver implementation: |
| 280 bool OnMessageReceived(const IPC::Message& message, | 296 bool OnMessageReceived(const IPC::Message& message, |
| 281 content::RenderFrameHost* render_frame_host) override; | 297 content::RenderFrameHost* render_frame_host) override; |
| 282 void DidStartNavigation( | 298 void DidStartNavigation( |
| 283 content::NavigationHandle* navigation_handle) override; | 299 content::NavigationHandle* navigation_handle) override; |
| 284 void DidFinishNavigation( | 300 void DidFinishNavigation( |
| 285 content::NavigationHandle* navigation_handle) override; | 301 content::NavigationHandle* navigation_handle) override; |
| 286 void DidRedirectNavigation( | 302 void DidRedirectNavigation( |
| 287 content::NavigationHandle* navigation_handle) override; | 303 content::NavigationHandle* navigation_handle) override; |
| 288 | 304 void NavigationStopped() override; |
| 289 void WasShown() override; | 305 void WasShown() override; |
| 290 void WasHidden() override; | 306 void WasHidden() override; |
| 291 | |
| 292 void RenderProcessGone(base::TerminationStatus status) override; | 307 void RenderProcessGone(base::TerminationStatus status) override; |
| 293 | 308 |
| 294 private: | 309 private: |
| 295 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 310 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
| 296 | 311 |
| 312 // Notify all loads, provisional and committed, that we performed an action |
| 313 // that might abort them. |
| 314 void NotifyAbortAllLoads(UserAbortType abort_type); |
| 315 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, |
| 316 const base::TimeTicks& timestamp); |
| 317 |
| 297 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); | 318 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); |
| 298 | 319 |
| 299 // True if the web contents is currently in the foreground. | 320 // True if the web contents is currently in the foreground. |
| 300 bool in_foreground_; | 321 bool in_foreground_; |
| 301 | 322 |
| 302 // The PageLoadTrackers must be deleted before the |embedded_interface_|, | 323 // The PageLoadTrackers must be deleted before the |embedded_interface_|, |
| 303 // because they hold a pointer to the |embedder_interface_|. | 324 // because they hold a pointer to the |embedder_interface_|. |
| 304 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; | 325 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; |
| 305 | 326 |
| 306 // This map tracks all of the navigations ongoing that are not committed | 327 // This map tracks all of the navigations ongoing that are not committed |
| 307 // yet. Once a navigation is committed, it moves from the map to | 328 // yet. Once a navigation is committed, it moves from the map to |
| 308 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | 329 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
| 309 // valid until commit time, when we remove it from the map. | 330 // valid until commit time, when we remove it from the map. |
| 310 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> | 331 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> |
| 311 provisional_loads_; | 332 provisional_loads_; |
| 333 // Tracks aborted provisional loads for a little bit longer than usual (one |
| 334 // more navigation commit at the max), in order to better understand how the |
| 335 // navigation failed. This is because most provisional loads are destroyed and |
| 336 // vanish before we get signal about what caused the abort (new navigation, |
| 337 // stop button, etc.). |
| 338 std::vector<scoped_ptr<PageLoadTracker>> aborted_provisional_loads_; |
| 312 scoped_ptr<PageLoadTracker> committed_load_; | 339 scoped_ptr<PageLoadTracker> committed_load_; |
| 313 | 340 |
| 314 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 341 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
| 315 }; | 342 }; |
| 316 | 343 |
| 317 } // namespace page_load_metrics | 344 } // namespace page_load_metrics |
| 318 | 345 |
| 319 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O
BSERVER_H_ | 346 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O
BSERVER_H_ |
| OLD | NEW |