OLD | NEW |
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 <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "chromeos/dbus/bluetooth_adapter_client.h" | |
16 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | |
17 #include "chromeos/dbus/bluetooth_device_client.h" | |
18 #include "chromeos/dbus/bluetooth_input_client.h" | |
19 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | |
20 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | |
21 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
22 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
23 #include "device/bluetooth/bluetooth_audio_sink.h" | 17 #include "device/bluetooth/bluetooth_audio_sink.h" |
24 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
25 #include "device/bluetooth/bluetooth_discovery_session.h" | 19 #include "device/bluetooth/bluetooth_discovery_session.h" |
26 #include "device/bluetooth/bluetooth_export.h" | 20 #include "device/bluetooth/bluetooth_export.h" |
| 21 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 22 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
| 23 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 24 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 25 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" |
| 26 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class SequencedTaskRunner; | 29 class SequencedTaskRunner; |
30 } // namespace base | 30 } // namespace base |
31 | 31 |
32 namespace device { | 32 namespace device { |
33 class BluetoothSocketThread; | 33 class BluetoothSocketThread; |
34 } // namespace device | 34 } // namespace device |
35 | 35 |
36 namespace chromeos { | 36 namespace chromeos { |
(...skipping 16 matching lines...) Expand all Loading... |
53 // single-threaded calls, and posts tasks to the UI thread. | 53 // single-threaded calls, and posts tasks to the UI thread. |
54 // | 54 // |
55 // Methods tolerate a shutdown scenario where BluetoothAdapterChromeOS::Shutdown | 55 // Methods tolerate a shutdown scenario where BluetoothAdapterChromeOS::Shutdown |
56 // causes IsPresent to return false just before the dbus system is shutdown but | 56 // causes IsPresent to return false just before the dbus system is shutdown but |
57 // while references to the BluetoothAdapterChromeOS object still exists. | 57 // while references to the BluetoothAdapterChromeOS object still exists. |
58 // | 58 // |
59 // When adding methods to this class verify shutdown behavior in | 59 // When adding methods to this class verify shutdown behavior in |
60 // BluetoothChromeOSTest, Shutdown. | 60 // BluetoothChromeOSTest, Shutdown. |
61 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS | 61 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS |
62 : public device::BluetoothAdapter, | 62 : public device::BluetoothAdapter, |
63 public chromeos::BluetoothAdapterClient::Observer, | 63 public bluez::BluetoothAdapterClient::Observer, |
64 public chromeos::BluetoothDeviceClient::Observer, | 64 public bluez::BluetoothDeviceClient::Observer, |
65 public chromeos::BluetoothInputClient::Observer, | 65 public bluez::BluetoothInputClient::Observer, |
66 public chromeos::BluetoothAgentServiceProvider::Delegate { | 66 public bluez::BluetoothAgentServiceProvider::Delegate { |
67 public: | 67 public: |
68 typedef base::Callback<void(const std::string& error_message)> | 68 typedef base::Callback<void(const std::string& error_message)> |
69 ErrorCompletionCallback; | 69 ErrorCompletionCallback; |
70 typedef base::Callback<void(BluetoothAdapterProfileChromeOS* profile)> | 70 typedef base::Callback<void(BluetoothAdapterProfileChromeOS* profile)> |
71 ProfileRegisteredCallback; | 71 ProfileRegisteredCallback; |
72 | 72 |
73 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 73 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
74 | 74 |
75 // BluetoothAdapter: | 75 // BluetoothAdapter: |
76 void Shutdown() override; | 76 void Shutdown() override; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // Request a profile on the adapter for a custom service with a | 146 // Request a profile on the adapter for a custom service with a |
147 // specific UUID for the device at |device_path| to be sent to |delegate|. | 147 // specific UUID for the device at |device_path| to be sent to |delegate|. |
148 // If |device_path| is the empty string, incoming connections will be | 148 // If |device_path| is the empty string, incoming connections will be |
149 // assigned to |delegate|. When the profile is | 149 // assigned to |delegate|. When the profile is |
150 // successfully registered, |success_callback| will be called with a pointer | 150 // successfully registered, |success_callback| will be called with a pointer |
151 // to the profile which is managed by BluetoothAdapterChromeOS. On failure, | 151 // to the profile which is managed by BluetoothAdapterChromeOS. On failure, |
152 // |error_callback| will be called. | 152 // |error_callback| will be called. |
153 void UseProfile(const device::BluetoothUUID& uuid, | 153 void UseProfile(const device::BluetoothUUID& uuid, |
154 const dbus::ObjectPath& device_path, | 154 const dbus::ObjectPath& device_path, |
155 const BluetoothProfileManagerClient::Options& options, | 155 const bluez::BluetoothProfileManagerClient::Options& options, |
156 BluetoothProfileServiceProvider::Delegate* delegate, | 156 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
157 const ProfileRegisteredCallback& success_callback, | 157 const ProfileRegisteredCallback& success_callback, |
158 const ErrorCompletionCallback& error_callback); | 158 const ErrorCompletionCallback& error_callback); |
159 | 159 |
160 // Release use of a profile by a device. | 160 // Release use of a profile by a device. |
161 void ReleaseProfile(const dbus::ObjectPath& device_path, | 161 void ReleaseProfile(const dbus::ObjectPath& device_path, |
162 BluetoothAdapterProfileChromeOS* profile); | 162 BluetoothAdapterProfileChromeOS* profile); |
163 | 163 |
164 protected: | 164 protected: |
165 // BluetoothAdapter: | 165 // BluetoothAdapter: |
166 void RemovePairingDelegateInternal( | 166 void RemovePairingDelegateInternal( |
(...skipping 15 matching lines...) Expand all Loading... |
182 DiscoverySessionErrorCallback> DiscoveryParamTuple; | 182 DiscoverySessionErrorCallback> DiscoveryParamTuple; |
183 typedef std::queue<DiscoveryParamTuple> DiscoveryCallbackQueue; | 183 typedef std::queue<DiscoveryParamTuple> DiscoveryCallbackQueue; |
184 | 184 |
185 // Callback pair for the profile registration queue. | 185 // Callback pair for the profile registration queue. |
186 typedef std::pair<base::Closure, ErrorCompletionCallback> | 186 typedef std::pair<base::Closure, ErrorCompletionCallback> |
187 RegisterProfileCompletionPair; | 187 RegisterProfileCompletionPair; |
188 | 188 |
189 BluetoothAdapterChromeOS(); | 189 BluetoothAdapterChromeOS(); |
190 ~BluetoothAdapterChromeOS() override; | 190 ~BluetoothAdapterChromeOS() override; |
191 | 191 |
192 // BluetoothAdapterClient::Observer override. | 192 // bluez::BluetoothAdapterClient::Observer override. |
193 void AdapterAdded(const dbus::ObjectPath& object_path) override; | 193 void AdapterAdded(const dbus::ObjectPath& object_path) override; |
194 void AdapterRemoved(const dbus::ObjectPath& object_path) override; | 194 void AdapterRemoved(const dbus::ObjectPath& object_path) override; |
195 void AdapterPropertyChanged(const dbus::ObjectPath& object_path, | 195 void AdapterPropertyChanged(const dbus::ObjectPath& object_path, |
196 const std::string& property_name) override; | 196 const std::string& property_name) override; |
197 | 197 |
198 // BluetoothDeviceClient::Observer override. | 198 // bluez::BluetoothDeviceClient::Observer override. |
199 void DeviceAdded(const dbus::ObjectPath& object_path) override; | 199 void DeviceAdded(const dbus::ObjectPath& object_path) override; |
200 void DeviceRemoved(const dbus::ObjectPath& object_path) override; | 200 void DeviceRemoved(const dbus::ObjectPath& object_path) override; |
201 void DevicePropertyChanged(const dbus::ObjectPath& object_path, | 201 void DevicePropertyChanged(const dbus::ObjectPath& object_path, |
202 const std::string& property_name) override; | 202 const std::string& property_name) override; |
203 | 203 |
204 // BluetoothInputClient::Observer override. | 204 // bluez::BluetoothInputClient::Observer override. |
205 void InputPropertyChanged(const dbus::ObjectPath& object_path, | 205 void InputPropertyChanged(const dbus::ObjectPath& object_path, |
206 const std::string& property_name) override; | 206 const std::string& property_name) override; |
207 | 207 |
208 // BluetoothAgentServiceProvider::Delegate override. | 208 // bluez::BluetoothAgentServiceProvider::Delegate override. |
209 void Released() override; | 209 void Released() override; |
210 void RequestPinCode(const dbus::ObjectPath& device_path, | 210 void RequestPinCode(const dbus::ObjectPath& device_path, |
211 const PinCodeCallback& callback) override; | 211 const PinCodeCallback& callback) override; |
212 void DisplayPinCode(const dbus::ObjectPath& device_path, | 212 void DisplayPinCode(const dbus::ObjectPath& device_path, |
213 const std::string& pincode) override; | 213 const std::string& pincode) override; |
214 void RequestPasskey(const dbus::ObjectPath& device_path, | 214 void RequestPasskey(const dbus::ObjectPath& device_path, |
215 const PasskeyCallback& callback) override; | 215 const PasskeyCallback& callback) override; |
216 void DisplayPasskey(const dbus::ObjectPath& device_path, | 216 void DisplayPasskey(const dbus::ObjectPath& device_path, |
217 uint32 passkey, | 217 uint32 passkey, |
218 uint16 entered) override; | 218 uint16 entered) override; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 void OnSetDiscoveryFilterError( | 321 void OnSetDiscoveryFilterError( |
322 const base::Closure& callback, | 322 const base::Closure& callback, |
323 const DiscoverySessionErrorCallback& error_callback, | 323 const DiscoverySessionErrorCallback& error_callback, |
324 const std::string& error_name, | 324 const std::string& error_name, |
325 const std::string& error_message); | 325 const std::string& error_message); |
326 | 326 |
327 // Called by dbus:: on completion of the D-Bus method to register a profile. | 327 // Called by dbus:: on completion of the D-Bus method to register a profile. |
328 void OnRegisterProfile(const device::BluetoothUUID& uuid, | 328 void OnRegisterProfile(const device::BluetoothUUID& uuid, |
329 scoped_ptr<BluetoothAdapterProfileChromeOS> profile); | 329 scoped_ptr<BluetoothAdapterProfileChromeOS> profile); |
330 | 330 |
331 void SetProfileDelegate(const device::BluetoothUUID& uuid, | 331 void SetProfileDelegate( |
332 const dbus::ObjectPath& device_path, | 332 const device::BluetoothUUID& uuid, |
333 BluetoothProfileServiceProvider::Delegate* delegate, | 333 const dbus::ObjectPath& device_path, |
334 const ProfileRegisteredCallback& success_callback, | 334 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
335 const ErrorCompletionCallback& error_callback); | 335 const ProfileRegisteredCallback& success_callback, |
| 336 const ErrorCompletionCallback& error_callback); |
336 void OnRegisterProfileError(const device::BluetoothUUID& uuid, | 337 void OnRegisterProfileError(const device::BluetoothUUID& uuid, |
337 const std::string& error_name, | 338 const std::string& error_name, |
338 const std::string& error_message); | 339 const std::string& error_message); |
339 | 340 |
340 // Called by BluetoothAdapterProfileChromeOS when no users of a profile | 341 // Called by BluetoothAdapterProfileChromeOS when no users of a profile |
341 // remain. | 342 // remain. |
342 void RemoveProfile(const device::BluetoothUUID& uuid); | 343 void RemoveProfile(const device::BluetoothUUID& uuid); |
343 | 344 |
344 // Processes the queued discovery requests. For each DiscoveryParamTuple in | 345 // Processes the queued discovery requests. For each DiscoveryParamTuple in |
345 // the queue, this method will try to add a new discovery session. This method | 346 // the queue, this method will try to add a new discovery session. This method |
(...skipping 19 matching lines...) Expand all Loading... |
365 // requested discovery, dropping our count to 0 won't necessarily result in | 366 // requested discovery, dropping our count to 0 won't necessarily result in |
366 // the controller actually stopping discovery if, for example, an application | 367 // the controller actually stopping discovery if, for example, an application |
367 // other than Chrome, such as bt_console, was also used to start discovery. | 368 // other than Chrome, such as bt_console, was also used to start discovery. |
368 DiscoveryCallbackQueue discovery_request_queue_; | 369 DiscoveryCallbackQueue discovery_request_queue_; |
369 | 370 |
370 // Object path of the adapter we track. | 371 // Object path of the adapter we track. |
371 dbus::ObjectPath object_path_; | 372 dbus::ObjectPath object_path_; |
372 | 373 |
373 // Instance of the D-Bus agent object used for pairing, initialized with | 374 // Instance of the D-Bus agent object used for pairing, initialized with |
374 // our own class as its delegate. | 375 // our own class as its delegate. |
375 scoped_ptr<BluetoothAgentServiceProvider> agent_; | 376 scoped_ptr<bluez::BluetoothAgentServiceProvider> agent_; |
376 | 377 |
377 // UI thread task runner and socket thread object used to create sockets. | 378 // UI thread task runner and socket thread object used to create sockets. |
378 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 379 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
379 scoped_refptr<device::BluetoothSocketThread> socket_thread_; | 380 scoped_refptr<device::BluetoothSocketThread> socket_thread_; |
380 | 381 |
381 // The profiles we have registered with the bluetooth daemon. | 382 // The profiles we have registered with the bluetooth daemon. |
382 std::map<device::BluetoothUUID, BluetoothAdapterProfileChromeOS*> profiles_; | 383 std::map<device::BluetoothUUID, BluetoothAdapterProfileChromeOS*> profiles_; |
383 | 384 |
384 // Queue of delegates waiting for a profile to register. | 385 // Queue of delegates waiting for a profile to register. |
385 std::map<device::BluetoothUUID, std::vector<RegisterProfileCompletionPair>*> | 386 std::map<device::BluetoothUUID, std::vector<RegisterProfileCompletionPair>*> |
386 profile_queues_; | 387 profile_queues_; |
387 | 388 |
388 scoped_ptr<device::BluetoothDiscoveryFilter> current_filter_; | 389 scoped_ptr<device::BluetoothDiscoveryFilter> current_filter_; |
389 | 390 |
390 // Note: This should remain the last member so it'll be destroyed and | 391 // Note: This should remain the last member so it'll be destroyed and |
391 // invalidate its weak pointers before any other members are destroyed. | 392 // invalidate its weak pointers before any other members are destroyed. |
392 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; | 393 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; |
393 | 394 |
394 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); | 395 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); |
395 }; | 396 }; |
396 | 397 |
397 } // namespace chromeos | 398 } // namespace chromeos |
398 | 399 |
399 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 400 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
OLD | NEW |