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