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

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

Issue 2142813003: bluetooth: Avoid including non-blink mojo bindings in blink code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Add DCHECK for enum Created 4 years, 5 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/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"
(...skipping 30 matching lines...) Expand all
41 , m_resolver(resolver) {} 41 , m_resolver(resolver) {}
42 42
43 void onSuccess() override 43 void onSuccess() override
44 { 44 {
45 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 45 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
46 return; 46 return;
47 m_device->gatt()->setConnected(true); 47 m_device->gatt()->setConnected(true);
48 m_resolver->resolve(m_device->gatt()); 48 m_resolver->resolve(m_device->gatt());
49 } 49 }
50 50
51 void onError(const WebBluetoothError& e) override 51 void onError(int32_t error /* Corresponds to WebBluetoothError in web_blueto oth.mojom */) override
52 { 52 {
53 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 53 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
54 return; 54 return;
55 m_resolver->reject(BluetoothError::take(m_resolver, e)); 55 m_resolver->reject(BluetoothError::take(m_resolver, error));
56 } 56 }
57 private: 57 private:
58 Persistent<BluetoothDevice> m_device; 58 Persistent<BluetoothDevice> m_device;
59 Persistent<ScriptPromiseResolver> m_resolver; 59 Persistent<ScriptPromiseResolver> m_resolver;
60 }; 60 };
61 61
62 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) 62 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState)
63 { 63 {
64 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 64 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
65 if (!webbluetooth) 65 if (!webbluetooth)
(...skipping 12 matching lines...) Expand all
78 m_connected = false; 78 m_connected = false;
79 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 79 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
80 webbluetooth->disconnect(device()->id()); 80 webbluetooth->disconnect(device()->id());
81 device()->dispatchEvent(Event::createBubble(EventTypeNames::gattserverdiscon nected)); 81 device()->dispatchEvent(Event::createBubble(EventTypeNames::gattserverdiscon nected));
82 } 82 }
83 83
84 // Class that allows us to resolve the promise with a single service or 84 // Class that allows us to resolve the promise with a single service or
85 // with a vector owning the services. 85 // with a vector owning the services.
86 class GetPrimaryServicesCallback : public WebBluetoothGetPrimaryServicesCallback s { 86 class GetPrimaryServicesCallback : public WebBluetoothGetPrimaryServicesCallback s {
87 public: 87 public:
88 GetPrimaryServicesCallback(BluetoothDevice* device, mojom::WebBluetoothGATTQ ueryQuantity quantity, ScriptPromiseResolver* resolver) 88 GetPrimaryServicesCallback(BluetoothDevice* device, mojom::blink::WebBluetoo thGATTQueryQuantity quantity, ScriptPromiseResolver* resolver)
89 : m_device(device) 89 : m_device(device)
90 , m_quantity(quantity) 90 , m_quantity(quantity)
91 , m_resolver(resolver) {} 91 , m_resolver(resolver) {}
92 92
93 void onSuccess(const WebVector<WebBluetoothRemoteGATTService*>& webServices) override 93 void onSuccess(const WebVector<WebBluetoothRemoteGATTService*>& webServices) override
94 { 94 {
95 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 95 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
96 return; 96 return;
97 97
98 if (m_quantity == mojom::WebBluetoothGATTQueryQuantity::SINGLE) { 98 if (m_quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) {
99 DCHECK_EQ(1u, webServices.size()); 99 DCHECK_EQ(1u, webServices.size());
100 m_resolver->resolve(BluetoothRemoteGATTService::take(m_resolver, wra pUnique(webServices[0]), m_device)); 100 m_resolver->resolve(BluetoothRemoteGATTService::take(m_resolver, wra pUnique(webServices[0]), m_device));
101 return; 101 return;
102 } 102 }
103 103
104 HeapVector<Member<BluetoothRemoteGATTService>> services; 104 HeapVector<Member<BluetoothRemoteGATTService>> services;
105 services.reserveInitialCapacity(webServices.size()); 105 services.reserveInitialCapacity(webServices.size());
106 for (WebBluetoothRemoteGATTService* webService : webServices) { 106 for (WebBluetoothRemoteGATTService* webService : webServices) {
107 services.append(BluetoothRemoteGATTService::take(m_resolver, wrapUni que(webService), m_device)); 107 services.append(BluetoothRemoteGATTService::take(m_resolver, wrapUni que(webService), m_device));
108 } 108 }
109 m_resolver->resolve(services); 109 m_resolver->resolve(services);
110 } 110 }
111 111
112 void onError(const WebBluetoothError& e) override 112 void onError(int32_t error /* Corresponds to WebBluetoothError in web_blueto oth.mojom */) override
113 { 113 {
114 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 114 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
115 return; 115 return;
116 m_resolver->reject(BluetoothError::take(m_resolver, e)); 116 m_resolver->reject(BluetoothError::take(m_resolver, error));
117 } 117 }
118 private: 118 private:
119 Persistent<BluetoothDevice> m_device; 119 Persistent<BluetoothDevice> m_device;
120 mojom::WebBluetoothGATTQueryQuantity m_quantity; 120 mojom::blink::WebBluetoothGATTQueryQuantity m_quantity;
121 Persistent<ScriptPromiseResolver> m_resolver; 121 Persistent<ScriptPromiseResolver> m_resolver;
122 }; 122 };
123 123
124 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService(ScriptState* scriptSt ate, const StringOrUnsignedLong& service, ExceptionState& exceptionState) 124 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService(ScriptState* scriptSt ate, const StringOrUnsignedLong& service, ExceptionState& exceptionState)
125 { 125 {
126 String serviceUUID = BluetoothUUID::getService(service, exceptionState); 126 String serviceUUID = BluetoothUUID::getService(service, exceptionState);
127 if (exceptionState.hadException()) 127 if (exceptionState.hadException())
128 return exceptionState.reject(scriptState); 128 return exceptionState.reject(scriptState);
129 129
130 return getPrimaryServicesImpl(scriptState, mojom::WebBluetoothGATTQueryQuant ity::SINGLE, serviceUUID); 130 return getPrimaryServicesImpl(scriptState, mojom::blink::WebBluetoothGATTQue ryQuantity::SINGLE, serviceUUID);
131 } 131 }
132 132
133 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServices(ScriptState* scriptS tate, const StringOrUnsignedLong& service, ExceptionState& exceptionState) 133 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServices(ScriptState* scriptS tate, const StringOrUnsignedLong& service, ExceptionState& exceptionState)
134 { 134 {
135 String serviceUUID = BluetoothUUID::getService(service, exceptionState); 135 String serviceUUID = BluetoothUUID::getService(service, exceptionState);
136 if (exceptionState.hadException()) 136 if (exceptionState.hadException())
137 return exceptionState.reject(scriptState); 137 return exceptionState.reject(scriptState);
138 138
139 return getPrimaryServicesImpl(scriptState, mojom::WebBluetoothGATTQueryQuant ity::MULTIPLE, serviceUUID); 139 return getPrimaryServicesImpl(scriptState, mojom::blink::WebBluetoothGATTQue ryQuantity::MULTIPLE, serviceUUID);
140 } 140 }
141 141
142 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServices(ScriptState* scriptS tate, ExceptionState&) 142 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServices(ScriptState* scriptS tate, ExceptionState&)
143 { 143 {
144 return getPrimaryServicesImpl(scriptState, mojom::WebBluetoothGATTQueryQuant ity::MULTIPLE); 144 return getPrimaryServicesImpl(scriptState, mojom::blink::WebBluetoothGATTQue ryQuantity::MULTIPLE);
145 } 145 }
146 146
147 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl(ScriptState* scr iptState, mojom::WebBluetoothGATTQueryQuantity quantity, String servicesUUID) 147 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl(ScriptState* scr iptState, mojom::blink::WebBluetoothGATTQueryQuantity quantity, String servicesU UID)
148 { 148 {
149 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 149 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
150 ScriptPromise promise = resolver->promise(); 150 ScriptPromise promise = resolver->promise();
151 151
152 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 152 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
153 webbluetooth->getPrimaryServices(device()->id(), quantity, servicesUUID, new GetPrimaryServicesCallback(device(), quantity, resolver)); 153 webbluetooth->getPrimaryServices(device()->id(), static_cast<int32_t>(quanti ty), servicesUUID, new GetPrimaryServicesCallback(device(), quantity, resolver)) ;
154 154
155 return promise; 155 return promise;
156 } 156 }
157 157
158 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698