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

Unified Diff: device/bluetooth/bluetooth_adapter_factory.cc

Issue 2815793003: bluetooth: Introduce SetLowEnergyAvailableForTesting (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_adapter_factory.h ('k') | device/bluetooth/bluetooth_adapter_factory_wrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter_factory.cc
diff --git a/device/bluetooth/bluetooth_adapter_factory.cc b/device/bluetooth/bluetooth_adapter_factory.cc
index ed64ecd2ee670bd91ed4328924455edf5de60f8b..3358c38bdbf4f3356507acba6ea2e24aa8580fb0 100644
--- a/device/bluetooth/bluetooth_adapter_factory.cc
+++ b/device/bluetooth/bluetooth_adapter_factory.cc
@@ -21,6 +21,9 @@ namespace device {
namespace {
+static base::LazyInstance<BluetoothAdapterFactory>::Leaky g_singleton =
+ LAZY_INSTANCE_INITIALIZER;
+
// Shared default adapter instance. We don't want to keep this class around
// if nobody is using it, so use a WeakPtr and create the object when needed.
// Since Google C++ Style (and clang's static analyzer) forbids us having
@@ -53,6 +56,13 @@ void RunAdapterCallbacks() {
} // namespace
+BluetoothAdapterFactory::~BluetoothAdapterFactory() {}
+
+// static
+BluetoothAdapterFactory& BluetoothAdapterFactory::Get() {
+ return g_singleton.Get();
+}
+
// static
bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
// SetAdapterForTesting() may be used to provide a test or mock adapter
@@ -67,8 +77,11 @@ bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
#endif
}
-// static
bool BluetoothAdapterFactory::IsLowEnergyAvailable() {
+ if (le_available_for_testing_) {
+ return le_available_for_testing_.value();
+ }
+
DCHECK(IsBluetoothAdapterAvailable());
// SetAdapterForTesting() may be used to provide a test or mock adapter
@@ -131,4 +144,10 @@ bool BluetoothAdapterFactory::HasSharedInstanceForTesting() {
return default_adapter.Get() != nullptr;
}
+void BluetoothAdapterFactory::SetLowEnergyAvailableForTesting(bool available) {
+ le_available_for_testing_ = base::make_optional(available);
+}
+
+BluetoothAdapterFactory::BluetoothAdapterFactory() {}
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_adapter_factory.h ('k') | device/bluetooth/bluetooth_adapter_factory_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698