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

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

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

Powered by Google App Engine
This is Rietveld 408576698