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

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

Issue 2433773006: Remove ExecutionContext::activeDOMObjectsAreStopped()
Patch Set: Created 4 years, 2 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 visitor->trace(m_activeAlgorithms); 53 visitor->trace(m_activeAlgorithms);
54 visitor->trace(m_device); 54 visitor->trace(m_device);
55 } 55 }
56 56
57 class ConnectCallback : public WebBluetoothRemoteGATTServerConnectCallbacks { 57 class ConnectCallback : public WebBluetoothRemoteGATTServerConnectCallbacks {
58 public: 58 public:
59 ConnectCallback(BluetoothDevice* device, ScriptPromiseResolver* resolver) 59 ConnectCallback(BluetoothDevice* device, ScriptPromiseResolver* resolver)
60 : m_device(device), m_resolver(resolver) {} 60 : m_device(device), m_resolver(resolver) {}
61 61
62 void onSuccess() override { 62 void onSuccess() override {
63 if (!m_resolver->getExecutionContext() || 63 if (!m_resolver->getExecutionContext())
64 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
65 return; 64 return;
66 m_device->gatt()->setConnected(true); 65 m_device->gatt()->setConnected(true);
67 m_resolver->resolve(m_device->gatt()); 66 m_resolver->resolve(m_device->gatt());
68 } 67 }
69 68
70 void onError( 69 void onError(
71 int32_t 70 int32_t
72 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) 71 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */)
73 override { 72 override {
74 if (!m_resolver->getExecutionContext() || 73 if (!m_resolver->getExecutionContext())
75 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
76 return; 74 return;
77 m_resolver->reject(BluetoothError::take(m_resolver, error)); 75 m_resolver->reject(BluetoothError::take(m_resolver, error));
78 } 76 }
79 77
80 private: 78 private:
81 Persistent<BluetoothDevice> m_device; 79 Persistent<BluetoothDevice> m_device;
82 Persistent<ScriptPromiseResolver> m_resolver; 80 Persistent<ScriptPromiseResolver> m_resolver;
83 }; 81 };
84 82
85 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) { 83 ScriptPromise BluetoothRemoteGATTServer::connect(ScriptState* scriptState) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 ScriptPromiseResolver* resolver) 117 ScriptPromiseResolver* resolver)
120 : m_device(device), m_quantity(quantity), m_resolver(resolver) { 118 : m_device(device), m_quantity(quantity), m_resolver(resolver) {
121 // We always check that the device is connected before constructing this 119 // We always check that the device is connected before constructing this
122 // object. 120 // object.
123 CHECK(m_device->gatt()->connected()); 121 CHECK(m_device->gatt()->connected());
124 m_device->gatt()->AddToActiveAlgorithms(m_resolver.get()); 122 m_device->gatt()->AddToActiveAlgorithms(m_resolver.get());
125 } 123 }
126 124
127 void onSuccess( 125 void onSuccess(
128 const WebVector<WebBluetoothRemoteGATTService*>& webServices) override { 126 const WebVector<WebBluetoothRemoteGATTService*>& webServices) override {
129 if (!m_resolver->getExecutionContext() || 127 if (!m_resolver->getExecutionContext())
130 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
131 return; 128 return;
132 129
133 // If the resolver is not in the set of ActiveAlgorithms then the frame 130 // If the resolver is not in the set of ActiveAlgorithms then the frame
134 // disconnected so we reject. 131 // disconnected so we reject.
135 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) { 132 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) {
136 m_resolver->reject( 133 m_resolver->reject(
137 DOMException::create(NetworkError, kGATTServerDisconnected)); 134 DOMException::create(NetworkError, kGATTServerDisconnected));
138 return; 135 return;
139 } 136 }
140 137
(...skipping 10 matching lines...) Expand all
151 services.append(BluetoothRemoteGATTService::take( 148 services.append(BluetoothRemoteGATTService::take(
152 m_resolver, wrapUnique(webService), m_device)); 149 m_resolver, wrapUnique(webService), m_device));
153 } 150 }
154 m_resolver->resolve(services); 151 m_resolver->resolve(services);
155 } 152 }
156 153
157 void onError( 154 void onError(
158 int32_t 155 int32_t
159 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) 156 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */)
160 override { 157 override {
161 if (!m_resolver->getExecutionContext() || 158 if (!m_resolver->getExecutionContext())
162 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
163 return; 159 return;
164 160
165 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) { 161 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) {
166 m_resolver->reject( 162 m_resolver->reject(
167 DOMException::create(NetworkError, kGATTServerDisconnected)); 163 DOMException::create(NetworkError, kGATTServerDisconnected));
168 return; 164 return;
169 } 165 }
170 166
171 m_resolver->reject(BluetoothError::take(m_resolver, error)); 167 m_resolver->reject(BluetoothError::take(m_resolver, error));
172 } 168 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 WebBluetooth* webbluetooth = 222 WebBluetooth* webbluetooth =
227 BluetoothSupplement::fromScriptState(scriptState); 223 BluetoothSupplement::fromScriptState(scriptState);
228 webbluetooth->getPrimaryServices( 224 webbluetooth->getPrimaryServices(
229 device()->id(), static_cast<int32_t>(quantity), servicesUUID, 225 device()->id(), static_cast<int32_t>(quantity), servicesUUID,
230 new GetPrimaryServicesCallback(device(), quantity, resolver)); 226 new GetPrimaryServicesCallback(device(), quantity, resolver));
231 227
232 return promise; 228 return promise;
233 } 229 }
234 230
235 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698