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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Clean up Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "modules/bluetooth/BluetoothRemoteGATTService.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTService.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 28 matching lines...) Expand all
39 if (exceptionState.hadException()) 39 if (exceptionState.hadException())
40 return exceptionState.reject(scriptState); 40 return exceptionState.reject(scriptState);
41 41
42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
43 ScriptPromise promise = resolver->promise(); 43 ScriptPromise promise = resolver->promise();
44 webbluetooth->getCharacteristic(m_webService->serviceInstanceID, characteris ticUUID, new CallbackPromiseAdapter<BluetoothRemoteGATTCharacteristic, Bluetooth Error>(resolver)); 44 webbluetooth->getCharacteristic(m_webService->serviceInstanceID, characteris ticUUID, new CallbackPromiseAdapter<BluetoothRemoteGATTCharacteristic, Bluetooth Error>(resolver));
45 45
46 return promise; 46 return promise;
47 } 47 }
48 48
49 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script State, ExceptionState&)
50 {
51 return getCharacteristicsImpl(scriptState, String());
52 }
53
54 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script State, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionStat e)
55 {
56 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic, exceptionState);
57 if (exceptionState.hadException())
58 return exceptionState.reject(scriptState);
59
60 return getCharacteristicsImpl(scriptState, characteristicUUID);
61 }
62
63 // Class that allows us to use CallbackPromiseAdapter to resolve a promise with a
64 // vector owning BluetoothRemoteGATTCharacteristics.
65 class RemoteCharacteristicArray {
66 STATIC_ONLY(RemoteCharacteristicArray);
67 public:
68 using WebType = OwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>> ;
69 static HeapVector<Member<BluetoothRemoteGATTCharacteristic>> take(ScriptProm iseResolver* resolver, PassOwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristic Init*>> webCharacteristics)
70 {
71 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> characteristics;
Jeffrey Yasskin 2016/02/24 23:20:30 Use characteristics.reserveInitialCapacity(webChar
ortuno 2016/02/25 23:08:27 Done.
72 for (WebBluetoothRemoteGATTCharacteristicInit* webCharacteristic : *webC haracteristics) {
73 characteristics.append(BluetoothRemoteGATTCharacteristic::take(resol ver, adoptPtr(webCharacteristic)));
74 }
75 return characteristics;
76 }
77 };
78
79 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* sc riptState, String characteristicUUID)
80 {
81 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
82 ScriptPromise promise = resolver->promise();
83
84 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
85 webbluetooth->getCharacteristics(m_webService->serviceInstanceID, characteri sticUUID, new CallbackPromiseAdapter<RemoteCharacteristicArray, BluetoothError>( resolver));
86
87 return promise;
88 }
89
49 } // namespace blink 90 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698