OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/proximity_auth/bluetooth_throttler_impl.h" | 5 #include "components/proximity_auth/bluetooth_throttler_impl.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
8 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
9 #include "components/proximity_auth/connection.h" | 11 #include "components/proximity_auth/connection.h" |
10 | 12 |
11 namespace proximity_auth { | 13 namespace proximity_auth { |
12 namespace { | 14 namespace { |
13 | 15 |
14 // Time to wait after disconnect before reconnecting. | 16 // Time to wait after disconnect before reconnecting. |
15 const int kCooldownTimeSecs = 7; | 17 const int kCooldownTimeSecs = 7; |
16 | 18 |
17 } // namespace | 19 } // namespace |
18 | 20 |
19 BluetoothThrottlerImpl::BluetoothThrottlerImpl( | 21 BluetoothThrottlerImpl::BluetoothThrottlerImpl( |
20 scoped_ptr<base::TickClock> clock) | 22 scoped_ptr<base::TickClock> clock) |
21 : clock_(clock.Pass()) { | 23 : clock_(std::move(clock)) {} |
22 } | |
23 | 24 |
24 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() { | 25 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() { |
25 for (Connection* connection : connections_) { | 26 for (Connection* connection : connections_) { |
26 connection->RemoveObserver(this); | 27 connection->RemoveObserver(this); |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 base::TimeDelta BluetoothThrottlerImpl::GetDelay() const { | 31 base::TimeDelta BluetoothThrottlerImpl::GetDelay() const { |
31 if (last_disconnect_time_.is_null()) | 32 if (last_disconnect_time_.is_null()) |
32 return base::TimeDelta(); | 33 return base::TimeDelta(); |
(...skipping 23 matching lines...) Expand all Loading... |
56 Connection::Status new_status) { | 57 Connection::Status new_status) { |
57 DCHECK(ContainsKey(connections_, connection)); | 58 DCHECK(ContainsKey(connections_, connection)); |
58 if (new_status == Connection::DISCONNECTED) { | 59 if (new_status == Connection::DISCONNECTED) { |
59 last_disconnect_time_ = clock_->NowTicks(); | 60 last_disconnect_time_ = clock_->NowTicks(); |
60 connection->RemoveObserver(this); | 61 connection->RemoveObserver(this); |
61 connections_.erase(connection); | 62 connections_.erase(connection); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 } // namespace proximity_auth | 66 } // namespace proximity_auth |
OLD | NEW |