Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 bluetooth_internals.html, served from | 6 * Javascript for bluetooth_internals.html, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 (function() { | 35 (function() { |
| 36 var adapterFactory = null; | 36 var adapterFactory = null; |
| 37 var adapter = null; | 37 var adapter = null; |
| 38 var adapterClient = null; | 38 var adapterClient = null; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * TODO: Move to shared location. See crbug.com/652361. | 41 * TODO: Move to shared location. See crbug.com/652361. |
| 42 * Logs basic information retrieved from the adapter. | |
| 43 */ | |
| 44 function logAdapterInfo() { | |
| 45 console.log('Getting adapter info'); | |
| 46 | |
| 47 adapter.getInfo().then(function(response) { console.log(response.info); }); | |
|
ortuno
2016/10/06 01:52:21
Q: Did you mean to return the promise here? Or is
mbrunson
2016/10/06 17:45:01
I didn't return it because I didn't care what orde
| |
| 48 } | |
| 49 | |
| 50 /** | |
| 42 * Helper to convert callback-based define() API to a promise-based API. | 51 * Helper to convert callback-based define() API to a promise-based API. |
| 43 * @param {!Array<string>} moduleNames | 52 * @param {!Array<string>} moduleNames |
| 44 * @return {!Promise} | 53 * @return {!Promise} |
| 45 */ | 54 */ |
| 46 function importModules(moduleNames) { | 55 function importModules(moduleNames) { |
| 47 return new Promise(function(resolve, reject) { | 56 return new Promise(function(resolve, reject) { |
| 48 define(moduleNames, function(var_args) { | 57 define(moduleNames, function(var_args) { |
| 49 resolve(Array.prototype.slice.call(arguments, 0)); | 58 resolve(Array.prototype.slice.call(arguments, 0)); |
| 50 }); | 59 }); |
| 51 }); | 60 }); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 // Create a message pipe and bind one end to client | 92 // Create a message pipe and bind one end to client |
| 84 // implementation and the other to the Adapter service. | 93 // implementation and the other to the Adapter service. |
| 85 adapterClient = new AdapterClient(); | 94 adapterClient = new AdapterClient(); |
| 86 adapter.setClient(connection.bindStubDerivedImpl(adapterClient)); | 95 adapter.setClient(connection.bindStubDerivedImpl(adapterClient)); |
| 87 }); | 96 }); |
| 88 }); | 97 }); |
| 89 } | 98 } |
| 90 | 99 |
| 91 document.addEventListener('DOMContentLoaded', function() { | 100 document.addEventListener('DOMContentLoaded', function() { |
| 92 initializeProxies() | 101 initializeProxies() |
| 102 .then(function() { logAdapterInfo(); }) | |
|
ortuno
2016/10/06 01:52:21
nit: Can you just do:
.then(logAdapterInfo)
?
mbrunson
2016/10/06 17:45:01
Done.
| |
| 93 .then(function() { return adapter.getDevices(); }) | 103 .then(function() { return adapter.getDevices(); }) |
| 94 .then(function(response) { console.log(response.devices); }) | 104 .then(function(response) { console.log(response.devices); }) |
| 95 .catch(function(error) { console.error(error); }); | 105 .catch(function(error) { console.error(error); }); |
| 96 }); | 106 }); |
| 97 })(); | 107 })(); |
| OLD | NEW |