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, 10 base::Time>::internal_value(const base::Time& time) { 11 return time.since_origin().InMicroseconds(); 12 } 13 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, 24 base::TimeDelta>::microseconds(const base::TimeDelta& delta) { 25 return delta.InMicroseconds(); 26 } 27 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, 37 base::TimeTicks>::internal_value(const base::TimeTicks& time) { 38 return time.since_origin().InMicroseconds(); 39 } 40 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