| 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/renderer/bluetooth/bluetooth_dispatcher.h" | 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 17 #include "content/common/bluetooth/bluetooth_messages.h" | 17 #include "content/common/bluetooth/bluetooth_messages.h" |
| 18 #include "device/bluetooth/bluetooth_uuid.h" | 18 #include "device/bluetooth/bluetooth_uuid.h" |
| 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" | 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" |
| 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError
.h" | 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError
.h" |
| 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" | 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" |
| 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" |
| 23 | 23 |
| 24 using blink::WebBluetoothDevice; | 24 using blink::WebBluetoothDevice; |
| 25 using blink::WebBluetoothError; | 25 using blink::WebBluetoothError; |
| 26 using blink::WebBluetoothRemoteGATTServerConnectCallbacks; | |
| 27 using blink::WebBluetoothRemoteGATTService; | 26 using blink::WebBluetoothRemoteGATTService; |
| 28 using blink::WebBluetoothReadValueCallbacks; | 27 using blink::WebBluetoothReadValueCallbacks; |
| 29 using blink::WebBluetoothRequestDeviceCallbacks; | 28 using blink::WebBluetoothRequestDeviceCallbacks; |
| 30 using blink::WebBluetoothScanFilter; | 29 using blink::WebBluetoothScanFilter; |
| 31 using blink::WebRequestDeviceOptions; | 30 using blink::WebRequestDeviceOptions; |
| 32 using blink::WebString; | 31 using blink::WebString; |
| 33 using blink::WebVector; | 32 using blink::WebVector; |
| 34 | 33 |
| 35 namespace content { | 34 namespace content { |
| 36 | 35 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 bool BluetoothDispatcher::Send(IPC::Message* msg) { | 87 bool BluetoothDispatcher::Send(IPC::Message* msg) { |
| 89 return thread_safe_sender_->Send(msg); | 88 return thread_safe_sender_->Send(msg); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { | 91 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 93 bool handled = true; | 92 bool handled = true; |
| 94 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) | 93 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) |
| 95 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, | 94 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, |
| 96 OnRequestDeviceSuccess); | 95 OnRequestDeviceSuccess); |
| 97 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); | 96 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); |
| 98 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectSuccess, | |
| 99 OnGATTServerConnectSuccess); | |
| 100 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectError, | |
| 101 OnGATTServerConnectError); | |
| 102 IPC_MESSAGE_UNHANDLED(handled = false) | 97 IPC_MESSAGE_UNHANDLED(handled = false) |
| 103 IPC_END_MESSAGE_MAP() | 98 IPC_END_MESSAGE_MAP() |
| 104 DCHECK(handled) << "Unhandled message:" << msg.type(); | 99 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 105 } | 100 } |
| 106 | 101 |
| 107 void BluetoothDispatcher::requestDevice( | 102 void BluetoothDispatcher::requestDevice( |
| 108 int frame_routing_id, | 103 int frame_routing_id, |
| 109 const WebRequestDeviceOptions& options, | 104 const WebRequestDeviceOptions& options, |
| 110 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 105 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 111 int request_id = pending_requests_.Add(callbacks); | 106 int request_id = pending_requests_.Add(callbacks); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 126 optional_services.reserve(options.optionalServices.size()); | 121 optional_services.reserve(options.optionalServices.size()); |
| 127 for (const WebString& optional_service : options.optionalServices) { | 122 for (const WebString& optional_service : options.optionalServices) { |
| 128 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); | 123 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); |
| 129 } | 124 } |
| 130 | 125 |
| 131 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, | 126 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, |
| 132 frame_routing_id, filters, | 127 frame_routing_id, filters, |
| 133 optional_services)); | 128 optional_services)); |
| 134 } | 129 } |
| 135 | 130 |
| 136 void BluetoothDispatcher::connect( | |
| 137 int frame_routing_id, | |
| 138 const blink::WebString& device_id, | |
| 139 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { | |
| 140 int request_id = pending_connect_requests_.Add(callbacks); | |
| 141 Send(new BluetoothHostMsg_GATTServerConnect( | |
| 142 CurrentWorkerId(), request_id, frame_routing_id, device_id.utf8())); | |
| 143 } | |
| 144 | |
| 145 void BluetoothDispatcher::disconnect(int frame_routing_id, | |
| 146 const blink::WebString& device_id) { | |
| 147 Send(new BluetoothHostMsg_GATTServerDisconnect( | |
| 148 CurrentWorkerId(), frame_routing_id, device_id.utf8())); | |
| 149 } | |
| 150 | |
| 151 void BluetoothDispatcher::WillStopCurrentWorkerThread() { | 131 void BluetoothDispatcher::WillStopCurrentWorkerThread() { |
| 152 delete this; | 132 delete this; |
| 153 } | 133 } |
| 154 | 134 |
| 155 void BluetoothDispatcher::OnRequestDeviceSuccess( | 135 void BluetoothDispatcher::OnRequestDeviceSuccess( |
| 156 int thread_id, | 136 int thread_id, |
| 157 int request_id, | 137 int request_id, |
| 158 const BluetoothDevice& device) { | 138 const BluetoothDevice& device) { |
| 159 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 139 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
| 160 | 140 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 } | 152 } |
| 173 | 153 |
| 174 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, | 154 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, |
| 175 int request_id, | 155 int request_id, |
| 176 WebBluetoothError error) { | 156 WebBluetoothError error) { |
| 177 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 157 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
| 178 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error)); | 158 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error)); |
| 179 pending_requests_.Remove(request_id); | 159 pending_requests_.Remove(request_id); |
| 180 } | 160 } |
| 181 | 161 |
| 182 void BluetoothDispatcher::OnGATTServerConnectSuccess(int thread_id, | |
| 183 int request_id) { | |
| 184 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; | |
| 185 pending_connect_requests_.Lookup(request_id)->onSuccess(); | |
| 186 pending_connect_requests_.Remove(request_id); | |
| 187 } | |
| 188 | |
| 189 void BluetoothDispatcher::OnGATTServerConnectError(int thread_id, | |
| 190 int request_id, | |
| 191 WebBluetoothError error) { | |
| 192 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; | |
| 193 pending_connect_requests_.Lookup(request_id) | |
| 194 ->onError(WebBluetoothError(error)); | |
| 195 pending_connect_requests_.Remove(request_id); | |
| 196 } | |
| 197 | |
| 198 } // namespace content | 162 } // namespace content |
| OLD | NEW |