| 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/lazy_instance.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "device/bluetooth/bluetooth_adapter.h" | 12 #include "device/bluetooth/bluetooth_adapter.h" |
| 12 #include "device/bluetooth/bluetooth_export.h" | 13 #include "device/bluetooth/bluetooth_export.h" |
| 13 | 14 |
| 14 namespace device { | 15 namespace device { |
| 15 | 16 |
| 16 // A factory class for building a Bluetooth adapter on platforms where Bluetooth | 17 // A factory class for building a Bluetooth adapter on platforms where Bluetooth |
| 17 // is available. | 18 // is available. |
| 18 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterFactory { | 19 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterFactory { |
| 19 public: | 20 public: |
| 20 typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)> | 21 typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)> |
| 21 AdapterCallback; | 22 AdapterCallback; |
| 22 | 23 |
| 24 ~BluetoothAdapterFactory(); |
| 25 |
| 26 static BluetoothAdapterFactory& Get(); |
| 27 |
| 23 // Returns true if the Bluetooth adapter is available for the current | 28 // Returns true if the Bluetooth adapter is available for the current |
| 24 // platform. | 29 // platform. |
| 25 static bool IsBluetoothAdapterAvailable(); | 30 static bool IsBluetoothAdapterAvailable(); |
| 26 | 31 |
| 27 // Returns true if Bluetooth Low Energy is available for the current | 32 // Returns true if Bluetooth Low Energy is available for the current |
| 28 // platform. | 33 // platform. |
| 29 static bool IsLowEnergyAvailable(); | 34 bool IsLowEnergyAvailable(); |
| 30 | 35 |
| 31 // Returns the shared instance of the default adapter, creating and | 36 // Returns the shared instance of the default adapter, creating and |
| 32 // initializing it if necessary. |callback| is called with the adapter | 37 // initializing it if necessary. |callback| is called with the adapter |
| 33 // instance passed only once the adapter is fully initialized and ready to | 38 // instance passed only once the adapter is fully initialized and ready to |
| 34 // use. | 39 // use. |
| 35 static void GetAdapter(const AdapterCallback& callback); | 40 static void GetAdapter(const AdapterCallback& callback); |
| 36 | 41 |
| 37 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 42 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 38 // Calls |BluetoothAdapter::Shutdown| on the adapter if | 43 // Calls |BluetoothAdapter::Shutdown| on the adapter if |
| 39 // present. | 44 // present. |
| 40 static void Shutdown(); | 45 static void Shutdown(); |
| 41 #endif | 46 #endif |
| 42 | 47 |
| 43 // Sets the shared instance of the default adapter for testing purposes only, | 48 // 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 | 49 // no reference is retained after completion of the call, removing the last |
| 45 // reference will reset the factory. | 50 // reference will reset the factory. |
| 46 static void SetAdapterForTesting(scoped_refptr<BluetoothAdapter> adapter); | 51 static void SetAdapterForTesting(scoped_refptr<BluetoothAdapter> adapter); |
| 47 | 52 |
| 48 // Returns true iff the implementation has a (non-NULL) shared instance of the | 53 // Returns true iff the implementation has a (non-NULL) shared instance of the |
| 49 // adapter. Exposed for testing. | 54 // adapter. Exposed for testing. |
| 50 static bool HasSharedInstanceForTesting(); | 55 static bool HasSharedInstanceForTesting(); |
| 56 |
| 57 // Sets the return value for IsLowEnergyAvailable() to |available|. |
| 58 void SetLowEnergyAvailableForTesting(bool available); |
| 59 |
| 60 private: |
| 61 // Friend LazyInstance to permit access to private constructor. |
| 62 friend base::LazyInstanceTraitsBase<BluetoothAdapterFactory>; |
| 63 |
| 64 BluetoothAdapterFactory(); |
| 65 |
| 66 base::Optional<bool> le_available_for_testing_; |
| 51 }; | 67 }; |
| 52 | 68 |
| 53 } // namespace device | 69 } // namespace device |
| 54 | 70 |
| 55 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ | 71 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_FACTORY_H_ |
| OLD | NEW |