[M108 Migration] Support standard build for armv7hl architecture
[platform/framework/web/chromium-efl.git] / ash / bluetooth_devices_observer.h
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_BLUETOOTH_DEVICES_OBSERVER_H_
6 #define ASH_BLUETOOTH_DEVICES_OBSERVER_H_
7
8 #include "ash/ash_export.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "ui/events/devices/input_device.h"
13
14 namespace ash {
15
16 // This class observes the bluetooth devices and sends out notification when
17 // bluetooth device changes. It's used as a supplementary to the class
18 // ui::InputDeviceEventObserver as InputDeviceEventObserver does not have
19 // knowledge about bluetooth device status thus does not send notifications of
20 // bluetooth device changes.
21 class ASH_EXPORT BluetoothDevicesObserver
22     : public device::BluetoothAdapter::Observer {
23  public:
24   // Note |device| can be nullptr here if only the bluetooth adapter status
25   // changes.
26   using AdapterOrDeviceChangedCallback =
27       base::RepeatingCallback<void(device::BluetoothDevice* device)>;
28
29   explicit BluetoothDevicesObserver(
30       const AdapterOrDeviceChangedCallback& device_changed_callback);
31
32   BluetoothDevicesObserver(const BluetoothDevicesObserver&) = delete;
33   BluetoothDevicesObserver& operator=(const BluetoothDevicesObserver&) = delete;
34
35   ~BluetoothDevicesObserver() override;
36
37   // device::BluetoothAdapter::Observer:
38   void AdapterPresentChanged(device::BluetoothAdapter* adapter,
39                              bool present) override;
40   void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
41                              bool powered) override;
42   void DeviceChanged(device::BluetoothAdapter* adapter,
43                      device::BluetoothDevice* device) override;
44
45   // Returns true if |input_device| is a connected bluetooth device. Note this
46   // function may not work well if there are more than one identical Bluetooth
47   // devices: the function might return true even if it should return false.
48   // E.g., Connect two idential bluetooth devices (Input device A & input device
49   // B, thus the same vendor id and same product id) to Chrome OS, and then
50   // disconnect device A, calling IsConnectedBluetoothDevice(Input device A)
51   // still returns true although it should return false as Input device B is
52   // still connected. Unfortunately there is no good map from an InputDevice to
53   // a BluetoothDevice, thus we can only guess a match.
54   bool IsConnectedBluetoothDevice(const ui::InputDevice& input_device) const;
55
56  private:
57   void InitializeOnAdapterReady(
58       scoped_refptr<device::BluetoothAdapter> adapter);
59
60   // Reference to the underlying Bluetooth Adapter. Used to listen for bluetooth
61   // device change event.
62   scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
63
64   // Callback function to be called when the bluetooth adapter's status or a
65   // bluetooth device's status changes.
66   AdapterOrDeviceChangedCallback adapter_or_device_changed_callback_;
67
68   base::WeakPtrFactory<BluetoothDevicesObserver> weak_factory_{this};
69 };
70
71 }  // namespace ash
72
73 #endif  // ASH_BLUETOOTH_DEVICES_OBSERVER_H_