| 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..22ec5505e23665708b80541e24c2f059047659b0 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,45 @@ PageAbortReason GetAbortReasonForEndReason(PageEndReason end_reason) {
|
|
|
| } // namespace
|
|
|
| +base::Optional<std::string> GetGoogleHostnamePrefix(const GURL& url) {
|
| + 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 base::Optional<std::string>();
|
| + }
|
| +
|
| + // 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")
|
| + return std::string("");
|
| +
|
| + if (!base::EndsWith(hostname_minus_registry, ".google",
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + return base::Optional<std::string>();
|
| + }
|
| +
|
| + return std::string(hostname_minus_registry.substr(
|
| + 0, hostname_minus_registry.length() - strlen(".google")));
|
| +}
|
| +
|
| +bool IsGoogleHostname(const GURL& url) {
|
| + return GetGoogleHostnamePrefix(url).has_value();
|
| +}
|
| +
|
| bool WasStartedInForegroundOptionalEventInForeground(
|
| const base::Optional<base::TimeDelta>& event,
|
| const PageLoadExtraInfo& info) {
|
|
|