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

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

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Major reorganization of Mojo interface code and DeviceCollection Created 4 years, 2 months 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/device_collection.js
diff --git a/chrome/browser/resources/bluetooth_internals/device_collection.js b/chrome/browser/resources/bluetooth_internals/device_collection.js
index 84c2b85ab7f84b847c2edbf463bc1984755b26ff..8929f724a27ce73f98e97d7757a189a21bb3413f 100644
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js
@@ -32,6 +32,7 @@ cr.define('device_collection', function() {
}
return null;
},
+
/**
* Adds or updates a Device with new DeviceInfo.
* @param {!interfaces.bluetoothDevice.DeviceInfo} deviceInfo
@@ -53,11 +54,17 @@ cr.define('device_collection', function() {
this.push(device);
}
},
+
+ /**
+ * Marks the Device as removed.
+ * @param {!interfaces.bluetoothDevice.DeviceInfo} deviceInfo
+ */
remove: function(deviceInfo) {
var device = this.getByAddress(deviceInfo.address);
assert(device,
'Device does not exist.');
device.removed = true;
+ this.updateIndex(this.indexOf(device));
}
};
@@ -70,6 +77,43 @@ cr.define('device_collection', function() {
this.info = info;
this.removed = false;
};
+ Device.prototype = {
+ /**
+ * Creates a connection to the device and updates the service listing.
+ * @return {Promise} rejects if connection failed, resolves otherwise.
+ */
+ connect: function() {
+ return interfaces.DefaultAdapter.connectToDevice(
+ this.info.address).then(
+ function(response) {
+ if (response.error ==
+ interfaces.BluetoothAdapter.ConnectErrorCode.SUCCESS) {
+ this.proxy = interfaces.Connection.bindHandleToProxy(
+ response.device,
+ interfaces.BluetoothDevice.Device);
+ return this.proxy.getServices();
+ }
+
+ // TODO(mbrunson): Replace with more descriptive error messages.
+ var errorString = Object.keys(
+ interfaces.BluetoothAdapter.ConnectErrorCode)[response.error];
+
+ throw new Error(errorString);
+ }.bind(this)).then(function(response) {
+ this.info.services = response.services;
+ }.bind(this));
+ },
+
+ /**
+ * Disconnects a device and removes the Device interface proxy.
+ */
+ disconnect: function() {
+ if (this.proxy) {
+ this.proxy.disconnect();
+ this.proxy = null;
+ }
+ }
+ };
return {
DeviceCollection, DeviceCollection,

Powered by Google App Engine
This is Rietveld 408576698