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/cryptauth/bluetooth_throttler_impl.h" | 5 #include "components/cryptauth/bluetooth_throttler_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/time/default_tick_clock.h" |
10 #include "base/time/tick_clock.h" | 12 #include "base/time/tick_clock.h" |
11 #include "components/cryptauth/connection.h" | 13 #include "components/cryptauth/connection.h" |
12 | 14 |
13 namespace cryptauth { | 15 namespace cryptauth { |
14 namespace { | 16 namespace { |
15 | 17 |
16 // Time to wait after disconnect before reconnecting. | 18 // Time to wait after disconnect before reconnecting. |
17 const int kCooldownTimeSecs = 7; | 19 const int kCooldownTimeSecs = 7; |
18 | 20 |
19 } // namespace | 21 } // namespace |
20 | 22 |
| 23 // static |
| 24 BluetoothThrottlerImpl* BluetoothThrottlerImpl::GetInstance() { |
| 25 return base::Singleton<BluetoothThrottlerImpl>::get(); |
| 26 } |
| 27 |
| 28 BluetoothThrottlerImpl::BluetoothThrottlerImpl() |
| 29 : BluetoothThrottlerImpl(base::MakeUnique<base::DefaultTickClock>()) {} |
| 30 |
21 BluetoothThrottlerImpl::BluetoothThrottlerImpl( | 31 BluetoothThrottlerImpl::BluetoothThrottlerImpl( |
22 std::unique_ptr<base::TickClock> clock) | 32 std::unique_ptr<base::TickClock> clock) |
23 : clock_(std::move(clock)) {} | 33 : clock_(std::move(clock)) {} |
24 | 34 |
25 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() { | 35 BluetoothThrottlerImpl::~BluetoothThrottlerImpl() { |
26 for (Connection* connection : connections_) { | 36 for (Connection* connection : connections_) { |
27 connection->RemoveObserver(this); | 37 connection->RemoveObserver(this); |
28 } | 38 } |
29 } | 39 } |
30 | 40 |
(...skipping 26 matching lines...) Expand all Loading... |
57 Connection::Status new_status) { | 67 Connection::Status new_status) { |
58 DCHECK(base::ContainsKey(connections_, connection)); | 68 DCHECK(base::ContainsKey(connections_, connection)); |
59 if (new_status == Connection::DISCONNECTED) { | 69 if (new_status == Connection::DISCONNECTED) { |
60 last_disconnect_time_ = clock_->NowTicks(); | 70 last_disconnect_time_ = clock_->NowTicks(); |
61 connection->RemoveObserver(this); | 71 connection->RemoveObserver(this); |
62 connections_.erase(connection); | 72 connections_.erase(connection); |
63 } | 73 } |
64 } | 74 } |
65 | 75 |
66 } // namespace cryptauth | 76 } // namespace cryptauth |
OLD | NEW |