| 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_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 62 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 63 bool powered) override; | 63 bool powered) override; |
| 64 void DeviceAdded(device::BluetoothAdapter* adapter, | 64 void DeviceAdded(device::BluetoothAdapter* adapter, |
| 65 device::BluetoothDevice* device) override; | 65 device::BluetoothDevice* device) override; |
| 66 void DeviceChanged(device::BluetoothAdapter* adapter, | 66 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 67 device::BluetoothDevice* device) override; | 67 device::BluetoothDevice* device) override; |
| 68 | 68 |
| 69 protected: | 69 protected: |
| 70 BluetoothLowEnergyConnectionFinder( | 70 BluetoothLowEnergyConnectionFinder( |
| 71 const cryptauth::RemoteDevice remote_device, | 71 const cryptauth::RemoteDevice remote_device, |
| 72 const std::string& service_uuid, |
| 72 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, | 73 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, |
| 73 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, | 74 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, |
| 74 cryptauth::BluetoothThrottler* bluetooth_throttler); | 75 cryptauth::BluetoothThrottler* bluetooth_throttler); |
| 75 | 76 |
| 76 // Creates a proximity_auth::Connection with the device given by | 77 // Creates a proximity_auth::Connection with the device given by |
| 77 // |device_address|. Exposed for testing. | 78 // |device_address|. Exposed for testing. |
| 78 virtual std::unique_ptr<cryptauth::Connection> CreateConnection( | 79 virtual std::unique_ptr<cryptauth::Connection> CreateConnection( |
| 79 const std::string& device_address); | 80 const std::string& device_address); |
| 80 | 81 |
| 82 // Checks if |device| is advertising the right EID. |
| 83 virtual bool IsRightDevice(device::BluetoothDevice* device); |
| 84 |
| 81 private: | 85 private: |
| 82 // Callback to be called when the Bluetooth adapter is initialized. | 86 // Callback to be called when the Bluetooth adapter is initialized. |
| 83 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 87 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| 84 | 88 |
| 85 // Checks if |remote_device| contains |remote_service_uuid| and creates a | 89 // Checks if |remote_device| contains |remote_service_uuid| and creates a |
| 86 // connection in that case. | 90 // connection in that case. |
| 87 void HandleDeviceUpdated(device::BluetoothDevice* remote_device); | 91 void HandleDeviceUpdated(device::BluetoothDevice* remote_device); |
| 88 | 92 |
| 89 // Callback called when a new discovery session is started. | 93 // Callback called when a new discovery session is started. |
| 90 void OnDiscoverySessionStarted( | 94 void OnDiscoverySessionStarted( |
| 91 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); | 95 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); |
| 92 | 96 |
| 93 // Callback called when there is an error starting a new discovery session. | 97 // Callback called when there is an error starting a new discovery session. |
| 94 void OnStartDiscoverySessionError(); | 98 void OnStartDiscoverySessionError(); |
| 95 | 99 |
| 96 // Starts a discovery session for |adapter_|. | 100 // Starts a discovery session for |adapter_|. |
| 97 void StartDiscoverySession(); | 101 void StartDiscoverySession(); |
| 98 | 102 |
| 99 // Stops the discovery session given by |discovery_session_|. | 103 // Stops the discovery session given by |discovery_session_|. |
| 100 void StopDiscoverySession(); | 104 void StopDiscoverySession(); |
| 101 | 105 |
| 102 // Checks if |device| is the right device: (i) has the adversement data or | |
| 103 // (ii) is paired and is the same as |remote_device|. | |
| 104 bool IsRightDevice(device::BluetoothDevice* device); | |
| 105 | |
| 106 // Restarts the discovery session after creating |connection_| fails. | 106 // Restarts the discovery session after creating |connection_| fails. |
| 107 void RestartDiscoverySessionAsync(); | 107 void RestartDiscoverySessionAsync(); |
| 108 | 108 |
| 109 // Used to invoke |connection_callback_| asynchronously, decoupling the | 109 // Used to invoke |connection_callback_| asynchronously, decoupling the |
| 110 // callback invocation from the ConnectionObserver callstack. | 110 // callback invocation from the ConnectionObserver callstack. |
| 111 void InvokeCallbackAsync(); | 111 void InvokeCallbackAsync(); |
| 112 | 112 |
| 113 // The remote BLE device being searched. It maybe empty, in this case the | 113 // The remote BLE device being searched. It maybe empty, in this case the |
| 114 // remote device should advertise |remote_service_uuid_| and | 114 // remote device should advertise |remote_service_uuid_| and |
| 115 // |advertised_name_|. | 115 // |advertised_name_|. |
| 116 cryptauth::RemoteDevice remote_device_; | 116 cryptauth::RemoteDevice remote_device_; |
| 117 | 117 |
| 118 // The UUID of the service used by the Weave socket. |
| 119 std::string service_uuid_; |
| 120 |
| 118 // The BeaconSeeds of the |remote_device|. | 121 // The BeaconSeeds of the |remote_device|. |
| 119 std::vector<cryptauth::BeaconSeed> beacon_seeds_; | 122 std::vector<cryptauth::BeaconSeed> beacon_seeds_; |
| 120 | 123 |
| 121 // Generates the expected EIDs that may be advertised by |remote_device_|. If | 124 // Generates the expected EIDs that may be advertised by |remote_device_|. If |
| 122 // an EID matches, we know its a device we should connect to. | 125 // an EID matches, we know its a device we should connect to. |
| 123 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator_; | 126 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator_; |
| 124 | 127 |
| 125 // Throttles repeated connection attempts to the same device. This is a | 128 // Throttles repeated connection attempts to the same device. This is a |
| 126 // workaround for crbug.com/508919. Not owned, must outlive this instance. | 129 // workaround for crbug.com/508919. Not owned, must outlive this instance. |
| 127 cryptauth::BluetoothThrottler* bluetooth_throttler_; | 130 cryptauth::BluetoothThrottler* bluetooth_throttler_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 139 cryptauth::ConnectionFinder::ConnectionCallback connection_callback_; | 142 cryptauth::ConnectionFinder::ConnectionCallback connection_callback_; |
| 140 | 143 |
| 141 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; | 144 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; |
| 142 | 145 |
| 143 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); | 146 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); |
| 144 }; | 147 }; |
| 145 | 148 |
| 146 } // namespace proximity_auth | 149 } // namespace proximity_auth |
| 147 | 150 |
| 148 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 151 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
| OLD | NEW |