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

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

Issue 2448713002: bluetooth: Add Device connection logic and accompanying user interface. (Closed)
Patch Set: Add comment for SetCallbackRan function in device connection helper 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/device_collection.js
diff --git a/chrome/browser/resources/bluetooth_internals/device_collection.js b/chrome/browser/resources/bluetooth_internals/device_collection.js
index 4d86d99c79d47e972aa809d210f54b8a59528384..ba352790cf138d80b4441c509527482bc3b16376 100644
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js
@@ -76,6 +76,44 @@ cr.define('device_collection', function() {
var Device = function(info) {
this.info = info;
this.removed = false;
+ this.connectionPending = false;
+ };
+ Device.prototype = {
+ /**
+ * Creates a connection to the device and updates the service listing.
+ * @return {Promise} rejects if connection failed, resolves otherwise.
+ */
+ connect: function() {
+ this.connectionPending = true;
+ return adapter_broker.getAdapterBroker().then(function(broker) {
+ return broker.connectToDevice(this.info.address);
+ }.bind(this)).then(function(response) {
+ this.connectionPending = false;
+ if (response.error ==
ortuno 2016/11/08 04:38:02 I would move this (if (response.error)... throw ne
mbrunson 2016/11/08 22:45:12 Done.
+ interfaces.BluetoothAdapter.ConnectResult.SUCCESS) {
+ this.proxy = response.device;
+ return this.proxy.getServices();
+ }
+
+ // TODO(mbrunson): Replace with more descriptive error messages.
ortuno 2016/11/08 04:38:02 TODOs are usually used when there are other depend
mbrunson 2016/11/08 22:45:12 Ok. I'll make an issue. Done.
+ var errorString = Object.keys(
+ interfaces.BluetoothAdapter.ConnectResult)[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 {

Powered by Google App Engine
This is Rietveld 408576698