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 "base/containers/scoped_ptr_map.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
10 #include "components/page_load_metrics/common/page_load_timing.h" | 11 #include "components/page_load_metrics/common/page_load_timing.h" |
11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
| 17 |
16 class NavigationHandle; | 18 class NavigationHandle; |
17 class RenderFrameHost; | 19 class RenderFrameHost; |
| 20 |
18 } // namespace content | 21 } // namespace content |
19 | 22 |
20 namespace IPC { | 23 namespace IPC { |
| 24 |
21 class Message; | 25 class Message; |
| 26 |
22 } // namespace IPC | 27 } // namespace IPC |
23 | 28 |
24 namespace page_load_metrics { | 29 namespace page_load_metrics { |
25 | 30 |
| 31 class PageLoadTracker { |
| 32 public: |
| 33 PageLoadTracker(bool in_foreground); |
| 34 ~PageLoadTracker(); |
| 35 void Commit(); |
| 36 // Either the onload handler was called, or the page load failed. |
| 37 void Finish(); |
| 38 void WebContentsHidden(); |
| 39 |
| 40 // Returns true if the timing was successfully updated. |
| 41 bool UpdateTiming(const PageLoadTiming& timing); |
| 42 |
| 43 private: |
| 44 void RecordTimingHistograms(); |
| 45 |
| 46 bool has_commit_; |
| 47 bool has_finished_; |
| 48 |
| 49 // True if the web contents stayed in the foreground for the entire |
| 50 // page load. We record separate metrics for any web contents that have been |
| 51 // backgrounded, because metrics like layout/paint are delayed artificially |
| 52 // when they occur in the bacground. |
| 53 bool page_load_stayed_in_foreground_; |
| 54 |
| 55 PageLoadTiming timing_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
| 58 }; |
| 59 |
26 // MetricsWebContentsObserver logs page load UMA metrics based on | 60 // MetricsWebContentsObserver logs page load UMA metrics based on |
27 // IPC messages received from a MetricsRenderFrameObserver. | 61 // IPC messages received from a MetricsRenderFrameObserver. |
28 class MetricsWebContentsObserver | 62 class MetricsWebContentsObserver |
29 : public content::WebContentsObserver, | 63 : public content::WebContentsObserver, |
30 public content::WebContentsUserData<MetricsWebContentsObserver> { | 64 public content::WebContentsUserData<MetricsWebContentsObserver> { |
31 public: | 65 public: |
32 ~MetricsWebContentsObserver() override; | 66 ~MetricsWebContentsObserver() override; |
33 | 67 |
34 // content::WebContentsObserver implementation: | 68 // content::WebContentsObserver implementation: |
35 bool OnMessageReceived(const IPC::Message& message, | 69 bool OnMessageReceived(const IPC::Message& message, |
36 content::RenderFrameHost* render_frame_host) override; | 70 content::RenderFrameHost* render_frame_host) override; |
37 void DidFinishNavigation( | 71 void DidFinishNavigation( |
38 content::NavigationHandle* navigation_handle) override; | 72 content::NavigationHandle* navigation_handle) override; |
39 void RenderProcessGone(base::TerminationStatus status) override; | 73 void DidStartNavigation( |
| 74 content::NavigationHandle* navigation_handle) override; |
| 75 |
| 76 // This method is called after the onload event is dispatched. |
| 77 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 78 const GURL& validated_url) override; |
| 79 void DidFailLoad(content::RenderFrameHost* render_frame_host, |
| 80 const GURL& validated_url, |
| 81 int error_code, |
| 82 const base::string16& error_description, |
| 83 bool was_ignored_by_handler) override; |
| 84 |
| 85 void WasShown() override; |
| 86 void WasHidden() override; |
40 | 87 |
41 private: | 88 private: |
42 explicit MetricsWebContentsObserver(content::WebContents* web_contents); | 89 explicit MetricsWebContentsObserver(content::WebContents* web_contents); |
43 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 90 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
44 friend class MetricsWebContentsObserverTest; | 91 friend class MetricsWebContentsObserverTest; |
45 | 92 |
46 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); | 93 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); |
47 void RecordTimingHistograms(); | |
48 | 94 |
49 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); | 95 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); |
50 | 96 |
51 // Will be null before any navigations have committed. When a navigation | 97 // True if the web contents is currently in the foreground. |
52 // commits we will initialize this as empty. | 98 bool in_foreground_; |
53 scoped_ptr<PageLoadTiming> current_timing_; | 99 |
| 100 // This map tracks all of the navigations ongoing that are not committed |
| 101 // yet. Once a navigation is committed, it moves from the map to |
| 102 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
| 103 // valid until commit time, when we remove it from the map. |
| 104 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> |
| 105 provisional_loads_; |
| 106 scoped_ptr<PageLoadTracker> committed_load_; |
54 | 107 |
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 108 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
56 }; | 109 }; |
57 | 110 |
58 } // namespace page_load_metrics | 111 } // namespace page_load_metrics |
59 | 112 |
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O
BSERVER_H_ | 113 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O
BSERVER_H_ |
OLD | NEW |