Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: net/quic/platform/impl/quic_chromium_clock.cc

Issue 2894173002: Use faster clock_gettime() instead of sysctl() to get current ticks on iOS10 (Closed)
Patch Set: Fixed bug on 32-bit platforms Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/time/time_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
13 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
14 #include "base/time/time.h" 8 #include "base/time/time.h"
15 9
16 namespace net { 10 namespace net {
17 11
18 QuicChromiumClock* QuicChromiumClock::GetInstance() { 12 QuicChromiumClock* QuicChromiumClock::GetInstance() {
19 return base::Singleton<QuicChromiumClock>::get(); 13 return base::Singleton<QuicChromiumClock>::get();
20 } 14 }
21 QuicChromiumClock::QuicChromiumClock() {} 15 QuicChromiumClock::QuicChromiumClock() {}
22 16
23 QuicChromiumClock::~QuicChromiumClock() {} 17 QuicChromiumClock::~QuicChromiumClock() {}
24 18
25 QuicTime QuicChromiumClock::ApproximateNow() const { 19 QuicTime QuicChromiumClock::ApproximateNow() const {
26 // At the moment, Chrome does not have a distinct notion of ApproximateNow(). 20 // At the moment, Chrome does not have a distinct notion of ApproximateNow().
27 // We should consider implementing this using MessageLoop::recent_time_. 21 // We should consider implementing this using MessageLoop::recent_time_.
28 return Now(); 22 return Now();
29 } 23 }
30 24
31 QuicTime QuicChromiumClock::Now() const { 25 QuicTime QuicChromiumClock::Now() const {
32 #if defined(OS_IOS) 26 int64_t ticks = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
33 if (base::ios::IsRunningOnIOS10OrLater()) { 27 DCHECK_GE(ticks, 0);
34 struct timespec tp; 28 return CreateTimeFromMicroseconds(ticks);
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());
42 } 29 }
43 30
44 QuicWallTime QuicChromiumClock::WallNow() const { 31 QuicWallTime QuicChromiumClock::WallNow() const {
45 return QuicWallTime::FromUNIXMicroseconds(base::Time::Now().ToJavaTime() * 32 const base::TimeDelta time_since_unix_epoch =
46 1000); 33 base::Time::Now() - base::Time::UnixEpoch();
34 int64_t time_since_unix_epoch_micro = time_since_unix_epoch.InMicroseconds();
35 DCHECK_GE(time_since_unix_epoch_micro, 0);
36 return QuicWallTime::FromUNIXMicroseconds(time_since_unix_epoch_micro);
47 } 37 }
48 38
49 } // namespace net 39 } // namespace net
OLDNEW
« no previous file with comments | « base/time/time_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698