Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: device/bluetooth/bluetooth_device_chromeos.h

Issue 1415573014: Reland "Add Linux support for the Bluetooth API" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner.h"
14 #include "dbus/object_path.h"
15 #include "device/bluetooth/bluetooth_device.h"
16 #include "device/bluetooth/bluetooth_export.h"
17 #include "device/bluetooth/dbus/bluetooth_device_client.h"
18 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
19
20 namespace device {
21 class BluetoothSocketThread;
22 } // namespace device
23
24 namespace chromeos {
25
26 class BluetoothAdapterChromeOS;
27 class BluetoothPairingChromeOS;
28
29 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the
30 // Chrome OS platform.
31 //
32 // This class is not thread-safe, but is only called from the UI thread.
33 //
34 // A socket thread is used to create sockets but posts all callbacks on the UI
35 // thread.
36 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS
37 : public device::BluetoothDevice,
38 public bluez::BluetoothGattServiceClient::Observer {
39 public:
40 // BluetoothDevice override
41 uint32 GetBluetoothClass() const override;
42 std::string GetAddress() const override;
43 VendorIDSource GetVendorIDSource() const override;
44 uint16 GetVendorID() const override;
45 uint16 GetProductID() const override;
46 uint16 GetDeviceID() const override;
47 bool IsPaired() const override;
48 bool IsConnected() const override;
49 bool IsGattConnected() const override;
50 bool IsConnectable() const override;
51 bool IsConnecting() const override;
52 UUIDList GetUUIDs() const override;
53 int16 GetInquiryRSSI() const override;
54 int16 GetInquiryTxPower() const override;
55 bool ExpectingPinCode() const override;
56 bool ExpectingPasskey() const override;
57 bool ExpectingConfirmation() const override;
58 void GetConnectionInfo(
59 const ConnectionInfoCallback& callback) override;
60 void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate,
61 const base::Closure& callback,
62 const ConnectErrorCallback& error_callback) override;
63 void SetPinCode(const std::string& pincode) override;
64 void SetPasskey(uint32 passkey) override;
65 void ConfirmPairing() override;
66 void RejectPairing() override;
67 void CancelPairing() override;
68 void Disconnect(const base::Closure& callback,
69 const ErrorCallback& error_callback) override;
70 void Forget(const ErrorCallback& error_callback) override;
71 void ConnectToService(
72 const device::BluetoothUUID& uuid,
73 const ConnectToServiceCallback& callback,
74 const ConnectToServiceErrorCallback& error_callback) override;
75 void ConnectToServiceInsecurely(
76 const device::BluetoothUUID& uuid,
77 const ConnectToServiceCallback& callback,
78 const ConnectToServiceErrorCallback& error_callback) override;
79 void CreateGattConnection(
80 const GattConnectionCallback& callback,
81 const ConnectErrorCallback& error_callback) override;
82 void Pair(device::BluetoothDevice::PairingDelegate* pairing_delegate,
83 const base::Closure& callback,
84 const ConnectErrorCallback& error_callback) override;
85
86 // Creates a pairing object with the given delegate |pairing_delegate| and
87 // establishes it as the pairing context for this device. All pairing-related
88 // method calls will be forwarded to this object until it is released.
89 BluetoothPairingChromeOS* BeginPairing(
90 BluetoothDevice::PairingDelegate* pairing_delegate);
91
92 // Releases the current pairing object, any pairing-related method calls will
93 // be ignored.
94 void EndPairing();
95
96 // Returns the current pairing object or NULL if no pairing is in progress.
97 BluetoothPairingChromeOS* GetPairing() const;
98
99 // Returns the object path of the device.
100 const dbus::ObjectPath& object_path() const { return object_path_; }
101
102 // Returns the adapter which owns this device instance.
103 BluetoothAdapterChromeOS* adapter() const;
104
105 protected:
106 // BluetoothDevice override
107 std::string GetDeviceName() const override;
108 void CreateGattConnectionImpl() override;
109 void DisconnectGatt() override;
110
111 private:
112 friend class BluetoothAdapterChromeOS;
113
114 BluetoothDeviceChromeOS(
115 BluetoothAdapterChromeOS* adapter,
116 const dbus::ObjectPath& object_path,
117 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
118 scoped_refptr<device::BluetoothSocketThread> socket_thread);
119 ~BluetoothDeviceChromeOS() override;
120
121 // bluez::BluetoothGattServiceClient::Observer overrides.
122 void GattServiceAdded(const dbus::ObjectPath& object_path) override;
123 void GattServiceRemoved(const dbus::ObjectPath& object_path) override;
124
125 // Called by dbus:: on completion of the D-Bus method call to get the
126 // connection attributes of the current connection to the device.
127 void OnGetConnInfo(const ConnectionInfoCallback& callback,
128 int16 rssi,
129 int16 transmit_power,
130 int16 max_transmit_power);
131 void OnGetConnInfoError(const ConnectionInfoCallback& callback,
132 const std::string& error_name,
133 const std::string& error_message);
134
135 // Internal method to initiate a connection to this device, and methods called
136 // by dbus:: on completion of the D-Bus method call.
137 void ConnectInternal(bool after_pairing,
138 const base::Closure& callback,
139 const ConnectErrorCallback& error_callback);
140 void OnConnect(bool after_pairing,
141 const base::Closure& callback);
142 void OnCreateGattConnection(const GattConnectionCallback& callback);
143 void OnConnectError(bool after_pairing,
144 const ConnectErrorCallback& error_callback,
145 const std::string& error_name,
146 const std::string& error_message);
147
148 // Called by dbus:: on completion of the D-Bus method call to pair the device,
149 // made inside |Connect()|.
150 void OnPairDuringConnect(const base::Closure& callback,
151 const ConnectErrorCallback& error_callback);
152 void OnPairDuringConnectError(const ConnectErrorCallback& error_callback,
153 const std::string& error_name,
154 const std::string& error_message);
155
156 // Called by dbus: on completion of the D-Bus method call to pair the device,
157 // made inside |Pair()|.
158 void OnPair(const base::Closure& callback);
159 void OnPairError(const ConnectErrorCallback& error_callback,
160 const std::string& error_name,
161 const std::string& error_message);
162
163 // Called by dbus:: on failure of the D-Bus method call to cancel pairing,
164 // there is no matching completion call since we don't do anything special
165 // in that case.
166 void OnCancelPairingError(const std::string& error_name,
167 const std::string& error_message);
168
169 // Internal method to set the device as trusted. Trusted devices can connect
170 // to us automatically, and we can connect to them after rebooting; it also
171 // causes the device to be remembered by the stack even if not paired.
172 // |success| to the callback indicates whether or not the request succeeded.
173 void SetTrusted();
174 void OnSetTrusted(bool success);
175
176 // Called by dbus:: on completion of the D-Bus method call to disconnect the
177 // device.
178 void OnDisconnect(const base::Closure& callback);
179 void OnDisconnectError(const ErrorCallback& error_callback,
180 const std::string& error_name,
181 const std::string& error_message);
182
183 // Called by dbus:: on failure of the D-Bus method call to unpair the device;
184 // there is no matching completion call since this object is deleted in the
185 // process of unpairing.
186 void OnForgetError(const ErrorCallback& error_callback,
187 const std::string& error_name,
188 const std::string& error_message);
189
190 // The dbus object path of the device object.
191 dbus::ObjectPath object_path_;
192
193 // Number of ongoing calls to Connect().
194 int num_connecting_calls_;
195
196 // True if the connection monitor has been started, tracking the connection
197 // RSSI and TX power.
198 bool connection_monitor_started_;
199
200 // UI thread task runner and socket thread object used to create sockets.
201 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
202 scoped_refptr<device::BluetoothSocketThread> socket_thread_;
203
204 // During pairing this is set to an object that we don't own, but on which
205 // we can make method calls to request, display or confirm PIN Codes and
206 // Passkeys. Generally it is the object that owns this one.
207 scoped_ptr<BluetoothPairingChromeOS> pairing_;
208
209 // Note: This should remain the last member so it'll be destroyed and
210 // invalidate its weak pointers before any other members are destroyed.
211 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_;
212
213 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS);
214 };
215
216 } // namespace chromeos
217
218 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698