OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "components/proximity_auth/bluetooth_throttler_impl.h" |
| 6 |
| 7 #include "base/time/tick_clock.h" |
| 8 |
| 9 namespace proximity_auth { |
| 10 namespace { |
| 11 |
| 12 // Time to wait after disconnect before reconnecting. |
| 13 const int kCooldownTimeSecs = 7; |
| 14 |
| 15 } // namespace |
| 16 |
| 17 BluetoothThrottlerImpl::BluetoothThrottlerImpl( |
| 18 scoped_ptr<base::TickClock> clock) |
| 19 : clock_(clock.Pass()) { |
| 20 } |
| 21 |
| 22 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() { |
| 23 } |
| 24 |
| 25 base::TimeDelta BluetoothThrottlerImpl::GetDelay() const { |
| 26 if (last_disconnect_time_.is_null()) |
| 27 return base::TimeDelta(); |
| 28 |
| 29 base::TimeTicks now = clock_->NowTicks(); |
| 30 base::TimeTicks throttled_start_time = |
| 31 last_disconnect_time_ + GetCooldownTimeDelta(); |
| 32 if (now >= throttled_start_time) |
| 33 return base::TimeDelta(); |
| 34 |
| 35 return throttled_start_time - now; |
| 36 } |
| 37 |
| 38 void BluetoothThrottlerImpl::OnConnectionClosed() { |
| 39 last_disconnect_time_ = clock_->NowTicks(); |
| 40 } |
| 41 |
| 42 base::TimeDelta BluetoothThrottlerImpl::GetCooldownTimeDelta() const { |
| 43 return base::TimeDelta::FromSeconds(kCooldownTimeSecs); |
| 44 } |
| 45 |
| 46 } // namespace proximity_auth |
OLD | NEW |