Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h |
| diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h |
| index f9ec0c337355b29a72bdf03da94e6c2cb30341b4..7cbd1f9ea8c78ab3aa96b7a0af8cdebeb143a120 100644 |
| --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h |
| +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h |
| @@ -33,6 +33,7 @@ class BrowserContext; |
| namespace extensions { |
| +class BluetoothLowEnergyConnection; |
| class Extension; |
| // The BluetoothLowEnergyEventRouter is used by the bluetoothLowEnergy API to |
| @@ -50,6 +51,9 @@ class BluetoothLowEnergyEventRouter |
| kStatusSuccess = 0, |
| kStatusErrorPermissionDenied, |
| kStatusErrorNotFound, |
| + kStatusErrorAlreadyConnected, |
| + kStatusErrorNotConnected, |
| + kStatusErrorInProgress, |
| kStatusErrorFailed |
| }; |
| @@ -70,6 +74,22 @@ class BluetoothLowEnergyEventRouter |
| // Returns true, if the BluetoothAdapter was initialized. |
| bool HasAdapter() const; |
| + // Creates a GATT connection to the device with address |device_address| for |
| + // extension |extension|. The connection is kept alive until the extension is |
| + // unloaded, the device is removed, or is disconnect by the host subsystem. |
| + Status Connect(const Extension* extension, |
| + const std::string& device_address, |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback); |
|
rpaquay
2014/06/19 19:07:27
Why are using both a "Status" return value and an
armansito
2014/06/19 21:58:35
Done.
|
| + |
| + // Disconnects the currently open GATT connection of extension |extension| to |
| + // device with address |device_address|. Returns an error if the device is not |
| + // found or the given extension does not have an open connection to the |
| + // device. |
| + Status Disconnect(const Extension* extension, |
| + const std::string& device_address, |
| + const base::Closure& callback); |
|
rpaquay
2014/06/19 19:07:26
Same comment as above, I'd suggest having "error_c
armansito
2014/06/19 21:58:35
Done.
|
| + |
| // Returns the list of api::bluetooth_low_energy::Service objects associated |
| // with the Bluetooth device with address |device_address| in |out_services|. |
| // Returns false, if no device with the given address is known. If the device |
| @@ -253,10 +273,40 @@ class BluetoothLowEnergyEventRouter |
| void OnValueSuccess(const base::Closure& callback, |
| const std::vector<uint8>& value); |
| + // Called by BluetoothDevice in response to a call to CreateGattConnection. |
| + void OnCreateGattConnection( |
| + const std::string& extension_id, |
| + const std::string& device_address, |
| + const base::Closure& callback, |
| + scoped_ptr<device::BluetoothGattConnection> connection); |
| + |
| + // Called by BluetoothGattConnection in response to a call to Disconnect. |
| + void OnDisconnect(const std::string& extension_id, |
| + const std::string& device_address, |
| + const base::Closure& callback); |
| + |
| // Called by BluetoothGattCharacteristic and BluetoothGattDescriptor in |
| // case of an error during the read/write operations. |
| void OnError(const ErrorCallback& error_callback); |
| + // Called by BluetoothDevice in response to a call to CreateGattConnection. |
| + void OnConnectError(const std::string& device_address, |
| + const ErrorCallback& error_callback, |
| + device::BluetoothDevice::ConnectErrorCode error_code); |
| + |
| + // Finds and returns a BluetoothLowEnergyConnection to device with address |
| + // |device_address| from the managed API resources for extension with ID |
| + // |extension_id|. |
| + BluetoothLowEnergyConnection* FindConnection( |
| + const std::string& extension_id, |
| + const std::string& device_address); |
| + |
| + // Removes the connection to device with address |device_address| from the |
| + // managed API resources for extension with ID |extension_id|. Returns false, |
| + // if the connection could not be found. |
| + bool RemoveConnection(const std::string& extension_id, |
| + const std::string& device_address); |
| + |
| // Mapping from instance ids to identifiers of owning instances. The keys are |
| // used to identify individual instances of GATT objects and are used by |
| // bluetoothLowEnergy API functions to obtain the correct GATT object to |
| @@ -284,6 +334,10 @@ class BluetoothLowEnergyEventRouter |
| // Bluetooth adapter of the system. |
| scoped_refptr<device::BluetoothAdapter> adapter_; |
| + // Set of device addresses to which a connect/disconnect is currently pending. |
| + std::set<std::string> connecting_devices_; |
| + std::set<std::string> disconnecting_devices_; |
| + |
| // BrowserContext passed during initialization. |
| content::BrowserContext* browser_context_; |