| 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 only call this function when the object gets destroyed. | 
|  | 151   // http://crbug.com/541390 | 
|  | 152   void UnregisterCharacteristicObject( | 
|  | 153       const blink::WebString& characteristic_instance_id); | 
|  | 154 | 
| 143   // IPC Handlers, see definitions in bluetooth_messages.h. | 155   // IPC Handlers, see definitions in bluetooth_messages.h. | 
| 144   void OnRequestDeviceSuccess(int thread_id, | 156   void OnRequestDeviceSuccess(int thread_id, | 
| 145                               int request_id, | 157                               int request_id, | 
| 146                               const BluetoothDevice& device); | 158                               const BluetoothDevice& device); | 
| 147   void OnRequestDeviceError(int thread_id, | 159   void OnRequestDeviceError(int thread_id, | 
| 148                             int request_id, | 160                             int request_id, | 
| 149                             blink::WebBluetoothError error); | 161                             blink::WebBluetoothError error); | 
| 150   void OnConnectGATTSuccess(int thread_id, | 162   void OnConnectGATTSuccess(int thread_id, | 
| 151                             int request_id, | 163                             int request_id, | 
| 152                             const std::string& message); | 164                             const std::string& message); | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 174                         blink::WebBluetoothError error); | 186                         blink::WebBluetoothError error); | 
| 175   void OnWriteValueSuccess(int thread_id, int request_id); | 187   void OnWriteValueSuccess(int thread_id, int request_id); | 
| 176   void OnWriteValueError(int thread_id, | 188   void OnWriteValueError(int thread_id, | 
| 177                          int request_id, | 189                          int request_id, | 
| 178                          blink::WebBluetoothError error); | 190                          blink::WebBluetoothError error); | 
| 179   void OnStartNotificationsSuccess(int thread_id, int request_id); | 191   void OnStartNotificationsSuccess(int thread_id, int request_id); | 
| 180   void OnStartNotificationsError(int thread_id, | 192   void OnStartNotificationsError(int thread_id, | 
| 181                                  int request_id, | 193                                  int request_id, | 
| 182                                  blink::WebBluetoothError error); | 194                                  blink::WebBluetoothError error); | 
| 183   void OnStopNotificationsSuccess(int thread_id, int request_id); | 195   void OnStopNotificationsSuccess(int thread_id, int request_id); | 
|  | 196   void OnCharacteristicValueChanged( | 
|  | 197       int thread_id, | 
|  | 198       const std::string& characteristic_instance_id, | 
|  | 199       const std::vector<uint8_t> value); | 
| 184 | 200 | 
| 185   scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 201   scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 
| 186 | 202 | 
| 187   // Map of characteristic_instance_id to a queue of Notification Requests' IDs. | 203   // Map of characteristic_instance_id to a queue of Notification Requests' IDs. | 
| 188   // See "Notifications Queueing Note" above. | 204   // See "Notifications Queueing Note" above. | 
| 189   std::map<std::string, std::queue<int>> notification_requests_queues_; | 205   std::map<std::string, std::queue<int>> notification_requests_queues_; | 
| 190 | 206 | 
| 191   // Tracks device requests sent to browser to match replies with callbacks. | 207   // Tracks device requests sent to browser to match replies with callbacks. | 
| 192   // Owns callback objects. | 208   // Owns callback objects. | 
| 193   IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | 209   IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 210       pending_write_value_requests_; | 226       pending_write_value_requests_; | 
| 211   IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> | 227   IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> | 
| 212       pending_notifications_requests_; | 228       pending_notifications_requests_; | 
| 213 | 229 | 
| 214   // Map of characteristic_instance_id to a set of | 230   // Map of characteristic_instance_id to a set of | 
| 215   // WebBluetoothGATTCharacteristic pointers. Keeps track of which | 231   // WebBluetoothGATTCharacteristic pointers. Keeps track of which | 
| 216   // objects are subscribed to notifications. | 232   // objects are subscribed to notifications. | 
| 217   std::map<std::string, std::set<blink::WebBluetoothGATTCharacteristic*>> | 233   std::map<std::string, std::set<blink::WebBluetoothGATTCharacteristic*>> | 
| 218       active_notification_subscriptions_; | 234       active_notification_subscriptions_; | 
| 219 | 235 | 
|  | 236   // Map of characteristic_instance_ids to WebBluetoothGATTCharacteristics. | 
|  | 237   // Keeps track of what characteristics have listeners. | 
|  | 238   // TODO(ortuno): We are assuming that there exists a single frame per | 
|  | 239   // dispatcher, so there could be at most one characteristic object per | 
|  | 240   // characteristic_instance_id. Change to a set when we support multiple | 
|  | 241   // frames. | 
|  | 242   // http://crbug.com/541388 | 
|  | 243   std::map<std::string, blink::WebBluetoothGATTCharacteristic*> | 
|  | 244       active_characteristics_; | 
|  | 245 | 
| 220   DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | 246   DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | 
| 221 }; | 247 }; | 
| 222 | 248 | 
| 223 }  // namespace content | 249 }  // namespace content | 
| 224 | 250 | 
| 225 #endif  // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 251 #endif  // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 
| OLD | NEW | 
|---|