| 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 #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 <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 blink::WebBluetoothWriteValueCallbacks*); | 79 blink::WebBluetoothWriteValueCallbacks*); |
| 80 void startNotifications(const blink::WebString& characteristic_instance_id, | 80 void startNotifications(const blink::WebString& characteristic_instance_id, |
| 81 blink::WebBluetoothGATTCharacteristic* delegate, | 81 blink::WebBluetoothGATTCharacteristic* delegate, |
| 82 blink::WebBluetoothNotificationsCallbacks*); | 82 blink::WebBluetoothNotificationsCallbacks*); |
| 83 void stopNotifications(const blink::WebString& characteristic_instance_id, | 83 void stopNotifications(const blink::WebString& characteristic_instance_id, |
| 84 blink::WebBluetoothGATTCharacteristic* delegate, | 84 blink::WebBluetoothGATTCharacteristic* delegate, |
| 85 blink::WebBluetoothNotificationsCallbacks*); | 85 blink::WebBluetoothNotificationsCallbacks*); |
| 86 void characteristicObjectRemoved( | 86 void characteristicObjectRemoved( |
| 87 const blink::WebString& characteristic_instance_id, | 87 const blink::WebString& characteristic_instance_id, |
| 88 blink::WebBluetoothGATTCharacteristic* delegate); | 88 blink::WebBluetoothGATTCharacteristic* delegate); |
| 89 void registerCharacteristicObject( |
| 90 const blink::WebString& characteristic_instance_id, |
| 91 blink::WebBluetoothGATTCharacteristic* characteristic); |
| 89 | 92 |
| 90 // WorkerThread::Observer implementation. | 93 // WorkerThread::Observer implementation. |
| 91 void WillStopCurrentWorkerThread() override; | 94 void WillStopCurrentWorkerThread() override; |
| 92 | 95 |
| 93 enum class NotificationsRequestType { START = 0, STOP = 1 }; | 96 enum class NotificationsRequestType { START = 0, STOP = 1 }; |
| 94 | 97 |
| 95 private: | 98 private: |
| 96 // Notifications Queueing Notes: | 99 // Notifications Queueing Notes: |
| 97 // To avoid races and sending unnecessary IPC messages we implement | 100 // To avoid races and sending unnecessary IPC messages we implement |
| 98 // a queueing system for notification requests. When receiving | 101 // a queueing system for notification requests. When receiving |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const std::string& characteristic_instance_id, | 136 const std::string& characteristic_instance_id, |
| 134 blink::WebBluetoothGATTCharacteristic* characteristic); | 137 blink::WebBluetoothGATTCharacteristic* characteristic); |
| 135 | 138 |
| 136 // The following functions decide whether to resolve the request immediately | 139 // The following functions decide whether to resolve the request immediately |
| 137 // or send an IPC to change the subscription state. | 140 // or send an IPC to change the subscription state. |
| 138 // You should never call these functions if PendingNotificationRequest | 141 // You should never call these functions if PendingNotificationRequest |
| 139 // is true since there is currently another request being processed. | 142 // is true since there is currently another request being processed. |
| 140 void ResolveOrSendStartNotificationRequest(int request_id); | 143 void ResolveOrSendStartNotificationRequest(int request_id); |
| 141 void ResolveOrSendStopNotificationsRequest(int request_id); | 144 void ResolveOrSendStopNotificationsRequest(int request_id); |
| 142 | 145 |
| 146 // Tells BluetoothDispatcherHost that we are no longer interested in |
| 147 // events for the characteristic. |
| 148 // TODO(ortuno): We should unregister a characteristic once there are no |
| 149 // characteristic objects that have listeners attached. |
| 150 // For now, we call this function when an object gets destroyed. So if there |
| 151 // are two frames registered for notifications from the same characteristic |
| 152 // and one of the characteristic objects gets destroyed both will stop |
| 153 // receiving notifications. |
| 154 // https://crbug.com/541388 |
| 155 void UnregisterCharacteristicObject( |
| 156 const blink::WebString& characteristic_instance_id); |
| 157 |
| 143 // IPC Handlers, see definitions in bluetooth_messages.h. | 158 // IPC Handlers, see definitions in bluetooth_messages.h. |
| 144 void OnRequestDeviceSuccess(int thread_id, | 159 void OnRequestDeviceSuccess(int thread_id, |
| 145 int request_id, | 160 int request_id, |
| 146 const BluetoothDevice& device); | 161 const BluetoothDevice& device); |
| 147 void OnRequestDeviceError(int thread_id, | 162 void OnRequestDeviceError(int thread_id, |
| 148 int request_id, | 163 int request_id, |
| 149 blink::WebBluetoothError error); | 164 blink::WebBluetoothError error); |
| 150 void OnConnectGATTSuccess(int thread_id, | 165 void OnConnectGATTSuccess(int thread_id, |
| 151 int request_id, | 166 int request_id, |
| 152 const std::string& message); | 167 const std::string& message); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 174 blink::WebBluetoothError error); | 189 blink::WebBluetoothError error); |
| 175 void OnWriteValueSuccess(int thread_id, int request_id); | 190 void OnWriteValueSuccess(int thread_id, int request_id); |
| 176 void OnWriteValueError(int thread_id, | 191 void OnWriteValueError(int thread_id, |
| 177 int request_id, | 192 int request_id, |
| 178 blink::WebBluetoothError error); | 193 blink::WebBluetoothError error); |
| 179 void OnStartNotificationsSuccess(int thread_id, int request_id); | 194 void OnStartNotificationsSuccess(int thread_id, int request_id); |
| 180 void OnStartNotificationsError(int thread_id, | 195 void OnStartNotificationsError(int thread_id, |
| 181 int request_id, | 196 int request_id, |
| 182 blink::WebBluetoothError error); | 197 blink::WebBluetoothError error); |
| 183 void OnStopNotificationsSuccess(int thread_id, int request_id); | 198 void OnStopNotificationsSuccess(int thread_id, int request_id); |
| 199 void OnCharacteristicValueChanged( |
| 200 int thread_id, |
| 201 const std::string& characteristic_instance_id, |
| 202 const std::vector<uint8_t> value); |
| 184 | 203 |
| 185 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 204 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 186 | 205 |
| 187 // Map of characteristic_instance_id to a queue of Notification Requests' IDs. | 206 // Map of characteristic_instance_id to a queue of Notification Requests' IDs. |
| 188 // See "Notifications Queueing Note" above. | 207 // See "Notifications Queueing Note" above. |
| 189 std::map<std::string, std::queue<int>> notification_requests_queues_; | 208 std::map<std::string, std::queue<int>> notification_requests_queues_; |
| 190 | 209 |
| 191 // Tracks device requests sent to browser to match replies with callbacks. | 210 // Tracks device requests sent to browser to match replies with callbacks. |
| 192 // Owns callback objects. | 211 // Owns callback objects. |
| 193 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | 212 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 210 pending_write_value_requests_; | 229 pending_write_value_requests_; |
| 211 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> | 230 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> |
| 212 pending_notifications_requests_; | 231 pending_notifications_requests_; |
| 213 | 232 |
| 214 // Map of characteristic_instance_id to a set of | 233 // Map of characteristic_instance_id to a set of |
| 215 // WebBluetoothGATTCharacteristic pointers. Keeps track of which | 234 // WebBluetoothGATTCharacteristic pointers. Keeps track of which |
| 216 // objects are subscribed to notifications. | 235 // objects are subscribed to notifications. |
| 217 std::map<std::string, std::set<blink::WebBluetoothGATTCharacteristic*>> | 236 std::map<std::string, std::set<blink::WebBluetoothGATTCharacteristic*>> |
| 218 active_notification_subscriptions_; | 237 active_notification_subscriptions_; |
| 219 | 238 |
| 239 // Map of characteristic_instance_ids to WebBluetoothGATTCharacteristics. |
| 240 // Keeps track of what characteristics have listeners. |
| 241 // TODO(ortuno): We are assuming that there exists a single frame per |
| 242 // dispatcher, so there could be at most one characteristic object per |
| 243 // characteristic_instance_id. Change to a set when we support multiple |
| 244 // frames. |
| 245 // http://crbug.com/541388 |
| 246 std::map<std::string, blink::WebBluetoothGATTCharacteristic*> |
| 247 active_characteristics_; |
| 248 |
| 220 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | 249 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); |
| 221 }; | 250 }; |
| 222 | 251 |
| 223 } // namespace content | 252 } // namespace content |
| 224 | 253 |
| 225 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 254 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
| OLD | NEW |