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/containers/scoped_ptr_map.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "components/page_load_metrics/common/page_load_timing.h" | 11 #include "components/page_load_metrics/common/page_load_timing.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
14 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class NavigationHandle; | 18 class NavigationHandle; |
19 class RenderFrameHost; | 19 class RenderFrameHost; |
20 } // namespace content | 20 } // namespace content |
21 | 21 |
22 namespace IPC { | 22 namespace IPC { |
23 class Message; | 23 class Message; |
24 } // namespace IPC | 24 } // namespace IPC |
25 | 25 |
26 namespace page_load_metrics { | 26 namespace page_load_metrics { |
27 | 27 |
28 // NOTE: Some of these histograms are separated into a separate histogram | |
29 // specified by the ".Background" suffix. For these events, we put them into the | |
30 // background histogram if the web contents was ever in the background from | |
31 // navigation start to the event in question. | |
32 | |
28 // If you add elements from this enum, make sure you update the enum | 33 // If you add elements from this enum, make sure you update the enum |
Alexei Svitkine (slow)
2015/10/16 16:48:54
Nit: "from" -> "to"
Charlie Harrison
2015/10/16 17:29:55
Done.
| |
29 // value in histograms.xml. Only add elements to the end to prevent | 34 // value in histograms.xml. Only add elements to the end to prevent |
30 // inconsistencies between versions. | 35 // inconsistencies between versions. |
31 enum PageLoadEvent { | 36 // |
32 PAGE_LOAD_STARTED, | 37 // ProvisionalLoadEvents count all main frame navigations before they commit. |
Alexei Svitkine (slow)
2015/10/16 16:48:53
Nit: Switch the order of the two paragraphs. I thi
Charlie Harrison
2015/10/16 17:29:55
Done.
| |
38 // The events in this enum are all disjoint, and summing them yields the total | |
39 // number of main frame provisional loads. | |
40 enum ProvisionalLoadEvent { | |
41 // This case occurs when the NavigationHandle finishes and reports | |
42 // !HasCommitted(), but reports no net::Error. This should not occur | |
43 // pre-PlzNavigate, but afterwards it should represent the navigation stopped | |
44 // by the user before it was ready to commit. | |
45 PROVISIONAL_LOAD_STOPPED, | |
33 | 46 |
34 // A provisional load is a load before it commits, i.e. before it receives the | 47 // An aborted provisional load has error net::ERR_ABORTED. Note that this can |
35 // first bytes of the response body or knows the encoding of the response | 48 // come from some non user-initiated errors, such as downloads, or 204 |
36 // body. A load failed before it was committed for any reason, e.g. from a | 49 // responses. See crbug.com/542369. |
37 // user abort or a network timeout. | 50 PROVISIONAL_LOAD_ERR_ABORTED, |
38 PAGE_LOAD_FAILED_BEFORE_COMMIT, | |
39 | 51 |
40 // A subset of PAGE_LOAD_FAILED_BEFORE_COMMIT, this counts the | 52 // This event captures all the other ways a provisional load can fail. |
41 // specific failures due to user aborts. | 53 PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT, |
42 PAGE_LOAD_ABORTED_BEFORE_COMMIT, | 54 // Counts the number of successful commits. |
Alexei Svitkine (slow)
2015/10/16 16:48:53
Nit: Add an empty line above.
Charlie Harrison
2015/10/16 17:29:55
Done.
| |
43 | 55 PROVISIONAL_LOAD_COMMITTED, |
44 // When a load is aborted anytime before the page's first layout, we increase | |
45 // these counts. This includes all failed provisional loads. | |
46 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, | |
47 | |
48 // We increase this count if a page load successfully has a layout. | |
49 // Differentiate between loads that were backgrounded before first layout. | |
50 // Note that a load that is backgrounded, then foregrounded before first | |
51 // layout will still end up in the backgrounded bucket. | |
52 PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_FOREGROUND, | |
53 PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND, | |
54 | 56 |
55 // Add values before this final count. | 57 // Add values before this final count. |
56 PAGE_LOAD_LAST_ENTRY | 58 PROVISIONAL_LOAD_LAST_ENTRY |
59 }; | |
60 | |
61 // If you add elements from this enum, make sure you update the enum | |
Alexei Svitkine (slow)
2015/10/16 16:48:54
Nit: "from" -> "to"
Charlie Harrison
2015/10/16 17:29:55
Done.
| |
62 // value in histograms.xml. Only add elements to the end to prevent | |
63 // inconsistencies between versions. | |
64 // | |
65 // CommittedLoadEvents are events that occur on committed loads that we track. | |
66 // Note that we capture events only for committed loads that: | |
67 // - Are http/https. | |
68 // - Not same-page navigations. | |
69 // - Are not navigations to an error page. | |
70 // We only know these things about a navigation post-commit. | |
71 enum CommittedLoadEvent { | |
72 // When a load that eventually commits started. Note we can't log this until | |
73 // commit time, but it represents when the actual page load started. Thus, we | |
74 // only separate this into .Background when a page load starts backgrounded. | |
75 COMMITTED_LOAD_STARTED, | |
76 | |
77 // These two events are disjoint. Sum them to find the total number of | |
78 // committed loads that we end up tracking. | |
79 COMMITTED_LOAD_FAILED_BEFORE_FIRST_LAYOUT, | |
80 COMMITTED_LOAD_SUCCESSFUL_FIRST_LAYOUT, | |
81 | |
82 // TODO(csharrison) once first paint metrics are in place, add new events. | |
83 | |
84 // Add values before this final count. | |
85 COMMITTED_LOAD_LAST_ENTRY | |
86 }; | |
87 | |
88 // These errors are internal to the page_load_metrics subsystem and do not | |
89 // reflect actual errors that occur during a page load. | |
Alexei Svitkine (slow)
2015/10/16 16:48:53
Nit: Add the same comment about UMA histograms.xml
Charlie Harrison
2015/10/16 17:29:55
Done.
| |
90 enum InternalErrorLoadEvent { | |
91 // A timing IPC was sent from the renderer that did not line up with previous | |
92 // data we've received (i.e. navigation start is different or the timing | |
93 // struct is somehow invalid). This error can only occur once the IPC is | |
94 // vetted in other ways (see other errors). | |
95 ERR_BAD_TIMING_IPC, | |
96 | |
97 // The following IPCs are not mutually exclusive. | |
98 // | |
99 // We received an IPC when we weren't tracking a committed load. This will | |
100 // often happen if we get an IPC from a bad URL scheme (that is, the renderer | |
101 // sent us an IPC from a navigation we don't care about). | |
102 ERR_IPC_WITH_NO_COMMITTED_LOAD, | |
103 | |
104 // Received a notification from a frame that has been navigated away from. | |
105 ERR_IPC_FROM_WRONG_FRAME, | |
106 | |
107 // We received an IPC even through the last committed url from the browser | |
108 // was not http/s. This can happen with the renderer sending IPCs for the | |
109 // new tab page. This will often come paired with | |
110 // ERR_IPC_WITH_NO_COMMITTED_LOAD. | |
111 ERR_IPC_FROM_BAD_URL_SCHEME, | |
112 | |
113 // If we track a navigation, but the renderer sends us no IPCs. This could | |
114 // occur if the browser filters loads less aggressively than the renderer. | |
115 ERR_NO_IPCS_RECEIVED, | |
116 | |
117 // Add values before this final count. | |
118 ERR_LAST_ENTRY | |
57 }; | 119 }; |
58 | 120 |
59 class PageLoadTracker { | 121 class PageLoadTracker { |
60 public: | 122 public: |
61 explicit PageLoadTracker(bool in_foreground); | 123 explicit PageLoadTracker(bool in_foreground); |
62 ~PageLoadTracker(); | 124 ~PageLoadTracker(); |
63 void Commit(); | 125 void Commit(); |
64 void WebContentsHidden(); | 126 void WebContentsHidden(); |
127 void WebContentsShown(); | |
65 | 128 |
66 // Returns true if the timing was successfully updated. | 129 // Returns true if the timing was successfully updated. |
67 bool UpdateTiming(const PageLoadTiming& timing); | 130 bool UpdateTiming(const PageLoadTiming& timing); |
68 void RecordEvent(PageLoadEvent event); | 131 void RecordProvisionalEvent(ProvisionalLoadEvent event); |
132 void RecordCommittedEvent(CommittedLoadEvent event, bool backgrounded); | |
133 bool HasBackgrounded(); | |
69 | 134 |
70 private: | 135 private: |
71 void RecordTimingHistograms(); | 136 void RecordTimingHistograms(); |
72 | 137 |
73 bool has_commit_; | 138 bool has_commit_; |
74 | 139 |
75 // We record separate metrics for events that occur after a background, | 140 // We record separate metrics for events that occur after a background, |
76 // because metrics like layout/paint are delayed artificially | 141 // because metrics like layout/paint are delayed artificially |
77 // when they occur in the bacground. | 142 // when they occur in the background. |
78 base::TimeTicks background_time_; | 143 base::TimeTicks background_time_; |
144 base::TimeTicks foreground_time_; | |
79 bool started_in_foreground_; | 145 bool started_in_foreground_; |
80 | 146 |
81 PageLoadTiming timing_; | 147 PageLoadTiming timing_; |
82 | 148 |
83 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | 149 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
84 }; | 150 }; |
85 | 151 |
86 // MetricsWebContentsObserver logs page load UMA metrics based on | 152 // MetricsWebContentsObserver logs page load UMA metrics based on |
87 // IPC messages received from a MetricsRenderFrameObserver. | 153 // IPC messages received from a MetricsRenderFrameObserver. |
88 class MetricsWebContentsObserver | 154 class MetricsWebContentsObserver |
(...skipping 15 matching lines...) Expand all Loading... | |
104 | 170 |
105 void RenderProcessGone(base::TerminationStatus status) override; | 171 void RenderProcessGone(base::TerminationStatus status) override; |
106 | 172 |
107 private: | 173 private: |
108 explicit MetricsWebContentsObserver(content::WebContents* web_contents); | 174 explicit MetricsWebContentsObserver(content::WebContents* web_contents); |
109 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 175 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
110 friend class MetricsWebContentsObserverTest; | 176 friend class MetricsWebContentsObserverTest; |
111 | 177 |
112 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); | 178 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); |
113 | 179 |
114 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); | |
115 | |
116 // True if the web contents is currently in the foreground. | 180 // True if the web contents is currently in the foreground. |
117 bool in_foreground_; | 181 bool in_foreground_; |
118 | 182 |
119 // This map tracks all of the navigations ongoing that are not committed | 183 // This map tracks all of the navigations ongoing that are not committed |
120 // yet. Once a navigation is committed, it moves from the map to | 184 // yet. Once a navigation is committed, it moves from the map to |
121 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | 185 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
122 // valid until commit time, when we remove it from the map. | 186 // valid until commit time, when we remove it from the map. |
123 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> | 187 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> |
124 provisional_loads_; | 188 provisional_loads_; |
125 scoped_ptr<PageLoadTracker> committed_load_; | 189 scoped_ptr<PageLoadTracker> committed_load_; |
126 | 190 |
127 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 191 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
128 }; | 192 }; |
129 | 193 |
130 } // namespace page_load_metrics | 194 } // namespace page_load_metrics |
131 | 195 |
132 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ | 196 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ |
OLD | NEW |