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/throttled_bluetooth_connection_finder.h" | 5 #include "components/proximity_auth/throttled_bluetooth_connection_finder.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "components/cryptauth/bluetooth_throttler.h" |
| 14 #include "components/cryptauth/connection.h" |
13 #include "components/proximity_auth/bluetooth_connection_finder.h" | 15 #include "components/proximity_auth/bluetooth_connection_finder.h" |
14 #include "components/proximity_auth/bluetooth_throttler.h" | |
15 | 16 |
16 namespace proximity_auth { | 17 namespace proximity_auth { |
17 | 18 |
18 ThrottledBluetoothConnectionFinder::ThrottledBluetoothConnectionFinder( | 19 ThrottledBluetoothConnectionFinder::ThrottledBluetoothConnectionFinder( |
19 std::unique_ptr<BluetoothConnectionFinder> connection_finder, | 20 std::unique_ptr<BluetoothConnectionFinder> connection_finder, |
20 scoped_refptr<base::TaskRunner> task_runner, | 21 scoped_refptr<base::TaskRunner> task_runner, |
21 BluetoothThrottler* throttler) | 22 cryptauth::BluetoothThrottler* throttler) |
22 : connection_finder_(std::move(connection_finder)), | 23 : connection_finder_(std::move(connection_finder)), |
23 task_runner_(task_runner), | 24 task_runner_(task_runner), |
24 throttler_(throttler), | 25 throttler_(throttler), |
25 weak_ptr_factory_(this) {} | 26 weak_ptr_factory_(this) {} |
26 | 27 |
27 ThrottledBluetoothConnectionFinder::~ThrottledBluetoothConnectionFinder() { | 28 ThrottledBluetoothConnectionFinder::~ThrottledBluetoothConnectionFinder() { |
28 } | 29 } |
29 | 30 |
30 void ThrottledBluetoothConnectionFinder::Find( | 31 void ThrottledBluetoothConnectionFinder::Find( |
31 const ConnectionCallback& connection_callback) { | 32 const cryptauth::ConnectionFinder::ConnectionCallback& |
| 33 connection_callback) { |
32 const base::TimeDelta delay = throttler_->GetDelay(); | 34 const base::TimeDelta delay = throttler_->GetDelay(); |
33 | 35 |
34 // Wait, if needed. | 36 // Wait, if needed. |
35 if (!delay.is_zero()) { | 37 if (!delay.is_zero()) { |
36 task_runner_->PostDelayedTask( | 38 task_runner_->PostDelayedTask( |
37 FROM_HERE, | 39 FROM_HERE, |
38 base::Bind(&ThrottledBluetoothConnectionFinder::Find, | 40 base::Bind(&ThrottledBluetoothConnectionFinder::Find, |
39 weak_ptr_factory_.GetWeakPtr(), connection_callback), | 41 weak_ptr_factory_.GetWeakPtr(), connection_callback), |
40 delay); | 42 delay); |
41 return; | 43 return; |
42 } | 44 } |
43 | 45 |
44 connection_finder_->Find( | 46 connection_finder_->Find( |
45 base::Bind(&ThrottledBluetoothConnectionFinder::OnConnection, | 47 base::Bind(&ThrottledBluetoothConnectionFinder::OnConnection, |
46 weak_ptr_factory_.GetWeakPtr(), connection_callback)); | 48 weak_ptr_factory_.GetWeakPtr(), connection_callback)); |
47 } | 49 } |
48 | 50 |
49 void ThrottledBluetoothConnectionFinder::OnConnection( | 51 void ThrottledBluetoothConnectionFinder::OnConnection( |
50 const ConnectionCallback& connection_callback, | 52 const cryptauth::ConnectionFinder::ConnectionCallback& connection_callback, |
51 std::unique_ptr<Connection> connection) { | 53 std::unique_ptr<cryptauth::Connection> connection) { |
52 throttler_->OnConnection(connection.get()); | 54 throttler_->OnConnection(connection.get()); |
53 connection_callback.Run(std::move(connection)); | 55 connection_callback.Run(std::move(connection)); |
54 } | 56 } |
55 | 57 |
56 } // namespace proximity_auth | 58 } // namespace proximity_auth |
OLD | NEW |