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

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

Issue 1775953004: bluetooth: Move writeValue to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Moar cleanup Created 4 years, 9 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 #ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ 6 #define CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 12
13 #include "base/id_map.h" 13 #include "base/id_map.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "content/common/bluetooth/bluetooth_device.h" 16 #include "content/common/bluetooth/bluetooth_device.h"
17 #include "content/common/bluetooth/bluetooth_service.mojom.h"
17 #include "content/public/child/worker_thread.h" 18 #include "content/public/child/worker_thread.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
20 21
21 namespace base { 22 namespace base {
22 class MessageLoop; 23 class MessageLoop;
23 class TaskRunner; 24 class TaskRunner;
24 } 25 }
25 26
26 namespace blink { 27 namespace blink {
27 class WebBluetoothRemoteGATTCharacteristic; 28 class WebBluetoothRemoteGATTCharacteristic;
28 } 29 }
29 30
30 namespace IPC { 31 namespace IPC {
31 class Message; 32 class Message;
32 } 33 }
33 34
34 struct BluetoothCharacteristicRequest; 35 struct BluetoothCharacteristicRequest;
35 struct BluetoothCharacteristicsRequest; 36 struct BluetoothCharacteristicsRequest;
36 struct BluetoothPrimaryServiceRequest; 37 struct BluetoothPrimaryServiceRequest;
37 struct BluetoothWriteValueRequest; 38 struct BluetoothWriteValueRequest;
38 struct BluetoothNotificationsRequest; 39 struct BluetoothNotificationsRequest;
39 40
40 namespace content { 41 namespace content {
42 class ServiceRegistry;
41 class ThreadSafeSender; 43 class ThreadSafeSender;
42 44
43 // Dispatcher for child process threads which communicates to the browser's 45 // Dispatcher for child process threads which communicates to the browser's
44 // BluetoothDispatcherHost. 46 // BluetoothDispatcherHost.
45 // 47 //
46 // Instances are created for each thread as necessary by WebBluetoothImpl. 48 // Instances are created for each thread as necessary by WebBluetoothImpl.
47 // 49 //
48 // Incoming IPC messages are received by the BluetoothMessageFilter and 50 // Incoming IPC messages are received by the BluetoothMessageFilter and
49 // directed to the thread specific instance of this class. 51 // directed to the thread specific instance of this class.
50 // Outgoing messages come from WebBluetoothImpl. 52 // Outgoing messages come from WebBluetoothImpl.
51 class BluetoothDispatcher : public WorkerThread::Observer { 53 class BluetoothDispatcher : public WorkerThread::Observer {
52 public: 54 public:
53 explicit BluetoothDispatcher(ThreadSafeSender* sender); 55 explicit BluetoothDispatcher(ThreadSafeSender* sender,
56 ServiceRegistry* service_registry);
54 ~BluetoothDispatcher() override; 57 ~BluetoothDispatcher() override;
55 58
56 // Gets or Creates a BluetoothDispatcher for the current thread. 59 // Gets or Creates a BluetoothDispatcher for the current thread.
57 // |thread_safe_sender| is required when constructing a BluetoothDispatcher. 60 // |thread_safe_sender| is required when constructing a BluetoothDispatcher.
58 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance( 61 static BluetoothDispatcher* GetOrCreateThreadSpecificInstance(
59 ThreadSafeSender* thread_safe_sender); 62 ThreadSafeSender* thread_safe_sender,
63 ServiceRegistry* service_registry);
60 64
61 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener. 65 // IPC Send and Receiving interface, see IPC::Sender and IPC::Listener.
62 bool Send(IPC::Message* msg); 66 bool Send(IPC::Message* msg);
63 void OnMessageReceived(const IPC::Message& msg); 67 void OnMessageReceived(const IPC::Message& msg);
64 68
65 // Corresponding to WebBluetoothImpl methods. 69 // Corresponding to WebBluetoothImpl methods.
66 void requestDevice(int frame_routing_id, 70 void requestDevice(int frame_routing_id,
67 const blink::WebRequestDeviceOptions& options, 71 const blink::WebRequestDeviceOptions& options,
68 blink::WebBluetoothRequestDeviceCallbacks* callbacks); 72 blink::WebBluetoothRequestDeviceCallbacks* callbacks);
69 void connect(int frame_routing_id, 73 void connect(int frame_routing_id,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const std::vector<uint32_t>& characteristic_properties); 213 const std::vector<uint32_t>& characteristic_properties);
210 void OnGetCharacteristicsError(int thread_id, 214 void OnGetCharacteristicsError(int thread_id,
211 int request_id, 215 int request_id,
212 blink::WebBluetoothError error); 216 blink::WebBluetoothError error);
213 void OnReadValueSuccess(int thread_id, 217 void OnReadValueSuccess(int thread_id,
214 int request_id, 218 int request_id,
215 const std::vector<uint8_t>& value); 219 const std::vector<uint8_t>& value);
216 void OnReadValueError(int thread_id, 220 void OnReadValueError(int thread_id,
217 int request_id, 221 int request_id,
218 blink::WebBluetoothError error); 222 blink::WebBluetoothError error);
219 void OnWriteValueSuccess(int thread_id, int request_id); 223 void OnWriteValue(
220 void OnWriteValueError(int thread_id, 224 const blink::WebVector<uint8_t>& value,
221 int request_id, 225 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks,
222 blink::WebBluetoothError error); 226 blink::mojom::WebBluetoothError error);
223 void OnStartNotificationsSuccess(int thread_id, int request_id); 227 void OnStartNotificationsSuccess(int thread_id, int request_id);
224 void OnStartNotificationsError(int thread_id, 228 void OnStartNotificationsError(int thread_id,
225 int request_id, 229 int request_id,
226 blink::WebBluetoothError error); 230 blink::WebBluetoothError error);
227 void OnStopNotificationsSuccess(int thread_id, int request_id); 231 void OnStopNotificationsSuccess(int thread_id, int request_id);
228 void OnCharacteristicValueChanged( 232 void OnCharacteristicValueChanged(
229 int thread_id, 233 int thread_id,
230 const std::string& characteristic_instance_id, 234 const std::string& characteristic_instance_id,
231 const std::vector<uint8_t> value); 235 const std::vector<uint8_t> value);
232 236
237 mojom::BluetoothServicePtr& GetBluetoothService();
238
233 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 239 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
234 240
235 // Map of characteristic_instance_id to a queue of Notification Requests' IDs. 241 // Map of characteristic_instance_id to a queue of Notification Requests' IDs.
236 // See "Notifications Queueing Note" above. 242 // See "Notifications Queueing Note" above.
237 std::map<std::string, std::queue<int>> notification_requests_queues_; 243 std::map<std::string, std::queue<int>> notification_requests_queues_;
238 244
239 // Tracks device requests sent to browser to match replies with callbacks. 245 // Tracks device requests sent to browser to match replies with callbacks.
240 // Owns callback objects. 246 // Owns callback objects.
241 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> 247 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer>
242 pending_requests_; 248 pending_requests_;
243 // Tracks requests to connect to a device. 249 // Tracks requests to connect to a device.
244 // Owns callback objects. 250 // Owns callback objects.
245 IDMap<blink::WebBluetoothRemoteGATTServerConnectCallbacks, IDMapOwnPointer> 251 IDMap<blink::WebBluetoothRemoteGATTServerConnectCallbacks, IDMapOwnPointer>
246 pending_connect_requests_; 252 pending_connect_requests_;
247 // Tracks requests to get a primary service from a device. 253 // Tracks requests to get a primary service from a device.
248 // Owns request objects. 254 // Owns request objects.
249 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> 255 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer>
250 pending_primary_service_requests_; 256 pending_primary_service_requests_;
251 // Tracks requests to get a characteristic from a service. 257 // Tracks requests to get a characteristic from a service.
252 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer> 258 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer>
253 pending_characteristic_requests_; 259 pending_characteristic_requests_;
254 // Tracks requests to get characteristics from a service. 260 // Tracks requests to get characteristics from a service.
255 IDMap<BluetoothCharacteristicsRequest, IDMapOwnPointer> 261 IDMap<BluetoothCharacteristicsRequest, IDMapOwnPointer>
256 pending_characteristics_requests_; 262 pending_characteristics_requests_;
257 // Tracks requests to read from a characteristics. 263 // Tracks requests to read from a characteristics.
258 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer> 264 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer>
259 pending_read_value_requests_; 265 pending_read_value_requests_;
260 IDMap<BluetoothWriteValueRequest, IDMapOwnPointer>
261 pending_write_value_requests_;
262 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> 266 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>
263 pending_notifications_requests_; 267 pending_notifications_requests_;
264 268
265 // Map of characteristic_instance_id to a set of 269 // Map of characteristic_instance_id to a set of
266 // WebBluetoothRemoteGATTCharacteristic pointers. Keeps track of which 270 // WebBluetoothRemoteGATTCharacteristic pointers. Keeps track of which
267 // objects are subscribed to notifications. 271 // objects are subscribed to notifications.
268 std::map<std::string, std::set<blink::WebBluetoothRemoteGATTCharacteristic*>> 272 std::map<std::string, std::set<blink::WebBluetoothRemoteGATTCharacteristic*>>
269 active_notification_subscriptions_; 273 active_notification_subscriptions_;
270 274
271 // Map of characteristic_instance_ids to 275 // Map of characteristic_instance_ids to
272 // WebBluetoothRemoteGATTCharacteristics. 276 // WebBluetoothRemoteGATTCharacteristics.
273 // Keeps track of what characteristics have listeners. 277 // Keeps track of what characteristics have listeners.
274 // TODO(ortuno): We are assuming that there exists a single frame per 278 // TODO(ortuno): We are assuming that there exists a single frame per
275 // dispatcher, so there could be at most one characteristic object per 279 // dispatcher, so there could be at most one characteristic object per
276 // characteristic_instance_id. Change to a set when we support multiple 280 // characteristic_instance_id. Change to a set when we support multiple
277 // frames. 281 // frames.
278 // http://crbug.com/541388 282 // http://crbug.com/541388
279 std::map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> 283 std::map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*>
280 active_characteristics_; 284 active_characteristics_;
281 285
286 mojom::BluetoothServicePtr bluetooth_service_;
287
288 ServiceRegistry* service_registry_;
282 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); 289 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher);
283 }; 290 };
284 291
285 } // namespace content 292 } // namespace content
286 293
287 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ 294 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698