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

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

Issue 1603893002: bluetooth: Switch BluetoothGattCharacteristic.value to DataView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetoothValue
Patch Set: Created 4 years, 11 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/BluetoothGATTCharacteristic.h" 5 #include "modules/bluetooth/BluetoothGATTCharacteristic.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/DOMException.h" 11 #include "core/dom/DOMException.h"
11 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
12 #include "core/events/Event.h" 13 #include "core/events/Event.h"
13 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" 14 #include "modules/bluetooth/BluetoothCharacteristicProperties.h"
14 #include "modules/bluetooth/BluetoothError.h" 15 #include "modules/bluetooth/BluetoothError.h"
15 #include "modules/bluetooth/BluetoothSupplement.h" 16 #include "modules/bluetooth/BluetoothSupplement.h"
16 #include "public/platform/modules/bluetooth/WebBluetooth.h" 17 #include "public/platform/modules/bluetooth/WebBluetooth.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
20 namespace { 21 namespace {
21 22
22 PassRefPtr<DOMArrayBuffer> ConvertWebVectorToArrayBuffer( 23 PassRefPtr<DOMDataView> ConvertWebVectorToDataView(
23 const WebVector<uint8_t>& webVector) 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 RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webVector.data(), webVector.size()); 27 RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webVector.data(), webVector.size());
27 return domBuffer; 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 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* conte xt, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) 34 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* conte xt, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
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 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic ) 44 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic )
43 { 45 {
44 if (!webCharacteristic) { 46 if (!webCharacteristic) {
45 return nullptr; 47 return nullptr;
46 } 48 }
47 BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristi c(resolver->executionContext(), webCharacteristic); 49 BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristi c(resolver->executionContext(), 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 BluetoothGATTCharacteristic::setValue( 55 void BluetoothGATTCharacteristic::setValue(
54 const PassRefPtr<DOMArrayBuffer>& domBuffer) 56 const PassRefPtr<DOMDataView>& domDataView)
55 { 57 {
56 m_value = domBuffer; 58 m_value = domDataView;
57 } 59 }
58 60
59 void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged( 61 void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged(
60 const WebVector<uint8_t>& value) 62 const WebVector<uint8_t>& value)
61 { 63 {
62 RefPtr<DOMArrayBuffer> domBuffer = ConvertWebVectorToArrayBuffer(value); 64 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
63 this->setValue(domBuffer); 65 this->setValue(domDataView);
64 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); 66 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
65 } 67 }
66 68
67 void BluetoothGATTCharacteristic::stop() 69 void BluetoothGATTCharacteristic::stop()
68 { 70 {
69 notifyCharacteristicObjectRemoved(); 71 notifyCharacteristicObjectRemoved();
70 } 72 }
71 73
72 void BluetoothGATTCharacteristic::dispose() 74 void BluetoothGATTCharacteristic::dispose()
73 { 75 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 108
107 class ReadValueCallback : public WebBluetoothReadValueCallbacks { 109 class ReadValueCallback : public WebBluetoothReadValueCallbacks {
108 public: 110 public:
109 ReadValueCallback(BluetoothGATTCharacteristic* characteristic, ScriptPromise Resolver* resolver) : m_webCharacteristic(characteristic), m_resolver(resolver) {} 111 ReadValueCallback(BluetoothGATTCharacteristic* characteristic, ScriptPromise Resolver* resolver) : m_webCharacteristic(characteristic), m_resolver(resolver) {}
110 112
111 void onSuccess(const WebVector<uint8_t>& value) override 113 void onSuccess(const WebVector<uint8_t>& value) override
112 { 114 {
113 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 115 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
114 return; 116 return;
115 117
116 RefPtr<DOMArrayBuffer> domBuffer = ConvertWebVectorToArrayBuffer(value); 118 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
117 if (m_webCharacteristic) { 119 if (m_webCharacteristic) {
118 m_webCharacteristic->setValue(domBuffer); 120 m_webCharacteristic->setValue(domDataView);
119 } 121 }
120 m_resolver->resolve(domBuffer); 122 m_resolver->resolve(domDataView);
121 } 123 }
122 124
123 void onError(const WebBluetoothError& e) override 125 void onError(const WebBluetoothError& e) override
124 { 126 {
125 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 127 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
126 return; 128 return;
127 m_resolver->reject(BluetoothError::take(m_resolver, e)); 129 m_resolver->reject(BluetoothError::take(m_resolver, e));
128 } 130 }
129 131
130 private: 132 private:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 187 }
186 188
187 DEFINE_TRACE(BluetoothGATTCharacteristic) 189 DEFINE_TRACE(BluetoothGATTCharacteristic)
188 { 190 {
189 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothGATTCharacteris tic>::trace(visitor); 191 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothGATTCharacteris tic>::trace(visitor);
190 ActiveDOMObject::trace(visitor); 192 ActiveDOMObject::trace(visitor);
191 visitor->trace(m_properties); 193 visitor->trace(m_properties);
192 } 194 }
193 195
194 } // namespace blink 196 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698