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

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

Issue 1902153003: bluetooth: Move connect/disconnect to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-connection-tests
Patch Set: Fix gypi Created 4 years, 7 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/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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bool BluetoothDispatcher::Send(IPC::Message* msg) { 73 bool BluetoothDispatcher::Send(IPC::Message* msg) {
75 return thread_safe_sender_->Send(msg); 74 return thread_safe_sender_->Send(msg);
76 } 75 }
77 76
78 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { 77 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
79 bool handled = true; 78 bool handled = true;
80 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) 79 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg)
81 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, 80 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess,
82 OnRequestDeviceSuccess); 81 OnRequestDeviceSuccess);
83 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); 82 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError);
84 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectSuccess,
85 OnGATTServerConnectSuccess);
86 IPC_MESSAGE_HANDLER(BluetoothMsg_GATTServerConnectError,
87 OnGATTServerConnectError);
88 IPC_MESSAGE_UNHANDLED(handled = false) 83 IPC_MESSAGE_UNHANDLED(handled = false)
89 IPC_END_MESSAGE_MAP() 84 IPC_END_MESSAGE_MAP()
90 DCHECK(handled) << "Unhandled message:" << msg.type(); 85 DCHECK(handled) << "Unhandled message:" << msg.type();
91 } 86 }
92 87
93 void BluetoothDispatcher::requestDevice( 88 void BluetoothDispatcher::requestDevice(
94 int frame_routing_id, 89 int frame_routing_id,
95 const WebRequestDeviceOptions& options, 90 const WebRequestDeviceOptions& options,
96 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 91 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
97 int request_id = pending_requests_.Add(callbacks); 92 int request_id = pending_requests_.Add(callbacks);
(...skipping 14 matching lines...) Expand all
112 optional_services.reserve(options.optionalServices.size()); 107 optional_services.reserve(options.optionalServices.size());
113 for (const WebString& optional_service : options.optionalServices) { 108 for (const WebString& optional_service : options.optionalServices) {
114 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); 109 optional_services.push_back(device::BluetoothUUID(optional_service.utf8()));
115 } 110 }
116 111
117 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, 112 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id,
118 frame_routing_id, filters, 113 frame_routing_id, filters,
119 optional_services)); 114 optional_services));
120 } 115 }
121 116
122 void BluetoothDispatcher::connect(
123 int frame_routing_id,
124 const blink::WebString& device_id,
125 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
126 int request_id = pending_connect_requests_.Add(callbacks);
127 Send(new BluetoothHostMsg_GATTServerConnect(
128 CurrentWorkerId(), request_id, frame_routing_id, device_id.utf8()));
129 }
130
131 void BluetoothDispatcher::disconnect(int frame_routing_id,
132 const blink::WebString& device_id) {
133 Send(new BluetoothHostMsg_GATTServerDisconnect(
134 CurrentWorkerId(), frame_routing_id, device_id.utf8()));
135 }
136
137 void BluetoothDispatcher::WillStopCurrentWorkerThread() { 117 void BluetoothDispatcher::WillStopCurrentWorkerThread() {
138 delete this; 118 delete this;
139 } 119 }
140 120
141 void BluetoothDispatcher::OnRequestDeviceSuccess( 121 void BluetoothDispatcher::OnRequestDeviceSuccess(
142 int thread_id, 122 int thread_id,
143 int request_id, 123 int request_id,
144 const BluetoothDevice& device) { 124 const BluetoothDevice& device) {
145 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 125 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
146 126
147 WebVector<WebString> uuids(device.uuids.size()); 127 WebVector<WebString> uuids(device.uuids.size());
148 for (size_t i = 0; i < device.uuids.size(); ++i) 128 for (size_t i = 0; i < device.uuids.size(); ++i)
149 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str()); 129 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str());
150 130
151 pending_requests_.Lookup(request_id) 131 pending_requests_.Lookup(request_id)
152 ->onSuccess(base::WrapUnique(new WebBluetoothDevice( 132 ->onSuccess(base::WrapUnique(new WebBluetoothDevice(
153 WebString::fromUTF8(device.id), WebString(device.name), 133 WebString::fromUTF8(device.id), WebString(device.name),
154 device.tx_power, device.rssi, uuids))); 134 device.tx_power, device.rssi, uuids)));
155 pending_requests_.Remove(request_id); 135 pending_requests_.Remove(request_id);
156 } 136 }
157 137
158 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 138 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
159 int request_id, 139 int request_id,
160 WebBluetoothError error) { 140 WebBluetoothError error) {
161 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 141 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
162 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error)); 142 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error));
163 pending_requests_.Remove(request_id); 143 pending_requests_.Remove(request_id);
164 } 144 }
165 145
166 void BluetoothDispatcher::OnGATTServerConnectSuccess(int thread_id,
167 int request_id) {
168 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
169 pending_connect_requests_.Lookup(request_id)->onSuccess();
170 pending_connect_requests_.Remove(request_id);
171 }
172
173 void BluetoothDispatcher::OnGATTServerConnectError(int thread_id,
174 int request_id,
175 WebBluetoothError error) {
176 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
177 pending_connect_requests_.Lookup(request_id)
178 ->onError(WebBluetoothError(error));
179 pending_connect_requests_.Remove(request_id);
180 }
181
182 } // namespace content 146 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/bluetooth/bluetooth_dispatcher.h ('k') | content/renderer/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698