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

Side by Side Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 1861013005: bluetooth: Move GetCharacteristic(s) over to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-read-value
Patch Set: Address jyasskin's comments 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/bluetooth/web_bluetooth_impl.h" 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "content/child/mojo/type_converters.h" 10 #include "content/child/mojo/type_converters.h"
11 #include "content/child/thread_safe_sender.h" 11 #include "content/child/thread_safe_sender.h"
12 #include "content/public/common/service_registry.h" 12 #include "content/public/common/service_registry.h"
13 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" 13 #include "content/renderer/bluetooth/bluetooth_dispatcher.h"
14 #include "ipc/ipc_message.h" 14 #include "ipc/ipc_message.h"
15 #include "mojo/public/cpp/bindings/array.h" 15 #include "mojo/public/cpp/bindings/array.h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h"
17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, 21 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry,
21 ThreadSafeSender* thread_safe_sender, 22 ThreadSafeSender* thread_safe_sender,
22 int frame_routing_id) 23 int frame_routing_id)
23 : service_registry_(service_registry), 24 : service_registry_(service_registry),
24 binding_(this), 25 binding_(this),
25 thread_safe_sender_(thread_safe_sender), 26 thread_safe_sender_(thread_safe_sender),
26 frame_routing_id_(frame_routing_id) {} 27 frame_routing_id_(frame_routing_id) {}
(...skipping 18 matching lines...) Expand all
45 } 46 }
46 47
47 void WebBluetoothImpl::getPrimaryService( 48 void WebBluetoothImpl::getPrimaryService(
48 const blink::WebString& device_id, 49 const blink::WebString& device_id,
49 const blink::WebString& service_uuid, 50 const blink::WebString& service_uuid,
50 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { 51 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
51 GetDispatcher()->getPrimaryService(frame_routing_id_, device_id, service_uuid, 52 GetDispatcher()->getPrimaryService(frame_routing_id_, device_id, service_uuid,
52 callbacks); 53 callbacks);
53 } 54 }
54 55
55 void WebBluetoothImpl::getCharacteristic(
56 const blink::WebString& service_instance_id,
57 const blink::WebString& characteristics_uuid,
58 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
59 GetDispatcher()->getCharacteristic(frame_routing_id_, service_instance_id,
60 characteristics_uuid, callbacks);
61 }
62
63 void WebBluetoothImpl::getCharacteristics( 56 void WebBluetoothImpl::getCharacteristics(
64 const blink::WebString& service_instance_id, 57 const blink::WebString& service_instance_id,
65 const blink::WebString& characteristic_uuid, 58 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
59 const blink::WebString& characteristics_uuid,
66 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { 60 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) {
67 GetDispatcher()->getCharacteristics(frame_routing_id_, service_instance_id, 61 GetWebBluetoothService().RemoteServiceGetCharacteristics(
68 characteristic_uuid, callbacks); 62 mojo::String::From(service_instance_id), quantity,
63 characteristics_uuid.isEmpty() ? nullptr
64 : mojo::String::From(characteristics_uuid),
65 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete,
66 base::Unretained(this), service_instance_id,
67 base::Passed(base::WrapUnique(callbacks))));
69 } 68 }
70 69
71 void WebBluetoothImpl::readValue( 70 void WebBluetoothImpl::readValue(
72 const blink::WebString& characteristic_instance_id, 71 const blink::WebString& characteristic_instance_id,
73 blink::WebBluetoothReadValueCallbacks* callbacks) { 72 blink::WebBluetoothReadValueCallbacks* callbacks) {
74 GetWebBluetoothService().RemoteCharacteristicReadValue( 73 GetWebBluetoothService().RemoteCharacteristicReadValue(
75 mojo::String::From(characteristic_instance_id), 74 mojo::String::From(characteristic_instance_id),
76 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), 75 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this),
77 base::Passed(base::WrapUnique(callbacks)))); 76 base::Passed(base::WrapUnique(callbacks))));
78 } 77 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 mojo::Array<uint8_t> value) { 129 mojo::Array<uint8_t> value) {
131 // We post a task so that the event is fired after any pending promises have 130 // We post a task so that the event is fired after any pending promises have
132 // resolved. 131 // resolved.
133 base::ThreadTaskRunnerHandle::Get()->PostTask( 132 base::ThreadTaskRunnerHandle::Get()->PostTask(
134 FROM_HERE, 133 FROM_HERE,
135 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, 134 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged,
136 base::Unretained(this), characteristic_instance_id, 135 base::Unretained(this), characteristic_instance_id,
137 value.PassStorage())); 136 value.PassStorage()));
138 } 137 }
139 138
139 void WebBluetoothImpl::OnGetCharacteristicsComplete(
140 const blink::WebString& service_instance_id,
141 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
142 blink::mojom::WebBluetoothError error,
143 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
144 characteristics) {
145 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
146 // TODO(dcheng): This WebVector should use smart pointers.
147 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*>
148 promise_characteristics(characteristics.size());
149
150 for (size_t i = 0; i < characteristics.size(); i++) {
151 promise_characteristics[i] =
152 new blink::WebBluetoothRemoteGATTCharacteristicInit(
153 service_instance_id,
154 blink::WebString::fromUTF8(characteristics[i]->instance_id),
155 blink::WebString::fromUTF8(characteristics[i]->uuid),
156 characteristics[i]->properties);
157 }
158 callbacks->onSuccess(promise_characteristics);
159 } else {
160 callbacks->onError(error);
161 }
162 }
163
140 void WebBluetoothImpl::OnReadValueComplete( 164 void WebBluetoothImpl::OnReadValueComplete(
141 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, 165 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
142 blink::mojom::WebBluetoothError error, 166 blink::mojom::WebBluetoothError error,
143 mojo::Array<uint8_t> value) { 167 mojo::Array<uint8_t> value) {
144 if (error == blink::mojom::WebBluetoothError::SUCCESS) { 168 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
145 callbacks->onSuccess(value.PassStorage()); 169 callbacks->onSuccess(value.PassStorage());
146 } else { 170 } else {
147 callbacks->onError(error); 171 callbacks->onError(error);
148 } 172 }
149 } 173 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Create an associated interface ptr and pass it to the WebBluetoothService 219 // Create an associated interface ptr and pass it to the WebBluetoothService
196 // so that it can send us events without us prompting. 220 // so that it can send us events without us prompting.
197 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 221 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
198 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 222 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
199 web_bluetooth_service_->SetClient(std::move(ptr_info)); 223 web_bluetooth_service_->SetClient(std::move(ptr_info));
200 } 224 }
201 return *web_bluetooth_service_; 225 return *web_bluetooth_service_;
202 } 226 }
203 227
204 } // namespace content 228 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698