| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FACTORY_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" |
| 12 #include "device/bluetooth/bluetooth_export.h" | 12 #include "device/bluetooth/bluetooth_export.h" |
| 13 | 13 |
| 14 namespace device { | 14 namespace device { |
| 15 | 15 |
| 16 // A factory class for building a Bluetooth adapter on platforms where Bluetooth | 16 // A factory class for building a Bluetooth adapter on platforms where Bluetooth |
| 17 // is available. | 17 // is available. |
| 18 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterFactory { | 18 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterFactory { |
| 19 public: | 19 public: |
| 20 typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)> | 20 typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)> |
| 21 AdapterCallback; | 21 AdapterCallback; |
| 22 | 22 |
| 23 // Returns true if the Bluetooth adapter is available for the current | 23 // Returns true if the platform supports Bluetooth. It does not imply that |
| 24 // platform. | 24 // there is a Bluetooth radio. Use BluetoothAdapter::IsPresent to know |
| 25 static bool IsBluetoothAdapterAvailable(); | 25 // if there is a Bluetooth radio present. |
| 26 static bool IsBluetoothSupported(); |
| 26 | 27 |
| 27 // Returns true if Bluetooth Low Energy is available for the current | 28 // Returns true if the platform supports Bluetooth Low Energy. This is |
| 28 // platform. | 29 // independent of whether or not there is a Bluetooth radio present e.g. |
| 29 static bool IsLowEnergyAvailable(); | 30 // Windows 7 does not support BLE so IsLowEnergySupported would return |
| 31 // false. Windows 10, on the other hand, supports BLE so this function |
| 32 // returns true even if there is no Bluetooth radio on the system. |
| 33 static bool IsLowEnergySupported(); |
| 30 | 34 |
| 31 // Returns the shared instance of the default adapter, creating and | 35 // Returns the shared instance of the default adapter, creating and |
| 32 // initializing it if necessary. |callback| is called with the adapter | 36 // initializing it if necessary. |callback| is called with the adapter |
| 33 // instance passed only once the adapter is fully initialized and ready to | 37 // instance passed only once the adapter is fully initialized and ready to |
| 34 // use. | 38 // use. |
| 35 static void GetAdapter(const AdapterCallback& callback); | 39 static void GetAdapter(const AdapterCallback& callback); |
| 36 | 40 |
| 37 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 41 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 38 // Calls |BluetoothAdapter::Shutdown| on the adapter if | 42 // Calls |BluetoothAdapter::Shutdown| on the adapter if |
| 39 // present. | 43 // present. |
| 40 static void Shutdown(); | 44 static void Shutdown(); |
| 41 #endif | 45 #endif |
| 42 | 46 |
| 43 // Sets the shared instance of the default adapter for testing purposes only, | 47 // Sets the shared instance of the default adapter for testing purposes only, |
| 44 // no reference is retained after completion of the call, removing the last | 48 // no reference is retained after completion of the call, removing the last |
| 45 // reference will reset the factory. | 49 // reference will reset the factory. |
| 46 static void SetAdapterForTesting(scoped_refptr<BluetoothAdapter> adapter); | 50 static void SetAdapterForTesting(scoped_refptr<BluetoothAdapter> adapter); |
| 47 | 51 |
| 48 // Returns true iff the implementation has a (non-NULL) shared instance of the | 52 // Returns true iff the implementation has a (non-NULL) shared instance of the |
| 49 // adapter. Exposed for testing. | 53 // adapter. Exposed for testing. |
| 50 static bool HasSharedInstanceForTesting(); | 54 static bool HasSharedInstanceForTesting(); |
| 51 }; | 55 }; |
| 52 | 56 |
| 53 } // namespace device | 57 } // namespace device |
| 54 | 58 |
| 55 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ | 59 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
| OLD | NEW |