Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.h

Issue 1984173002: Log First User Interaction in Page Load Metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only record user interaction after first paint Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" 14 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
15 #include "components/page_load_metrics/common/page_load_timing.h" 15 #include "components/page_load_metrics/common/page_load_timing.h"
16 #include "content/public/browser/render_widget_host.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h" 19 #include "content/public/browser/web_contents_user_data.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h"
20 22
21 namespace content { 23 namespace content {
22 class NavigationHandle; 24 class NavigationHandle;
23 class RenderFrameHost; 25 class RenderFrameHost;
24 } // namespace content 26 } // namespace content
25 27
26 namespace IPC { 28 namespace IPC {
27 class Message; 29 class Message;
28 } // namespace IPC 30 } // namespace IPC
29 31
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // cc file for details). We use this error counter to understand how often it 82 // cc file for details). We use this error counter to understand how often it
81 // happens. 83 // happens.
82 ERR_ABORT_BEFORE_NAVIGATION_START, 84 ERR_ABORT_BEFORE_NAVIGATION_START,
83 85
84 // A new navigation triggers abort updates in multiple trackers in 86 // A new navigation triggers abort updates in multiple trackers in
85 // |aborted_provisional_loads_|, when usually there should only be one (the 87 // |aborted_provisional_loads_|, when usually there should only be one (the
86 // navigation that just aborted because of this one). If this happens, the 88 // navigation that just aborted because of this one). If this happens, the
87 // latest aborted load is used to track the chain size. 89 // latest aborted load is used to track the chain size.
88 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS, 90 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS,
89 91
92 // Receives user input before navigation start
93 ERR_USER_INPUT_WITH_NO_RELEVANT_LOAD,
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;
100 virtual void RegisterObservers(PageLoadTracker* metrics) = 0; 105 virtual void RegisterObservers(PageLoadTracker* metrics) = 0;
101 }; 106 };
(...skipping 14 matching lines...) Expand all
116 content::NavigationHandle* navigation_handle, 121 content::NavigationHandle* navigation_handle,
117 int aborted_chain_size, 122 int aborted_chain_size,
118 int aborted_chain_size_same_url); 123 int aborted_chain_size_same_url);
119 ~PageLoadTracker(); 124 ~PageLoadTracker();
120 void Redirect(content::NavigationHandle* navigation_handle); 125 void Redirect(content::NavigationHandle* navigation_handle);
121 void Commit(content::NavigationHandle* navigation_handle); 126 void Commit(content::NavigationHandle* navigation_handle);
122 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle); 127 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle);
123 void WebContentsHidden(); 128 void WebContentsHidden();
124 void WebContentsShown(); 129 void WebContentsShown();
125 130
131 void OnInputEvent(const blink::WebInputEvent& event);
132
126 // Returns true if the timing was successfully updated. 133 // Returns true if the timing was successfully updated.
127 bool UpdateTiming(const PageLoadTiming& timing, 134 bool UpdateTiming(const PageLoadTiming& timing,
128 const PageLoadMetadata& metadata); 135 const PageLoadMetadata& metadata);
129 136
130 void set_renderer_tracked(bool renderer_tracked); 137 void set_renderer_tracked(bool renderer_tracked);
131 bool renderer_tracked() const { return renderer_tracked_; } 138 bool renderer_tracked() const { return renderer_tracked_; }
132 139
133 int aborted_chain_size() const { return aborted_chain_size_; } 140 int aborted_chain_size() const { return aborted_chain_size_; }
134 int aborted_chain_size_same_url() const { 141 int aborted_chain_size_same_url() const {
135 return aborted_chain_size_same_url_; 142 return aborted_chain_size_same_url_;
(...skipping 21 matching lines...) Expand all
157 164
158 // Only valid to call post-commit. 165 // Only valid to call post-commit.
159 const GURL& committed_url() const { 166 const GURL& committed_url() const {
160 DCHECK(!commit_time_.is_null()); 167 DCHECK(!commit_time_.is_null());
161 return url_; 168 return url_;
162 } 169 }
163 170
164 private: 171 private:
165 PageLoadExtraInfo GetPageLoadMetricsInfo(); 172 PageLoadExtraInfo GetPageLoadMetricsInfo();
166 173
167 void UpdateAbortInternal(UserAbortType abort_type, 174 void UpdateAbortInternal(UserAbortType abort_type, base::TimeTicks timestamp);
168 base::TimeTicks timestamp);
169 175
170 // If |final_navigation| is null, then this is an "unparented" abort chain, 176 // 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 177 // and represents a sequence of provisional aborts that never ends with a
172 // committed load. 178 // committed load.
173 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); 179 void LogAbortChainHistograms(content::NavigationHandle* final_navigation);
174 180
175 // Whether the renderer should be sending timing IPCs to this page load. 181 // Whether the renderer should be sending timing IPCs to this page load.
176 bool renderer_tracked_; 182 bool renderer_tracked_;
177 183
178 // The navigation start in TimeTicks, not the wall time reported by Blink. 184 // The navigation start in TimeTicks, not the wall time reported by Blink.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; 225 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_;
220 226
221 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); 227 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
222 }; 228 };
223 229
224 // MetricsWebContentsObserver tracks page loads and loading metrics 230 // MetricsWebContentsObserver tracks page loads and loading metrics
225 // related data based on IPC messages received from a 231 // related data based on IPC messages received from a
226 // MetricsRenderFrameObserver. 232 // MetricsRenderFrameObserver.
227 class MetricsWebContentsObserver 233 class MetricsWebContentsObserver
228 : public content::WebContentsObserver, 234 : public content::WebContentsObserver,
229 public content::WebContentsUserData<MetricsWebContentsObserver> { 235 public content::WebContentsUserData<MetricsWebContentsObserver>,
236 public content::RenderWidgetHost::InputEventObserver {
230 public: 237 public:
231 // Note that the returned metrics is owned by the web contents. 238 // Note that the returned metrics is owned by the web contents.
232 static MetricsWebContentsObserver* CreateForWebContents( 239 static MetricsWebContentsObserver* CreateForWebContents(
233 content::WebContents* web_contents, 240 content::WebContents* web_contents,
234 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 241 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
235 MetricsWebContentsObserver( 242 MetricsWebContentsObserver(
236 content::WebContents* web_contents, 243 content::WebContents* web_contents,
237 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 244 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
238 ~MetricsWebContentsObserver() override; 245 ~MetricsWebContentsObserver() override;
239 246
240 // content::WebContentsObserver implementation: 247 // content::WebContentsObserver implementation:
241 bool OnMessageReceived(const IPC::Message& message, 248 bool OnMessageReceived(const IPC::Message& message,
242 content::RenderFrameHost* render_frame_host) override; 249 content::RenderFrameHost* render_frame_host) override;
243 void DidStartNavigation( 250 void DidStartNavigation(
244 content::NavigationHandle* navigation_handle) override; 251 content::NavigationHandle* navigation_handle) override;
245 void DidFinishNavigation( 252 void DidFinishNavigation(
246 content::NavigationHandle* navigation_handle) override; 253 content::NavigationHandle* navigation_handle) override;
247 void DidRedirectNavigation( 254 void DidRedirectNavigation(
248 content::NavigationHandle* navigation_handle) override; 255 content::NavigationHandle* navigation_handle) override;
249 void NavigationStopped() override; 256 void NavigationStopped() override;
257 bool OnInputEvent(const blink::WebInputEvent& event) override;
250 void WasShown() override; 258 void WasShown() override;
251 void WasHidden() override; 259 void WasHidden() override;
252 void RenderProcessGone(base::TerminationStatus status) override; 260 void RenderProcessGone(base::TerminationStatus status) override;
261 void RenderViewHostChanged(content::RenderViewHost* old_host,
262 content::RenderViewHost* new_host) override;
253 263
254 private: 264 private:
255 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 265 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
256 266
257 // Notify all loads, provisional and committed, that we performed an action 267 // Notify all loads, provisional and committed, that we performed an action
258 // that might abort them. 268 // that might abort them.
259 void NotifyAbortAllLoads(UserAbortType abort_type); 269 void NotifyAbortAllLoads(UserAbortType abort_type);
260 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, 270 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
261 base::TimeTicks timestamp); 271 base::TimeTicks timestamp);
272
273 // Register / Unregister input event callback to given RenderViewHost
274 void RegisterInputEventObserver(content::RenderViewHost* host);
275 void UnregisterInputEventObserver(content::RenderViewHost* host);
276
262 // Notify aborted provisional loads that a new navigation occurred. This is 277 // Notify aborted provisional loads that a new navigation occurred. This is
263 // used for more consistent attribution tracking for aborted provisional 278 // used for more consistent attribution tracking for aborted provisional
264 // loads. This method returns the provisional load that was likely aborted by 279 // loads. This method returns the provisional load that was likely aborted
265 // this navigation, to help instantiate the new PageLoadTracker. 280 // by this navigation, to help instantiate the new PageLoadTracker.
266 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( 281 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation(
267 content::NavigationHandle* new_navigation); 282 content::NavigationHandle* new_navigation);
268 283
269 void OnTimingUpdated(content::RenderFrameHost*, 284 void OnTimingUpdated(content::RenderFrameHost*,
270 const PageLoadTiming& timing, 285 const PageLoadTiming& timing,
271 const PageLoadMetadata& metadata); 286 const PageLoadMetadata& metadata);
272 287
273 // True if the web contents is currently in the foreground. 288 // True if the web contents is currently in the foreground.
274 bool in_foreground_; 289 bool in_foreground_;
275 290
276 // The PageLoadTrackers must be deleted before the |embedded_interface_|, 291 // The PageLoadTrackers must be deleted before the |embedded_interface_|,
277 // because they hold a pointer to the |embedder_interface_|. 292 // because they hold a pointer to the |embedder_interface_|.
278 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 293 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
279 294
280 // This map tracks all of the navigations ongoing that are not committed 295 // This map tracks all of the navigations ongoing that are not committed
281 // yet. Once a navigation is committed, it moves from the map to 296 // yet. Once a navigation is committed, it moves from the map to
282 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 297 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
283 // valid until commit time, when we remove it from the map. 298 // valid until commit time, when we remove it from the map.
284 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> 299 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>>
285 provisional_loads_; 300 provisional_loads_;
286 301
287 // Tracks aborted provisional loads for a little bit longer than usual (one 302 // Tracks aborted provisional loads for a little bit longer than usual (one
288 // more navigation commit at the max), in order to better understand how the 303 // more navigation commit at the max), in order to better understand how the
289 // navigation failed. This is because most provisional loads are destroyed and 304 // navigation failed. This is because most provisional loads are destroyed
290 // vanish before we get signal about what caused the abort (new navigation, 305 // and vanish before we get signal about what caused the abort (new
291 // stop button, etc.). 306 // navigation, stop button, etc.).
292 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; 307 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
293 308
294 std::unique_ptr<PageLoadTracker> committed_load_; 309 std::unique_ptr<PageLoadTracker> committed_load_;
295 310
296 // Has the MWCO observed at least one navigation? 311 // Has the MWCO observed at least one navigation?
297 bool has_navigated_; 312 bool has_navigated_;
298 313
299 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 314 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
300 }; 315 };
301 316
302 } // namespace page_load_metrics 317 } // namespace page_load_metrics
303 318
304 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 319 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698