forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_cache.h
86 lines (63 loc) · 2.93 KB
/
device_cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_BLUETOOTH_CONFIG_DEVICE_CACHE_H_
#define CHROMEOS_SERVICES_BLUETOOTH_CONFIG_DEVICE_CACHE_H_
#include <vector>
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chromeos/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"
namespace chromeos {
namespace bluetooth_config {
class AdapterStateController;
// Caches known Bluetooth devices, providing getters and an observer interface
// for receiving updates when devices change.
class DeviceCache {
public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
// Invoked when the list of paired devices has changed. This callback is
// used when a device has been added/removed from the list, or when one or
// more properties of a device in the list has changed.
virtual void OnPairedDevicesListChanged() {}
// Invoked when the list of unpaired devices has changed. This callback is
// used when a device has been added/removed from the list, or when one or
// more properties of a device in the list has changed.
virtual void OnUnpairedDevicesListChanged() {}
};
virtual ~DeviceCache();
// Returns a sorted list of all paired devices. The list is sorted such that
// connected devices appear before connecting devices, which appear before
// disconnected devices. If Bluetooth is disabled, disabling, or unavailable,
// this function returns an empty list.
std::vector<mojom::PairedBluetoothDevicePropertiesPtr> GetPairedDevices()
const;
// Returns a sorted list of unpaired devices. This list is sorted by signal
// strength.
std::vector<mojom::BluetoothDevicePropertiesPtr> GetUnpairedDevices() const;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
protected:
explicit DeviceCache(AdapterStateController* adapter_state_controller);
// Implementation-specific version of GetPairedDevices(), which is invoked
// only if Bluetooth is enabled or enabling.
virtual std::vector<mojom::PairedBluetoothDevicePropertiesPtr>
PerformGetPairedDevices() const = 0;
// Implementation-specific version of GetUnpairedDevices(), which is invoked
// only if Bluetooth is enabled or enabling.
virtual std::vector<mojom::BluetoothDevicePropertiesPtr>
PerformGetUnpairedDevices() const = 0;
AdapterStateController* adapter_state_controller() {
return adapter_state_controller_;
}
void NotifyPairedDevicesListChanged();
void NotifyUnpairedDevicesListChanged();
private:
bool IsBluetoothEnabledOrEnabling() const;
AdapterStateController* adapter_state_controller_;
base::ObserverList<Observer> observers_;
};
} // namespace bluetooth_config
} // namespace chromeos
#endif // CHROMEOS_SERVICES_BLUETOOTH_CONFIG_DEVICE_CACHE_H_