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

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

Issue 2478013002: bluetooth: Invalidate services upon disconnection (Closed)
Patch Set: Address scheib's comments Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
11 #include "core/inspector/ConsoleMessage.h" 11 #include "core/inspector/ConsoleMessage.h"
12 #include "modules/bluetooth/BluetoothError.h" 12 #include "modules/bluetooth/BluetoothError.h"
13 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" 13 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h"
14 #include "modules/bluetooth/BluetoothSupplement.h" 14 #include "modules/bluetooth/BluetoothSupplement.h"
15 #include "modules/bluetooth/BluetoothUUID.h" 15 #include "modules/bluetooth/BluetoothUUID.h"
16 #include "public/platform/modules/bluetooth/WebBluetooth.h" 16 #include "public/platform/modules/bluetooth/WebBluetooth.h"
17 #include "wtf/PtrUtil.h" 17 #include "wtf/PtrUtil.h"
18 #include <memory> 18 #include <memory>
19 #include <utility> 19 #include <utility>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 namespace { 23 namespace {
24 24
25 const char kGATTServerDisconnected[] = 25 const char kGATTServerDisconnected[] =
26 "GATT Server disconnected while retrieving characteristics."; 26 "GATT Server disconnected while retrieving characteristics.";
27 const char kGATTServerNotConnected[] = 27 const char kGATTServerNotConnected[] =
28 "GATT Server is disconnected. Cannot retrieve characteristics."; 28 "GATT Server is disconnected. Cannot retrieve characteristics.";
29 const char kInvalidService[] =
30 "Service is no longer valid. Remember to retrieve the service again after "
31 "reconnecting.";
29 32
30 } // namespace 33 } // namespace
31 34
32 BluetoothRemoteGATTService::BluetoothRemoteGATTService( 35 BluetoothRemoteGATTService::BluetoothRemoteGATTService(
33 std::unique_ptr<WebBluetoothRemoteGATTService> webService, 36 std::unique_ptr<WebBluetoothRemoteGATTService> webService,
34 BluetoothDevice* device) 37 BluetoothDevice* device)
35 : m_webService(std::move(webService)), m_device(device) { 38 : m_webService(std::move(webService)), m_device(device) {
36 DCHECK(m_webService); 39 DCHECK(m_webService);
37 } 40 }
38 41
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl( 155 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(
153 ScriptState* scriptState, 156 ScriptState* scriptState,
154 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 157 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
155 String characteristicsUUID) { 158 String characteristicsUUID) {
156 if (!device()->gatt()->connected()) { 159 if (!device()->gatt()->connected()) {
157 return ScriptPromise::rejectWithDOMException( 160 return ScriptPromise::rejectWithDOMException(
158 scriptState, 161 scriptState,
159 DOMException::create(NetworkError, kGATTServerNotConnected)); 162 DOMException::create(NetworkError, kGATTServerNotConnected));
160 } 163 }
161 164
165 if (!device()->isValidService(m_webService->serviceInstanceID)) {
166 return ScriptPromise::rejectWithDOMException(
167 scriptState, DOMException::create(InvalidStateError, kInvalidService));
168 }
169
162 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 170 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
163 ScriptPromise promise = resolver->promise(); 171 ScriptPromise promise = resolver->promise();
164 172
165 WebBluetooth* webbluetooth = 173 WebBluetooth* webbluetooth =
166 BluetoothSupplement::fromScriptState(scriptState); 174 BluetoothSupplement::fromScriptState(scriptState);
167 webbluetooth->getCharacteristics( 175 webbluetooth->getCharacteristics(
168 m_webService->serviceInstanceID, static_cast<int32_t>(quantity), 176 m_webService->serviceInstanceID, static_cast<int32_t>(quantity),
169 characteristicsUUID, 177 characteristicsUUID,
170 new GetCharacteristicsCallback(this, quantity, resolver)); 178 new GetCharacteristicsCallback(this, quantity, resolver));
171 179
172 return promise; 180 return promise;
173 } 181 }
174 182
175 } // namespace blink 183 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698