page_load_metrics_util.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_
  5. #define COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_
  6. #include <string>
  7. #include "base/time/time.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. #include "url/gurl.h"
  10. namespace page_load_metrics {
  11. // Returns the minimum value of the optional TimeDeltas, if both values are
  12. // set. Otherwise, if one value is set, returns that value. Otherwise, returns
  13. // an unset value.
  14. absl::optional<base::TimeDelta> OptionalMin(
  15. const absl::optional<base::TimeDelta>& a,
  16. const absl::optional<base::TimeDelta>& b);
  17. // Whether the given url has a google hostname.
  18. bool IsGoogleHostname(const GURL& url);
  19. // If the given hostname is a google hostname, returns the portion of the
  20. // hostname before the google hostname. Otherwise, returns an unset optional
  21. // value.
  22. //
  23. // For example:
  24. // https://example.com/foo => returns an unset optional value
  25. // https://google.com/foo => returns ''
  26. // https://www.google.com/foo => returns 'www'
  27. // https://news.google.com/foo => returns 'news'
  28. // https://a.b.c.google.com/foo => returns 'a.b.c'
  29. absl::optional<std::string> GetGoogleHostnamePrefix(const GURL& url);
  30. // Distinguishes the renderer-side timer from the browser-side timer.
  31. enum class TimerType { kRenderer = 0, kBrowser = 1 };
  32. // Returns the maximum amount of time to delay dispatch of metrics updates
  33. // from the renderer process.
  34. int GetBufferTimerDelayMillis(TimerType timer_type);
  35. } // namespace page_load_metrics
  36. #endif // COMPONENTS_PAGE_LOAD_METRICS_COMMON_PAGE_LOAD_METRICS_UTIL_H_