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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/device_collection.js

Issue 2446823002: bluetooth: Componentize device list in chrome://bluetooth-internals. (Closed)
Patch Set: Formatting changes, comments 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for Device-related features, served from
7 * chrome://bluetooth-internals/.
8 */
9
10 cr.define('device_collection', function() {
11 /*
12 * Collection of devices.
13 * @constructor
14 * @param {!Array} array the starting collection of devices.
15 * @extends {cr.ui.ArrayDataModel}
16 */
17 var DeviceCollection = function(array) {
18 cr.ui.ArrayDataModel.call(this, array);
19 };
20 DeviceCollection.prototype = {
21 __proto__: cr.ui.ArrayDataModel.prototype,
22
23 /**
24 * Finds the Device in the collection with the matching address.
25 * @param {!string} address
26 */
27 getByAddress: function(address) {
28 for (var i = 0; i < this.length; i++) {
29 var device = this.item(i);
30 if (address == device.info.address)
31 return device;
32 }
33 return null;
34 },
35
36 /**
37 * Adds or updates a Device with new DeviceInfo.
38 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo
39 */
40 addOrUpdate: function(deviceInfo) {
41 var oldDevice = this.getByAddress(deviceInfo.address);
42 if (oldDevice) {
43 // Update rssi if it's valid
44 var rssi = (deviceInfo.rssi && deviceInfo.rssi.value) ||
45 (oldDevice.info.rssi && oldDevice.info.rssi.value);
46
47 oldDevice.info = deviceInfo;
48 oldDevice.info.rssi = { value: rssi };
49 oldDevice.removed = false;
50
51 this.updateIndex(this.indexOf(oldDevice));
52 } else {
53 var device = new Device(deviceInfo);
54 this.push(device);
ortuno 2016/11/03 22:14:15 nit: I would just do this.push(new Device(deviceIn
mbrunson 2016/11/03 23:59:40 Done.
55 }
56 },
57
58 /**
59 * Marks the Device as removed.
60 * @param {!interfaces.bluetoothDevice.DeviceInfo} deviceInfo
61 */
62 remove: function(deviceInfo) {
63 var device = this.getByAddress(deviceInfo.address);
64 assert(device,
65 'Device does not exist.');
ortuno 2016/11/03 22:14:15 nit: Why is this on a different line?
mbrunson 2016/11/03 23:59:40 Should be on same line. Done.
66 device.removed = true;
67 this.updateIndex(this.indexOf(device));
68 }
69 };
70
71 /*
72 * Data model for a cached device.
73 * @constructor
74 * @param {!interfaces.BluetoothDevice.DeviceInfo} info
75 */
76 var Device = function(info) {
77 this.info = info;
78 this.removed = false;
79 };
80
81 return {
82 DeviceCollection, DeviceCollection,
ortuno 2016/11/03 22:14:15 qq: What are you returning here? Shouldn't this be
mbrunson 2016/11/03 23:59:40 Must have hit a key by accident or something. Shou
83 };
84 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698