1 // Copyright 2013 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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
10 #include "base/memory/weak_ptr.h"
11 #include "chromeos/dbus/bluetooth_adapter_client.h"
12 #include "chromeos/dbus/bluetooth_device_client.h"
13 #include "chromeos/dbus/bluetooth_input_client.h"
14 #include "dbus/object_path.h"
15 #include "device/bluetooth/bluetooth_adapter.h"
19 class BluetoothAdapterFactory;
25 class BluetoothChromeOSTest;
26 class BluetoothDeviceChromeOS;
28 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the
29 // Chrome OS platform.
30 class BluetoothAdapterChromeOS
31 : public device::BluetoothAdapter,
32 private chromeos::BluetoothAdapterClient::Observer,
33 private chromeos::BluetoothDeviceClient::Observer,
34 private chromeos::BluetoothInputClient::Observer {
36 // BluetoothAdapter override
37 virtual void AddObserver(
38 device::BluetoothAdapter::Observer* observer) OVERRIDE;
39 virtual void RemoveObserver(
40 device::BluetoothAdapter::Observer* observer) OVERRIDE;
41 virtual std::string GetAddress() const OVERRIDE;
42 virtual std::string GetName() const OVERRIDE;
43 virtual void SetName(const std::string& name,
44 const base::Closure& callback,
45 const ErrorCallback& error_callback) OVERRIDE;
46 virtual bool IsInitialized() const OVERRIDE;
47 virtual bool IsPresent() const OVERRIDE;
48 virtual bool IsPowered() const OVERRIDE;
49 virtual void SetPowered(
51 const base::Closure& callback,
52 const ErrorCallback& error_callback) OVERRIDE;
53 virtual bool IsDiscoverable() const OVERRIDE;
54 virtual void SetDiscoverable(
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) OVERRIDE;
58 virtual bool IsDiscovering() const OVERRIDE;
59 virtual void StartDiscovering(
60 const base::Closure& callback,
61 const ErrorCallback& error_callback) OVERRIDE;
62 virtual void StopDiscovering(
63 const base::Closure& callback,
64 const ErrorCallback& error_callback) OVERRIDE;
65 virtual void ReadLocalOutOfBandPairingData(
66 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
68 const ErrorCallback& error_callback) OVERRIDE;
71 friend class device::BluetoothAdapterFactory;
72 friend class BluetoothChromeOSTest;
73 friend class BluetoothDeviceChromeOS;
74 friend class BluetoothProfileChromeOS;
75 friend class BluetoothProfileChromeOSTest;
77 BluetoothAdapterChromeOS();
78 virtual ~BluetoothAdapterChromeOS();
80 // BluetoothAdapterClient::Observer override.
81 virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE;
82 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE;
83 virtual void AdapterPropertyChanged(
84 const dbus::ObjectPath& object_path,
85 const std::string& property_name) OVERRIDE;
87 // BluetoothDeviceClient::Observer override.
88 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE;
89 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE;
90 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
91 const std::string& property_name) OVERRIDE;
93 // BluetoothInputClient::Observer override.
94 virtual void InputPropertyChanged(const dbus::ObjectPath& object_path,
95 const std::string& property_name) OVERRIDE;
97 // Internal method used to locate the device object by object path
98 // (the devices map and BluetoothDevice methods are by address)
99 BluetoothDeviceChromeOS* GetDeviceWithPath(
100 const dbus::ObjectPath& object_path);
102 // Set the tracked adapter to the one in |object_path|, this object will
103 // subsequently operate on that adapter until it is removed.
104 void SetAdapter(const dbus::ObjectPath& object_path);
106 // Set the adapter name to one chosen from the system information.
107 void SetDefaultAdapterName();
109 // Remove the currently tracked adapter. IsPresent() will return false after
111 void RemoveAdapter();
113 // Announce to observers a change in the adapter state.
114 void PoweredChanged(bool powered);
115 void DiscoverableChanged(bool discoverable);
116 void DiscoveringChanged(bool discovering);
117 void PresentChanged(bool present);
119 // Announce to observers a change in device state that is not reflected by
120 // its D-Bus properties.
121 void NotifyDeviceChanged(BluetoothDeviceChromeOS* device);
123 // Called by dbus:: on completion of the discoverable property change.
124 void OnSetDiscoverable(const base::Closure& callback,
125 const ErrorCallback& error_callback,
128 // Called by dbus:: on completion of an adapter property change.
129 void OnPropertyChangeCompleted(const base::Closure& callback,
130 const ErrorCallback& error_callback,
133 // Called by dbus:: on completion of the D-Bus method call to start discovery.
134 void OnStartDiscovery(const base::Closure& callback);
135 void OnStartDiscoveryError(const ErrorCallback& error_callback,
136 const std::string& error_name,
137 const std::string& error_message);
139 // Called by dbus:: on completion of the D-Bus method call to stop discovery.
140 void OnStopDiscovery(const base::Closure& callback);
141 void OnStopDiscoveryError(const ErrorCallback& error_callback,
142 const std::string& error_name,
143 const std::string& error_message);
145 // Object path of the adapter we track.
146 dbus::ObjectPath object_path_;
148 // List of observers interested in event notifications from us.
149 ObserverList<device::BluetoothAdapter::Observer> observers_;
151 // Note: This should remain the last member so it'll be destroyed and
152 // invalidate its weak pointers before any other members are destroyed.
153 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_;
155 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
158 } // namespace chromeos
160 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_