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

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

Issue 851123002: Manage profiles in BluetoothAdapter on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments, slight refactor Created 5 years, 11 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
7 7
8 #include <map>
8 #include <queue> 9 #include <queue>
9 #include <string> 10 #include <string>
10 11
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
13 #include "chromeos/dbus/bluetooth_adapter_client.h" 14 #include "chromeos/dbus/bluetooth_adapter_client.h"
14 #include "chromeos/dbus/bluetooth_agent_service_provider.h" 15 #include "chromeos/dbus/bluetooth_agent_service_provider.h"
15 #include "chromeos/dbus/bluetooth_device_client.h" 16 #include "chromeos/dbus/bluetooth_device_client.h"
16 #include "chromeos/dbus/bluetooth_input_client.h" 17 #include "chromeos/dbus/bluetooth_input_client.h"
18 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
19 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
17 #include "dbus/object_path.h" 20 #include "dbus/object_path.h"
18 #include "device/bluetooth/bluetooth_adapter.h" 21 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_device.h" 22 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_export.h" 23 #include "device/bluetooth/bluetooth_export.h"
21 24
22 namespace device { 25 namespace device {
23 class BluetoothSocketThread; 26 class BluetoothSocketThread;
24 } // namespace device 27 } // namespace device
25 28
26 namespace chromeos { 29 namespace chromeos {
27 30
28 class BluetoothChromeOSTest; 31 class BluetoothChromeOSTest;
32 class BluetoothAdapterProfileChromeOS;
29 class BluetoothDeviceChromeOS; 33 class BluetoothDeviceChromeOS;
30 class BluetoothPairingChromeOS; 34 class BluetoothPairingChromeOS;
31 class BluetoothRemoteGattCharacteristicChromeOS; 35 class BluetoothRemoteGattCharacteristicChromeOS;
32 class BluetoothRemoteGattDescriptorChromeOS; 36 class BluetoothRemoteGattDescriptorChromeOS;
33 class BluetoothRemoteGattServiceChromeOS; 37 class BluetoothRemoteGattServiceChromeOS;
34 38
35 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the 39 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the
36 // Chrome OS platform. 40 // Chrome OS platform.
37 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS 41 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS
38 : public device::BluetoothAdapter, 42 : public device::BluetoothAdapter,
39 public chromeos::BluetoothAdapterClient::Observer, 43 public chromeos::BluetoothAdapterClient::Observer,
40 public chromeos::BluetoothDeviceClient::Observer, 44 public chromeos::BluetoothDeviceClient::Observer,
41 public chromeos::BluetoothInputClient::Observer, 45 public chromeos::BluetoothInputClient::Observer,
42 public chromeos::BluetoothAgentServiceProvider::Delegate { 46 public chromeos::BluetoothAgentServiceProvider::Delegate {
43 public: 47 public:
48 typedef base::Callback<void(const std::string& error_message)>
49 ErrorCompletionCallback;
50 typedef base::Callback<void(BluetoothAdapterProfileChromeOS* profile)>
51 ProfileRegisteredCallback;
52
44 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); 53 static base::WeakPtr<BluetoothAdapter> CreateAdapter();
45 54
46 // BluetoothAdapter: 55 // BluetoothAdapter:
47 void DeleteOnCorrectThread() const override; 56 void DeleteOnCorrectThread() const override;
48 virtual void AddObserver( 57 virtual void AddObserver(
49 device::BluetoothAdapter::Observer* observer) override; 58 device::BluetoothAdapter::Observer* observer) override;
50 virtual void RemoveObserver( 59 virtual void RemoveObserver(
51 device::BluetoothAdapter::Observer* observer) override; 60 device::BluetoothAdapter::Observer* observer) override;
52 virtual std::string GetAddress() const override; 61 virtual std::string GetAddress() const override;
53 virtual std::string GetName() const override; 62 virtual std::string GetName() const override;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void NotifyGattCharacteristicValueChanged( 113 void NotifyGattCharacteristicValueChanged(
105 BluetoothRemoteGattCharacteristicChromeOS* characteristic, 114 BluetoothRemoteGattCharacteristicChromeOS* characteristic,
106 const std::vector<uint8>& value); 115 const std::vector<uint8>& value);
107 void NotifyGattDescriptorValueChanged( 116 void NotifyGattDescriptorValueChanged(
108 BluetoothRemoteGattDescriptorChromeOS* descriptor, 117 BluetoothRemoteGattDescriptorChromeOS* descriptor,
109 const std::vector<uint8>& value); 118 const std::vector<uint8>& value);
110 119
111 // Returns the object path of the adapter. 120 // Returns the object path of the adapter.
112 const dbus::ObjectPath& object_path() const { return object_path_; } 121 const dbus::ObjectPath& object_path() const { return object_path_; }
113 122
123 // Request a profile on the adapter for a custom service with a
124 // specific UUID for the device at |device_path| to be sent to |delegate|.
125 // If |device_path| is the empty string, incoming connections will be
126 // assigned to |delegate|. When the profile is
127 // successfully registered, |success_callback| will be called with a pointer
128 // to the profile which is managed by BluetoothAdapterChromeOS. On failure,
129 // |error_callback| will be called.
130 void UseProfile(const device::BluetoothUUID& uuid,
131 const dbus::ObjectPath& device_path,
132 const BluetoothProfileManagerClient::Options& options,
133 BluetoothProfileServiceProvider::Delegate* delegate,
134 const ProfileRegisteredCallback& success_callback,
135 const ErrorCompletionCallback& error_callback);
136
137 // Releases the profile associated with |uuid|
138 void ReleaseProfile(const device::BluetoothUUID& uuid);
139
114 protected: 140 protected:
115 // BluetoothAdapter: 141 // BluetoothAdapter:
116 virtual void RemovePairingDelegateInternal( 142 virtual void RemovePairingDelegateInternal(
117 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; 143 device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
118 144
119 private: 145 private:
120 friend class base::DeleteHelper<BluetoothAdapterChromeOS>; 146 friend class base::DeleteHelper<BluetoothAdapterChromeOS>;
121 friend class BluetoothChromeOSTest; 147 friend class BluetoothChromeOSTest;
122 148
123 // typedef for callback parameters that are passed to AddDiscoverySession 149 // typedef for callback parameters that are passed to AddDiscoverySession
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 const ErrorCallback& error_callback, 254 const ErrorCallback& error_callback,
229 const std::string& error_name, 255 const std::string& error_name,
230 const std::string& error_message); 256 const std::string& error_message);
231 257
232 // Called by dbus:: on completion of the D-Bus method call to stop discovery. 258 // Called by dbus:: on completion of the D-Bus method call to stop discovery.
233 void OnStopDiscovery(const base::Closure& callback); 259 void OnStopDiscovery(const base::Closure& callback);
234 void OnStopDiscoveryError(const ErrorCallback& error_callback, 260 void OnStopDiscoveryError(const ErrorCallback& error_callback,
235 const std::string& error_name, 261 const std::string& error_name,
236 const std::string& error_message); 262 const std::string& error_message);
237 263
264 // Called by dbus:: on completion of the D-Bus method to register a profile.
265 void OnRegisterProfile(const device::BluetoothUUID& uuid,
266 const dbus::ObjectPath& device_path,
267 BluetoothProfileServiceProvider::Delegate* delegate,
268 const ProfileRegisteredCallback& success_callback,
269 const ErrorCompletionCallback& error_callback);
270 bool SetProfileDelegate(const device::BluetoothUUID& uuid,
271 const dbus::ObjectPath& device_path,
272 BluetoothProfileServiceProvider::Delegate* delegate,
273 const ProfileRegisteredCallback& success_callback,
274 const ErrorCompletionCallback& error_callback);
275 void OnRegisterProfileError(const device::BluetoothUUID& uuid,
276 const ErrorCompletionCallback& error_callback,
277 const std::string& error_name,
278 const std::string& error_message);
279
238 // Processes the queued discovery requests. For each DiscoveryCallbackPair in 280 // Processes the queued discovery requests. For each DiscoveryCallbackPair in
239 // the queue, this method will try to add a new discovery session. This method 281 // the queue, this method will try to add a new discovery session. This method
240 // is called whenever a pending D-Bus call to start or stop discovery has 282 // is called whenever a pending D-Bus call to start or stop discovery has
241 // ended (with either success or failure). 283 // ended (with either success or failure).
242 void ProcessQueuedDiscoveryRequests(); 284 void ProcessQueuedDiscoveryRequests();
243 285
244 // Number of discovery sessions that have been added. 286 // Number of discovery sessions that have been added.
245 int num_discovery_sessions_; 287 int num_discovery_sessions_;
246 288
247 // True, if there is a pending request to start or stop discovery. 289 // True, if there is a pending request to start or stop discovery.
(...skipping 17 matching lines...) Expand all
265 ObserverList<device::BluetoothAdapter::Observer> observers_; 307 ObserverList<device::BluetoothAdapter::Observer> observers_;
266 308
267 // Instance of the D-Bus agent object used for pairing, initialized with 309 // Instance of the D-Bus agent object used for pairing, initialized with
268 // our own class as its delegate. 310 // our own class as its delegate.
269 scoped_ptr<BluetoothAgentServiceProvider> agent_; 311 scoped_ptr<BluetoothAgentServiceProvider> agent_;
270 312
271 // UI thread task runner and socket thread object used to create sockets. 313 // UI thread task runner and socket thread object used to create sockets.
272 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; 314 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
273 scoped_refptr<device::BluetoothSocketThread> socket_thread_; 315 scoped_refptr<device::BluetoothSocketThread> socket_thread_;
274 316
317 // The profiles we have registered with the bluetooth daemon.
318 std::map<device::BluetoothUUID, BluetoothAdapterProfileChromeOS*> profiles_;
319
275 // Note: This should remain the last member so it'll be destroyed and 320 // Note: This should remain the last member so it'll be destroyed and
276 // invalidate its weak pointers before any other members are destroyed. 321 // invalidate its weak pointers before any other members are destroyed.
277 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; 322 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_;
278 323
279 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); 324 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
280 }; 325 };
281 326
282 } // namespace chromeos 327 } // namespace chromeos
283 328
284 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ 329 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698