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

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

Issue 1172853004: Chromium side of RequestDeviceOptions implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Add an end-namespace comment 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 "device/bluetooth/bluetooth_uuid.h"
13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h" 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h"
17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" 18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
18 20
19 using blink::WebBluetoothConnectGATTCallbacks; 21 using blink::WebBluetoothConnectGATTCallbacks;
20 using blink::WebBluetoothDevice; 22 using blink::WebBluetoothDevice;
21 using blink::WebBluetoothError; 23 using blink::WebBluetoothError;
22 using blink::WebBluetoothGATTCharacteristic; 24 using blink::WebBluetoothGATTCharacteristic;
23 using blink::WebBluetoothGATTRemoteServer; 25 using blink::WebBluetoothGATTRemoteServer;
24 using blink::WebBluetoothGATTService; 26 using blink::WebBluetoothGATTService;
25 using blink::WebBluetoothReadValueCallbacks; 27 using blink::WebBluetoothReadValueCallbacks;
26 using blink::WebBluetoothRequestDeviceCallbacks; 28 using blink::WebBluetoothRequestDeviceCallbacks;
29 using blink::WebBluetoothScanFilter;
30 using blink::WebRequestDeviceOptions;
27 using blink::WebString; 31 using blink::WebString;
28 using blink::WebVector; 32 using blink::WebVector;
29 33
30 struct BluetoothPrimaryServiceRequest { 34 struct BluetoothPrimaryServiceRequest {
31 BluetoothPrimaryServiceRequest( 35 BluetoothPrimaryServiceRequest(
32 blink::WebString device_instance_id, 36 blink::WebString device_instance_id,
33 blink::WebString service_uuid, 37 blink::WebString service_uuid,
34 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) 38 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks)
35 : device_instance_id(device_instance_id), 39 : device_instance_id(device_instance_id),
36 service_uuid(service_uuid), 40 service_uuid(service_uuid),
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, 162 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess,
159 OnReadValueSuccess); 163 OnReadValueSuccess);
160 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, 164 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError,
161 OnReadValueError); 165 OnReadValueError);
162 IPC_MESSAGE_UNHANDLED(handled = false) 166 IPC_MESSAGE_UNHANDLED(handled = false)
163 IPC_END_MESSAGE_MAP() 167 IPC_END_MESSAGE_MAP()
164 DCHECK(handled) << "Unhandled message:" << msg.type(); 168 DCHECK(handled) << "Unhandled message:" << msg.type();
165 } 169 }
166 170
167 void BluetoothDispatcher::requestDevice( 171 void BluetoothDispatcher::requestDevice(
172 const WebRequestDeviceOptions& options,
168 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 173 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
169 int request_id = pending_requests_.Add(callbacks); 174 int request_id = pending_requests_.Add(callbacks);
170 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 175
176 // Convert |options| to its IPC form.
177 std::vector<content::BluetoothScanFilter> filters(options.filters.size());
178 for (size_t i = 0; i < options.filters.size(); ++i) {
179 const WebBluetoothScanFilter& web_filter = options.filters[i];
180 BluetoothScanFilter& filter = filters[i];
181 filter.services.reserve(web_filter.services.size());
182 for (const WebString& service : web_filter.services) {
183 filter.services.push_back(device::BluetoothUUID(service.utf8()));
184 }
185 }
186 std::vector<device::BluetoothUUID> optional_services;
187 optional_services.reserve(options.optionalServices.size());
188 for (const WebString& optional_service : options.optionalServices) {
189 optional_services.push_back(device::BluetoothUUID(optional_service.utf8()));
190 }
191
192 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id,
193 filters, optional_services));
171 } 194 }
172 195
173 void BluetoothDispatcher::connectGATT( 196 void BluetoothDispatcher::connectGATT(
174 const blink::WebString& device_instance_id, 197 const blink::WebString& device_instance_id,
175 blink::WebBluetoothConnectGATTCallbacks* callbacks) { 198 blink::WebBluetoothConnectGATTCallbacks* callbacks) {
176 int request_id = pending_connect_requests_.Add(callbacks); 199 int request_id = pending_connect_requests_.Add(callbacks);
177 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, 200 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id,
178 device_instance_id.utf8())); 201 device_instance_id.utf8()));
179 } 202 }
180 203
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 ->onError(new WebBluetoothError( 398 ->onError(new WebBluetoothError(
376 // TODO(ortuno): Return more descriptive error messages. 399 // TODO(ortuno): Return more descriptive error messages.
377 // http://crbug.com/490419 400 // http://crbug.com/490419
378 WebBluetoothErrorFromBluetoothError(error_type), 401 WebBluetoothErrorFromBluetoothError(error_type),
379 WebString::fromUTF8(error_message))); 402 WebString::fromUTF8(error_message)));
380 403
381 pending_read_value_requests_.Remove(request_id); 404 pending_read_value_requests_.Remove(request_id);
382 } 405 }
383 406
384 } // namespace content 407 } // 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