Index: content/browser/bluetooth/bluetooth_dispatcher_host.h |
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.h b/content/browser/bluetooth/bluetooth_dispatcher_host.h |
index e0c92f74df913f5549fffddee167bf7fb67d11dc..8dfee761acaf7410161785429fe57815228eac9a 100644 |
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.h |
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.h |
@@ -6,7 +6,9 @@ |
#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
#include "base/basictypes.h" |
+#include "base/id_map.h" |
#include "base/memory/weak_ptr.h" |
+#include "content/public/browser/bluetooth_chooser.h" |
#include "content/public/browser/browser_message_filter.h" |
#include "device/bluetooth/bluetooth_adapter.h" |
#include "device/bluetooth/bluetooth_gatt_connection.h" |
@@ -57,6 +59,16 @@ class CONTENT_EXPORT BluetoothDispatcherHost final |
// releasing references to previous |adapter_|. |
void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
+ // Stops all BluetoothDiscoverySessions being run for requestDevice() |
+ // choosers. |
+ void StopDeviceDiscovery(); |
+ |
+ // BluetoothAdapter::Observer: |
+ void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
+ bool powered) override; |
+ void DeviceAdded(device::BluetoothAdapter* adapter, |
+ device::BluetoothDevice* device) override; |
+ |
// IPC Handlers, see definitions in bluetooth_messages.h. |
void OnRequestDevice( |
int thread_id, |
@@ -84,20 +96,21 @@ class CONTENT_EXPORT BluetoothDispatcherHost final |
// Callbacks for BluetoothAdapter::StartDiscoverySession. |
void OnDiscoverySessionStarted( |
- int thread_id, |
- int request_id, |
+ int chooser_id, |
scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
- void OnDiscoverySessionStartedError(int thread_id, int request_id); |
+ void OnDiscoverySessionStartedError(int chooser_id); |
- // Stop in progress discovery session. |
- void StopDiscoverySession( |
- int thread_id, |
- int request_id, |
- scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
+ // BluetoothChooser::EventHandler: |
+ void OnBluetoothChooserEvent(int chooser_id, |
+ BluetoothChooser::Event event, |
+ const std::string& device_id); |
- // Callbacks for BluetoothDiscoverySession::Stop. |
- void OnDiscoverySessionStopped(int thread_id, int request_id); |
- void OnDiscoverySessionStoppedError(int thread_id, int request_id); |
+ // The chooser implementation yields to the event loop to avoid re-entering |
+ // code that's still using the RequestDeviceSession, and continues with this |
+ // function. |
+ void FinishClosingChooser(int chooser_id, |
+ BluetoothChooser::Event event, |
+ const std::string& device_id); |
// Callbacks for BluetoothDevice::CreateGattConnection. |
void OnGATTConnectionCreated( |
@@ -142,7 +155,7 @@ class CONTENT_EXPORT BluetoothDispatcherHost final |
// including the chooser dialog. |
// An entry is added to this map in OnRequestDevice, and should be removed |
// again everywhere a requestDevice() reply is sent. |
- std::map<std::pair<int, int>, RequestDeviceSession> request_device_sessions_; |
+ IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; |
// Maps to get the object's parent based on it's instanceID |
// Map of service_instance_id to device_instance_id. |
@@ -156,6 +169,13 @@ class CONTENT_EXPORT BluetoothDispatcherHost final |
// A BluetoothAdapter instance representing an adapter of the system. |
scoped_refptr<device::BluetoothAdapter> adapter_; |
+ // Automatically stops Bluetooth discovery a set amount of time after it was |
+ // started. We have a single timer for all of Web Bluetooth because it's |
+ // simpler than tracking timeouts for each RequestDeviceSession individually, |
+ // and because there's no harm in extending the length of a few discovery |
+ // sessions when other sessions are active. |
+ base::Timer discovery_session_timer_; |
+ |
// Must be last member, see base/memory/weak_ptr.h documentation |
base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |