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

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: 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/WebBluetoothGATTR emoteServer.h" 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
17 19
18 using blink::WebBluetoothConnectGATTCallbacks; 20 using blink::WebBluetoothConnectGATTCallbacks;
19 using blink::WebBluetoothDevice; 21 using blink::WebBluetoothDevice;
20 using blink::WebBluetoothError; 22 using blink::WebBluetoothError;
21 using blink::WebBluetoothGATTRemoteServer; 23 using blink::WebBluetoothGATTRemoteServer;
22 using blink::WebBluetoothGATTService; 24 using blink::WebBluetoothGATTService;
23 using blink::WebBluetoothRequestDeviceCallbacks; 25 using blink::WebBluetoothRequestDeviceCallbacks;
26 using blink::WebBluetoothScanFilter;
27 using blink::WebRequestDeviceOptions;
24 using blink::WebString; 28 using blink::WebString;
25 using blink::WebVector; 29 using blink::WebVector;
26 30
27 struct BluetoothPrimaryServiceRequest { 31 struct BluetoothPrimaryServiceRequest {
28 BluetoothPrimaryServiceRequest( 32 BluetoothPrimaryServiceRequest(
29 blink::WebString device_instance_id, 33 blink::WebString device_instance_id,
30 blink::WebString service_uuid, 34 blink::WebString service_uuid,
31 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) 35 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks)
32 : device_instance_id(device_instance_id), 36 : device_instance_id(device_instance_id),
33 service_uuid(service_uuid), 37 service_uuid(service_uuid),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, 126 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess,
123 OnGetPrimaryServiceSuccess); 127 OnGetPrimaryServiceSuccess);
124 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, 128 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
125 OnGetPrimaryServiceError); 129 OnGetPrimaryServiceError);
126 IPC_MESSAGE_UNHANDLED(handled = false) 130 IPC_MESSAGE_UNHANDLED(handled = false)
127 IPC_END_MESSAGE_MAP() 131 IPC_END_MESSAGE_MAP()
128 DCHECK(handled) << "Unhandled message:" << msg.type(); 132 DCHECK(handled) << "Unhandled message:" << msg.type();
129 } 133 }
130 134
131 void BluetoothDispatcher::requestDevice( 135 void BluetoothDispatcher::requestDevice(
136 const WebRequestDeviceOptions& options,
132 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 137 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
133 int request_id = pending_requests_.Add(callbacks); 138 int request_id = pending_requests_.Add(callbacks);
134 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 139
140 // Convert |options| to its IPC form.
141 std::vector<content::BluetoothScanFilter> filters(options.filters.size());
142 for (size_t i = 0; i < options.filters.size(); ++i) {
143 const WebBluetoothScanFilter& web_filter = options.filters[i];
144 BluetoothScanFilter& filter = filters[i];
145 filter.services.reserve(web_filter.services.size());
146 for (const WebString& service : web_filter.services) {
147 filter.services.push_back(device::BluetoothUUID(service.utf8()));
148 }
149 }
150 std::vector<device::BluetoothUUID> optional_services;
151 optional_services.reserve(options.optionalServices.size());
152 for (const WebString& optional_service : options.optionalServices) {
153 optional_services.push_back(device::BluetoothUUID(optional_service.utf8()));
154 }
155
156 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id,
157 filters, optional_services));
135 } 158 }
136 159
137 void BluetoothDispatcher::connectGATT( 160 void BluetoothDispatcher::connectGATT(
138 const blink::WebString& device_instance_id, 161 const blink::WebString& device_instance_id,
139 blink::WebBluetoothConnectGATTCallbacks* callbacks) { 162 blink::WebBluetoothConnectGATTCallbacks* callbacks) {
140 int request_id = pending_connect_requests_.Add(callbacks); 163 int request_id = pending_connect_requests_.Add(callbacks);
141 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, 164 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id,
142 device_instance_id.utf8())); 165 device_instance_id.utf8()));
143 } 166 }
144 167
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 265
243 pending_primary_service_requests_.Lookup(request_id) 266 pending_primary_service_requests_.Lookup(request_id)
244 ->callbacks->onError(new WebBluetoothError( 267 ->callbacks->onError(new WebBluetoothError(
245 // TODO(ortuno): Return more descriptive error messages. 268 // TODO(ortuno): Return more descriptive error messages.
246 // http://crbug.com/490419 269 // http://crbug.com/490419
247 WebBluetoothErrorFromBluetoothError(error_type), "")); 270 WebBluetoothErrorFromBluetoothError(error_type), ""));
248 pending_primary_service_requests_.Remove(request_id); 271 pending_primary_service_requests_.Remove(request_id);
249 } 272 }
250 273
251 } // namespace content 274 } // 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