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..7c49d5724370c0768bd47e33797a37769e834523 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" |
@@ -32,6 +34,7 @@ struct BluetoothScanFilter; |
// thread because BluetoothAdapter and related objects live there. |
class CONTENT_EXPORT BluetoothDispatcherHost final |
: public BrowserMessageFilter, |
+ public BluetoothChooser::Observer, |
public device::BluetoothAdapter::Observer { |
public: |
BluetoothDispatcherHost(int render_process_id); |
@@ -57,6 +60,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 implementation: |
+ 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 +97,22 @@ 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::Observer implementation: |
+ void DialogCancelled(int chooser_id) override; |
+ void DeviceSelected(int chooser_id, const std::string& device_id) override; |
- // Callbacks for BluetoothDiscoverySession::Stop. |
- void OnDiscoverySessionStopped(int thread_id, int request_id); |
- void OnDiscoverySessionStoppedError(int thread_id, int request_id); |
+ // Helper function for the above two functions: |
+ void CloseDialog(int chooser_id, const base::Closure& callback); |
+ |
+ // The chooser implementation yields to the event loop to avoid re-entering |
+ // code that's still using the RequestDeviceSession. These are the |
+ // continuation functions. |
+ void OnRequestDeviceCancelled(int chooser_id); |
+ void OnRequestDeviceSelected(int chooser_id, const std::string& device_id); |
// Callbacks for BluetoothDevice::CreateGattConnection. |
void OnGATTConnectionCreated( |
@@ -142,7 +157,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 +171,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_; |