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

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

Issue 2752663002: Remove RemoteServerDisconnect() from web_bluetooth.mojom (Closed)
Patch Set: rebase Created 3 years, 9 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 19 matching lines...) Expand all
30 ExecutionContext* context, 30 ExecutionContext* context,
31 BluetoothDevice* device) { 31 BluetoothDevice* device) {
32 return new BluetoothRemoteGATTServer(context, device); 32 return new BluetoothRemoteGATTServer(context, device);
33 } 33 }
34 34
35 void BluetoothRemoteGATTServer::contextDestroyed(ExecutionContext*) { 35 void BluetoothRemoteGATTServer::contextDestroyed(ExecutionContext*) {
36 Dispose(); 36 Dispose();
37 } 37 }
38 38
39 void BluetoothRemoteGATTServer::GATTServerDisconnected() { 39 void BluetoothRemoteGATTServer::GATTServerDisconnected() {
40 DispatchDisconnected(); 40 // This function can only be called if m_clientBinding is bound and
scheib 2017/03/20 21:39:14 Can we assert these claims with DCHECKs?
juncai 2017/03/21 00:52:35 Added a "DCHECK(m_clientBinding.is_bound());" here
41 // m_clientBinding can only be bound if |m_connected| is true.
42 // Therefore we skip Step 2 of Responding to Disconnection.
43 // https://webbluetoothcg.github.io/web-bluetooth/#disconnection-events
44 CleanupDisconnectedDevice();
45 m_device->dispatchEvent(
scheib 2017/03/20 21:39:14 Nearly all locations CleanupDisconnectedDevice is
juncai 2017/03/21 00:52:35 Added an extra parameter to CleanupDisconnectedDev
46 Event::createBubble(EventTypeNames::gattserverdisconnected));
41 } 47 }
42 48
43 void BluetoothRemoteGATTServer::AddToActiveAlgorithms( 49 void BluetoothRemoteGATTServer::AddToActiveAlgorithms(
44 ScriptPromiseResolver* resolver) { 50 ScriptPromiseResolver* resolver) {
45 auto result = m_activeAlgorithms.insert(resolver); 51 auto result = m_activeAlgorithms.insert(resolver);
46 CHECK(result.isNewEntry); 52 CHECK(result.isNewEntry);
47 } 53 }
48 54
49 bool BluetoothRemoteGATTServer::RemoveFromActiveAlgorithms( 55 bool BluetoothRemoteGATTServer::RemoveFromActiveAlgorithms(
50 ScriptPromiseResolver* resolver) { 56 ScriptPromiseResolver* resolver) {
51 if (!m_activeAlgorithms.contains(resolver)) { 57 if (!m_activeAlgorithms.contains(resolver)) {
52 return false; 58 return false;
53 } 59 }
54 m_activeAlgorithms.erase(resolver); 60 m_activeAlgorithms.erase(resolver);
55 return true; 61 return true;
56 } 62 }
57 63
58 void BluetoothRemoteGATTServer::DisconnectIfConnected() { 64 void BluetoothRemoteGATTServer::DisconnectIfConnected() {
59 if (m_connected) { 65 if (!m_connected) {
60 SetConnected(false); 66 return;
61 ClearActiveAlgorithms();
62 mojom::blink::WebBluetoothService* service =
63 m_device->bluetooth()->Service();
64 service->RemoteServerDisconnect(m_device->id());
65 } 67 }
68
69 CleanupDisconnectedDevice();
scheib 2017/03/20 21:39:14 This location doesn't create a disconnected event.
juncai 2017/03/21 00:52:35 This function DisconnectIfConnected() is removed s
70 DCHECK(m_clientBinding.is_bound());
71 m_clientBinding.Close();
66 } 72 }
67 73
68 void BluetoothRemoteGATTServer::CleanupDisconnectedDeviceAndFireEvent() { 74 void BluetoothRemoteGATTServer::CleanupDisconnectedDevice() {
69 DCHECK(m_connected); 75 DCHECK(m_connected);
70 SetConnected(false); 76 SetConnected(false);
71 ClearActiveAlgorithms(); 77 ClearActiveAlgorithms();
72 m_device->ClearAttributeInstanceMapAndFireEvent(); 78 m_device->ClearAttributeInstanceMap();
73 } 79 }
74 80
75 void BluetoothRemoteGATTServer::DispatchDisconnected() { 81 void BluetoothRemoteGATTServer::HandleClientConnectionError() {
76 if (!m_connected) { 82 if (!m_connected) {
77 return; 83 return;
78 } 84 }
79 CleanupDisconnectedDeviceAndFireEvent(); 85
86 CleanupDisconnectedDevice();
87 m_device->dispatchEvent(
88 Event::createBubble(EventTypeNames::gattserverdisconnected));
80 } 89 }
81 90
82 void BluetoothRemoteGATTServer::Dispose() { 91 void BluetoothRemoteGATTServer::Dispose() {
83 DisconnectIfConnected(); 92 DisconnectIfConnected();
84 // The pipe to this object must be closed when is marked unreachable to
85 // prevent messages from being dispatched before lazy sweeping.
86 m_clientBinding.Close();
87 } 93 }
88 94
89 DEFINE_TRACE(BluetoothRemoteGATTServer) { 95 DEFINE_TRACE(BluetoothRemoteGATTServer) {
90 visitor->trace(m_activeAlgorithms); 96 visitor->trace(m_activeAlgorithms);
91 visitor->trace(m_device); 97 visitor->trace(m_device);
92 ContextLifecycleObserver::trace(visitor); 98 ContextLifecycleObserver::trace(visitor);
93 } 99 }
94 100
95 void BluetoothRemoteGATTServer::ConnectCallback( 101 void BluetoothRemoteGATTServer::ConnectCallback(
96 ScriptPromiseResolver* resolver, 102 ScriptPromiseResolver* resolver,
(...skipping 10 matching lines...) Expand all
107 } 113 }
108 } 114 }
109 115
110 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) { 116 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) {
111 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 117 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
112 ScriptPromise promise = resolver->promise(); 118 ScriptPromise promise = resolver->promise();
113 119
114 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service(); 120 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service();
115 mojom::blink::WebBluetoothServerClientAssociatedPtrInfo ptrInfo; 121 mojom::blink::WebBluetoothServerClientAssociatedPtrInfo ptrInfo;
116 m_clientBinding.Bind(&ptrInfo); 122 m_clientBinding.Bind(&ptrInfo);
123 m_clientBinding.set_connection_error_handler(convertToBaseCallback(
124 WTF::bind(&BluetoothRemoteGATTServer::HandleClientConnectionError,
125 wrapWeakPersistent(this))));
117 service->RemoteServerConnect( 126 service->RemoteServerConnect(
118 m_device->id(), std::move(ptrInfo), 127 m_device->id(), std::move(ptrInfo),
119 convertToBaseCallback( 128 convertToBaseCallback(
120 WTF::bind(&BluetoothRemoteGATTServer::ConnectCallback, 129 WTF::bind(&BluetoothRemoteGATTServer::ConnectCallback,
121 wrapPersistent(this), wrapPersistent(resolver)))); 130 wrapPersistent(this), wrapPersistent(resolver))));
122 131
123 return promise; 132 return promise;
124 } 133 }
125 134
126 void BluetoothRemoteGATTServer::disconnect(ScriptState* scriptState) { 135 void BluetoothRemoteGATTServer::disconnect(ScriptState* scriptState) {
127 if (!m_connected) 136 ClearActiveAlgorithms();
137 if (!m_connected) {
128 return; 138 return;
129 CleanupDisconnectedDeviceAndFireEvent(); 139 }
140
141 CleanupDisconnectedDevice();
142 m_device->dispatchEvent(
143 Event::createBubble(EventTypeNames::gattserverdisconnected));
144
145 DCHECK(m_clientBinding.is_bound());
130 m_clientBinding.Close(); 146 m_clientBinding.Close();
131 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service();
132 service->RemoteServerDisconnect(m_device->id());
133 } 147 }
134 148
135 // Callback that allows us to resolve the promise with a single service or 149 // Callback that allows us to resolve the promise with a single service or
136 // with a vector owning the services. 150 // with a vector owning the services.
137 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( 151 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback(
138 const String& requestedServiceUUID, 152 const String& requestedServiceUUID,
139 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 153 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
140 ScriptPromiseResolver* resolver, 154 ScriptPromiseResolver* resolver,
141 mojom::blink::WebBluetoothResult result, 155 mojom::blink::WebBluetoothResult result,
142 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { 156 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 service->RemoteServerGetPrimaryServices( 247 service->RemoteServerGetPrimaryServices(
234 m_device->id(), quantity, servicesUUID, 248 m_device->id(), quantity, servicesUUID,
235 convertToBaseCallback( 249 convertToBaseCallback(
236 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, 250 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback,
237 wrapPersistent(this), servicesUUID, quantity, 251 wrapPersistent(this), servicesUUID, quantity,
238 wrapPersistent(resolver)))); 252 wrapPersistent(resolver))));
239 return promise; 253 return promise;
240 } 254 }
241 255
242 } // namespace blink 256 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698