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 #ifndef COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H |
6 #define COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "components/proximity_auth/connection_finder.h" | 13 #include "components/cryptauth/bluetooth_throttler.h" |
| 14 #include "components/cryptauth/connection.h" |
| 15 #include "components/cryptauth/connection_finder.h" |
14 | 16 |
15 namespace base { | 17 namespace base { |
16 class TaskRunner; | 18 class TaskRunner; |
17 } | 19 } |
18 | 20 |
19 namespace proximity_auth { | 21 namespace proximity_auth { |
20 | 22 |
21 class BluetoothConnectionFinder; | 23 class BluetoothConnectionFinder; |
22 class BluetoothThrottler; | |
23 class Connection; | |
24 | 24 |
25 // A Bluetooth connection finder that delays Find() requests according to the | 25 // A Bluetooth connection finder that delays Find() requests according to the |
26 // throttler's cooldown period. | 26 // throttler's cooldown period. |
27 class ThrottledBluetoothConnectionFinder : public ConnectionFinder { | 27 class ThrottledBluetoothConnectionFinder : public cryptauth::ConnectionFinder { |
28 public: | 28 public: |
29 // Note: The |throttler| is not owned, and must outlive |this| instance. | 29 // Note: The |throttler| is not owned, and must outlive |this| instance. |
30 ThrottledBluetoothConnectionFinder( | 30 ThrottledBluetoothConnectionFinder( |
31 std::unique_ptr<BluetoothConnectionFinder> connection_finder, | 31 std::unique_ptr<BluetoothConnectionFinder> connection_finder, |
32 scoped_refptr<base::TaskRunner> task_runner, | 32 scoped_refptr<base::TaskRunner> task_runner, |
33 BluetoothThrottler* throttler); | 33 cryptauth::BluetoothThrottler* throttler); |
34 ~ThrottledBluetoothConnectionFinder() override; | 34 ~ThrottledBluetoothConnectionFinder() override; |
35 | 35 |
36 // ConnectionFinder: | 36 // cryptauth::ConnectionFinder: |
37 void Find(const ConnectionCallback& connection_callback) override; | 37 void Find(const cryptauth::ConnectionFinder::ConnectionCallback& |
| 38 connection_callback) override; |
38 | 39 |
39 private: | 40 private: |
40 // Callback to be called when a connection is found. | 41 // Callback to be called when a connection is found. |
41 void OnConnection(const ConnectionCallback& connection_callback, | 42 void OnConnection(const cryptauth::ConnectionFinder::ConnectionCallback& |
42 std::unique_ptr<Connection> connection); | 43 connection_callback, |
| 44 std::unique_ptr<cryptauth::Connection> connection); |
43 | 45 |
44 // The underlying connection finder. | 46 // The underlying connection finder. |
45 std::unique_ptr<BluetoothConnectionFinder> connection_finder_; | 47 std::unique_ptr<BluetoothConnectionFinder> connection_finder_; |
46 | 48 |
47 // The task runner used for posting delayed messages. | 49 // The task runner used for posting delayed messages. |
48 scoped_refptr<base::TaskRunner> task_runner_; | 50 scoped_refptr<base::TaskRunner> task_runner_; |
49 | 51 |
50 // The throttler managing this connection finder. The throttler is not owned, | 52 // The throttler managing this connection finder. The throttler is not owned, |
51 // and must outlive |this| instance. | 53 // and must outlive |this| instance. |
52 BluetoothThrottler* throttler_; | 54 cryptauth::BluetoothThrottler* throttler_; |
53 | 55 |
54 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_; | 56 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_; |
55 | 57 |
56 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder); | 58 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder); |
57 }; | 59 }; |
58 | 60 |
59 } // namespace proximity_auth | 61 } // namespace proximity_auth |
60 | 62 |
61 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H | 63 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H |
OLD | NEW |