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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/adapter_broker.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 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 AdapterBroker, served from 6 * Javascript for AdapterBroker, served from
7 * chrome://bluetooth-internals/. 7 * chrome://bluetooth-internals/.
8 */ 8 */
9 cr.define('adapter_broker', function() { 9 cr.define('adapter_broker', function() {
10 /** @typedef {interfaces.BluetoothAdapter.Adapter.ptrClass} */ 10 /** @typedef {interfaces.BluetoothAdapter.Adapter.ptrClass} */
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 getInfo: function() { 82 getInfo: function() {
83 return this.adapter_.getInfo(); 83 return this.adapter_.getInfo();
84 }, 84 },
85 85
86 /** 86 /**
87 * Sets client of Adapter service. 87 * Sets client of Adapter service.
88 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient 88 * @param {!interfaces.BluetoothAdapter.AdapterClient} adapterClient
89 */ 89 */
90 setClient: function(adapterClient) { 90 setClient: function(adapterClient) {
91 adapterClient.binding = new interfaces.Bindings.Binding( 91 adapterClient.binding = new interfaces.Bindings.Binding(
92 interfaces.BluetoothAdapter.AdapterClient, 92 interfaces.BluetoothAdapter.AdapterClient, adapterClient);
93 adapterClient);
94 93
95 this.adapter_.setClient( 94 this.adapter_.setClient(
96 adapterClient.binding.createInterfacePtrAndBind()); 95 adapterClient.binding.createInterfacePtrAndBind());
97 }, 96 },
98 97
99 /** 98 /**
100 * Requests the adapter to start a new discovery session. 99 * Requests the adapter to start a new discovery session.
101 * @return {!Promise<!DiscoverySessionPtr>} 100 * @return {!Promise<!DiscoverySessionPtr>}
102 */ 101 */
103 startDiscoverySession: function() { 102 startDiscoverySession: function() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 177 }
179 }); 178 });
180 this.adapterBroker_.dispatchEvent(event); 179 this.adapterBroker_.dispatchEvent(event);
181 }, 180 },
182 181
183 /** 182 /**
184 * Fires deviceadded event. 183 * Fires deviceadded event.
185 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo 184 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo
186 */ 185 */
187 deviceAdded: function(deviceInfo) { 186 deviceAdded: function(deviceInfo) {
188 var event = new CustomEvent('deviceadded', { 187 var event =
189 detail: { 188 new CustomEvent('deviceadded', {detail: {deviceInfo: deviceInfo}});
190 deviceInfo: deviceInfo
191 }
192 });
193 this.adapterBroker_.dispatchEvent(event); 189 this.adapterBroker_.dispatchEvent(event);
194 }, 190 },
195 191
196 /** 192 /**
197 * Fires devicechanged event. 193 * Fires devicechanged event.
198 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo 194 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo
199 */ 195 */
200 deviceChanged: function(deviceInfo) { 196 deviceChanged: function(deviceInfo) {
201 var event = new CustomEvent('devicechanged', { 197 var event =
202 detail: { 198 new CustomEvent('devicechanged', {detail: {deviceInfo: deviceInfo}});
203 deviceInfo: deviceInfo
204 }
205 });
206 this.adapterBroker_.dispatchEvent(event); 199 this.adapterBroker_.dispatchEvent(event);
207 }, 200 },
208 201
209 /** 202 /**
210 * Fires deviceremoved event. 203 * Fires deviceremoved event.
211 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo 204 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo
212 */ 205 */
213 deviceRemoved: function(deviceInfo) { 206 deviceRemoved: function(deviceInfo) {
214 var event = new CustomEvent('deviceremoved', { 207 var event =
215 detail: { 208 new CustomEvent('deviceremoved', {detail: {deviceInfo: deviceInfo}});
216 deviceInfo: deviceInfo
217 }
218 });
219 this.adapterBroker_.dispatchEvent(event); 209 this.adapterBroker_.dispatchEvent(event);
220 }, 210 },
221 }; 211 };
222 212
223 var adapterBroker = null; 213 var adapterBroker = null;
224 214
225 /** 215 /**
226 * Initializes an AdapterBroker if one doesn't exist. 216 * Initializes an AdapterBroker if one doesn't exist.
227 * @return {!Promise<!AdapterBroker>} resolves with AdapterBroker, 217 * @return {!Promise<!AdapterBroker>} resolves with AdapterBroker,
228 * rejects if Bluetooth is not supported. 218 * rejects if Bluetooth is not supported.
229 */ 219 */
230 function getAdapterBroker() { 220 function getAdapterBroker() {
231 if (adapterBroker) return Promise.resolve(adapterBroker); 221 if (adapterBroker)
222 return Promise.resolve(adapterBroker);
232 223
233 return interfaces.setupInterfaces().then(function(adapter) { 224 return interfaces.setupInterfaces()
234 var adapterFactory = new interfaces.BluetoothAdapter.AdapterFactoryPtr( 225 .then(function(adapter) {
235 interfaces.FrameInterfaces.getInterface( 226 var adapterFactory =
236 interfaces.BluetoothAdapter.AdapterFactory.name)); 227 new interfaces.BluetoothAdapter.AdapterFactoryPtr(
228 interfaces.FrameInterfaces.getInterface(
229 interfaces.BluetoothAdapter.AdapterFactory.name));
237 230
238 // Get an Adapter service. 231 // Get an Adapter service.
239 return adapterFactory.getAdapter(); 232 return adapterFactory.getAdapter();
240 }).then(function(response) { 233 })
241 if (!response.adapter.ptr.isBound()) { 234 .then(function(response) {
242 throw new Error('Bluetooth Not Supported on this platform.'); 235 if (!response.adapter.ptr.isBound()) {
243 } 236 throw new Error('Bluetooth Not Supported on this platform.');
237 }
244 238
245 adapterBroker = new AdapterBroker(response.adapter); 239 adapterBroker = new AdapterBroker(response.adapter);
246 return adapterBroker; 240 return adapterBroker;
247 }); 241 });
248 } 242 }
249 243
250 return { 244 return {
251 AdapterProperty: AdapterProperty, 245 AdapterProperty: AdapterProperty,
252 getAdapterBroker: getAdapterBroker, 246 getAdapterBroker: getAdapterBroker,
253 }; 247 };
254 }); 248 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698