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

Unified Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.h

Issue 2435233002: Factor PageLoadTracker into its own header and impl files. (Closed)
Patch Set: share IsNavigationUserInitiated impl Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/page_load_metrics/metrics_web_contents_observer.h
diff --git a/chrome/browser/page_load_metrics/metrics_web_contents_observer.h b/chrome/browser/page_load_metrics/metrics_web_contents_observer.h
index 3d6daece59a17bb31c4fb1ed0d43619187a96c06..4a43b9d1beaa9f4bf33827f2b329be1e9ce5ab06 100644
--- a/chrome/browser/page_load_metrics/metrics_web_contents_observer.h
+++ b/chrome/browser/page_load_metrics/metrics_web_contents_observer.h
@@ -18,7 +18,6 @@
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "content/public/common/resource_type.h"
-#include "net/base/net_errors.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace content {
@@ -32,277 +31,9 @@ class Message;
namespace page_load_metrics {
+class PageLoadMetricsEmbedderInterface;
class PageLoadTracker;
-namespace internal {
-
-extern const char kErrorEvents[];
-extern const char kAbortChainSizeReload[];
-extern const char kAbortChainSizeForwardBack[];
-extern const char kAbortChainSizeNewNavigation[];
-extern const char kAbortChainSizeNoCommit[];
-extern const char kAbortChainSizeSameURL[];
-extern const char kPageLoadCompletedAfterAppBackground[];
-
-} // namespace internal
-
-// These errors are internal to the page_load_metrics subsystem and do not
-// reflect actual errors that occur during a page load.
-//
-// If you add elements to this enum, make sure you update the enum
-// value in histograms.xml. Only add elements to the end to prevent
-// inconsistencies between versions.
-enum InternalErrorLoadEvent {
- // A timing IPC was sent from the renderer that did not line up with previous
- // data we've received (i.e. navigation start is different or the timing
- // struct is somehow invalid). This error can only occur once the IPC is
- // vetted in other ways (see other errors).
- ERR_BAD_TIMING_IPC,
-
- // The following IPCs are not mutually exclusive.
- //
- // We received an IPC when we weren't tracking a committed load. This will
- // often happen if we get an IPC from a bad URL scheme (that is, the renderer
- // sent us an IPC from a navigation we don't care about).
- ERR_IPC_WITH_NO_RELEVANT_LOAD,
-
- // Received a notification from a frame that has been navigated away from.
- ERR_IPC_FROM_WRONG_FRAME,
-
- // We received an IPC even through the last committed url from the browser
- // was not http/s. This can happen with the renderer sending IPCs for the
- // new tab page. This will often come paired with
- // ERR_IPC_WITH_NO_RELEVANT_LOAD.
- ERR_IPC_FROM_BAD_URL_SCHEME,
-
- // If we track a navigation, but the renderer sends us no IPCs. This could
- // occur if the browser filters loads less aggressively than the renderer.
- ERR_NO_IPCS_RECEIVED,
-
- // Tracks frequency with which we record an abort time that occurred before
- // navigation start. This is expected to happen in some cases (see comments in
- // cc file for details). We use this error counter to understand how often it
- // happens.
- ERR_ABORT_BEFORE_NAVIGATION_START,
-
- // A new navigation triggers abort updates in multiple trackers in
- // |aborted_provisional_loads_|, when usually there should only be one (the
- // navigation that just aborted because of this one). If this happens, the
- // latest aborted load is used to track the chain size.
- ERR_NAVIGATION_SIGNALS_MULIPLE_ABORTED_LOADS,
-
- // Received user input without a relevant load. This error type is deprecated,
- // as it is valid to receive user input without a relevant load. We leave the
- // enum value here since it's also used in histogram recording, so it's
- // important that we not re-use this enum entry for a different value.
- DEPRECATED_ERR_USER_INPUT_WITH_NO_RELEVANT_LOAD,
-
- // A TimeTicks value in the browser process has value less than
- // navigation_start_. This could happen if navigation_start_ was computed in
- // renderer process and the system clock has inter process time tick skew.
- ERR_INTER_PROCESS_TIME_TICK_SKEW,
-
- // At the time a PageLoadTracker was destroyed, we had received neither a
- // commit nor a failed provisional load.
- ERR_NO_COMMIT_OR_FAILED_PROVISIONAL_LOAD,
-
- // Add values before this final count.
- ERR_LAST_ENTRY,
-};
-
-// This class serves as a functional interface to various chrome// features.
-// Impl version is defined in chrome/browser/page_load_metrics.
-class PageLoadMetricsEmbedderInterface {
- public:
- virtual ~PageLoadMetricsEmbedderInterface() {}
- virtual bool IsPrerendering(content::WebContents* web_contents) = 0;
- virtual bool IsNewTabPageUrl(const GURL& url) = 0;
- virtual void RegisterObservers(PageLoadTracker* metrics) = 0;
-};
-
-// This class tracks a given page load, starting from navigation start /
-// provisional load, until a new navigation commits or the navigation fails.
-// MetricsWebContentsObserver manages a set of provisional PageLoadTrackers, as
-// well as a committed PageLoadTracker.
-class PageLoadTracker {
- public:
- // Caller must guarantee that the embedder_interface pointer outlives this
- // class. The PageLoadTracker must not hold on to
- // currently_committed_load_or_null or navigation_handle beyond the scope of
- // the constructor.
- PageLoadTracker(bool in_foreground,
- PageLoadMetricsEmbedderInterface* embedder_interface,
- const GURL& currently_committed_url,
- content::NavigationHandle* navigation_handle,
- int aborted_chain_size,
- int aborted_chain_size_same_url);
- ~PageLoadTracker();
- void Redirect(content::NavigationHandle* navigation_handle);
- void Commit(content::NavigationHandle* navigation_handle);
- void FailedProvisionalLoad(content::NavigationHandle* navigation_handle);
- void WebContentsHidden();
- void WebContentsShown();
-
- void OnInputEvent(const blink::WebInputEvent& event);
-
- // Flush any buffered metrics, as part of the metrics subsystem persisting
- // metrics as the application goes into the background. The application may be
- // killed at any time after this method is invoked without further
- // notification.
- void FlushMetricsOnAppEnterBackground();
-
- void NotifyClientRedirectTo(const PageLoadTracker& destination);
-
- // Returns true if the timing was successfully updated.
- bool UpdateTiming(const PageLoadTiming& timing,
- const PageLoadMetadata& metadata);
-
- void OnLoadedSubresource(bool was_cached);
-
- // Signals that we should stop tracking metrics for the associated page load.
- // We may stop tracking a page load if it doesn't meet the criteria for
- // tracking metrics in DidFinishNavigation.
- void StopTracking();
-
- int aborted_chain_size() const { return aborted_chain_size_; }
- int aborted_chain_size_same_url() const {
- return aborted_chain_size_same_url_;
- }
-
- UserAbortType abort_type() const { return abort_type_; }
- base::TimeTicks abort_time() const { return abort_time_; }
-
- void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer);
-
- // If the user performs some abort-like action while we are tracking this page
- // load, notify the tracker. Note that we may not classify this as an abort if
- // we've already performed a first paint.
- // is_certainly_browser_timestamp signifies if the timestamp passed is taken
- // in the
- // browser process or not. We need this to possibly clamp browser timestamp on
- // a machine with inter process time tick skew.
- void NotifyAbort(UserAbortType abort_type,
- bool user_initiated,
- base::TimeTicks timestamp,
- bool is_certainly_browser_timestamp);
- void UpdateAbort(UserAbortType abort_type,
- bool user_initiated,
- base::TimeTicks timestamp,
- bool is_certainly_browser_timestamp);
-
- // This method returns true if this page load has been aborted with type of
- // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close
- // delta to when it was aborted. Note that only provisional loads can be
- // aborted with ABORT_OTHER. While this heuristic is coarse, it works better
- // and is simpler than other feasible methods. See https://goo.gl/WKRG98.
- bool IsLikelyProvisionalAbort(base::TimeTicks abort_cause_time) const;
-
- bool MatchesOriginalNavigation(content::NavigationHandle* navigation_handle);
-
- // Only valid to call post-commit.
- const GURL& committed_url() const {
- DCHECK(!committed_url_.is_empty());
- return committed_url_;
- }
-
- base::TimeTicks navigation_start() const { return navigation_start_; }
-
- PageLoadExtraInfo ComputePageLoadExtraInfo();
-
- ui::PageTransition page_transition() const { return page_transition_; }
-
- private:
- // This function converts a TimeTicks value taken in the browser process
- // to navigation_start_ if:
- // - base::TimeTicks is not comparable across processes because the clock
- // is not system wide monotonic.
- // - *event_time < navigation_start_
- void ClampBrowserTimestampIfInterProcessTimeTickSkew(
- base::TimeTicks* event_time);
-
- void UpdateAbortInternal(UserAbortType abort_type,
- bool user_initiated,
- base::TimeTicks timestamp,
- bool is_certainly_browser_timestamp);
-
- // If |final_navigation| is null, then this is an "unparented" abort chain,
- // and represents a sequence of provisional aborts that never ends with a
- // committed load.
- void LogAbortChainHistograms(content::NavigationHandle* final_navigation);
-
- // Whether we stopped tracking this navigation after it was initiated. We may
- // stop tracking a navigation if it doesn't meet the criteria for tracking
- // metrics in DidFinishNavigation.
- bool did_stop_tracking_;
-
- // Whether the application went into the background when this PageLoadTracker
- // was active. This is a temporary boolean for UMA tracking.
- bool app_entered_background_;
-
- // The navigation start in TimeTicks, not the wall time reported by Blink.
- const base::TimeTicks navigation_start_;
-
- // The committed URL of this page load.
- GURL committed_url_;
-
- // The start URL for this page load (before redirects).
- GURL start_url_;
-
- std::unique_ptr<FailedProvisionalLoadInfo> failed_provisional_load_info_;
-
- // Will be ABORT_NONE if we have not aborted this load yet. Otherwise will
- // be the first abort action the user performed.
- UserAbortType abort_type_;
-
- // This boolean is only an approximation. As the aborts pipeline is updated,
- // more abort types will have this set to true. Currently, this is only set
- // for navigations aborting navigations.
- bool abort_user_initiated_;
-
- base::TimeTicks abort_time_;
-
- // We record separate metrics for events that occur after a background,
- // because metrics like layout/paint are delayed artificially
- // when they occur in the background.
- base::TimeTicks background_time_;
- base::TimeTicks foreground_time_;
- bool started_in_foreground_;
-
- PageLoadTiming timing_;
- PageLoadMetadata metadata_;
-
- ui::PageTransition page_transition_;
-
- // Note: these are only approximations, based on WebContents attribution from
- // ResourceRequestInfo objects while this is the currently committed load in
- // the WebContents.
- int num_cache_requests_;
- int num_network_requests_;
-
- // This is derived from the user gesture bit in the renderer. For browser
- // initiated navigations this will always be true.
- bool user_gesture_;
-
- // This is a subtle member. If a provisional load A gets aborted by
- // provisional load B, which gets aborted by C that eventually commits, then
- // there exists an abort chain of length 2, starting at A's navigation_start.
- // This is useful because it allows histograming abort chain lengths based on
- // what the last load's transition type is. i.e. holding down F-5 to spam
- // reload will produce a long chain with the RELOAD transition.
- const int aborted_chain_size_;
-
- // This member counts consecutive provisional aborts that share a url. It will
- // always be less than or equal to |aborted_chain_size_|.
- const int aborted_chain_size_same_url_;
-
- // Interface to chrome features. Must outlive the class.
- PageLoadMetricsEmbedderInterface* const embedder_interface_;
-
- std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_;
-
- DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
-};
-
// MetricsWebContentsObserver tracks page loads and loading metrics
// related data based on IPC messages received from a
// MetricsRenderFrameObserver.

Powered by Google App Engine
This is Rietveld 408576698