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 "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 Loading... |
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 HasActiveCharacteristicNotification( |
| 94 const blink::WebString& characteristic_instance_id); |
| 95 void AddToActiveNotificationsMap( |
| 96 const blink::WebString& characteristic_instance_id, |
| 97 blink::WebBluetoothGATTCharacteristicDelegate* delegate); |
| 98 bool WillBeActiveNotificationWhenRemoved( |
| 99 const blink::WebString& characteristic_instance_id, |
| 100 blink::WebBluetoothGATTCharacteristicDelegate* delegate); |
| 101 void RemoveFromActiveNotificationsMap( |
| 102 const blink::WebString& characteristic_instance_id, |
| 103 blink::WebBluetoothGATTCharacteristicDelegate* delegate); |
| 104 |
77 // IPC Handlers, see definitions in bluetooth_messages.h. | 105 // IPC Handlers, see definitions in bluetooth_messages.h. |
78 void OnRequestDeviceSuccess(int thread_id, | 106 void OnRequestDeviceSuccess(int thread_id, |
79 int request_id, | 107 int request_id, |
80 const BluetoothDevice& device); | 108 const BluetoothDevice& device); |
81 void OnRequestDeviceError(int thread_id, | 109 void OnRequestDeviceError(int thread_id, |
82 int request_id, | 110 int request_id, |
83 blink::WebBluetoothError error); | 111 blink::WebBluetoothError error); |
84 | 112 |
85 void OnConnectGATTSuccess(int thread_id, | 113 void OnConnectGATTSuccess(int thread_id, |
86 int request_id, | 114 int request_id, |
(...skipping 18 matching lines...) Expand all Loading... |
105 void OnReadValueSuccess(int thread_id, | 133 void OnReadValueSuccess(int thread_id, |
106 int request_id, | 134 int request_id, |
107 const std::vector<uint8_t>& value); | 135 const std::vector<uint8_t>& value); |
108 void OnReadValueError(int thread_id, | 136 void OnReadValueError(int thread_id, |
109 int request_id, | 137 int request_id, |
110 blink::WebBluetoothError error); | 138 blink::WebBluetoothError error); |
111 void OnWriteValueSuccess(int thread_id, int request_id); | 139 void OnWriteValueSuccess(int thread_id, int request_id); |
112 void OnWriteValueError(int thread_id, | 140 void OnWriteValueError(int thread_id, |
113 int request_id, | 141 int request_id, |
114 blink::WebBluetoothError error); | 142 blink::WebBluetoothError error); |
| 143 void OnStartNotificationsSuccess(int thread_id, int request_id); |
| 144 void OnStartNotificationsError(int thread_id, |
| 145 int request_id, |
| 146 blink::WebBluetoothError error); |
| 147 void OnStopNotificationsSuccess(int thread_id, int request_id); |
115 | 148 |
116 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 149 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
117 | 150 |
| 151 // Map of characteristic instance ids to characteristic delegates. |
| 152 // Keeps track of which characteristic objects are subscribed |
| 153 // to notifications. |
| 154 std::map<std::string, |
| 155 std::set<blink::WebBluetoothGATTCharacteristicDelegate*>> |
| 156 active_characteristic_notifications; |
| 157 |
118 // Tracks device requests sent to browser to match replies with callbacks. | 158 // Tracks device requests sent to browser to match replies with callbacks. |
119 // Owns callback objects. | 159 // Owns callback objects. |
120 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> | 160 IDMap<blink::WebBluetoothRequestDeviceCallbacks, IDMapOwnPointer> |
121 pending_requests_; | 161 pending_requests_; |
122 // Tracks requests to connect to a device. | 162 // Tracks requests to connect to a device. |
123 // Owns callback objects. | 163 // Owns callback objects. |
124 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> | 164 IDMap<blink::WebBluetoothConnectGATTCallbacks, IDMapOwnPointer> |
125 pending_connect_requests_; | 165 pending_connect_requests_; |
126 // Tracks requests to get a primary service from a device. | 166 // Tracks requests to get a primary service from a device. |
127 // Owns request objects. | 167 // Owns request objects. |
128 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> | 168 IDMap<BluetoothPrimaryServiceRequest, IDMapOwnPointer> |
129 pending_primary_service_requests_; | 169 pending_primary_service_requests_; |
130 // Tracks requests to get a characteristic from a service. | 170 // Tracks requests to get a characteristic from a service. |
131 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer> | 171 IDMap<BluetoothCharacteristicRequest, IDMapOwnPointer> |
132 pending_characteristic_requests_; | 172 pending_characteristic_requests_; |
133 // Tracks requests to read from a characteristics. | 173 // Tracks requests to read from a characteristics. |
134 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer> | 174 IDMap<blink::WebBluetoothReadValueCallbacks, IDMapOwnPointer> |
135 pending_read_value_requests_; | 175 pending_read_value_requests_; |
136 IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer> | 176 IDMap<blink::WebBluetoothWriteValueCallbacks, IDMapOwnPointer> |
137 pending_write_value_requests_; | 177 pending_write_value_requests_; |
| 178 // Tracks requests to start notifications from a characteristic. |
| 179 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> |
| 180 pending_start_notifications_requests_; |
| 181 // Tracks requests to stop notifications from a characteristic. |
| 182 IDMap<BluetoothNotificationsRequest, IDMapOwnPointer> |
| 183 pending_stop_notifications_requests_; |
138 | 184 |
139 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); | 185 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcher); |
140 }; | 186 }; |
141 | 187 |
142 } // namespace content | 188 } // namespace content |
143 | 189 |
144 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ | 190 #endif // CONTENT_CHILD_BLUETOOTH_BLUETOOTH_DISPATCHER_H_ |
OLD | NEW |