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