Chromium Code Reviews| 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 <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 | |
| 44 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 51 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
| 45 | 52 |
| 46 // BluetoothAdapter: | 53 // BluetoothAdapter: |
| 47 void DeleteOnCorrectThread() const override; | 54 void DeleteOnCorrectThread() const override; |
| 48 virtual void AddObserver( | 55 virtual void AddObserver( |
| 49 device::BluetoothAdapter::Observer* observer) override; | 56 device::BluetoothAdapter::Observer* observer) override; |
| 50 virtual void RemoveObserver( | 57 virtual void RemoveObserver( |
| 51 device::BluetoothAdapter::Observer* observer) override; | 58 device::BluetoothAdapter::Observer* observer) override; |
| 52 virtual std::string GetAddress() const override; | 59 virtual std::string GetAddress() const override; |
| 53 virtual std::string GetName() const override; | 60 virtual std::string GetName() const override; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 void NotifyGattCharacteristicValueChanged( | 111 void NotifyGattCharacteristicValueChanged( |
| 105 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 112 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
| 106 const std::vector<uint8>& value); | 113 const std::vector<uint8>& value); |
| 107 void NotifyGattDescriptorValueChanged( | 114 void NotifyGattDescriptorValueChanged( |
| 108 BluetoothRemoteGattDescriptorChromeOS* descriptor, | 115 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
| 109 const std::vector<uint8>& value); | 116 const std::vector<uint8>& value); |
| 110 | 117 |
| 111 // Returns the object path of the adapter. | 118 // Returns the object path of the adapter. |
| 112 const dbus::ObjectPath& object_path() const { return object_path_; } | 119 const dbus::ObjectPath& object_path() const { return object_path_; } |
| 113 | 120 |
| 121 // Uses (creating if necessary) a profile on the adapter for a custom service. | |
| 122 // Returns the associated profile object. When the profile is successfully | |
|
armansito
2015/01/21 01:44:47
I would add a note here that the returned object i
Marie Janssen
2015/01/22 21:55:32
Done.
| |
| 123 // created, |success_callback| will be called. On failure, |error_callback| | |
| 124 // will be | |
| 125 // called. | |
|
armansito
2015/01/21 01:44:47
nit: "// will be called." instead of having "// ca
Marie Janssen
2015/01/22 21:55:32
Done.
| |
| 126 BluetoothAdapterProfileChromeOS* UseProfile( | |
|
armansito
2015/01/21 01:44:47
Well we are returning the profile here but technic
Marie Janssen
2015/01/22 21:55:32
Done.
| |
| 127 const device::BluetoothUUID& uuid, | |
| 128 const dbus::ObjectPath& device_path, | |
|
armansito
2015/01/21 01:44:47
Will local (listening) services also use this func
Marie Janssen
2015/01/22 21:55:32
Yes. Empty string for |device_path| is a listening
| |
| 129 const BluetoothProfileManagerClient::Options* options, | |
|
armansito
2015/01/21 01:44:47
Should |options| be passed by const reference inst
Marie Janssen
2015/01/22 21:55:32
Using a pointer is because of consistency with pre
| |
| 130 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 131 const base::Closure& success_callback, | |
| 132 const ErrorCompletionCallback& error_callback); | |
| 133 | |
| 134 // Releases the profile associated with |uuid| | |
| 135 void ReleaseProfile(const device::BluetoothUUID& uuid); | |
| 136 | |
| 114 protected: | 137 protected: |
| 115 // BluetoothAdapter: | 138 // BluetoothAdapter: |
| 116 virtual void RemovePairingDelegateInternal( | 139 virtual void RemovePairingDelegateInternal( |
| 117 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 140 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 118 | 141 |
| 119 private: | 142 private: |
| 120 friend class base::DeleteHelper<BluetoothAdapterChromeOS>; | 143 friend class base::DeleteHelper<BluetoothAdapterChromeOS>; |
| 121 friend class BluetoothChromeOSTest; | 144 friend class BluetoothChromeOSTest; |
| 122 | 145 |
| 123 // typedef for callback parameters that are passed to AddDiscoverySession | 146 // typedef for callback parameters that are passed to AddDiscoverySession |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 const ErrorCallback& error_callback, | 251 const ErrorCallback& error_callback, |
| 229 const std::string& error_name, | 252 const std::string& error_name, |
| 230 const std::string& error_message); | 253 const std::string& error_message); |
| 231 | 254 |
| 232 // Called by dbus:: on completion of the D-Bus method call to stop discovery. | 255 // Called by dbus:: on completion of the D-Bus method call to stop discovery. |
| 233 void OnStopDiscovery(const base::Closure& callback); | 256 void OnStopDiscovery(const base::Closure& callback); |
| 234 void OnStopDiscoveryError(const ErrorCallback& error_callback, | 257 void OnStopDiscoveryError(const ErrorCallback& error_callback, |
| 235 const std::string& error_name, | 258 const std::string& error_name, |
| 236 const std::string& error_message); | 259 const std::string& error_message); |
| 237 | 260 |
| 261 // Called by dbus:: on completion of the D-Bus method to register a profile. | |
| 262 void OnRegisterProfile(const device::BluetoothUUID& uuid, | |
| 263 const dbus::ObjectPath& device_path, | |
| 264 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 265 const base::Closure& success_callback, | |
| 266 const ErrorCompletionCallback& error_callback); | |
| 267 bool SetProfileDelegate(const device::BluetoothUUID& uuid, | |
| 268 const dbus::ObjectPath& device_path, | |
| 269 BluetoothProfileServiceProvider::Delegate* delegate, | |
| 270 const base::Closure& success_callback, | |
| 271 const ErrorCompletionCallback& error_callback); | |
| 272 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, | |
| 273 const std::string& error_name, | |
| 274 const std::string& error_message); | |
| 275 | |
| 238 // Processes the queued discovery requests. For each DiscoveryCallbackPair in | 276 // Processes the queued discovery requests. For each DiscoveryCallbackPair in |
| 239 // the queue, this method will try to add a new discovery session. This method | 277 // 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 | 278 // is called whenever a pending D-Bus call to start or stop discovery has |
| 241 // ended (with either success or failure). | 279 // ended (with either success or failure). |
| 242 void ProcessQueuedDiscoveryRequests(); | 280 void ProcessQueuedDiscoveryRequests(); |
| 243 | 281 |
| 244 // Number of discovery sessions that have been added. | 282 // Number of discovery sessions that have been added. |
| 245 int num_discovery_sessions_; | 283 int num_discovery_sessions_; |
| 246 | 284 |
| 247 // True, if there is a pending request to start or stop discovery. | 285 // True, if there is a pending request to start or stop discovery. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 265 ObserverList<device::BluetoothAdapter::Observer> observers_; | 303 ObserverList<device::BluetoothAdapter::Observer> observers_; |
| 266 | 304 |
| 267 // Instance of the D-Bus agent object used for pairing, initialized with | 305 // Instance of the D-Bus agent object used for pairing, initialized with |
| 268 // our own class as its delegate. | 306 // our own class as its delegate. |
| 269 scoped_ptr<BluetoothAgentServiceProvider> agent_; | 307 scoped_ptr<BluetoothAgentServiceProvider> agent_; |
| 270 | 308 |
| 271 // UI thread task runner and socket thread object used to create sockets. | 309 // UI thread task runner and socket thread object used to create sockets. |
| 272 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 310 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 273 scoped_refptr<device::BluetoothSocketThread> socket_thread_; | 311 scoped_refptr<device::BluetoothSocketThread> socket_thread_; |
| 274 | 312 |
| 313 // The profiles we have registered with the bluetooth daemon. | |
| 314 std::map<device::BluetoothUUID, BluetoothAdapterProfileChromeOS*> profiles_; | |
| 315 | |
| 275 // Note: This should remain the last member so it'll be destroyed and | 316 // Note: This should remain the last member so it'll be destroyed and |
| 276 // invalidate its weak pointers before any other members are destroyed. | 317 // invalidate its weak pointers before any other members are destroyed. |
| 277 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; | 318 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; |
| 278 | 319 |
| 279 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); | 320 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); |
| 280 }; | 321 }; |
| 281 | 322 |
| 282 } // namespace chromeos | 323 } // namespace chromeos |
| 283 | 324 |
| 284 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 325 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
| OLD | NEW |