OLD | NEW |
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/BluetoothRemoteGATTServer.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTServer.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" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/events/Event.h" | 12 #include "core/events/Event.h" |
13 #include "modules/bluetooth/BluetoothError.h" | 13 #include "modules/bluetooth/BluetoothError.h" |
14 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 14 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
15 #include "modules/bluetooth/BluetoothSupplement.h" | 15 #include "modules/bluetooth/BluetoothSupplement.h" |
16 #include "modules/bluetooth/BluetoothUUID.h" | 16 #include "modules/bluetooth/BluetoothUUID.h" |
17 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 17 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| 18 #include "wtf/OwnPtr.h" |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 BluetoothRemoteGATTServer::BluetoothRemoteGATTServer(BluetoothDevice* device) | 22 BluetoothRemoteGATTServer::BluetoothRemoteGATTServer(BluetoothDevice* device) |
22 : m_device(device) | 23 : m_device(device) |
23 , m_connected(false) | 24 , m_connected(false) |
24 { | 25 { |
25 } | 26 } |
26 | 27 |
27 BluetoothRemoteGATTServer* BluetoothRemoteGATTServer::create(BluetoothDevice* de
vice) | 28 BluetoothRemoteGATTServer* BluetoothRemoteGATTServer::create(BluetoothDevice* de
vice) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 : m_resolver(resolver) | 90 : m_resolver(resolver) |
90 , m_quantity(quantity) {} | 91 , m_quantity(quantity) {} |
91 | 92 |
92 void onSuccess(const WebVector<WebBluetoothRemoteGATTService*>& webServices)
override | 93 void onSuccess(const WebVector<WebBluetoothRemoteGATTService*>& webServices)
override |
93 { | 94 { |
94 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 95 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
95 return; | 96 return; |
96 | 97 |
97 if (m_quantity == mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 98 if (m_quantity == mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
98 DCHECK_EQ(1u, webServices.size()); | 99 DCHECK_EQ(1u, webServices.size()); |
99 m_resolver->resolve(BluetoothRemoteGATTService::take(m_resolver, wra
pUnique(webServices[0]))); | 100 m_resolver->resolve(BluetoothRemoteGATTService::take(m_resolver, ado
ptPtr(webServices[0]))); |
100 return; | 101 return; |
101 } | 102 } |
102 | 103 |
103 HeapVector<Member<BluetoothRemoteGATTService>> services; | 104 HeapVector<Member<BluetoothRemoteGATTService>> services; |
104 services.reserveInitialCapacity(webServices.size()); | 105 services.reserveInitialCapacity(webServices.size()); |
105 for (WebBluetoothRemoteGATTService* webService : webServices) { | 106 for (WebBluetoothRemoteGATTService* webService : webServices) { |
106 services.append(BluetoothRemoteGATTService::take(m_resolver, wrapUni
que(webService))); | 107 services.append(BluetoothRemoteGATTService::take(m_resolver, adoptPt
r(webService))); |
107 } | 108 } |
108 m_resolver->resolve(services); | 109 m_resolver->resolve(services); |
109 } | 110 } |
110 | 111 |
111 void onError(const WebBluetoothError& e) override | 112 void onError(const WebBluetoothError& e) override |
112 { | 113 { |
113 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) | 114 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) |
114 return; | 115 return; |
115 m_resolver->reject(BluetoothError::take(m_resolver, e)); | 116 m_resolver->reject(BluetoothError::take(m_resolver, e)); |
116 } | 117 } |
(...skipping 30 matching lines...) Expand all Loading... |
147 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 148 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
148 ScriptPromise promise = resolver->promise(); | 149 ScriptPromise promise = resolver->promise(); |
149 | 150 |
150 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); | 151 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); |
151 webbluetooth->getPrimaryServices(device()->id(), quantity, servicesUUID, new
GetPrimaryServicesCallback(quantity, resolver)); | 152 webbluetooth->getPrimaryServices(device()->id(), quantity, servicesUUID, new
GetPrimaryServicesCallback(quantity, resolver)); |
152 | 153 |
153 return promise; | 154 return promise; |
154 } | 155 } |
155 | 156 |
156 } // namespace blink | 157 } // namespace blink |
OLD | NEW |