| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BLUETOOTH_CONNECTION_FINDER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "components/proximity_auth/bluetooth_util.h" | 15 #include "components/proximity_auth/bluetooth_util.h" |
| 15 #include "components/proximity_auth/connection_finder.h" | 16 #include "components/proximity_auth/connection_finder.h" |
| 16 #include "components/proximity_auth/connection_observer.h" | 17 #include "components/proximity_auth/connection_observer.h" |
| 17 #include "components/proximity_auth/remote_device.h" | 18 #include "components/proximity_auth/remote_device.h" |
| 18 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
| 19 #include "device/bluetooth/bluetooth_uuid.h" | 20 #include "device/bluetooth/bluetooth_uuid.h" |
| 20 | 21 |
| 21 namespace proximity_auth { | 22 namespace proximity_auth { |
| 22 | 23 |
| 23 class BluetoothConnection; | 24 class BluetoothConnection; |
| 24 | 25 |
| 25 // This ConnectionFinder implementation tries to find a Bluetooth connection to | 26 // This ConnectionFinder implementation tries to find a Bluetooth connection to |
| 26 // the remote device by polling at a fixed interval. | 27 // the remote device by polling at a fixed interval. |
| 27 class BluetoothConnectionFinder : public ConnectionFinder, | 28 class BluetoothConnectionFinder : public ConnectionFinder, |
| 28 public ConnectionObserver, | 29 public ConnectionObserver, |
| 29 public device::BluetoothAdapter::Observer { | 30 public device::BluetoothAdapter::Observer { |
| 30 public: | 31 public: |
| 31 BluetoothConnectionFinder(const RemoteDevice& remote_device, | 32 BluetoothConnectionFinder(const RemoteDevice& remote_device, |
| 32 const device::BluetoothUUID& uuid, | 33 const device::BluetoothUUID& uuid, |
| 33 const base::TimeDelta& polling_interval); | 34 const base::TimeDelta& polling_interval); |
| 34 ~BluetoothConnectionFinder() override; | 35 ~BluetoothConnectionFinder() override; |
| 35 | 36 |
| 36 // ConnectionFinder: | 37 // ConnectionFinder: |
| 37 void Find(const ConnectionCallback& connection_callback) override; | 38 void Find(const ConnectionCallback& connection_callback) override; |
| 38 | 39 |
| 39 protected: | 40 protected: |
| 40 // Exposed for mocking out the connection in tests. | 41 // Exposed for mocking out the connection in tests. |
| 41 virtual scoped_ptr<Connection> CreateConnection(); | 42 virtual std::unique_ptr<Connection> CreateConnection(); |
| 42 | 43 |
| 43 // Calls bluetooth_util::SeekDeviceByAddress. Exposed for testing, as this | 44 // Calls bluetooth_util::SeekDeviceByAddress. Exposed for testing, as this |
| 44 // utility function is platform dependent. | 45 // utility function is platform dependent. |
| 45 virtual void SeekDeviceByAddress( | 46 virtual void SeekDeviceByAddress( |
| 46 const std::string& bluetooth_address, | 47 const std::string& bluetooth_address, |
| 47 const base::Closure& callback, | 48 const base::Closure& callback, |
| 48 const bluetooth_util::ErrorCallback& error_callback); | 49 const bluetooth_util::ErrorCallback& error_callback); |
| 49 | 50 |
| 50 // BluetoothAdapter::Observer: | 51 // BluetoothAdapter::Observer: |
| 51 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 52 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Records the time at which the finder began searching for connections. | 99 // Records the time at which the finder began searching for connections. |
| 99 base::TimeTicks start_time_; | 100 base::TimeTicks start_time_; |
| 100 | 101 |
| 101 // The callback that should be called upon a successful connection. | 102 // The callback that should be called upon a successful connection. |
| 102 ConnectionCallback connection_callback_; | 103 ConnectionCallback connection_callback_; |
| 103 | 104 |
| 104 // The Bluetooth adapter over which the Bluetooth connection will be made. | 105 // The Bluetooth adapter over which the Bluetooth connection will be made. |
| 105 scoped_refptr<device::BluetoothAdapter> adapter_; | 106 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 106 | 107 |
| 107 // The Bluetooth connection that will be opened. | 108 // The Bluetooth connection that will be opened. |
| 108 scoped_ptr<Connection> connection_; | 109 std::unique_ptr<Connection> connection_; |
| 109 | 110 |
| 110 // Whether there is currently a polling task scheduled. | 111 // Whether there is currently a polling task scheduled. |
| 111 bool has_delayed_poll_scheduled_; | 112 bool has_delayed_poll_scheduled_; |
| 112 | 113 |
| 113 // Used to schedule everything else. | 114 // Used to schedule everything else. |
| 114 base::WeakPtrFactory<BluetoothConnectionFinder> weak_ptr_factory_; | 115 base::WeakPtrFactory<BluetoothConnectionFinder> weak_ptr_factory_; |
| 115 | 116 |
| 116 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder); | 117 DISALLOW_COPY_AND_ASSIGN(BluetoothConnectionFinder); |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 // TODO(isherman): Make sure to wire up the controller to listen for screen lock | 120 // TODO(isherman): Make sure to wire up the controller to listen for screen lock |
| 120 // state change events, and create or destroy the connection finder as | 121 // state change events, and create or destroy the connection finder as |
| 121 // appropriate. | 122 // appropriate. |
| 122 | 123 |
| 123 } // namespace proximity_auth | 124 } // namespace proximity_auth |
| 124 | 125 |
| 125 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H | 126 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H |
| OLD | NEW |