| 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/id_map.h" |
| 9 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/public/browser/bluetooth_chooser.h" |
| 10 #include "content/public/browser/browser_message_filter.h" | 12 #include "content/public/browser/browser_message_filter.h" |
| 11 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
| 12 #include "device/bluetooth/bluetooth_gatt_connection.h" | 14 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 13 #include "device/bluetooth/bluetooth_gatt_service.h" | 15 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 14 | 16 |
| 15 namespace device { | 17 namespace device { |
| 16 class BluetoothUUID; | 18 class BluetoothUUID; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 private: | 52 private: |
| 51 friend class base::DeleteHelper<BluetoothDispatcherHost>; | 53 friend class base::DeleteHelper<BluetoothDispatcherHost>; |
| 52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 54 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 53 | 55 |
| 54 struct RequestDeviceSession; | 56 struct RequestDeviceSession; |
| 55 | 57 |
| 56 // Set |adapter_| to a BluetoothAdapter instance and register observers, | 58 // Set |adapter_| to a BluetoothAdapter instance and register observers, |
| 57 // releasing references to previous |adapter_|. | 59 // releasing references to previous |adapter_|. |
| 58 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 60 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 59 | 61 |
| 62 // Stops all BluetoothDiscoverySessions being run for requestDevice() |
| 63 // choosers. |
| 64 void StopDeviceDiscovery(); |
| 65 |
| 66 // BluetoothAdapter::Observer: |
| 67 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 68 bool powered) override; |
| 69 void DeviceAdded(device::BluetoothAdapter* adapter, |
| 70 device::BluetoothDevice* device) override; |
| 71 |
| 60 // IPC Handlers, see definitions in bluetooth_messages.h. | 72 // IPC Handlers, see definitions in bluetooth_messages.h. |
| 61 void OnRequestDevice( | 73 void OnRequestDevice( |
| 62 int thread_id, | 74 int thread_id, |
| 63 int request_id, | 75 int request_id, |
| 64 int frame_routing_id, | 76 int frame_routing_id, |
| 65 const std::vector<content::BluetoothScanFilter>& filters, | 77 const std::vector<content::BluetoothScanFilter>& filters, |
| 66 const std::vector<device::BluetoothUUID>& optional_services); | 78 const std::vector<device::BluetoothUUID>& optional_services); |
| 67 void OnConnectGATT(int thread_id, int request_id, | 79 void OnConnectGATT(int thread_id, int request_id, |
| 68 const std::string& device_instance_id); | 80 const std::string& device_instance_id); |
| 69 void OnGetPrimaryService(int thread_id, | 81 void OnGetPrimaryService(int thread_id, |
| 70 int request_id, | 82 int request_id, |
| 71 const std::string& device_instance_id, | 83 const std::string& device_instance_id, |
| 72 const std::string& service_uuid); | 84 const std::string& service_uuid); |
| 73 void OnGetCharacteristic(int thread_id, | 85 void OnGetCharacteristic(int thread_id, |
| 74 int request_id, | 86 int request_id, |
| 75 const std::string& service_instance_id, | 87 const std::string& service_instance_id, |
| 76 const std::string& characteristic_uuid); | 88 const std::string& characteristic_uuid); |
| 77 void OnReadValue(int thread_id, | 89 void OnReadValue(int thread_id, |
| 78 int request_id, | 90 int request_id, |
| 79 const std::string& characteristic_instance_id); | 91 const std::string& characteristic_instance_id); |
| 80 void OnWriteValue(int thread_id, | 92 void OnWriteValue(int thread_id, |
| 81 int request_id, | 93 int request_id, |
| 82 const std::string& characteristic_instance_id, | 94 const std::string& characteristic_instance_id, |
| 83 const std::vector<uint8_t>& value); | 95 const std::vector<uint8_t>& value); |
| 84 | 96 |
| 85 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 97 // Callbacks for BluetoothAdapter::StartDiscoverySession. |
| 86 void OnDiscoverySessionStarted( | 98 void OnDiscoverySessionStarted( |
| 87 int thread_id, | 99 int chooser_id, |
| 88 int request_id, | |
| 89 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 100 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| 90 void OnDiscoverySessionStartedError(int thread_id, int request_id); | 101 void OnDiscoverySessionStartedError(int chooser_id); |
| 91 | 102 |
| 92 // Stop in progress discovery session. | 103 // BluetoothChooser::EventHandler: |
| 93 void StopDiscoverySession( | 104 void OnBluetoothChooserEvent(int chooser_id, |
| 94 int thread_id, | 105 BluetoothChooser::Event event, |
| 95 int request_id, | 106 const std::string& device_id); |
| 96 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | |
| 97 | 107 |
| 98 // Callbacks for BluetoothDiscoverySession::Stop. | 108 // The chooser implementation yields to the event loop to avoid re-entering |
| 99 void OnDiscoverySessionStopped(int thread_id, int request_id); | 109 // code that's still using the RequestDeviceSession, and continues with this |
| 100 void OnDiscoverySessionStoppedError(int thread_id, int request_id); | 110 // function. |
| 111 void FinishClosingChooser(int chooser_id, |
| 112 BluetoothChooser::Event event, |
| 113 const std::string& device_id); |
| 101 | 114 |
| 102 // Callbacks for BluetoothDevice::CreateGattConnection. | 115 // Callbacks for BluetoothDevice::CreateGattConnection. |
| 103 void OnGATTConnectionCreated( | 116 void OnGATTConnectionCreated( |
| 104 int thread_id, | 117 int thread_id, |
| 105 int request_id, | 118 int request_id, |
| 106 const std::string& device_instance_id, | 119 const std::string& device_instance_id, |
| 107 base::TimeTicks start_time, | 120 base::TimeTicks start_time, |
| 108 scoped_ptr<device::BluetoothGattConnection> connection); | 121 scoped_ptr<device::BluetoothGattConnection> connection); |
| 109 void OnCreateGATTConnectionError( | 122 void OnCreateGATTConnectionError( |
| 110 int thread_id, | 123 int thread_id, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 135 void OnWriteValueFailed(int thread_id, | 148 void OnWriteValueFailed(int thread_id, |
| 136 int request_id, | 149 int request_id, |
| 137 device::BluetoothGattService::GattErrorCode); | 150 device::BluetoothGattService::GattErrorCode); |
| 138 | 151 |
| 139 int render_process_id_; | 152 int render_process_id_; |
| 140 | 153 |
| 141 // Maps a (thread_id,request_id) to information about its requestDevice call, | 154 // Maps a (thread_id,request_id) to information about its requestDevice call, |
| 142 // including the chooser dialog. | 155 // including the chooser dialog. |
| 143 // An entry is added to this map in OnRequestDevice, and should be removed | 156 // An entry is added to this map in OnRequestDevice, and should be removed |
| 144 // again everywhere a requestDevice() reply is sent. | 157 // again everywhere a requestDevice() reply is sent. |
| 145 std::map<std::pair<int, int>, RequestDeviceSession> request_device_sessions_; | 158 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; |
| 146 | 159 |
| 147 // Maps to get the object's parent based on it's instanceID | 160 // Maps to get the object's parent based on it's instanceID |
| 148 // Map of service_instance_id to device_instance_id. | 161 // Map of service_instance_id to device_instance_id. |
| 149 std::map<std::string, std::string> service_to_device_; | 162 std::map<std::string, std::string> service_to_device_; |
| 150 // Map of characteristic_instance_id to service_instance_id. | 163 // Map of characteristic_instance_id to service_instance_id. |
| 151 std::map<std::string, std::string> characteristic_to_service_; | 164 std::map<std::string, std::string> characteristic_to_service_; |
| 152 | 165 |
| 153 // Defines how long to scan for and how long to discover services for. | 166 // Defines how long to scan for and how long to discover services for. |
| 154 int current_delay_time_; | 167 int current_delay_time_; |
| 155 | 168 |
| 156 // A BluetoothAdapter instance representing an adapter of the system. | 169 // A BluetoothAdapter instance representing an adapter of the system. |
| 157 scoped_refptr<device::BluetoothAdapter> adapter_; | 170 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 158 | 171 |
| 172 // Automatically stops Bluetooth discovery a set amount of time after it was |
| 173 // started. We have a single timer for all of Web Bluetooth because it's |
| 174 // simpler than tracking timeouts for each RequestDeviceSession individually, |
| 175 // and because there's no harm in extending the length of a few discovery |
| 176 // sessions when other sessions are active. |
| 177 base::Timer discovery_session_timer_; |
| 178 |
| 159 // Must be last member, see base/memory/weak_ptr.h documentation | 179 // Must be last member, see base/memory/weak_ptr.h documentation |
| 160 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 180 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
| 161 | 181 |
| 162 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 182 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
| 163 }; | 183 }; |
| 164 | 184 |
| 165 } // namespace content | 185 } // namespace content |
| 166 | 186 |
| 167 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 187 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| OLD | NEW |