| 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/cryptauth/bluetooth_throttler.h" |
| 14 #include "components/cryptauth/connection.h" |
| 13 #include "components/proximity_auth/connection_finder.h" | 15 #include "components/proximity_auth/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 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 // ConnectionFinder: |
| 37 void Find(const ConnectionCallback& connection_callback) override; | 37 void Find(const ConnectionCallback& connection_callback) override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // Callback to be called when a connection is found. | 40 // Callback to be called when a connection is found. |
| 41 void OnConnection(const ConnectionCallback& connection_callback, | 41 void OnConnection(const ConnectionCallback& connection_callback, |
| 42 std::unique_ptr<Connection> connection); | 42 std::unique_ptr<cryptauth::Connection> connection); |
| 43 | 43 |
| 44 // The underlying connection finder. | 44 // The underlying connection finder. |
| 45 std::unique_ptr<BluetoothConnectionFinder> connection_finder_; | 45 std::unique_ptr<BluetoothConnectionFinder> connection_finder_; |
| 46 | 46 |
| 47 // The task runner used for posting delayed messages. | 47 // The task runner used for posting delayed messages. |
| 48 scoped_refptr<base::TaskRunner> task_runner_; | 48 scoped_refptr<base::TaskRunner> task_runner_; |
| 49 | 49 |
| 50 // The throttler managing this connection finder. The throttler is not owned, | 50 // The throttler managing this connection finder. The throttler is not owned, |
| 51 // and must outlive |this| instance. | 51 // and must outlive |this| instance. |
| 52 BluetoothThrottler* throttler_; | 52 cryptauth::BluetoothThrottler* throttler_; |
| 53 | 53 |
| 54 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_; | 54 base::WeakPtrFactory<ThrottledBluetoothConnectionFinder> weak_ptr_factory_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder); | 56 DISALLOW_COPY_AND_ASSIGN(ThrottledBluetoothConnectionFinder); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace proximity_auth | 59 } // namespace proximity_auth |
| 60 | 60 |
| 61 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H | 61 #endif // COMPONENTS_PROXIMITY_AUTH_THROTTLED_BLUETOOTH_CONNECTION_FINDER_H |
| OLD | NEW |