forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_struct_traits.h
55 lines (44 loc) · 1.56 KB
/
time_struct_traits.h
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 2017 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.
#ifndef MOJO_COMMON_TIME_STRUCT_TRAITS_H_
#define MOJO_COMMON_TIME_STRUCT_TRAITS_H_
#include "base/time/time.h"
#include "mojo/common/time.mojom-shared.h"
namespace mojo {
template <>
struct StructTraits<common::mojom::TimeDataView, base::Time> {
static int64_t internal_value(const base::Time& time) {
return time.since_origin().InMicroseconds();
}
static bool Read(common::mojom::TimeDataView data, base::Time* time) {
*time =
base::Time() + base::TimeDelta::FromMicroseconds(data.internal_value());
return true;
}
};
template <>
struct StructTraits<common::mojom::TimeDeltaDataView, base::TimeDelta> {
static int64_t microseconds(const base::TimeDelta& delta) {
return delta.InMicroseconds();
}
static bool Read(common::mojom::TimeDeltaDataView data,
base::TimeDelta* delta) {
*delta = base::TimeDelta::FromMicroseconds(data.microseconds());
return true;
}
};
template <>
struct StructTraits<common::mojom::TimeTicksDataView, base::TimeTicks> {
static int64_t internal_value(const base::TimeTicks& time) {
return time.since_origin().InMicroseconds();
}
static bool Read(common::mojom::TimeTicksDataView data,
base::TimeTicks* time) {
*time = base::TimeTicks() +
base::TimeDelta::FromMicroseconds(data.internal_value());
return true;
}
};
} // namespace mojo
#endif // MOJO_COMMON_TIME_STRUCT_TRAITS_H_