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_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/containers/scoped_ptr_map.h" |
9 #include "base/id_map.h" | 10 #include "base/id_map.h" |
10 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "content/public/browser/bluetooth_chooser.h" | 13 #include "content/public/browser/bluetooth_chooser.h" |
13 #include "content/public/browser/browser_message_filter.h" | 14 #include "content/public/browser/browser_message_filter.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_gatt_connection.h" | 16 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 17 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
16 #include "device/bluetooth/bluetooth_gatt_service.h" | 18 #include "device/bluetooth/bluetooth_gatt_service.h" |
17 | 19 |
18 namespace device { | 20 namespace device { |
19 class BluetoothUUID; | 21 class BluetoothUUID; |
20 } | 22 } |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 struct BluetoothScanFilter; | 26 struct BluetoothScanFilter; |
25 | 27 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // choosers. | 70 // choosers. |
69 void StopDeviceDiscovery(); | 71 void StopDeviceDiscovery(); |
70 | 72 |
71 // BluetoothAdapter::Observer: | 73 // BluetoothAdapter::Observer: |
72 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 74 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
73 bool powered) override; | 75 bool powered) override; |
74 void DeviceAdded(device::BluetoothAdapter* adapter, | 76 void DeviceAdded(device::BluetoothAdapter* adapter, |
75 device::BluetoothDevice* device) override; | 77 device::BluetoothDevice* device) override; |
76 void DeviceRemoved(device::BluetoothAdapter* adapter, | 78 void DeviceRemoved(device::BluetoothAdapter* adapter, |
77 device::BluetoothDevice* device) override; | 79 device::BluetoothDevice* device) override; |
| 80 void GattCharacteristicValueChanged( |
| 81 device::BluetoothAdapter* adapter, |
| 82 device::BluetoothGattCharacteristic* characteristic, |
| 83 const std::vector<uint8>& value) override; |
78 | 84 |
79 // IPC Handlers, see definitions in bluetooth_messages.h. | 85 // IPC Handlers, see definitions in bluetooth_messages.h. |
80 void OnRequestDevice( | 86 void OnRequestDevice( |
81 int thread_id, | 87 int thread_id, |
82 int request_id, | 88 int request_id, |
83 int frame_routing_id, | 89 int frame_routing_id, |
84 const std::vector<content::BluetoothScanFilter>& filters, | 90 const std::vector<content::BluetoothScanFilter>& filters, |
85 const std::vector<device::BluetoothUUID>& optional_services); | 91 const std::vector<device::BluetoothUUID>& optional_services); |
86 void OnConnectGATT(int thread_id, int request_id, | 92 void OnConnectGATT(int thread_id, int request_id, |
87 const std::string& device_instance_id); | 93 const std::string& device_instance_id); |
88 void OnGetPrimaryService(int thread_id, | 94 void OnGetPrimaryService(int thread_id, |
89 int request_id, | 95 int request_id, |
90 const std::string& device_instance_id, | 96 const std::string& device_instance_id, |
91 const std::string& service_uuid); | 97 const std::string& service_uuid); |
92 void OnGetCharacteristic(int thread_id, | 98 void OnGetCharacteristic(int thread_id, |
93 int request_id, | 99 int request_id, |
94 const std::string& service_instance_id, | 100 const std::string& service_instance_id, |
95 const std::string& characteristic_uuid); | 101 const std::string& characteristic_uuid); |
96 void OnReadValue(int thread_id, | 102 void OnReadValue(int thread_id, |
97 int request_id, | 103 int request_id, |
98 const std::string& characteristic_instance_id); | 104 const std::string& characteristic_instance_id); |
99 void OnWriteValue(int thread_id, | 105 void OnWriteValue(int thread_id, |
100 int request_id, | 106 int request_id, |
101 const std::string& characteristic_instance_id, | 107 const std::string& characteristic_instance_id, |
102 const std::vector<uint8_t>& value); | 108 const std::vector<uint8_t>& value); |
| 109 void OnStartNotifications(int thread_id, |
| 110 int request_id, |
| 111 const std::string& characteristic_instance_id); |
| 112 void OnStopNotifications(int thread_id, |
| 113 int request_id, |
| 114 const std::string& characteristic_instance_id); |
103 | 115 |
104 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 116 // Callbacks for BluetoothAdapter::StartDiscoverySession. |
105 void OnDiscoverySessionStarted( | 117 void OnDiscoverySessionStarted( |
106 int chooser_id, | 118 int chooser_id, |
107 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 119 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
108 void OnDiscoverySessionStartedError(int chooser_id); | 120 void OnDiscoverySessionStartedError(int chooser_id); |
109 | 121 |
110 // BluetoothChooser::EventHandler: | 122 // BluetoothChooser::EventHandler: |
111 void OnBluetoothChooserEvent(int chooser_id, | 123 void OnBluetoothChooserEvent(int chooser_id, |
112 BluetoothChooser::Event event, | 124 BluetoothChooser::Event event, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 int thread_id, | 161 int thread_id, |
150 int request_id, | 162 int request_id, |
151 device::BluetoothGattService::GattErrorCode); | 163 device::BluetoothGattService::GattErrorCode); |
152 | 164 |
153 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | 165 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. |
154 void OnWriteValueSuccess(int thread_id, int request_id); | 166 void OnWriteValueSuccess(int thread_id, int request_id); |
155 void OnWriteValueFailed(int thread_id, | 167 void OnWriteValueFailed(int thread_id, |
156 int request_id, | 168 int request_id, |
157 device::BluetoothGattService::GattErrorCode); | 169 device::BluetoothGattService::GattErrorCode); |
158 | 170 |
| 171 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. |
| 172 void OnStartNotifySessionSuccess( |
| 173 int thread_id, |
| 174 int request_id, |
| 175 scoped_ptr<device::BluetoothGattNotifySession> notify_session); |
| 176 void OnStartNotifySessionFailed( |
| 177 int thread_id, |
| 178 int request_id, |
| 179 device::BluetoothGattService::GattErrorCode error_code); |
| 180 |
| 181 // Callback for BluetoothGattNotifySession::Stop. |
| 182 void OnStopNotifySession(int thread_id, |
| 183 int request_id, |
| 184 const std::string& characteristic_instance_id); |
| 185 |
159 // Show help pages from the chooser dialog. | 186 // Show help pages from the chooser dialog. |
160 void ShowBluetoothOverviewLink(); | 187 void ShowBluetoothOverviewLink(); |
161 void ShowBluetoothPairingLink(); | 188 void ShowBluetoothPairingLink(); |
162 void ShowBluetoothAdapterOffLink(); | 189 void ShowBluetoothAdapterOffLink(); |
163 | 190 |
164 int render_process_id_; | 191 int render_process_id_; |
165 | 192 |
166 // Maps a (thread_id,request_id) to information about its requestDevice call, | 193 // Maps a (thread_id,request_id) to information about its requestDevice call, |
167 // including the chooser dialog. | 194 // including the chooser dialog. |
168 // An entry is added to this map in OnRequestDevice, and should be removed | 195 // An entry is added to this map in OnRequestDevice, and should be removed |
169 // again everywhere a requestDevice() reply is sent. | 196 // again everywhere a requestDevice() reply is sent. |
170 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; | 197 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; |
171 | 198 |
172 // Maps to get the object's parent based on it's instanceID | 199 // Maps to get the object's parent based on it's instanceID |
173 // Map of service_instance_id to device_instance_id. | 200 // Map of service_instance_id to device_instance_id. |
174 std::map<std::string, std::string> service_to_device_; | 201 std::map<std::string, std::string> service_to_device_; |
175 // Map of characteristic_instance_id to service_instance_id. | 202 // Map of characteristic_instance_id to service_instance_id. |
176 std::map<std::string, std::string> characteristic_to_service_; | 203 std::map<std::string, std::string> characteristic_to_service_; |
177 | 204 |
| 205 // Map that matches characteristic_instance_id to notify session. |
| 206 // TODO(ortuno): Also key by thread_id once support for web workers, |
| 207 // is added: http://crbug.com/537372 |
| 208 base::ScopedPtrMap<std::string, |
| 209 scoped_ptr<device::BluetoothGattNotifySession>> |
| 210 characteristic_id_to_notify_session_; |
| 211 |
178 // Defines how long to scan for and how long to discover services for. | 212 // Defines how long to scan for and how long to discover services for. |
179 int current_delay_time_; | 213 int current_delay_time_; |
180 | 214 |
181 // A BluetoothAdapter instance representing an adapter of the system. | 215 // A BluetoothAdapter instance representing an adapter of the system. |
182 scoped_refptr<device::BluetoothAdapter> adapter_; | 216 scoped_refptr<device::BluetoothAdapter> adapter_; |
183 | 217 |
184 // Automatically stops Bluetooth discovery a set amount of time after it was | 218 // Automatically stops Bluetooth discovery a set amount of time after it was |
185 // started. We have a single timer for all of Web Bluetooth because it's | 219 // started. We have a single timer for all of Web Bluetooth because it's |
186 // simpler than tracking timeouts for each RequestDeviceSession individually, | 220 // simpler than tracking timeouts for each RequestDeviceSession individually, |
187 // and because there's no harm in extending the length of a few discovery | 221 // and because there's no harm in extending the length of a few discovery |
188 // sessions when other sessions are active. | 222 // sessions when other sessions are active. |
189 base::Timer discovery_session_timer_; | 223 base::Timer discovery_session_timer_; |
190 | 224 |
191 // Retain BluetoothGattConnection objects to keep connections open. | 225 // Retain BluetoothGattConnection objects to keep connections open. |
192 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 | 226 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 |
193 ScopedVector<device::BluetoothGattConnection> connections_; | 227 ScopedVector<device::BluetoothGattConnection> connections_; |
194 | 228 |
195 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and | 229 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and |
196 // because it exists and has been bound to the UI thread enforces that all | 230 // because it exists and has been bound to the UI thread enforces that all |
197 // copies verify they are also used on the UI thread. | 231 // copies verify they are also used on the UI thread. |
198 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 232 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
199 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 233 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
200 | 234 |
201 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 235 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
202 }; | 236 }; |
203 | 237 |
204 } // namespace content | 238 } // namespace content |
205 | 239 |
206 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 240 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
OLD | NEW |