| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * Javascript for bluetooth_internals.html, served from | 6 * Javascript for bluetooth_internals.html, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 // Expose for testing. |
| 11 var adapterBroker = null; |
| 12 var devices = null; |
| 13 |
| 10 cr.define('bluetooth_internals', function() { | 14 cr.define('bluetooth_internals', function() { |
| 11 | 15 |
| 12 /** @type {!Map<string, !interfaces.BluetoothDevice.Device.proxyClass>} */ | 16 /** @type {!Map<string, !interfaces.BluetoothDevice.Device.proxyClass>} */ |
| 13 var deviceAddressToProxy = new Map(); | 17 var deviceAddressToProxy = new Map(); |
| 14 | 18 |
| 15 function initializeViews() { | 19 function initializeViews() { |
| 16 var adapterBroker = null; | |
| 17 adapter_broker.getAdapterBroker() | 20 adapter_broker.getAdapterBroker() |
| 18 .then(function(broker) { adapterBroker = broker; }) | 21 .then(function(broker) { adapterBroker = broker; }) |
| 19 .then(function() { return adapterBroker.getInfo(); }) | 22 .then(function() { return adapterBroker.getInfo(); }) |
| 20 .then(function(response) { console.log('adapter', response.info); }) | 23 .then(function(response) { console.log('adapter', response.info); }) |
| 21 .then(function() { return adapterBroker.getDevices(); }) | 24 .then(function() { return adapterBroker.getDevices(); }) |
| 22 .then(function(response) { | 25 .then(function(response) { |
| 23 // Hook up device collection events. | 26 // Hook up device collection events. |
| 24 var devices = new device_collection.DeviceCollection([]); | 27 devices = new device_collection.DeviceCollection([]); |
| 25 adapterBroker.addEventListener('deviceadded', function(event) { | 28 adapterBroker.addEventListener('deviceadded', function(event) { |
| 26 devices.addOrUpdate(event.detail.deviceInfo); | 29 devices.addOrUpdate(event.detail.deviceInfo); |
| 27 }); | 30 }); |
| 28 adapterBroker.addEventListener('devicechanged', function(event) { | 31 adapterBroker.addEventListener('devicechanged', function(event) { |
| 29 devices.addOrUpdate(event.detail.deviceInfo); | 32 devices.addOrUpdate(event.detail.deviceInfo); |
| 30 }); | 33 }); |
| 31 adapterBroker.addEventListener('deviceremoved', function(event) { | 34 adapterBroker.addEventListener('deviceremoved', function(event) { |
| 32 devices.remove(event.detail.deviceInfo); | 35 devices.remove(event.detail.deviceInfo); |
| 33 }); | 36 }); |
| 34 | 37 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 devices.addOrUpdate(deviceInfo); | 76 devices.addOrUpdate(deviceInfo); |
| 74 }).catch(function(error) { | 77 }).catch(function(error) { |
| 75 devices.updateConnectionStatus( | 78 devices.updateConnectionStatus( |
| 76 address, | 79 address, |
| 77 device_collection.ConnectionStatus.DISCONNECTED, | 80 device_collection.ConnectionStatus.DISCONNECTED, |
| 78 error); | 81 error); |
| 79 }); | 82 }); |
| 80 }); | 83 }); |
| 81 | 84 |
| 82 deviceTable.setDevices(devices); | 85 deviceTable.setDevices(devices); |
| 86 deviceTable.id = 'device-table'; |
| 87 |
| 83 document.body.appendChild(deviceTable); | 88 document.body.appendChild(deviceTable); |
| 84 }) | 89 }) |
| 85 .catch(function(error) { console.error(error); }); | 90 .catch(function(error) { console.error(error); }); |
| 86 } | 91 } |
| 87 | 92 |
| 88 return { | 93 return { |
| 89 initializeViews: initializeViews | 94 initializeViews: initializeViews |
| 90 }; | 95 }; |
| 91 | |
| 92 }); | 96 }); |
| 93 | 97 |
| 94 document.addEventListener( | 98 document.addEventListener( |
| 95 'DOMContentLoaded', bluetooth_internals.initializeViews); | 99 'DOMContentLoaded', bluetooth_internals.initializeViews); |
| OLD | NEW |