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