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