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

Side by Side Diff: chrome/browser/page_load_metrics/page_load_tracker.h

Issue 2435233002: Factor PageLoadTracker into its own header and impl files. (Closed)
Patch Set: share IsNavigationUserInitiated impl Created 4 years, 1 month 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 2016 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 CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_
7 7
8 #include <map>
9 #include <memory> 8 #include <memory>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/time/time.h" 12 #include "base/time/time.h"
14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" 13 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
15 #include "chrome/common/page_load_metrics/page_load_timing.h" 14 #include "chrome/common/page_load_metrics/page_load_timing.h"
16 #include "content/public/browser/render_widget_host.h" 15 #include "ui/base/page_transition_types.h"
17 #include "content/public/browser/web_contents.h" 16
18 #include "content/public/browser/web_contents_observer.h" 17 class GURL;
19 #include "content/public/browser/web_contents_user_data.h" 18
20 #include "content/public/common/resource_type.h" 19 namespace blink {
21 #include "net/base/net_errors.h" 20 class WebInputEvent;
22 #include "third_party/WebKit/public/web/WebInputEvent.h" 21 } // namespace blink
23 22
24 namespace content { 23 namespace content {
25 class NavigationHandle; 24 class NavigationHandle;
26 class RenderFrameHost;
27 } // namespace content 25 } // namespace content
28 26
29 namespace IPC {
30 class Message;
31 } // namespace IPC
32
33 namespace page_load_metrics { 27 namespace page_load_metrics {
34 28
35 class PageLoadTracker; 29 class PageLoadMetricsEmbedderInterface;
30 class PageLoadMetricsObserver;
36 31
37 namespace internal { 32 namespace internal {
38 33
39 extern const char kErrorEvents[]; 34 extern const char kErrorEvents[];
40 extern const char kAbortChainSizeReload[]; 35 extern const char kAbortChainSizeReload[];
41 extern const char kAbortChainSizeForwardBack[]; 36 extern const char kAbortChainSizeForwardBack[];
42 extern const char kAbortChainSizeNewNavigation[]; 37 extern const char kAbortChainSizeNewNavigation[];
43 extern const char kAbortChainSizeNoCommit[]; 38 extern const char kAbortChainSizeNoCommit[];
44 extern const char kAbortChainSizeSameURL[]; 39 extern const char kAbortChainSizeSameURL[];
45 extern const char kPageLoadCompletedAfterAppBackground[]; 40 extern const char kPageLoadCompletedAfterAppBackground[];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ERR_INTER_PROCESS_TIME_TICK_SKEW, 98 ERR_INTER_PROCESS_TIME_TICK_SKEW,
104 99
105 // At the time a PageLoadTracker was destroyed, we had received neither a 100 // At the time a PageLoadTracker was destroyed, we had received neither a
106 // commit nor a failed provisional load. 101 // commit nor a failed provisional load.
107 ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD, 102 ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD,
108 103
109 // Add values before this final count. 104 // Add values before this final count.
110 ERR_LAST_ENTRY, 105 ERR_LAST_ENTRY,
111 }; 106 };
112 107
113 // This class serves as a functional interface to various chrome// features. 108 // NOTE: these functions are shared by page_load_tracker.cc and
114 // Impl version is defined in chrome/browser/page_load_metrics. 109 // metrics_web_contents_observer.cc. They are declared here to allow both files
115 class PageLoadMetricsEmbedderInterface { 110 // to access them.
116 public: 111 void RecordInternalError(InternalErrorLoadEvent event);
117 virtual ~PageLoadMetricsEmbedderInterface() {} 112 UserAbortType AbortTypeForPageTransition(ui::PageTransition transition);
118 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; 113 void LogAbortChainSameURLHistogram(int aborted_chain_size_same_url);
119 virtual bool IsNewTabPageUrl(const GURL& url) = 0; 114 bool IsNavigationUserInitiated(content::NavigationHandle* handle);
120 virtual void RegisterObservers(PageLoadTracker* metrics) = 0;
121 };
122 115
123 // This class tracks a given page load, starting from navigation start / 116 // This class tracks a given page load, starting from navigation start /
124 // provisional load, until a new navigation commits or the navigation fails. 117 // provisional load, until a new navigation commits or the navigation fails.
125 // MetricsWebContentsObserver manages a set of provisional PageLoadTrackers, as 118 // MetricsWebContentsObserver manages a set of provisional PageLoadTrackers, as
126 // well as a committed PageLoadTracker. 119 // well as a committed PageLoadTracker.
127 class PageLoadTracker { 120 class PageLoadTracker {
128 public: 121 public:
129 // Caller must guarantee that the embedder_interface pointer outlives this 122 // Caller must guarantee that the embedder_interface pointer outlives this
130 // class. The PageLoadTracker must not hold on to 123 // class. The PageLoadTracker must not hold on to
131 // currently_committed_load_or_null or navigation_handle beyond the scope of 124 // currently_committed_load_or_null or navigation_handle beyond the scope of
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 const int aborted_chain_size_same_url_; 289 const int aborted_chain_size_same_url_;
297 290
298 // Interface to chrome features. Must outlive the class. 291 // Interface to chrome features. Must outlive the class.
299 PageLoadMetricsEmbedderInterface* const embedder_interface_; 292 PageLoadMetricsEmbedderInterface* const embedder_interface_;
300 293
301 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; 294 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_;
302 295
303 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); 296 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
304 }; 297 };
305 298
306 // MetricsWebContentsObserver tracks page loads and loading metrics
307 // related data based on IPC messages received from a
308 // MetricsRenderFrameObserver.
309 class MetricsWebContentsObserver
310 : public content::WebContentsObserver,
311 public content::WebContentsUserData<MetricsWebContentsObserver>,
312 public content::RenderWidgetHost::InputEventObserver {
313 public:
314 // Note that the returned metrics is owned by the web contents.
315 static MetricsWebContentsObserver* CreateForWebContents(
316 content::WebContents* web_contents,
317 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
318 MetricsWebContentsObserver(
319 content::WebContents* web_contents,
320 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
321 ~MetricsWebContentsObserver() override;
322
323 // content::WebContentsObserver implementation:
324 bool OnMessageReceived(const IPC::Message& message,
325 content::RenderFrameHost* render_frame_host) override;
326 void DidFinishNavigation(
327 content::NavigationHandle* navigation_handle) override;
328 void DidRedirectNavigation(
329 content::NavigationHandle* navigation_handle) override;
330 void NavigationStopped() override;
331 void OnInputEvent(const blink::WebInputEvent& event) override;
332 void WasShown() override;
333 void WasHidden() override;
334 void RenderProcessGone(base::TerminationStatus status) override;
335 void RenderViewHostChanged(content::RenderViewHost* old_host,
336 content::RenderViewHost* new_host) override;
337
338 // This method is forwarded from the MetricsNavigationThrottle.
339 void WillStartNavigationRequest(content::NavigationHandle* navigation_handle);
340
341 // A resource request completed on the IO thread.
342 void OnRequestComplete(content::ResourceType resource_type,
343 bool was_cached,
344 int net_error);
345
346 // Flush any buffered metrics, as part of the metrics subsystem persisting
347 // metrics as the application goes into the background. The application may be
348 // killed at any time after this method is invoked without further
349 // notification.
350 void FlushMetricsOnAppEnterBackground();
351
352 // This getter function is required for testing.
353 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad();
354
355 private:
356 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
357
358 void HandleFailedNavigationForTrackedLoad(
359 content::NavigationHandle* navigation_handle,
360 std::unique_ptr<PageLoadTracker> tracker);
361
362 void HandleCommittedNavigationForTrackedLoad(
363 content::NavigationHandle* navigation_handle,
364 std::unique_ptr<PageLoadTracker> tracker);
365
366 // Notify all loads, provisional and committed, that we performed an action
367 // that might abort them.
368 void NotifyAbortAllLoads(UserAbortType abort_type, bool user_initiated);
369 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
370 bool user_initiated,
371 base::TimeTicks timestamp,
372 bool is_certainly_browser_timestamp);
373
374 // Register / Unregister input event callback to given RenderViewHost
375 void RegisterInputEventObserver(content::RenderViewHost* host);
376 void UnregisterInputEventObserver(content::RenderViewHost* host);
377
378 // Notify aborted provisional loads that a new navigation occurred. This is
379 // used for more consistent attribution tracking for aborted provisional
380 // loads. This method returns the provisional load that was likely aborted
381 // by this navigation, to help instantiate the new PageLoadTracker.
382 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation(
383 content::NavigationHandle* new_navigation);
384
385 void OnTimingUpdated(content::RenderFrameHost*,
386 const PageLoadTiming& timing,
387 const PageLoadMetadata& metadata);
388
389 bool ShouldTrackNavigation(
390 content::NavigationHandle* navigation_handle) const;
391
392 // True if the web contents is currently in the foreground.
393 bool in_foreground_;
394
395 // The PageLoadTrackers must be deleted before the |embedder_interface_|,
396 // because they hold a pointer to the |embedder_interface_|.
397 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
398
399 // This map tracks all of the navigations ongoing that are not committed
400 // yet. Once a navigation is committed, it moves from the map to
401 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
402 // valid until commit time, when we remove it from the map.
403 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>>
404 provisional_loads_;
405
406 // Tracks aborted provisional loads for a little bit longer than usual (one
407 // more navigation commit at the max), in order to better understand how the
408 // navigation failed. This is because most provisional loads are destroyed
409 // and vanish before we get signal about what caused the abort (new
410 // navigation, stop button, etc.).
411 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
412
413 std::unique_ptr<PageLoadTracker> committed_load_;
414
415 // Has the MWCO observed at least one navigation?
416 bool has_navigated_;
417
418 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
419 };
420
421 } // namespace page_load_metrics 299 } // namespace page_load_metrics
422 300
423 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 301 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698