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

Unified Diff: chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc

Issue 2880323003: Various cleaups for AMP page load metrics. (Closed)
Patch Set: improve tests Created 3 years, 7 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/observers/from_gws_page_load_metrics_observer.cc
diff --git a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
index c11c9587767fe76972d17018c67d24d71cfee75b..67be4a081b59a12b7502a3d6e5df6c5809dde993 100644
--- a/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
+++ b/chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_observer.cc
@@ -9,7 +9,6 @@
#include "base/strings/string_util.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
#include "chrome/common/page_load_metrics/page_load_timing.h"
-#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
using page_load_metrics::PageAbortReason;
@@ -321,39 +320,18 @@ bool WasAbortedBeforeInteraction(
// for additional details.
// static
-bool FromGWSPageLoadMetricsLogger::IsGoogleSearchHostname(
- base::StringPiece host) {
- const char kGoogleSearchHostnamePrefix[] = "www.";
-
- // Hostname must start with 'www.' Hostnames are not case sensitive.
- if (!base::StartsWith(host, kGoogleSearchHostnamePrefix,
- base::CompareCase::INSENSITIVE_ASCII)) {
- return false;
- }
- std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
- host,
- // Do not include private registries, such as appspot.com. We don't want
- // to match URLs like www.google.appspot.com.
- net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
-
- // Domain and registry must start with 'google.' e.g. 'google.com' or
- // 'google.co.uk'.
- if (!base::StartsWith(domain, "google.",
- base::CompareCase::INSENSITIVE_ASCII)) {
- return false;
- }
-
- // Finally, the length of the URL before the domain and registry must be equal
- // in length to the search hostname prefix.
- const size_t url_hostname_prefix_length = host.length() - domain.length();
- return url_hostname_prefix_length == strlen(kGoogleSearchHostnamePrefix);
+bool FromGWSPageLoadMetricsLogger::IsGoogleSearchHostname(const GURL& url) {
+ base::StringPiece google_hostname_prefix;
+ return page_load_metrics::IsGoogleHostnameAndGetPrefix(
+ url, &google_hostname_prefix) &&
+ google_hostname_prefix == "www";
}
// static
bool FromGWSPageLoadMetricsLogger::IsGoogleSearchResultUrl(const GURL& url) {
// NOTE: we do not require 'q=' in the query, as AJAXy search may instead
// store the query in the URL fragment.
- if (!IsGoogleSearchHostname(url.host_piece())) {
+ if (!IsGoogleSearchHostname(url)) {
return false;
}
@@ -370,7 +348,7 @@ bool FromGWSPageLoadMetricsLogger::IsGoogleSearchResultUrl(const GURL& url) {
// static
bool FromGWSPageLoadMetricsLogger::IsGoogleSearchRedirectorUrl(
const GURL& url) {
- if (!IsGoogleSearchHostname(url.host_piece()))
+ if (!IsGoogleSearchHostname(url))
return false;
// The primary search redirector. Google search result redirects are
@@ -466,8 +444,7 @@ void FromGWSPageLoadMetricsLogger::SetPreviouslyCommittedUrl(const GURL& url) {
}
void FromGWSPageLoadMetricsLogger::SetProvisionalUrl(const GURL& url) {
- provisional_url_has_search_hostname_ =
- IsGoogleSearchHostname(url.host_piece());
+ provisional_url_has_search_hostname_ = IsGoogleSearchHostname(url);
}
FromGWSPageLoadMetricsObserver::FromGWSPageLoadMetricsObserver() {}
@@ -643,7 +620,7 @@ bool FromGWSPageLoadMetricsLogger::ShouldLogPostCommitMetrics(const GURL& url) {
// these cases are relatively uncommon, and we run the risk of logging metrics
// for some search redirector URLs. Thus we choose the more conservative
// approach of ignoring all urls on known search hostnames.
- if (IsGoogleSearchHostname(url.host_piece()))
+ if (IsGoogleSearchHostname(url))
return false;
// We're only interested in tracking navigations (e.g. clicks) initiated via

Powered by Google App Engine
This is Rietveld 408576698