1 // Copyright 2018 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 #include "mojo/public/cpp/base/time_mojom_traits.h"
6
7 namespace mojo {
8
9 int64_t StructTraits<mojo_base::mojom::TimeDataView,
internal_value(const base::Time & time)10 base::Time>::internal_value(const base::Time& time) {
11 return time.since_origin().InMicroseconds();
12 }
13
Read(mojo_base::mojom::TimeDataView data,base::Time * time)14 bool StructTraits<mojo_base::mojom::TimeDataView, base::Time>::Read(
15 mojo_base::mojom::TimeDataView data,
16 base::Time* time) {
17 *time =
18 base::Time() + base::TimeDelta::FromMicroseconds(data.internal_value());
19 return true;
20 }
21
22 int64_t
23 StructTraits<mojo_base::mojom::TimeDeltaDataView,
microseconds(const base::TimeDelta & delta)24 base::TimeDelta>::microseconds(const base::TimeDelta& delta) {
25 return delta.InMicroseconds();
26 }
27
Read(mojo_base::mojom::TimeDeltaDataView data,base::TimeDelta * delta)28 bool StructTraits<mojo_base::mojom::TimeDeltaDataView, base::TimeDelta>::Read(
29 mojo_base::mojom::TimeDeltaDataView data,
30 base::TimeDelta* delta) {
31 *delta = base::TimeDelta::FromMicroseconds(data.microseconds());
32 return true;
33 }
34
35 int64_t
36 StructTraits<mojo_base::mojom::TimeTicksDataView,
internal_value(const base::TimeTicks & time)37 base::TimeTicks>::internal_value(const base::TimeTicks& time) {
38 return time.since_origin().InMicroseconds();
39 }
40
Read(mojo_base::mojom::TimeTicksDataView data,base::TimeTicks * time)41 bool StructTraits<mojo_base::mojom::TimeTicksDataView, base::TimeTicks>::Read(
42 mojo_base::mojom::TimeTicksDataView data,
43 base::TimeTicks* time) {
44 *time = base::TimeTicks() +
45 base::TimeDelta::FromMicroseconds(data.internal_value());
46 return true;
47 }
48
49 } // namespace mojo