OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
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 CHROME_BROWSER_UI_ASH_TRAY_BLUETOOTH_HELPER_H_ | |
6 #define CHROME_BROWSER_UI_ASH_TRAY_BLUETOOTH_HELPER_H_ | |
7 | |
8 #include <memory> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "device/bluetooth/bluetooth_adapter.h" | |
15 | |
16 namespace ash { | |
17 struct BluetoothDeviceInfo; | |
18 } | |
19 | |
20 namespace device { | |
21 class BluetoothDiscoverySession; | |
22 } | |
23 | |
24 // Maps UI concepts from the Bluetooth system tray (e.g. "Bluetooth is on") into | |
25 // device concepts ("Bluetooth adapter enabled"). Note that most Bluetooth | |
26 // device operations are asynchronous, hence the two step initialization. | |
27 // TODO(jamescook): Move into //ash/system next to TrayBluetooth. This isn't | |
28 // named "delegate" because long-term there should not be any delegation. | |
29 class TrayBluetoothHelper : public device::BluetoothAdapter::Observer { | |
30 public: | |
31 TrayBluetoothHelper(); | |
32 ~TrayBluetoothHelper() override; | |
33 | |
34 // Called after SystemTray has been instantiated. | |
35 void Initialize(); | |
36 | |
37 // Completes initialization after the Bluetooth adapter is ready. | |
38 void InitializeOnAdapterReady( | |
39 scoped_refptr<device::BluetoothAdapter> adapter); | |
40 | |
41 // Returns a list of available bluetooth devices. | |
42 // TODO(jamescook): Just return the list. | |
43 void GetAvailableDevices(std::vector<ash::BluetoothDeviceInfo>* list); | |
44 | |
45 // Requests bluetooth start discovering devices, which happens asynchronously. | |
46 void StartDiscovering(); | |
47 | |
48 // Requests bluetooth stop discovering devices. | |
49 void StopDiscovering(); | |
50 | |
51 // Connect to a specific bluetooth device. | |
52 void ConnectToDevice(const std::string& address); | |
53 | |
54 // Returns true if bluetooth adapter is discovering bluetooth devices. | |
55 bool IsDiscovering() const; | |
56 | |
57 // Toggles whether bluetooth is enabled. | |
58 void ToggleEnabled(); | |
59 | |
60 // Returns whether bluetooth capability is available (e.g. the device has | |
61 // hardware support). | |
62 bool GetAvailable(); | |
63 | |
64 // Returns whether bluetooth is enabled. | |
65 bool GetEnabled(); | |
66 | |
67 // Returns whether the delegate has initiated a bluetooth discovery session. | |
68 // TODO(jamescook): Why do we need both this and IsDiscovering()? | |
69 bool HasDiscoverySession(); | |
70 | |
71 // BluetoothAdapter::Observer: | |
72 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | |
73 bool present) override; | |
74 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | |
75 bool powered) override; | |
76 void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, | |
77 bool discovering) override; | |
78 void DeviceAdded(device::BluetoothAdapter* adapter, | |
79 device::BluetoothDevice* device) override; | |
80 void DeviceChanged(device::BluetoothAdapter* adapter, | |
81 device::BluetoothDevice* device) override; | |
82 void DeviceRemoved(device::BluetoothAdapter* adapter, | |
83 device::BluetoothDevice* device) override; | |
84 | |
85 private: | |
86 void OnStartDiscoverySession( | |
87 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); | |
88 | |
89 bool should_run_discovery_ = false; | |
90 scoped_refptr<device::BluetoothAdapter> adapter_; | |
91 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | |
92 | |
93 // Object could be deleted during a prolonged Bluetooth operation. | |
94 base::WeakPtrFactory<TrayBluetoothHelper> weak_ptr_factory_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(TrayBluetoothHelper); | |
97 }; | |
98 | |
99 #endif // CHROME_BROWSER_UI_ASH_TRAY_BLUETOOTH_HELPER_H_ | |
OLD | NEW |