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

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

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Javascript for ValueControl, served from chrome://bluetooth-internals/. 6 * Javascript for ValueControl, served from chrome://bluetooth-internals/.
7 */ 7 */
8 8
9 cr.define('value_control', function() { 9 cr.define('value_control', function() {
10 /** @const */ var Snackbar = snackbar.Snackbar; 10 /** @const */ var Snackbar = snackbar.Snackbar;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 /** 334 /**
335 * Called when the read button is pressed. Connects to the device and 335 * Called when the read button is pressed. Connects to the device and
336 * retrieves the current value of the characteristic in the |service_id| 336 * retrieves the current value of the characteristic in the |service_id|
337 * with id |characteristic_id|. If |descriptor_id| is defined, the 337 * with id |characteristic_id|. If |descriptor_id| is defined, the
338 * descriptor value with |descriptor_id| is read instead. 338 * descriptor value with |descriptor_id| is read instead.
339 * @private 339 * @private
340 */ 340 */
341 readValue_: function() { 341 readValue_: function() {
342 this.readBtn_.disabled = true; 342 this.readBtn_.disabled = true;
343 343
344 device_broker.connectToDevice(this.deviceAddress_).then(function(device) { 344 device_broker.connectToDevice(this.deviceAddress_)
345 if (this.descriptorId_) { 345 .then(function(device) {
346 return device.readValueForDescriptor( 346 if (this.descriptorId_) {
347 this.serviceId_, this.characteristicId_, this.descriptorId_); 347 return device.readValueForDescriptor(
348 } 348 this.serviceId_, this.characteristicId_, this.descriptorId_);
349 }
349 350
350 return device.readValueForCharacteristic( 351 return device.readValueForCharacteristic(
351 this.serviceId_, this.characteristicId_); 352 this.serviceId_, this.characteristicId_);
352 }.bind(this)).then(function(response) { 353 }.bind(this))
353 this.readBtn_.disabled = false; 354 .then(function(response) {
355 this.readBtn_.disabled = false;
354 356
355 if (response.result === interfaces.BluetoothDevice.GattResult.SUCCESS) { 357 if (response.result ===
356 this.setValue(response.value); 358 interfaces.BluetoothDevice.GattResult.SUCCESS) {
357 Snackbar.show( 359 this.setValue(response.value);
358 this.deviceAddress_ + ': Read succeeded', SnackbarType.SUCCESS); 360 Snackbar.show(
359 return; 361 this.deviceAddress_ + ': Read succeeded',
360 } 362 SnackbarType.SUCCESS);
363 return;
364 }
361 365
362 var errorString = this.getErrorString_(response.result); 366 var errorString = this.getErrorString_(response.result);
363 Snackbar.show( 367 Snackbar.show(
364 this.deviceAddress_ + ': ' + errorString, SnackbarType.ERROR, 368 this.deviceAddress_ + ': ' + errorString, SnackbarType.ERROR,
365 'Retry', this.readValue_.bind(this)); 369 'Retry', this.readValue_.bind(this));
366 }.bind(this)); 370 }.bind(this));
367 }, 371 },
368 372
369 /** 373 /**
370 * Called when the write button is pressed. Connects to the device and 374 * Called when the write button is pressed. Connects to the device and
371 * retrieves the current value of the characteristic in the 375 * retrieves the current value of the characteristic in the
372 * |service_id| with id |characteristic_id|. If |descriptor_id| is defined, 376 * |service_id| with id |characteristic_id|. If |descriptor_id| is defined,
373 * the descriptor value with |descriptor_id| is written instead. 377 * the descriptor value with |descriptor_id| is written instead.
374 * @private 378 * @private
375 */ 379 */
376 writeValue_: function() { 380 writeValue_: function() {
377 this.writeBtn_.disabled = true; 381 this.writeBtn_.disabled = true;
378 382
379 device_broker.connectToDevice(this.deviceAddress_).then(function(device) { 383 device_broker.connectToDevice(this.deviceAddress_)
380 if (this.descriptorId_) { 384 .then(function(device) {
381 return device.writeValueForDescriptor( 385 if (this.descriptorId_) {
382 this.serviceId_, this.characteristicId_, this.descriptorId_, 386 return device.writeValueForDescriptor(
383 this.value_.getArray()); 387 this.serviceId_, this.characteristicId_, this.descriptorId_,
384 } 388 this.value_.getArray());
389 }
385 390
386 return device.writeValueForCharacteristic( 391 return device.writeValueForCharacteristic(
387 this.serviceId_, this.characteristicId_, this.value_.getArray()); 392 this.serviceId_, this.characteristicId_,
388 }.bind(this)).then(function(response) { 393 this.value_.getArray());
389 this.writeBtn_.disabled = false; 394 }.bind(this))
395 .then(function(response) {
396 this.writeBtn_.disabled = false;
390 397
391 if (response.result === interfaces.BluetoothDevice.GattResult.SUCCESS) { 398 if (response.result ===
392 Snackbar.show( 399 interfaces.BluetoothDevice.GattResult.SUCCESS) {
393 this.deviceAddress_ + ': Write succeeded', SnackbarType.SUCCESS); 400 Snackbar.show(
394 return; 401 this.deviceAddress_ + ': Write succeeded',
395 } 402 SnackbarType.SUCCESS);
403 return;
404 }
396 405
397 var errorString = this.getErrorString_(response.result); 406 var errorString = this.getErrorString_(response.result);
398 Snackbar.show( 407 Snackbar.show(
399 this.deviceAddress_ + ': ' + errorString, SnackbarType.ERROR, 408 this.deviceAddress_ + ': ' + errorString, SnackbarType.ERROR,
400 'Retry', this.writeValue_.bind(this)); 409 'Retry', this.writeValue_.bind(this));
401 }.bind(this)); 410 }.bind(this));
402 }, 411 },
403 }; 412 };
404 413
405 return { 414 return {
406 ValueControl: ValueControl, 415 ValueControl: ValueControl,
407 ValueDataType: ValueDataType, 416 ValueDataType: ValueDataType,
408 }; 417 };
409 }); 418 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698