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

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

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Keep track of objects on the renderer side Created 5 years, 3 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 "base/id_map.h" 8 #include "base/id_map.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "content/common/bluetooth/bluetooth_device.h" 10 #include "content/common/bluetooth/bluetooth_device.h"
11 #include "content/public/child/worker_thread.h" 11 #include "content/public/child/worker_thread.h"
12 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h" 12 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h"
13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
14 14
15 namespace base { 15 namespace base {
16 class MessageLoop; 16 class MessageLoop;
17 class TaskRunner; 17 class TaskRunner;
18 } 18 }
19 19
20 namespace blink {
21 class WebBluetoothGATTCharacteristicDelegate;
22 }
23
20 namespace IPC { 24 namespace IPC {
21 class Message; 25 class Message;
22 } 26 }
23 27
24 struct BluetoothCharacteristicRequest; 28 struct BluetoothCharacteristicRequest;
25 struct BluetoothPrimaryServiceRequest; 29 struct BluetoothPrimaryServiceRequest;
30 struct BluetoothNotificationsRequest;
26 31
27 namespace content { 32 namespace content {
28 class ThreadSafeSender; 33 class ThreadSafeSender;
29 34
30 // Dispatcher for child process threads which communicates to the browser's 35 // Dispatcher for child process threads which communicates to the browser's
31 // BluetoothDispatcherHost. 36 // BluetoothDispatcherHost.
32 // 37 //
33 // Instances are created for each thread as necessary by WebBluetoothImpl. 38 // Instances are created for each thread as necessary by WebBluetoothImpl.
34 // 39 //
35 // Incoming IPC messages are received by the BluetoothMessageFilter and 40 // Incoming IPC messages are received by the BluetoothMessageFilter and
(...skipping 26 matching lines...) Expand all
62 67
63 void getCharacteristic( 68 void getCharacteristic(
64 const blink::WebString& service_instance_id, 69 const blink::WebString& service_instance_id,
65 const blink::WebString& characteristic_uuid, 70 const blink::WebString& characteristic_uuid,
66 blink::WebBluetoothGetCharacteristicCallbacks* callbacks); 71 blink::WebBluetoothGetCharacteristicCallbacks* callbacks);
67 void readValue(const blink::WebString& characteristic_instance_id, 72 void readValue(const blink::WebString& characteristic_instance_id,
68 blink::WebBluetoothReadValueCallbacks* callbacks); 73 blink::WebBluetoothReadValueCallbacks* callbacks);
69 void writeValue(const blink::WebString& characteristic_instance_id, 74 void writeValue(const blink::WebString& characteristic_instance_id,
70 const std::vector<uint8_t>& value, 75 const std::vector<uint8_t>& value,
71 blink::WebBluetoothWriteValueCallbacks*); 76 blink::WebBluetoothWriteValueCallbacks*);
77 void startNotifications(
78 const blink::WebString& characteristic_instance_id,
79 blink::WebBluetoothGATTCharacteristicDelegate* delegate,
80 blink::WebBluetoothNotificationsCallbacks*);
81 void stopNotifications(
82 const blink::WebString& characteristic_instance_id,
83 blink::WebBluetoothGATTCharacteristicDelegate* delegate,
84 blink::WebBluetoothNotificationsCallbacks*);
85 void characteristicDelegateRemoved(
86 const blink::WebString& characteristic_instance_id,
87 blink::WebBluetoothGATTCharacteristicDelegate* delegate);
72 88
73 // WorkerThread::Observer implementation. 89 // WorkerThread::Observer implementation.
74 void WillStopCurrentWorkerThread() override; 90 void WillStopCurrentWorkerThread() override;
75 91
76 private: 92 private:
93 bool IsActiveCharacteristicNotification(
Jeffrey Yasskin 2015/09/15 03:45:37 Maybe s/Is/Has/?
ortuno 2015/09/15 21:38:20 Done.
94 const blink::WebString& characteristic_instance_id);
95
96 void AddToActiveNotificationsMap(
97 const blink::WebString& characteristic_instance_id,
98 blink::WebBluetoothGATTCharacteristicDelegate* delegate);
99
100 void RemoveFromActiveNotificationsMap(
101 const blink::WebString& characteristic_instance_id,
102 blink::WebBluetoothGATTCharacteristicDelegate* delegate);
103
77 // IPC Handlers, see definitions in bluetooth_messages.h. 104 // IPC Handlers, see definitions in bluetooth_messages.h.
78 void OnRequestDeviceSuccess(int thread_id, 105 void OnRequestDeviceSuccess(int thread_id,
79 int request_id, 106 int request_id,
80 const BluetoothDevice& device); 107 const BluetoothDevice& device);
81 void OnRequestDeviceError(int thread_id, 108 void OnRequestDeviceError(int thread_id,
82 int request_id, 109 int request_id,
83 blink::WebBluetoothError error); 110 blink::WebBluetoothError error);
84 111
85 void OnConnectGATTSuccess(int thread_id, 112 void OnConnectGATTSuccess(int thread_id,
86 int request_id, 113 int request_id,
(...skipping 18 matching lines...) Expand all
105 void OnReadValueSuccess(int thread_id, 132 void OnReadValueSuccess(int thread_id,
106 int request_id, 133 int request_id,
107 const std::vector<uint8_t>& value); 134 const std::vector<uint8_t>& value);
108 void OnReadValueError(int thread_id, 135 void OnReadValueError(int thread_id,
109 int request_id, 136 int request_id,
110 blink::WebBluetoothError error); 137 blink::WebBluetoothError error);
111 void OnWriteValueSuccess(int thread_id, int request_id); 138 void OnWriteValueSuccess(int thread_id, int request_id);
112 void OnWriteValueError(int thread_id, 139 void OnWriteValueError(int thread_id,
113 int request_id, 140 int request_id,
114 blink::WebBluetoothError error); 141 blink::WebBluetoothError error);
142 void OnStartNotificationsSuccess(int thread_id, int request_id);
143 void OnStartNotificationsError(int thread_id,
144 int request_id,
145 blink::WebBluetoothError error);
146 void OnStopNotificationsSuccess(int thread_id, int request_id);
115 147
116 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 148 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
117 149
150 // Map that keeps track of which characteristic are subscribed to
Jeffrey Yasskin 2015/09/15 03:45:37 Mention that the keys are characteristic UUIDs.
ortuno 2015/09/15 21:38:20 You mean instance IDs right? Multiple characterist
151 // notifications.
152 std::map<std::string,
153 std::set<blink::WebBluetoothGATTCharacteristicDelegate*>>
154 active_characteristic_notifications;
155
118 // Tracks device requests sent to browser to match replies with callbacks. 156 // Tracks device requests sent to browser to match replies with callbacks.
119 // Owns callback objects. 157 // Owns callback objects.
120 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> 158 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer>
121 pending_requests_; 159 pending_requests_;
122 // Tracks requests to connect to a device. 160 // Tracks requests to connect to a device.
123 // Owns callback objects. 161 // Owns callback objects.
124 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> 162 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer>
125 pending_connect_requests_; 163 pending_connect_requests_;
126 // Tracks requests to get a primary service from a device. 164 // Tracks requests to get a primary service from a device.
127 // Owns request objects. 165 // Owns request objects.
128 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> 166 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer>
129 pending_primary_service_requests_; 167 pending_primary_service_requests_;
130 // Tracks requests to get a characteristic from a service. 168 // Tracks requests to get a characteristic from a service.
131 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer> 169 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer>
132 pending_characteristic_requests_; 170 pending_characteristic_requests_;
133 // Tracks requests to read from a characteristics. 171 // Tracks requests to read from a characteristics.
134 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer> 172 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer>
135 pending_read_value_requests_; 173 pending_read_value_requests_;
136 IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer> 174 IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer>
137 pending_write_value_requests_; 175 pending_write_value_requests_;
176 // Tracks requests to start notifications from a characteristic.
177 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>
178 pending_start_notifications_requests_;
179 // Tracks requests to stop notifications from a characteristic.
180 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer>
181 pending_stop_notifications_requests_;
138 182
139 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); 183 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher);
140 }; 184 };
141 185
142 } // namespace content 186 } // namespace content
143 187
144 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ 188 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698