Chromium Code Reviews| 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/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class NavigationHandle; | 23 class NavigationHandle; |
| 23 class RenderFrameHost; | 24 class RenderFrameHost; |
| 24 } // namespace content | 25 } // namespace content |
| 25 | 26 |
| 26 namespace IPC { | 27 namespace IPC { |
| 27 class Message; | 28 class Message; |
| 28 } // namespace IPC | 29 } // namespace IPC |
| 29 | 30 |
| (...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 | 81 // cc file for details). We use this error counter to understand how often it |
| 81 // happens. | 82 // happens. |
| 82 ERR_ABORT_BEFORE_NAVIGATION_START, | 83 ERR_ABORT_BEFORE_NAVIGATION_START, |
| 83 | 84 |
| 84 // A new navigation triggers abort updates in multiple trackers in | 85 // A new navigation triggers abort updates in multiple trackers in |
| 85 // |aborted_provisional_loads_|, when usually there should only be one (the | 86 // |aborted_provisional_loads_|, when usually there should only be one (the |
| 86 // navigation that just aborted because of this one). If this happens, the | 87 // navigation that just aborted because of this one). If this happens, the |
| 87 // latest aborted load is used to track the chain size. | 88 // latest aborted load is used to track the chain size. |
| 88 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS, | 89 ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS, |
| 89 | 90 |
| 91 // Receives user interaction before navigation start | |
| 92 ERR_USER_INTERACTION_WITH_NO_RELEVANT_LOAD, | |
| 93 | |
| 90 // Add values before this final count. | 94 // Add values before this final count. |
| 91 ERR_LAST_ENTRY | 95 ERR_LAST_ENTRY, |
| 92 }; | 96 }; |
| 93 | 97 |
| 94 // This class serves as a functional interface to various chrome// features. | 98 // This class serves as a functional interface to various chrome// features. |
| 95 // Impl version is defined in chrome/browser/page_load_metrics. | 99 // Impl version is defined in chrome/browser/page_load_metrics. |
| 96 class PageLoadMetricsEmbedderInterface { | 100 class PageLoadMetricsEmbedderInterface { |
| 97 public: | 101 public: |
| 98 virtual ~PageLoadMetricsEmbedderInterface() {} | 102 virtual ~PageLoadMetricsEmbedderInterface() {} |
| 99 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; | 103 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; |
| 100 virtual void RegisterObservers(PageLoadTracker* metrics) = 0; | 104 virtual void RegisterObservers(PageLoadTracker* metrics) = 0; |
| 101 }; | 105 }; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 116 content::NavigationHandle* navigation_handle, | 120 content::NavigationHandle* navigation_handle, |
| 117 int aborted_chain_size, | 121 int aborted_chain_size, |
| 118 int aborted_chain_size_same_url); | 122 int aborted_chain_size_same_url); |
| 119 ~PageLoadTracker(); | 123 ~PageLoadTracker(); |
| 120 void Redirect(content::NavigationHandle* navigation_handle); | 124 void Redirect(content::NavigationHandle* navigation_handle); |
| 121 void Commit(content::NavigationHandle* navigation_handle); | 125 void Commit(content::NavigationHandle* navigation_handle); |
| 122 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle); | 126 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle); |
| 123 void WebContentsHidden(); | 127 void WebContentsHidden(); |
| 124 void WebContentsShown(); | 128 void WebContentsShown(); |
| 125 | 129 |
| 130 void OnInputEvent(const blink::WebInputEvent& event); | |
| 131 | |
| 126 // Returns true if the timing was successfully updated. | 132 // Returns true if the timing was successfully updated. |
| 127 bool UpdateTiming(const PageLoadTiming& timing, | 133 bool UpdateTiming(const PageLoadTiming& timing, |
| 128 const PageLoadMetadata& metadata); | 134 const PageLoadMetadata& metadata); |
| 129 | 135 |
| 130 void set_renderer_tracked(bool renderer_tracked); | 136 void set_renderer_tracked(bool renderer_tracked); |
| 131 bool renderer_tracked() const { return renderer_tracked_; } | 137 bool renderer_tracked() const { return renderer_tracked_; } |
| 132 | 138 |
| 133 int aborted_chain_size() const { return aborted_chain_size_; } | 139 int aborted_chain_size() const { return aborted_chain_size_; } |
| 134 int aborted_chain_size_same_url() const { | 140 int aborted_chain_size_same_url() const { |
| 135 return aborted_chain_size_same_url_; | 141 return aborted_chain_size_same_url_; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 157 | 163 |
| 158 // Only valid to call post-commit. | 164 // Only valid to call post-commit. |
| 159 const GURL& committed_url() const { | 165 const GURL& committed_url() const { |
| 160 DCHECK(!commit_time_.is_null()); | 166 DCHECK(!commit_time_.is_null()); |
| 161 return url_; | 167 return url_; |
| 162 } | 168 } |
| 163 | 169 |
| 164 private: | 170 private: |
| 165 PageLoadExtraInfo GetPageLoadMetricsInfo(); | 171 PageLoadExtraInfo GetPageLoadMetricsInfo(); |
| 166 | 172 |
| 167 void UpdateAbortInternal(UserAbortType abort_type, | 173 void UpdateAbortInternal(UserAbortType abort_type, base::TimeTicks timestamp); |
| 168 base::TimeTicks timestamp); | |
| 169 | 174 |
| 170 // If |final_navigation| is null, then this is an "unparented" abort chain, | 175 // 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 | 176 // and represents a sequence of provisional aborts that never ends with a |
| 172 // committed load. | 177 // committed load. |
| 173 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); | 178 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); |
| 174 | 179 |
| 175 // Whether the renderer should be sending timing IPCs to this page load. | 180 // Whether the renderer should be sending timing IPCs to this page load. |
| 176 bool renderer_tracked_; | 181 bool renderer_tracked_; |
| 177 | 182 |
| 178 // The navigation start in TimeTicks, not the wall time reported by Blink. | 183 // The navigation start in TimeTicks, not the wall time reported by Blink. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 191 UserAbortType abort_type_; | 196 UserAbortType abort_type_; |
| 192 base::TimeTicks abort_time_; | 197 base::TimeTicks abort_time_; |
| 193 | 198 |
| 194 // We record separate metrics for events that occur after a background, | 199 // We record separate metrics for events that occur after a background, |
| 195 // because metrics like layout/paint are delayed artificially | 200 // because metrics like layout/paint are delayed artificially |
| 196 // when they occur in the background. | 201 // when they occur in the background. |
| 197 base::TimeTicks background_time_; | 202 base::TimeTicks background_time_; |
| 198 base::TimeTicks foreground_time_; | 203 base::TimeTicks foreground_time_; |
| 199 bool started_in_foreground_; | 204 bool started_in_foreground_; |
| 200 | 205 |
| 206 base::TimeTicks user_interaction_time_; | |
|
Bryan McQuade
2016/05/25 21:32:30
let's remove this (see related comment with more d
| |
| 207 | |
| 201 PageLoadTiming timing_; | 208 PageLoadTiming timing_; |
| 202 PageLoadMetadata metadata_; | 209 PageLoadMetadata metadata_; |
| 203 | 210 |
| 204 // This is a subtle member. If a provisional load A gets aborted by | 211 // This is a subtle member. If a provisional load A gets aborted by |
| 205 // provisional load B, which gets aborted by C that eventually commits, then | 212 // provisional load B, which gets aborted by C that eventually commits, then |
| 206 // there exists an abort chain of length 2, starting at A's navigation_start. | 213 // there exists an abort chain of length 2, starting at A's navigation_start. |
| 207 // This is useful because it allows histograming abort chain lengths based on | 214 // This is useful because it allows histograming abort chain lengths based on |
| 208 // what the last load's transition type is. i.e. holding down F-5 to spam | 215 // what the last load's transition type is. i.e. holding down F-5 to spam |
| 209 // reload will produce a long chain with the RELOAD transition. | 216 // reload will produce a long chain with the RELOAD transition. |
| 210 const int aborted_chain_size_; | 217 const int aborted_chain_size_; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 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); | |
| 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; |
| 253 | 261 |
| 254 private: | 262 private: |
| 255 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 263 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
| 256 | 264 |
| 257 // Notify all loads, provisional and committed, that we performed an action | 265 // Notify all loads, provisional and committed, that we performed an action |
| 258 // that might abort them. | 266 // that might abort them. |
| 259 void NotifyAbortAllLoads(UserAbortType abort_type); | 267 void NotifyAbortAllLoads(UserAbortType abort_type); |
| 260 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, | 268 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, |
| 261 base::TimeTicks timestamp); | 269 base::TimeTicks timestamp); |
| 262 // Notify aborted provisional loads that a new navigation occurred. This is | 270 // Notify aborted provisional loads that a new navigation occurred. This is |
| 263 // used for more consistent attribution tracking for aborted provisional | 271 // used for more consistent attribution tracking for aborted provisional |
| 264 // loads. This method returns the provisional load that was likely aborted by | 272 // loads. This method returns the provisional load that was likely aborted |
| 273 // by | |
| 265 // this navigation, to help instantiate the new PageLoadTracker. | 274 // this navigation, to help instantiate the new PageLoadTracker. |
|
tdresser
2016/05/24 14:28:38
Awkward whitespace.
| |
| 266 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( | 275 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( |
| 267 content::NavigationHandle* new_navigation); | 276 content::NavigationHandle* new_navigation); |
| 268 | 277 |
| 269 void OnTimingUpdated(content::RenderFrameHost*, | 278 void OnTimingUpdated(content::RenderFrameHost*, |
| 270 const PageLoadTiming& timing, | 279 const PageLoadTiming& timing, |
| 271 const PageLoadMetadata& metadata); | 280 const PageLoadMetadata& metadata); |
| 272 | 281 |
| 273 // True if the web contents is currently in the foreground. | 282 // True if the web contents is currently in the foreground. |
| 274 bool in_foreground_; | 283 bool in_foreground_; |
| 275 | 284 |
| 276 // The PageLoadTrackers must be deleted before the |embedded_interface_|, | 285 // The PageLoadTrackers must be deleted before the |embedded_interface_|, |
| 277 // because they hold a pointer to the |embedder_interface_|. | 286 // because they hold a pointer to the |embedder_interface_|. |
| 278 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; | 287 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; |
| 279 | 288 |
| 280 // This map tracks all of the navigations ongoing that are not committed | 289 // 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 | 290 // yet. Once a navigation is committed, it moves from the map to |
| 282 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | 291 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only |
| 283 // valid until commit time, when we remove it from the map. | 292 // valid until commit time, when we remove it from the map. |
| 284 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> | 293 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> |
| 285 provisional_loads_; | 294 provisional_loads_; |
| 286 | 295 |
| 287 // Tracks aborted provisional loads for a little bit longer than usual (one | 296 // 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 | 297 // 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 | 298 // navigation failed. This is because most provisional loads are destroyed |
| 299 // and | |
| 290 // vanish before we get signal about what caused the abort (new navigation, | 300 // vanish before we get signal about what caused the abort (new navigation, |
|
tdresser
2016/05/24 14:28:38
Awkward whitespace.
| |
| 291 // stop button, etc.). | 301 // stop button, etc.). |
| 292 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 302 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
| 293 | 303 |
| 294 std::unique_ptr<PageLoadTracker> committed_load_; | 304 std::unique_ptr<PageLoadTracker> committed_load_; |
| 295 | 305 |
| 296 // Has the MWCO observed at least one navigation? | 306 // Has the MWCO observed at least one navigation? |
| 297 bool has_navigated_; | 307 bool has_navigated_; |
| 298 | 308 |
| 299 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 309 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
| 300 }; | 310 }; |
| 301 | 311 |
| 302 } // namespace page_load_metrics | 312 } // namespace page_load_metrics |
| 303 | 313 |
| 304 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ | 314 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| OLD | NEW |