| OLD | NEW |
| (Empty) | |
| 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 |
| 5 #ifndef TimeStructTraits_h |
| 6 #define TimeStructTraits_h |
| 7 |
| 8 #include "ipc/ipc_message_utils.h" |
| 9 #include "platform/wtf/Time.h" |
| 10 |
| 11 namespace IPC { |
| 12 |
| 13 template <> |
| 14 struct ParamTraits<WTF::Time> { |
| 15 typedef WTF::Time param_type; |
| 16 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 17 ParamTraits<base::Time>::GetSize(sizer, base::Time::FromInternalValue(p.ToIn
ternalValueForTesting())); |
| 18 } |
| 19 static void Write(base::Pickle* m, const param_type& p) { |
| 20 ParamTraits<base::Time>::Write(m, base::Time::FromInternalValue(p.ToInternal
ValueForTesting())); |
| 21 } |
| 22 static bool Read(const base::Pickle* m, base::PickleIterator* iter, param_type
* r) { |
| 23 base::Time t; |
| 24 bool result = ParamTraits<base::Time>::Read(m, iter, &t); |
| 25 if (!result) return false; |
| 26 *r = WTF::Time::FromSeconds(t.ToDoubleT()); |
| 27 return true; |
| 28 } |
| 29 static void Log(const param_type& p, std::string* l) { |
| 30 ParamTraits<base::Time>::Log(base::Time::FromInternalValue(p.ToInternalValue
ForTesting()), l); |
| 31 } |
| 32 }; |
| 33 |
| 34 template <> |
| 35 struct ParamTraits<WTF::TimeTicks> { |
| 36 typedef WTF::TimeTicks param_type; |
| 37 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 38 ParamTraits<base::TimeTicks>::GetSize(sizer, base::TimeTicks::FromInternalVa
lue(p.ToInternalValueForTesting())); |
| 39 } |
| 40 static void Write(base::Pickle* m, const param_type& p) { |
| 41 ParamTraits<base::TimeTicks>::Write(m, base::TimeTicks::FromInternalValue(p.
ToInternalValueForTesting())); |
| 42 } |
| 43 static bool Read(const base::Pickle* m, base::PickleIterator* iter, param_type
* r) { |
| 44 base::TimeTicks t; |
| 45 bool result = ParamTraits<base::TimeTicks>::Read(m, iter, &t); |
| 46 if (!result) return false; |
| 47 *r = WTF::TimeTicks::FromSeconds((t - base::TimeTicks()).InSecondsF()); |
| 48 return true; |
| 49 } |
| 50 static void Log(const param_type& p, std::string* l) { |
| 51 ParamTraits<base::TimeTicks>::Log(base::TimeTicks::FromInternalValue(p.ToInt
ernalValueForTesting()), l); |
| 52 } |
| 53 }; |
| 54 |
| 55 } // namespace IPC |
| 56 |
| 57 #endif // TimeStructTraits_h |
| OLD | NEW |