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