OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/platform/impl/quic_chromium_clock.h" | 5 #include "net/quic/platform/impl/quic_chromium_clock.h" |
6 | 6 |
| 7 #if defined(OS_IOS) |
| 8 #include <time.h> |
| 9 |
| 10 #include "base/ios/ios_util.h" |
| 11 #endif |
| 12 |
7 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
8 #include "base/time/time.h" | 14 #include "base/time/time.h" |
9 | 15 |
10 namespace net { | 16 namespace net { |
11 | 17 |
12 QuicChromiumClock* QuicChromiumClock::GetInstance() { | 18 QuicChromiumClock* QuicChromiumClock::GetInstance() { |
13 return base::Singleton<QuicChromiumClock>::get(); | 19 return base::Singleton<QuicChromiumClock>::get(); |
14 } | 20 } |
15 QuicChromiumClock::QuicChromiumClock() {} | 21 QuicChromiumClock::QuicChromiumClock() {} |
16 | 22 |
17 QuicChromiumClock::~QuicChromiumClock() {} | 23 QuicChromiumClock::~QuicChromiumClock() {} |
18 | 24 |
19 QuicTime QuicChromiumClock::ApproximateNow() const { | 25 QuicTime QuicChromiumClock::ApproximateNow() const { |
20 // At the moment, Chrome does not have a distinct notion of ApproximateNow(). | 26 // At the moment, Chrome does not have a distinct notion of ApproximateNow(). |
21 // We should consider implementing this using MessageLoop::recent_time_. | 27 // We should consider implementing this using MessageLoop::recent_time_. |
22 return Now(); | 28 return Now(); |
23 } | 29 } |
24 | 30 |
25 QuicTime QuicChromiumClock::Now() const { | 31 QuicTime QuicChromiumClock::Now() const { |
26 return QuicTime(base::TimeTicks::Now()); | 32 #if defined(OS_IOS) |
| 33 if (base::ios::IsRunningOnIOS10OrLater()) { |
| 34 struct timespec tp; |
| 35 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) { |
| 36 return CreateTimeFromMicroseconds(tp.tv_sec * 1000000 + |
| 37 tp.tv_nsec / 1000); |
| 38 } |
| 39 } |
| 40 #endif |
| 41 return CreateTimeFromMicroseconds(base::TimeTicks::Now().ToInternalValue()); |
27 } | 42 } |
28 | 43 |
29 QuicWallTime QuicChromiumClock::WallNow() const { | 44 QuicWallTime QuicChromiumClock::WallNow() const { |
30 return QuicWallTime::FromUNIXMicroseconds(base::Time::Now().ToJavaTime() * | 45 return QuicWallTime::FromUNIXMicroseconds(base::Time::Now().ToJavaTime() * |
31 1000); | 46 1000); |
32 } | 47 } |
33 | 48 |
34 } // namespace net | 49 } // namespace net |
OLD | NEW |