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

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 pub/sub system for device events, various issue fixes 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..30329ba6e19f73aeb9dbd51bd957cac4b70d2a76 100644
--- a/chrome/browser/resources/bluetooth_internals/device_collection.js
+++ b/chrome/browser/resources/bluetooth_internals/device_collection.js
@@ -46,7 +46,7 @@ cr.define('device_collection', function() {
var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) ||
(oldDevice.info.rssi && oldDevice.info.rssi.value);
- oldDevice.info = deviceInfo;
+ Object.assign(oldDevice.info, deviceInfo);
oldDevice.info.rssi = { value: rssi };
oldDevice.removed = false;
@@ -63,9 +63,25 @@ cr.define('device_collection', function() {
remove: function(deviceInfo) {
var device = this.getByAddress(deviceInfo.address);
assert(device, 'Device does not exist.');
+
device.removed = true;
+ device.proxy = null;
this.updateIndex(this.indexOf(device));
- }
+ },
+
+ /**
+ *
+ */
+ updateConnectionStatus: function(index, optional_error) {
ortuno 2016/11/09 03:24:03 I would use the address instead. If I understand c
mbrunson 2016/11/09 23:39:37 Done.
+ var message = (optional_error && optional_error.message) || '';
ortuno 2016/11/09 03:24:03 I would save the information in the device object
mbrunson 2016/11/09 23:39:37 Done.
+ var event = new CustomEvent('connectstatus', {
+ detail: {
+ index: index,
+ message: message,
+ }
+ });
+ this.dispatchEvent(event);
+ },
};
/*
@@ -78,6 +94,37 @@ cr.define('device_collection', function() {
this.removed = false;
};
+ Device.prototype = {
ortuno 2016/11/09 03:24:03 Before this patch this class used to only hold inf
mbrunson 2016/11/09 23:39:37 Hmm ok. So in the final design, DeviceDetailsView
+ /**
+ * Creates a connection to this device and updates the service list.
+ * @return {Promise} rejects if connection failed, resolves otherwise.
+ */
+ connect: function() {
+ return adapter_broker.getAdapterBroker().then(function(broker) {
+ return broker.connectToDevice(this.info.address);
+ }.bind(this)).then(function(response) {
+ this.proxy = response.device;
+ }.bind(this));
+ },
+
+ /**
+ * Disconnects the device and removes the Device interface proxy.
+ */
+ disconnect: function() {
+ if (this.proxy) {
+ this.proxy.disconnect();
+ this.proxy = null;
+ }
+ },
+
+ getServices: function() {
+ return this.proxy.getServices().then(function(response) {
+ this.info.services = response.services;
+ return this.info.services;
+ }.bind(this));
+ }
+ };
+
return {
Device: Device,
DeviceCollection: DeviceCollection,

Powered by Google App Engine
This is Rietveld 408576698