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

Side by Side Diff: content/child/bluetooth/bluetooth_dispatcher.cc

Issue 1149883011: bluetooth: Browser-side implementation of readValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-get-characteristic-initial
Patch Set: Fix merge conflicts Created 5 years, 6 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/child/bluetooth/bluetooth_dispatcher.h" 5 #include "content/child/bluetooth/bluetooth_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "content/child/thread_safe_sender.h" 11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/bluetooth/bluetooth_messages.h" 12 #include "content/common/bluetooth/bluetooth_messages.h"
13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h"
17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h"
18 18
19 using blink::WebBluetoothConnectGATTCallbacks; 19 using blink::WebBluetoothConnectGATTCallbacks;
20 using blink::WebBluetoothDevice; 20 using blink::WebBluetoothDevice;
21 using blink::WebBluetoothError; 21 using blink::WebBluetoothError;
22 using blink::WebBluetoothGATTCharacteristic; 22 using blink::WebBluetoothGATTCharacteristic;
23 using blink::WebBluetoothGATTRemoteServer; 23 using blink::WebBluetoothGATTRemoteServer;
24 using blink::WebBluetoothGATTService; 24 using blink::WebBluetoothGATTService;
25 using blink::WebBluetoothReadValueCallbacks;
25 using blink::WebBluetoothRequestDeviceCallbacks; 26 using blink::WebBluetoothRequestDeviceCallbacks;
26 using blink::WebString; 27 using blink::WebString;
27 using blink::WebVector; 28 using blink::WebVector;
28 29
29 struct BluetoothPrimaryServiceRequest { 30 struct BluetoothPrimaryServiceRequest {
30 BluetoothPrimaryServiceRequest( 31 BluetoothPrimaryServiceRequest(
31 blink::WebString device_instance_id, 32 blink::WebString device_instance_id,
32 blink::WebString service_uuid, 33 blink::WebString service_uuid,
33 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) 34 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks)
34 : device_instance_id(device_instance_id), 35 : device_instance_id(device_instance_id),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); 138 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess);
138 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); 139 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError);
139 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, 140 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess,
140 OnGetPrimaryServiceSuccess); 141 OnGetPrimaryServiceSuccess);
141 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, 142 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
142 OnGetPrimaryServiceError); 143 OnGetPrimaryServiceError);
143 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, 144 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess,
144 OnGetCharacteristicSuccess); 145 OnGetCharacteristicSuccess);
145 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, 146 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError,
146 OnGetCharacteristicError); 147 OnGetCharacteristicError);
148 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
149 OnReadValueSuccess);
150 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
151 OnReadValueError);
147 IPC_MESSAGE_UNHANDLED(handled = false) 152 IPC_MESSAGE_UNHANDLED(handled = false)
148 IPC_END_MESSAGE_MAP() 153 IPC_END_MESSAGE_MAP()
149 DCHECK(handled) << "Unhandled message:" << msg.type(); 154 DCHECK(handled) << "Unhandled message:" << msg.type();
150 } 155 }
151 156
152 void BluetoothDispatcher::requestDevice( 157 void BluetoothDispatcher::requestDevice(
153 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 158 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
154 int request_id = pending_requests_.Add(callbacks); 159 int request_id = pending_requests_.Add(callbacks);
155 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 160 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id));
156 } 161 }
(...skipping 23 matching lines...) Expand all
180 const blink::WebString& characteristic_uuid, 185 const blink::WebString& characteristic_uuid,
181 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { 186 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) {
182 int request_id = 187 int request_id =
183 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( 188 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest(
184 service_instance_id, characteristic_uuid, callbacks)); 189 service_instance_id, characteristic_uuid, callbacks));
185 Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id, 190 Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id,
186 service_instance_id.utf8(), 191 service_instance_id.utf8(),
187 characteristic_uuid.utf8())); 192 characteristic_uuid.utf8()));
188 } 193 }
189 194
195 void BluetoothDispatcher::readValue(
196 const blink::WebString& characteristic_instance_id,
197 blink::WebBluetoothReadValueCallbacks* callbacks) {
198 int request_id = pending_read_value_requests_.Add(callbacks);
199 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id,
200 characteristic_instance_id.utf8()));
201 }
202
190 void BluetoothDispatcher::OnWorkerRunLoopStopped() { 203 void BluetoothDispatcher::OnWorkerRunLoopStopped() {
191 delete this; 204 delete this;
192 } 205 }
193 206
194 void BluetoothDispatcher::OnRequestDeviceSuccess( 207 void BluetoothDispatcher::OnRequestDeviceSuccess(
195 int thread_id, 208 int thread_id,
196 int request_id, 209 int request_id,
197 const BluetoothDevice& device) { 210 const BluetoothDevice& device) {
198 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 211 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
199 212
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } else { 323 } else {
311 pending_characteristic_requests_.Lookup(request_id) 324 pending_characteristic_requests_.Lookup(request_id)
312 ->callbacks->onError(new WebBluetoothError( 325 ->callbacks->onError(new WebBluetoothError(
313 // TODO(ortuno): Return more descriptive error messages. 326 // TODO(ortuno): Return more descriptive error messages.
314 // http://crbug.com/490419 327 // http://crbug.com/490419
315 WebBluetoothErrorFromBluetoothError(error_type), "")); 328 WebBluetoothErrorFromBluetoothError(error_type), ""));
316 } 329 }
317 pending_characteristic_requests_.Remove(request_id); 330 pending_characteristic_requests_.Remove(request_id);
318 } 331 }
319 332
333 void BluetoothDispatcher::OnReadValueSuccess(
334 int thread_id,
335 int request_id,
336 const std::vector<uint8_t>& value) {
337 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
338
339 // WebArrayBuffer is not accessible from Source/modules so we pass a
340 // WebVector instead.
341 pending_read_value_requests_.Lookup(request_id)
342 ->onSuccess(new WebVector<uint8_t>(value));
343
344 pending_read_value_requests_.Remove(request_id);
345 }
346
347 void BluetoothDispatcher::OnReadValueError(int thread_id,
348 int request_id,
349 BluetoothError error_type) {
350 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
351
352 pending_read_value_requests_.Lookup(request_id)
353 ->onError(new WebBluetoothError(
354 // TODO(ortuno): Return more descriptive error messages.
355 // http://crbug.com/490419
356 WebBluetoothErrorFromBluetoothError(error_type), ""));
357
358 pending_read_value_requests_.Remove(request_id);
359 }
360
320 } // namespace content 361 } // namespace content
OLDNEW
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/child/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698