OLD | NEW |
---|---|
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/WebBluetoothGATTR emoteServer.h" | 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" |
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" | |
16 | 17 |
17 using blink::WebBluetoothConnectGATTCallbacks; | 18 using blink::WebBluetoothConnectGATTCallbacks; |
18 using blink::WebBluetoothDevice; | 19 using blink::WebBluetoothDevice; |
19 using blink::WebBluetoothError; | 20 using blink::WebBluetoothError; |
20 using blink::WebBluetoothGATTRemoteServer; | 21 using blink::WebBluetoothGATTRemoteServer; |
22 using blink::WebBluetoothGATTService; | |
21 using blink::WebBluetoothRequestDeviceCallbacks; | 23 using blink::WebBluetoothRequestDeviceCallbacks; |
22 using blink::WebString; | 24 using blink::WebString; |
23 using blink::WebVector; | 25 using blink::WebVector; |
24 | 26 |
25 namespace content { | 27 namespace content { |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky | 31 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky |
30 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 32 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 } | 97 } |
96 | 98 |
97 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { | 99 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { |
98 bool handled = true; | 100 bool handled = true; |
99 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) | 101 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) |
100 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, | 102 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, |
101 OnRequestDeviceSuccess); | 103 OnRequestDeviceSuccess); |
102 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); | 104 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); |
103 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); | 105 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); |
104 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); | 106 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); |
107 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, | |
108 OnGetPrimaryServiceSuccess); | |
109 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, | |
110 OnGetPrimaryServiceError); | |
105 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
106 IPC_END_MESSAGE_MAP() | 112 IPC_END_MESSAGE_MAP() |
107 DCHECK(handled) << "Unhandled message:" << msg.type(); | 113 DCHECK(handled) << "Unhandled message:" << msg.type(); |
108 } | 114 } |
109 | 115 |
110 void BluetoothDispatcher::requestDevice( | 116 void BluetoothDispatcher::requestDevice( |
111 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 117 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
112 int request_id = pending_requests_.Add(callbacks); | 118 int request_id = pending_requests_.Add(callbacks); |
113 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); | 119 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); |
114 } | 120 } |
115 | 121 |
116 void BluetoothDispatcher::connectGATT( | 122 void BluetoothDispatcher::connectGATT( |
117 const blink::WebString& device_instance_id, | 123 const blink::WebString& device_instance_id, |
118 blink::WebBluetoothConnectGATTCallbacks* callbacks) { | 124 blink::WebBluetoothConnectGATTCallbacks* callbacks) { |
119 int request_id = pending_connect_requests_.Add(callbacks); | 125 int request_id = pending_connect_requests_.Add(callbacks); |
120 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, | 126 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, |
121 device_instance_id.utf8())); | 127 device_instance_id.utf8())); |
122 } | 128 } |
123 | 129 |
130 void BluetoothDispatcher::getPrimaryService( | |
131 const blink::WebString& device_instance_id, | |
132 const blink::WebString& service_uuid, | |
133 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | |
134 // TODO(ortuno): Check that service_uuid is a valid UUID. | |
scheib
2015/05/28 23:09:16
UUIDs per spec should be verified by BluetoothUUID
ortuno
2015/05/29 17:53:54
Done.
| |
135 int request_id = pending_primary_service_requests_.Add(callbacks); | |
136 Send(new BluetoothHostMsg_GetPrimaryService(CurrentWorkerId(), request_id, | |
137 device_instance_id.utf8(), | |
138 service_uuid.utf8())); | |
139 } | |
140 | |
124 void BluetoothDispatcher::OnWorkerRunLoopStopped() { | 141 void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
125 delete this; | 142 delete this; |
126 } | 143 } |
127 | 144 |
128 void BluetoothDispatcher::OnRequestDeviceSuccess( | 145 void BluetoothDispatcher::OnRequestDeviceSuccess( |
129 int thread_id, | 146 int thread_id, |
130 int request_id, | 147 int request_id, |
131 const BluetoothDevice& device) { | 148 const BluetoothDevice& device) { |
132 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 149 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
133 | 150 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 BluetoothError error_type) { | 189 BluetoothError error_type) { |
173 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; | 190 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; |
174 pending_connect_requests_.Lookup(request_id) | 191 pending_connect_requests_.Lookup(request_id) |
175 ->onError(new WebBluetoothError( | 192 ->onError(new WebBluetoothError( |
176 // TODO(ortuno): Return more descriptive error messages. | 193 // TODO(ortuno): Return more descriptive error messages. |
177 // http://crbug.com/490419 | 194 // http://crbug.com/490419 |
178 WebBluetoothErrorFromBluetoothError(error_type), "")); | 195 WebBluetoothErrorFromBluetoothError(error_type), "")); |
179 pending_connect_requests_.Remove(request_id); | 196 pending_connect_requests_.Remove(request_id); |
180 } | 197 } |
181 | 198 |
199 void BluetoothDispatcher::OnGetPrimaryServiceSuccess( | |
200 int thread_id, | |
201 int request_id, | |
202 const std::string& device_instance_id, | |
203 const std::string& service_instance_id, | |
204 const std::string& uuid) { | |
205 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; | |
206 pending_primary_service_requests_.Lookup(request_id) | |
207 ->onSuccess(new WebBluetoothGATTService( | |
208 WebString::fromUTF8(service_instance_id), WebString::fromUTF8(uuid), | |
209 true /* isPrimary */, WebString::fromUTF8(device_instance_id))); | |
210 pending_primary_service_requests_.Remove(request_id); | |
211 } | |
212 | |
213 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id, | |
214 int request_id, | |
215 BluetoothError error_type) { | |
216 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; | |
217 | |
218 // Since we couldn't find the service return null. See Step 3 of | |
scheib
2015/05/28 23:09:16
Let's cross reference from https://github.com/WebB
ortuno
2015/05/29 17:53:55
Not sure what you mean. You want me to add a refer
scheib
2015/05/31 19:48:41
Sorry, more clearly:
Please add comments into the
| |
219 // getPrimaryService algorithm: | |
220 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserv er-getprimaryservice | |
221 if (error_type == BluetoothError::NOT_FOUND) { | |
222 pending_primary_service_requests_.Lookup(request_id)->onSuccess(nullptr); | |
223 pending_primary_service_requests_.Remove(request_id); | |
224 return; | |
225 } | |
226 | |
227 pending_primary_service_requests_.Lookup(request_id) | |
228 ->onError(new WebBluetoothError( | |
229 // TODO(ortuno): Return more descriptive error messages. | |
230 // http://crbug.com/490419 | |
231 WebBluetoothErrorFromBluetoothError(error_type), "")); | |
232 pending_primary_service_requests_.Remove(request_id); | |
233 } | |
234 | |
182 } // namespace content | 235 } // namespace content |
OLD | NEW |