1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_ 7 8 #include <string> 9 10 #include "base/optional.h" 11 #include "base/time/time.h" 12 #include "url/gurl.h" 13 14 namespace page_load_metrics { 15 16 // Returns the minimum value of the optional TimeDeltas, if both values are 17 // set. Otherwise, if one value is set, returns that value. Otherwise, returns 18 // an unset value. 19 base::Optional<base::TimeDelta> OptionalMin( 20 const base::Optional<base::TimeDelta>& a, 21 const base::Optional<base::TimeDelta>& b); 22 23 // Whether the given url has a google hostname. 24 bool IsGoogleHostname(const GURL& url); 25 26 // If the given hostname is a google hostname, returns the portion of the 27 // hostname before the google hostname. Otherwise, returns an unset optional 28 // value. 29 // 30 // For example: 31 // https://example.com/foo => returns an unset optional value 32 // https://google.com/foo => returns '' 33 // https://www.google.com/foo => returns 'www' 34 // https://news.google.com/foo => returns 'news' 35 // https://a.b.c.google.com/foo => returns 'a.b.c' 36 base::Optional<std::string> GetGoogleHostnamePrefix(const GURL& url); 37 38 } // namespace page_load_metrics 39 40 #endif // COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_ 41