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> |
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 Loading... |
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 Loading... |
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; | 226 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; |
220 | 227 |
221 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | 228 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
222 }; | 229 }; |
223 | 230 |
224 // MetricsWebContentsObserver tracks page loads and loading metrics | 231 // MetricsWebContentsObserver tracks page loads and loading metrics |
225 // related data based on IPC messages received from a | 232 // related data based on IPC messages received from a |
226 // MetricsRenderFrameObserver. | 233 // MetricsRenderFrameObserver. |
227 class MetricsWebContentsObserver | 234 class MetricsWebContentsObserver |
228 : public content::WebContentsObserver, | 235 : public content::WebContentsObserver, |
229 public content::WebContentsUserData<MetricsWebContentsObserver> { | 236 public content::WebContentsUserData<MetricsWebContentsObserver>, |
| 237 public content::RenderWidgetHost::InputEventObserver { |
230 public: | 238 public: |
231 // Note that the returned metrics is owned by the web contents. | 239 // Note that the returned metrics is owned by the web contents. |
232 static MetricsWebContentsObserver* CreateForWebContents( | 240 static MetricsWebContentsObserver* CreateForWebContents( |
233 content::WebContents* web_contents, | 241 content::WebContents* web_contents, |
234 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 242 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
235 MetricsWebContentsObserver( | 243 MetricsWebContentsObserver( |
236 content::WebContents* web_contents, | 244 content::WebContents* web_contents, |
237 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 245 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
238 ~MetricsWebContentsObserver() override; | 246 ~MetricsWebContentsObserver() override; |
239 | 247 |
240 // content::WebContentsObserver implementation: | 248 // content::WebContentsObserver implementation: |
241 bool OnMessageReceived(const IPC::Message& message, | 249 bool OnMessageReceived(const IPC::Message& message, |
242 content::RenderFrameHost* render_frame_host) override; | 250 content::RenderFrameHost* render_frame_host) override; |
243 void DidStartNavigation( | 251 void DidStartNavigation( |
244 content::NavigationHandle* navigation_handle) override; | 252 content::NavigationHandle* navigation_handle) override; |
245 void DidFinishNavigation( | 253 void DidFinishNavigation( |
246 content::NavigationHandle* navigation_handle) override; | 254 content::NavigationHandle* navigation_handle) override; |
247 void DidRedirectNavigation( | 255 void DidRedirectNavigation( |
248 content::NavigationHandle* navigation_handle) override; | 256 content::NavigationHandle* navigation_handle) override; |
249 void NavigationStopped() override; | 257 void NavigationStopped() override; |
| 258 void OnInputEvent(const blink::WebInputEvent& event) override; |
250 void WasShown() override; | 259 void WasShown() override; |
251 void WasHidden() override; | 260 void WasHidden() override; |
252 void RenderProcessGone(base::TerminationStatus status) override; | 261 void RenderProcessGone(base::TerminationStatus status) override; |
| 262 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 263 content::RenderViewHost* new_host) override; |
253 | 264 |
254 private: | 265 private: |
255 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 266 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
256 | 267 |
257 // Notify all loads, provisional and committed, that we performed an action | 268 // Notify all loads, provisional and committed, that we performed an action |
258 // that might abort them. | 269 // that might abort them. |
259 void NotifyAbortAllLoads(UserAbortType abort_type); | 270 void NotifyAbortAllLoads(UserAbortType abort_type); |
260 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, | 271 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, |
261 base::TimeTicks timestamp); | 272 base::TimeTicks timestamp); |
| 273 |
| 274 // Register / Unregister input event callback to given RenderViewHost |
| 275 void RegisterInputEventObserver(content::RenderViewHost* host); |
| 276 void UnregisterInputEventObserver(content::RenderViewHost* host); |
| 277 |
262 // Notify aborted provisional loads that a new navigation occurred. This is | 278 // Notify aborted provisional loads that a new navigation occurred. This is |
263 // used for more consistent attribution tracking for aborted provisional | 279 // used for more consistent attribution tracking for aborted provisional |
264 // loads. This method returns the provisional load that was likely aborted by | 280 // loads. This method returns the provisional load that was likely aborted |
265 // this navigation, to help instantiate the new PageLoadTracker. | 281 // by this navigation, to help instantiate the new PageLoadTracker. |
266 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( | 282 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( |
267 content::NavigationHandle* new_navigation); | 283 content::NavigationHandle* new_navigation); |
268 | 284 |
269 void OnTimingUpdated(content::RenderFrameHost*, | 285 void OnTimingUpdated(content::RenderFrameHost*, |
270 const PageLoadTiming& timing, | 286 const PageLoadTiming& timing, |
271 const PageLoadMetadata& metadata); | 287 const PageLoadMetadata& metadata); |
272 | 288 |
273 // True if the web contents is currently in the foreground. | 289 // True if the web contents is currently in the foreground. |
274 bool in_foreground_; | 290 bool in_foreground_; |
275 | 291 |
276 // The PageLoadTrackers must be deleted before the |embedded_interface_|, | 292 // The PageLoadTrackers must be deleted before the |embedded_interface_|, |
277 // because they hold a pointer to the |embedder_interface_|. | 293 // because they hold a pointer to the |embedder_interface_|. |
278 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; | 294 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; |
279 | 295 |
280 // This map tracks all of the navigations ongoing that are not committed | 296 // 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 | 297 // yet. Once a navigation is committed, it moves from the map to |
282 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | 298 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
283 // valid until commit time, when we remove it from the map. | 299 // valid until commit time, when we remove it from the map. |
284 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> | 300 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> |
285 provisional_loads_; | 301 provisional_loads_; |
286 | 302 |
287 // Tracks aborted provisional loads for a little bit longer than usual (one | 303 // 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 | 304 // 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 | 305 // navigation failed. This is because most provisional loads are destroyed |
290 // vanish before we get signal about what caused the abort (new navigation, | 306 // and vanish before we get signal about what caused the abort (new |
291 // stop button, etc.). | 307 // navigation, stop button, etc.). |
292 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 308 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
293 | 309 |
294 std::unique_ptr<PageLoadTracker> committed_load_; | 310 std::unique_ptr<PageLoadTracker> committed_load_; |
295 | 311 |
296 // Has the MWCO observed at least one navigation? | 312 // Has the MWCO observed at least one navigation? |
297 bool has_navigated_; | 313 bool has_navigated_; |
298 | 314 |
299 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 315 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
300 }; | 316 }; |
301 | 317 |
302 } // namespace page_load_metrics | 318 } // namespace page_load_metrics |
303 | 319 |
304 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ | 320 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |