summaryrefslogtreecommitdiff
path: root/chrome_to_android_compatibility.h
blob: 91c442aac959eccfd46de8b01b8396c5ffbbf2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once

#include "base/time/time.h"

// Android's external/libchrome directory is out of date.
// Add missing templates here as a temporary solution
namespace base {

/**
 * Workaround for the error in unit tests: ISO C++20 considers use of overloaded
 * operator '==' (with operand types 'const base::TimeTicks'
 * and 'const base::TimeTicks') to be ambiguous despite there being a unique
 * best viable function [-Werror,-Wambiguous-reversed-operator]
 */
bool operator==(const TimeTicks& t1, const TimeTicks& t2);

namespace time_internal {

// clang-format off
template <typename T>
using EnableIfIntegral = typename std::
    enable_if<std::is_integral<T>::value || std::is_enum<T>::value, int>::type;
template <typename T>
using EnableIfFloat =
    typename std::enable_if<std::is_floating_point<T>::value, int>::type;

}  // namespace time_internal


template <typename T, time_internal::EnableIfIntegral<T> = 0>
constexpr TimeDelta Seconds(T n) {
  return TimeDelta::FromInternalValue(
      ClampMul(static_cast<int64_t>(n), Time::kMicrosecondsPerSecond));
}
template <typename T, time_internal::EnableIfIntegral<T> = 0>
constexpr TimeDelta Milliseconds(T n) {
  return TimeDelta::FromInternalValue(
      ClampMul(static_cast<int64_t>(n), Time::kMicrosecondsPerMillisecond));
}
template <typename T, time_internal::EnableIfFloat<T> = 0>
constexpr TimeDelta Seconds(T n) {
  return TimeDelta::FromInternalValue(
      saturated_cast<int64_t>(n * Time::kMicrosecondsPerSecond));
}
template <typename T, time_internal::EnableIfFloat<T> = 0>
constexpr TimeDelta Milliseconds(T n) {
  return TimeDelta::FromInternalValue(
      saturated_cast<int64_t>(n * Time::kMicrosecondsPerMillisecond));
}

} // namespace base