Chromium Code Reviews| Index: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| index fe2167d80141459dfd65a757856a545aed7d1530..0dd5390fd3e028a0c0a98907a8027ab05642445b 100644 |
| --- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| +++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js |
| @@ -50,6 +50,12 @@ cr.define('bluetooth_internals', function() { |
| /** @type {devices_page.DevicesPage} */ |
| var devicesPage = null; |
| + /** @type {interfaces.BluetoothAdapter.DiscoverySession.ptrClass} */ |
| + var discoverySession = null; |
| + |
| + /** @type {boolean} */ |
| + var userRequestedScanStop = false; |
| + |
| function handleInspect(event) { |
| // TODO(crbug.com/663470): Move connection logic to DeviceDetailsView |
| // when it's added in chrome://bluetooth-internals. |
| @@ -108,6 +114,26 @@ cr.define('bluetooth_internals', function() { |
| }); |
| } |
| + function updateStoppedDiscoverySession() { |
| + devicesPage.setScanStatus(devices_page.ScanStatus.OFF); |
| + discoverySession.ptr.reset(); |
| + discoverySession = null; |
| + } |
| + |
| + function setupAdapterSystem(response) { |
| + console.log('adapter', response.info); |
| + |
| + adapterBroker.addEventListener('adapterchanged', function(event) { |
| + if (event.detail.property === 'discovering') { |
|
dpapad
2017/01/05 23:30:33
Is there a need for two separate if conditions? Ho
mbrunson
2017/01/06 01:18:56
Done.
|
| + if (!event.detail.value && !userRequestedScanStop && discoverySession) { |
| + updateStoppedDiscoverySession(); |
| + Snackbar.show( |
| + 'Discovery session ended unexpectedly', SnackbarType.WARNING); |
| + } |
| + } |
| + }); |
| + } |
| + |
| function setupDeviceSystem(response) { |
| // Hook up device collection events. |
| adapterBroker.addEventListener('deviceadded', function(event) { |
| @@ -124,6 +150,44 @@ cr.define('bluetooth_internals', function() { |
| devicesPage.setDevices(devices); |
| devicesPage.pageDiv.addEventListener('inspectpressed', handleInspect); |
| + |
| + devicesPage.pageDiv.addEventListener('scanpressed', function(event) { |
| + if (discoverySession && discoverySession.ptr.isBound()) { |
| + userRequestedScanStop = true; |
| + devicesPage.setScanStatus(devices_page.ScanStatus.STOPPING); |
| + |
| + discoverySession.stop().then(function(response) { |
| + if (response.success) { |
| + updateStoppedDiscoverySession(); |
|
dpapad
2017/01/05 23:30:33
Is the |userRequestedScanStop| really necessary? M
mbrunson
2017/01/06 01:18:56
It's because of the 'adapterchanged' event that I
|
| + userRequestedScanStop = false; |
| + return; |
| + } |
| + |
| + devicesPage.setScanStatus(devices_page.ScanStatus.ON); |
| + Snackbar.show( |
| + 'Failed to stop discovery session', SnackbarType.ERROR); |
| + userRequestedScanStop = false; |
| + }); |
| + |
| + return; |
| + } |
| + |
| + devicesPage.setScanStatus(devices_page.ScanStatus.STARTING); |
| + adapterBroker.startDiscoverySession().then(function(session) { |
| + discoverySession = session; |
| + |
| + discoverySession.ptr.setConnectionErrorHandler(function() { |
| + updateStoppedDiscoverySession(); |
| + Snackbar.show('Discovery session ended', SnackbarType.WARNING); |
| + }); |
| + |
| + devicesPage.setScanStatus(devices_page.ScanStatus.ON); |
| + }).catch(function(error) { |
| + devicesPage.setScanStatus(devices_page.ScanStatus.OFF); |
| + Snackbar.show('Failed to start discovery session', SnackbarType.ERROR); |
| + console.error(error); |
| + }); |
| + }); |
| } |
| function setupPages() { |
| @@ -154,7 +218,7 @@ cr.define('bluetooth_internals', function() { |
| adapter_broker.getAdapterBroker() |
| .then(function(broker) { adapterBroker = broker; }) |
| .then(function() { return adapterBroker.getInfo(); }) |
|
dpapad
2017/01/05 23:30:33
The info returned by this call is never used by se
mbrunson
2017/01/06 01:18:56
The info returned is currently logged to console b
|
| - .then(function(response) { console.log('adapter', response.info); }) |
| + .then(setupAdapterSystem) |
| .then(function() { return adapterBroker.getDevices(); }) |
| .then(setupDeviceSystem) |
| .catch(function(error) { |