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, | |
Jeffrey Yasskin
2015/05/27 18:36:59
Add a TODO to check that the service_uuid is valid
ortuno
2015/05/27 21:07:45
Done.
| |
133 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | |
134 int request_id = pending_primary_service_requests_.Add(callbacks); | |
135 Send(new BluetoothHostMsg_GetPrimaryService(CurrentWorkerId(), request_id, | |
136 device_instance_id.utf8(), | |
137 service_uuid.utf8())); | |
138 } | |
139 | |
124 void BluetoothDispatcher::OnWorkerRunLoopStopped() { | 140 void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
125 delete this; | 141 delete this; |
126 } | 142 } |
127 | 143 |
128 void BluetoothDispatcher::OnRequestDeviceSuccess( | 144 void BluetoothDispatcher::OnRequestDeviceSuccess( |
129 int thread_id, | 145 int thread_id, |
130 int request_id, | 146 int request_id, |
131 const BluetoothDevice& device) { | 147 const BluetoothDevice& device) { |
132 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 148 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
133 | 149 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 BluetoothError error_type) { | 188 BluetoothError error_type) { |
173 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; | 189 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; |
174 pending_connect_requests_.Lookup(request_id) | 190 pending_connect_requests_.Lookup(request_id) |
175 ->onError(new WebBluetoothError( | 191 ->onError(new WebBluetoothError( |
176 // TODO(ortuno): Return more descriptive error messages. | 192 // TODO(ortuno): Return more descriptive error messages. |
177 // http://crbug.com/490419 | 193 // http://crbug.com/490419 |
178 WebBluetoothErrorFromBluetoothError(error_type), "")); | 194 WebBluetoothErrorFromBluetoothError(error_type), "")); |
179 pending_connect_requests_.Remove(request_id); | 195 pending_connect_requests_.Remove(request_id); |
180 } | 196 } |
181 | 197 |
198 void BluetoothDispatcher::OnGetPrimaryServiceSuccess( | |
199 int thread_id, | |
200 int request_id, | |
201 const std::string& device_instance_id, | |
202 const std::string& uuid) { | |
203 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; | |
204 pending_primary_service_requests_.Lookup(request_id) | |
205 ->onSuccess(new WebBluetoothGATTService( | |
Jeffrey Yasskin
2015/05/27 18:36:59
Would putting the instance ID in here be more obvi
ortuno
2015/05/27 21:07:45
I don't think it would make that much of a differe
| |
206 WebString::fromUTF8(uuid), true /* isPrimary */, | |
207 WebString::fromUTF8(device_instance_id))); | |
208 pending_primary_service_requests_.Remove(request_id); | |
209 } | |
210 | |
211 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id, | |
212 int request_id, | |
213 BluetoothError error_type) { | |
214 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; | |
215 | |
216 // Since we couldn't find the service return null. See Step 3 of | |
217 // getPrimaryService algorithm: | |
218 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserv er-getprimaryservice | |
219 if (error_type == BluetoothError::NOT_FOUND) { | |
220 pending_primary_service_requests_.Lookup(request_id)->onSuccess(nullptr); | |
221 pending_primary_service_requests_.Remove(request_id); | |
222 return; | |
223 } | |
224 | |
225 pending_primary_service_requests_.Lookup(request_id) | |
226 ->onError(new WebBluetoothError( | |
227 // TODO(ortuno): Return more descriptive error messages. | |
228 // http://crbug.com/490419 | |
229 WebBluetoothErrorFromBluetoothError(error_type), "")); | |
230 pending_primary_service_requests_.Remove(request_id); | |
231 } | |
232 | |
182 } // namespace content | 233 } // namespace content |
OLD | NEW |