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

Unified Diff: device/bluetooth/bluetooth_adapter_factory.cc

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback. Created 6 years, 9 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
Index: device/bluetooth/bluetooth_adapter_factory.cc
diff --git a/device/bluetooth/bluetooth_adapter_factory.cc b/device/bluetooth/bluetooth_adapter_factory.cc
index c15d26a514b3082a1fe5c89649e88d70dbfedeba..b9889c6742934e96a55f10db940832f1984d0355 100644
--- a/device/bluetooth/bluetooth_adapter_factory.cc
+++ b/device/bluetooth/bluetooth_adapter_factory.cc
@@ -26,6 +26,9 @@ namespace {
using device::BluetoothAdapter;
using device::BluetoothAdapterFactory;
+base::LazyInstance<BluetoothAdapterFactory> adapter_factory =
+ 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
@@ -61,6 +64,12 @@ void RunAdapterCallbacks() {
namespace device {
// static
+void BluetoothAdapterFactory::SetAdapterInitializer(
+ AdapterInitializer initializer) {
+ adapter_factory.Get().adapter_initializer_ = initializer;
keybuk 2014/03/20 01:21:56 This doesn't run the initializer if the adapter is
rpaquay 2014/03/20 18:21:11 The issue is that the "device" layer needs initial
keybuk 2014/03/20 18:38:40 Sure, but the extensions::BluetoothAPI may not be
rpaquay 2014/03/25 20:06:10 These are all good points. After thinking about th
+}
+
+// static
bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
#if defined(OS_CHROMEOS)
return true;
@@ -68,8 +77,9 @@ bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
return true;
#elif defined(OS_MACOSX)
return base::mac::IsOSLionOrLater();
-#endif
+#else
return false;
+#endif
}
// static
@@ -78,15 +88,18 @@ void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) {
#if defined(OS_CHROMEOS)
chromeos::BluetoothAdapterChromeOS* new_adapter =
new chromeos::BluetoothAdapterChromeOS();
+ adapter_factory.Get().adapter_initializer_.Run(new_adapter);
default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
#elif defined(OS_WIN)
BluetoothAdapterWin* new_adapter = new BluetoothAdapterWin(
base::Bind(&RunAdapterCallbacks));
new_adapter->Init();
+ adapter_factory.Get().adapter_initializer_.Run(new_adapter);
keybuk 2014/03/20 01:21:56 the adapter might not be initialized yet?
rpaquay 2014/03/20 18:21:11 The initialization callback is intended to be part
keybuk 2014/03/20 18:38:40 Ack
default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
#elif defined(OS_MACOSX)
BluetoothAdapterMac* new_adapter = new BluetoothAdapterMac();
new_adapter->Init();
+ adapter_factory.Get().adapter_initializer_.Run(new_adapter);
keybuk 2014/03/20 01:21:56 adapter might not be initialized yet
rpaquay 2014/03/20 18:21:11 See Above.
default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
#endif
}

Powered by Google App Engine
This is Rietveld 408576698