Chromium Code Reviews| Index: chrome/browser/page_load_metrics/page_load_metrics_util.cc |
| diff --git a/chrome/browser/page_load_metrics/page_load_metrics_util.cc b/chrome/browser/page_load_metrics/page_load_metrics_util.cc |
| index aba5131a409bdfe4a83b2bb5e1697e9ba252d748..1d52abaf82afa66b2623717e2e4afc0e94db55ca 100644 |
| --- a/chrome/browser/page_load_metrics/page_load_metrics_util.cc |
| +++ b/chrome/browser/page_load_metrics/page_load_metrics_util.cc |
| @@ -7,6 +7,8 @@ |
| #include <algorithm> |
| #include "chrome/common/page_load_metrics/page_load_timing.h" |
| +#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| +#include "url/gurl.h" |
| namespace page_load_metrics { |
| @@ -43,6 +45,51 @@ PageAbortReason GetAbortReasonForEndReason(PageEndReason end_reason) { |
| } // namespace |
| +bool IsGoogleHostnameAndGetPrefix(const GURL& url, |
|
RyanSturm
2017/05/15 20:42:06
nit: Thoughts on getting rid of the out param and
Bryan McQuade
2017/05/16 03:59:15
This is a great idea. I needed to change to option
|
| + base::StringPiece* out_google_host_prefix) { |
| + const size_t registry_length = |
| + net::registry_controlled_domains::GetRegistryLength( |
| + url, |
| + |
| + // Do not include unknown registries (registries that don't have any |
| + // matches in effective TLD names). |
| + net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
| + |
| + // 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); |
| + |
| + const base::StringPiece hostname = url.host_piece(); |
| + if (registry_length == 0 || registry_length == std::string::npos || |
| + registry_length >= hostname.length()) |
| + return false; |
| + |
| + // Removes the tld and the preceding dot. |
| + const base::StringPiece hostname_minus_registry = |
| + hostname.substr(0, hostname.length() - (registry_length + 1)); |
| + |
| + if (hostname_minus_registry == "google") { |
| + if (out_google_host_prefix) |
| + *out_google_host_prefix = ""; |
| + return true; |
| + } |
| + |
| + if (!base::EndsWith(hostname_minus_registry, ".google", |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + return false; |
| + } |
| + |
| + if (out_google_host_prefix) { |
| + *out_google_host_prefix = hostname_minus_registry.substr( |
| + 0, hostname_minus_registry.length() - strlen(".google")); |
| + } |
| + return true; |
| +} |
| + |
| +bool IsGoogleHostname(const GURL& url) { |
| + return IsGoogleHostnameAndGetPrefix(url, nullptr); |
| +} |
| + |
| bool WasStartedInForegroundOptionalEventInForeground( |
| const base::Optional<base::TimeDelta>& event, |
| const PageLoadExtraInfo& info) { |