| Index: chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.h
|
| diff --git a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.h b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.h
|
| index 0465ede23619906d8eefeaae1f945b34c6a43681..429bd90fd845e0ebc05f3e82dcc3453d9a539848 100644
|
| --- a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.h
|
| +++ b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.h
|
| @@ -7,24 +7,90 @@
|
|
|
| #include "base/macros.h"
|
| #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace internal {
|
| +// Exposed for tests.
|
| +extern const char kHistogramFromGWSFirstTextPaint[];
|
| +} // namespace internal
|
| +
|
| +// FromGWSPageLoadMetricsLogger is a peer class to
|
| +// FromGWSPageLoadMetricsObserver. FromGWSPageLoadMetricsLogger is responsible
|
| +// for tracking state needed to decide if metrics should be logged, and to log
|
| +// metrics in cases where metrics should be logged. FromGWSPageLoadMetricsLogger
|
| +// exists to decouple the logging policy implementation from other Chromium
|
| +// classes such as NavigationHandle and related infrastructure, in order to make
|
| +// the code more unit testable.
|
| +class FromGWSPageLoadMetricsLogger {
|
| + public:
|
| + FromGWSPageLoadMetricsLogger() {}
|
| +
|
| + void set_previously_committed_url(const GURL& url) {
|
| + previously_committed_url_ = url;
|
| + }
|
| +
|
| + void set_navigation_initiated_via_link(bool navigation_initiated_via_link) {
|
| + navigation_initiated_via_link_ = navigation_initiated_via_link;
|
| + }
|
| +
|
| + // Invoked when metrics for the given page are complete.
|
| + void OnComplete(const page_load_metrics::PageLoadTiming& timing,
|
| + const page_load_metrics::PageLoadExtraInfo& extra_info);
|
| +
|
| + // The methods below are public only for testing.
|
| + static bool IsGoogleSearchHostname(base::StringPiece host);
|
| + static bool IsGoogleSearchResultUrl(const GURL& url);
|
| + static bool IsGoogleRedirectorUrl(const GURL& url);
|
| + static bool IsGoogleSearchRedirectorUrl(const GURL& url);
|
| +
|
| + // Whether the given query string contains the given component. The query
|
| + // parameter should contain the query string of a URL (the portion following
|
| + // the question mark, excluding the question mark). The component must fully
|
| + // match a component in the query string. For example, 'foo=bar' would match
|
| + // the query string 'a=b&foo=bar&c=d' but would not match 'a=b&zzzfoo=bar&c=d'
|
| + // since, though foo=bar appears in the query string, the key specified in the
|
| + // component 'foo' does not match the full key in the query string
|
| + // 'zzzfoo'. For QueryContainsComponent, the component should of the form
|
| + // 'key=value'. For QueryContainsComponentPrefix, the component should be of
|
| + // the form 'key=' (where the value is not specified).
|
| + static bool QueryContainsComponent(const base::StringPiece query,
|
| + const base::StringPiece component);
|
| + static bool QueryContainsComponentPrefix(const base::StringPiece query,
|
| + const base::StringPiece component);
|
| +
|
| + // Whether metrics should be logged based on state provided via setters and
|
| + // the given committed_url.
|
| + bool ShouldLogMetrics(const GURL& committed_url) const;
|
| +
|
| + private:
|
| + GURL previously_committed_url_;
|
| + bool navigation_initiated_via_link_ = false;
|
| +
|
| + // Common helper for QueryContainsComponent and QueryContainsComponentPrefix.
|
| + static bool QueryContainsComponentHelper(const base::StringPiece query,
|
| + const base::StringPiece component,
|
| + bool component_is_prefix);
|
| +
|
| + void LogMetrics(const page_load_metrics::PageLoadTiming& timing,
|
| + const page_load_metrics::PageLoadExtraInfo& extra_info);
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FromGWSPageLoadMetricsLogger);
|
| +};
|
|
|
| class FromGWSPageLoadMetricsObserver
|
| : public page_load_metrics::PageLoadMetricsObserver {
|
| public:
|
| FromGWSPageLoadMetricsObserver();
|
| // page_load_metrics::PageLoadMetricsObserver implementation:
|
| + void OnStart(content::NavigationHandle* navigation_handle,
|
| + const GURL& currently_committed_url) override;
|
| void OnCommit(content::NavigationHandle* navigation_handle) override;
|
| void OnComplete(
|
| const page_load_metrics::PageLoadTiming& timing,
|
| const page_load_metrics::PageLoadExtraInfo& extra_info) override;
|
|
|
| - protected:
|
| - // Called in tests.
|
| - void SetCommittedURLAndReferrer(const GURL& url,
|
| - const content::Referrer& referrer);
|
| -
|
| private:
|
| - bool navigation_from_gws_;
|
| + FromGWSPageLoadMetricsLogger logger_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FromGWSPageLoadMetricsObserver);
|
| };
|
|
|