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

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

Issue 1964183004: Revert of Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/BluetoothRemoteGATTCharacteristic.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.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/DOMDataView.h" 10 #include "core/dom/DOMDataView.h"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/events/Event.h" 13 #include "core/events/Event.h"
14 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" 14 #include "modules/bluetooth/BluetoothCharacteristicProperties.h"
15 #include "modules/bluetooth/BluetoothError.h" 15 #include "modules/bluetooth/BluetoothError.h"
16 #include "modules/bluetooth/BluetoothSupplement.h" 16 #include "modules/bluetooth/BluetoothSupplement.h"
17 #include "public/platform/modules/bluetooth/WebBluetooth.h" 17 #include "public/platform/modules/bluetooth/WebBluetooth.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 namespace { 21 namespace {
22 22
23 DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector) 23 PassRefPtr<DOMDataView> ConvertWebVectorToDataView(
24 const WebVector<uint8_t>& webVector)
24 { 25 {
25 static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single by te"); 26 static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single by te");
26 DOMArrayBuffer* domBuffer = DOMArrayBuffer::create(webVector.data(), webVect or.size()); 27 RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webVector.data(), webVector.size());
27 return DOMDataView::create(domBuffer, 0, webVector.size()); 28 RefPtr<DOMDataView> domDataView = DOMDataView::create(domBuffer, 0, webVecto r.size());
29 return domDataView;
28 } 30 }
29 31
30 } // anonymous namespace 32 } // anonymous namespace
31 33
32 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(ExecutionCo ntext* context, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacte ristic) 34 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(ExecutionCo ntext* context, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacte ristic)
33 : ActiveDOMObject(context) 35 : ActiveDOMObject(context)
34 , m_webCharacteristic(webCharacteristic) 36 , m_webCharacteristic(webCharacteristic)
35 , m_stopped(false) 37 , m_stopped(false)
36 { 38 {
37 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic ->characteristicProperties); 39 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic ->characteristicProperties);
38 // See example in Source/platform/heap/ThreadState.h 40 // See example in Source/platform/heap/ThreadState.h
39 ThreadState::current()->registerPreFinalizer(this); 41 ThreadState::current()->registerPreFinalizer(this);
40 } 42 }
41 43
42 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip tPromiseResolver* resolver, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic) 44 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip tPromiseResolver* resolver, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic)
43 { 45 {
44 if (!webCharacteristic) { 46 if (!webCharacteristic) {
45 return nullptr; 47 return nullptr;
46 } 48 }
47 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC haracteristic(resolver->getExecutionContext(), webCharacteristic); 49 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC haracteristic(resolver->getExecutionContext(), webCharacteristic);
48 // See note in ActiveDOMObject about suspendIfNeeded. 50 // See note in ActiveDOMObject about suspendIfNeeded.
49 characteristic->suspendIfNeeded(); 51 characteristic->suspendIfNeeded();
50 return characteristic; 52 return characteristic;
51 } 53 }
52 54
53 void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) 55 void BluetoothRemoteGATTCharacteristic::setValue(
56 const PassRefPtr<DOMDataView>& domDataView)
54 { 57 {
55 m_value = domDataView; 58 m_value = domDataView;
56 } 59 }
57 60
58 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged( 61 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
59 const WebVector<uint8_t>& value) 62 const WebVector<uint8_t>& value)
60 { 63 {
61 this->setValue(ConvertWebVectorToDataView(value)); 64 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
65 this->setValue(domDataView);
62 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); 66 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
63 } 67 }
64 68
65 void BluetoothRemoteGATTCharacteristic::stop() 69 void BluetoothRemoteGATTCharacteristic::stop()
66 { 70 {
67 notifyCharacteristicObjectRemoved(); 71 notifyCharacteristicObjectRemoved();
68 } 72 }
69 73
70 void BluetoothRemoteGATTCharacteristic::dispose() 74 void BluetoothRemoteGATTCharacteristic::dispose()
71 { 75 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 108
105 class ReadValueCallback : public WebBluetoothReadValueCallbacks { 109 class ReadValueCallback : public WebBluetoothReadValueCallbacks {
106 public: 110 public:
107 ReadValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, ScriptP romiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(reso lver) {} 111 ReadValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, ScriptP romiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(reso lver) {}
108 112
109 void onSuccess(const WebVector<uint8_t>& value) override 113 void onSuccess(const WebVector<uint8_t>& value) override
110 { 114 {
111 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 115 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
112 return; 116 return;
113 117
114 DOMDataView* domDataView = ConvertWebVectorToDataView(value); 118 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
115 if (m_webCharacteristic) 119 if (m_webCharacteristic) {
116 m_webCharacteristic->setValue(domDataView); 120 m_webCharacteristic->setValue(domDataView);
117 121 }
118 m_resolver->resolve(domDataView); 122 m_resolver->resolve(domDataView);
119 } 123 }
120 124
121 void onError(const WebBluetoothError& e) override 125 void onError(const WebBluetoothError& e) override
122 { 126 {
123 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped()) 127 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
124 return; 128 return;
125 m_resolver->reject(BluetoothError::take(m_resolver, e)); 129 m_resolver->reject(BluetoothError::take(m_resolver, e));
126 } 130 }
127 131
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 { 208 {
205 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 209 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
206 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 210 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
207 ScriptPromise promise = resolver->promise(); 211 ScriptPromise promise = resolver->promise();
208 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 212 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
209 return promise; 213 return promise;
210 } 214 }
211 215
212 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) 216 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic)
213 { 217 {
214 visitor->trace(m_properties);
215 visitor->trace(m_value);
216 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothRemoteGATTChara cteristic>::trace(visitor); 218 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothRemoteGATTChara cteristic>::trace(visitor);
217 ActiveDOMObject::trace(visitor); 219 ActiveDOMObject::trace(visitor);
220 visitor->trace(m_properties);
218 } 221 }
219 222
220 } // namespace blink 223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698