| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/base/network_time_notifier.h" | 5 #include "net/base/network_time_notifier.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 NetworkTimeNotifier::~NetworkTimeNotifier() {} | 36 NetworkTimeNotifier::~NetworkTimeNotifier() {} |
| 37 | 37 |
| 38 void NetworkTimeNotifier::UpdateNetworkTime(const base::Time& network_time, | 38 void NetworkTimeNotifier::UpdateNetworkTime(const base::Time& network_time, |
| 39 const base::TimeDelta& resolution, | 39 const base::TimeDelta& resolution, |
| 40 const base::TimeDelta& latency, | 40 const base::TimeDelta& latency, |
| 41 const base::TimeTicks& post_time) { | 41 const base::TimeTicks& post_time) { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); | 42 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 DVLOG(1) << "Network time updating to " | 43 DVLOG(1) << "Network time updating to " |
| 44 << UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(network_time)); | 44 << base::UTF16ToUTF8( |
| 45 base::TimeFormatFriendlyDateAndTime(network_time)); |
| 45 // Update network time on every request to limit dependency on ticks lag. | 46 // Update network time on every request to limit dependency on ticks lag. |
| 46 // TODO(mad): Find a heuristic to avoid augmenting the | 47 // TODO(mad): Find a heuristic to avoid augmenting the |
| 47 // network_time_uncertainty_ too much by a particularly long latency. | 48 // network_time_uncertainty_ too much by a particularly long latency. |
| 48 // Maybe only update when the the new time either improves in accuracy or | 49 // Maybe only update when the the new time either improves in accuracy or |
| 49 // drifts too far from |network_time_|. | 50 // drifts too far from |network_time_|. |
| 50 network_time_ = network_time; | 51 network_time_ = network_time; |
| 51 | 52 |
| 52 // Calculate the delay since the network time was received. | 53 // Calculate the delay since the network time was received. |
| 53 base::TimeTicks now = tick_clock_->NowTicks(); | 54 base::TimeTicks now = tick_clock_->NowTicks(); |
| 54 base::TimeDelta task_delay = now - post_time; | 55 base::TimeDelta task_delay = now - post_time; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 82 base::MessageLoop::current()->PostTask( | 83 base::MessageLoop::current()->PostTask( |
| 83 FROM_HERE, | 84 FROM_HERE, |
| 84 base::Bind(observer_callback, | 85 base::Bind(observer_callback, |
| 85 network_time_, | 86 network_time_, |
| 86 network_time_ticks_, | 87 network_time_ticks_, |
| 87 network_time_uncertainty_)); | 88 network_time_uncertainty_)); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 } // namespace net | 92 } // namespace net |
| OLD | NEW |