Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3471)

Unified Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Fix naming, merge upstream Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4057293273bc1ddaa7726553896bef63b21fd86d..1daa88adc011e885654725f8f6102ea663c8a57e 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -8,6 +8,9 @@
*/
cr.define('bluetooth_internals', function() {
+
+ var deviceAddressToProxy = new Map();
dpapad 2016/11/10 19:05:02 Can you annotate this with the appropriate K,V typ
mbrunson 2016/11/10 22:02:22 Done.
+
function initializeViews() {
var adapterBroker = null;
adapter_broker.getAdapterBroker()
@@ -32,6 +35,42 @@ cr.define('bluetooth_internals', function() {
devices /* this */);
var deviceTable = new device_table.DeviceTable();
+
+ deviceTable.addEventListener('inspectpressed', function(event) {
+ // TODO(crbug.com/663470): Move connection logic to DeviceDetailsView
+ // when it's added in chrome://bluetooth-internals.
+ var address = event.detail.address;
+ var proxy = deviceAddressToProxy.get(address);
+
+ if (proxy) {
dpapad 2016/11/10 19:05:02 Nit: if (proxy) { ... return; } // No need fo
mbrunson 2016/11/10 22:02:22 Done.
+ // Device is already connected, so disconnect.
+ proxy.disconnect();
+ deviceAddressToProxy.delete(address);
+ devices.updateConnectionStatus(address, 'disconnected');
dpapad 2016/11/10 19:05:02 Please explain where those string literals come fr
mbrunson 2016/11/10 22:02:22 Done.
+ } else {
+ devices.updateConnectionStatus(address, 'connecting');
+ adapterBroker.connectToDevice(address).then(function(deviceProxy) {
+ if (!devices.getByAddress(address)) {
+ // Device no longer in list, so drop the connection.
+ deviceProxy.disconnect();
+ return;
+ }
+
+ deviceAddressToProxy.set(address, deviceProxy);
+ devices.updateConnectionStatus(address, 'connected');
+
+ // Fetch services asynchronously.
+ deviceProxy.getServices().then(function(response) {
+ var deviceInfo = devices.getByAddress(address);
+ deviceInfo.services = response.services;
+ devices.addOrUpdate(deviceInfo);
+ });
+ }).catch(function(error) {
+ devices.updateConnectionStatus(address, 'disconnected', error);
+ });
+ }
+ });
+
deviceTable.setDevices(devices);
document.body.appendChild(deviceTable);
})

Powered by Google App Engine
This is Rietveld 408576698