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_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
7 | 7 |
| 8 #include <memory> |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "components/proximity_auth/connection.h" | 16 #include "components/proximity_auth/connection.h" |
17 #include "components/proximity_auth/connection_finder.h" | 17 #include "components/proximity_auth/connection_finder.h" |
18 #include "components/proximity_auth/connection_observer.h" | 18 #include "components/proximity_auth/connection_observer.h" |
19 #include "components/proximity_auth/remote_device.h" | 19 #include "components/proximity_auth/remote_device.h" |
20 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
21 #include "device/bluetooth/bluetooth_device.h" | 21 #include "device/bluetooth/bluetooth_device.h" |
22 #include "device/bluetooth/bluetooth_discovery_session.h" | 22 #include "device/bluetooth/bluetooth_discovery_session.h" |
23 #include "device/bluetooth/bluetooth_gatt_connection.h" | 23 #include "device/bluetooth/bluetooth_gatt_connection.h" |
24 | 24 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 74 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
75 bool powered) override; | 75 bool powered) override; |
76 void DeviceAdded(device::BluetoothAdapter* adapter, | 76 void DeviceAdded(device::BluetoothAdapter* adapter, |
77 device::BluetoothDevice* device) override; | 77 device::BluetoothDevice* device) override; |
78 void DeviceChanged(device::BluetoothAdapter* adapter, | 78 void DeviceChanged(device::BluetoothAdapter* adapter, |
79 device::BluetoothDevice* device) override; | 79 device::BluetoothDevice* device) override; |
80 | 80 |
81 protected: | 81 protected: |
82 // Creates a proximity_auth::Connection with the device given by | 82 // Creates a proximity_auth::Connection with the device given by |
83 // |device_address|. Exposed for testing. | 83 // |device_address|. Exposed for testing. |
84 virtual scoped_ptr<Connection> CreateConnection( | 84 virtual std::unique_ptr<Connection> CreateConnection( |
85 const std::string& device_address); | 85 const std::string& device_address); |
86 | 86 |
87 private: | 87 private: |
88 // Callback to be called when the Bluetooth adapter is initialized. | 88 // Callback to be called when the Bluetooth adapter is initialized. |
89 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 89 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
90 | 90 |
91 // Checks if |remote_device| contains |remote_service_uuid| and creates a | 91 // Checks if |remote_device| contains |remote_service_uuid| and creates a |
92 // connection in that case. | 92 // connection in that case. |
93 void HandleDeviceUpdated(device::BluetoothDevice* remote_device); | 93 void HandleDeviceUpdated(device::BluetoothDevice* remote_device); |
94 | 94 |
95 // Callback called when a new discovery session is started. | 95 // Callback called when a new discovery session is started. |
96 void OnDiscoverySessionStarted( | 96 void OnDiscoverySessionStarted( |
97 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 97 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); |
98 | 98 |
99 // Callback called when there is an error starting a new discovery session. | 99 // Callback called when there is an error starting a new discovery session. |
100 void OnStartDiscoverySessionError(); | 100 void OnStartDiscoverySessionError(); |
101 | 101 |
102 // Starts a discovery session for |adapter_|. | 102 // Starts a discovery session for |adapter_|. |
103 void StartDiscoverySession(); | 103 void StartDiscoverySession(); |
104 | 104 |
105 // Stops the discovery session given by |discovery_session_|. | 105 // Stops the discovery session given by |discovery_session_|. |
106 void StopDiscoverySession(); | 106 void StopDiscoverySession(); |
107 | 107 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 const BluetoothLowEnergyDeviceWhitelist* device_whitelist_; | 140 const BluetoothLowEnergyDeviceWhitelist* device_whitelist_; |
141 | 141 |
142 // Throttles repeated connection attempts to the same device. This is a | 142 // Throttles repeated connection attempts to the same device. This is a |
143 // workaround for crbug.com/508919. Not owned, must outlive this instance. | 143 // workaround for crbug.com/508919. Not owned, must outlive this instance. |
144 BluetoothThrottler* bluetooth_throttler_; | 144 BluetoothThrottler* bluetooth_throttler_; |
145 | 145 |
146 // The Bluetooth adapter over which the Bluetooth connection will be made. | 146 // The Bluetooth adapter over which the Bluetooth connection will be made. |
147 scoped_refptr<device::BluetoothAdapter> adapter_; | 147 scoped_refptr<device::BluetoothAdapter> adapter_; |
148 | 148 |
149 // The discovery session associated to this object. | 149 // The discovery session associated to this object. |
150 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; | 150 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
151 | 151 |
152 // The connection with |remote_device|. | 152 // The connection with |remote_device|. |
153 scoped_ptr<Connection> connection_; | 153 std::unique_ptr<Connection> connection_; |
154 | 154 |
155 // Callback called when the connection is established. | 155 // Callback called when the connection is established. |
156 // device::BluetoothDevice::GattConnectionCallback connection_callback_; | 156 // device::BluetoothDevice::GattConnectionCallback connection_callback_; |
157 ConnectionCallback connection_callback_; | 157 ConnectionCallback connection_callback_; |
158 | 158 |
159 // BluetoothLowEnergyConnection parameter. | 159 // BluetoothLowEnergyConnection parameter. |
160 int max_number_of_tries_; | 160 int max_number_of_tries_; |
161 | 161 |
162 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; | 162 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); | 164 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); |
165 }; | 165 }; |
166 | 166 |
167 } // namespace proximity_auth | 167 } // namespace proximity_auth |
168 | 168 |
169 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CONNECTION_FINDER_H | 169 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CONNECTION_FINDER_H |
OLD | NEW |