Index: chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc |
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc |
index eb88330326103cb61d1658307d5711e18a38ce52..5c3d5a9d9f81b97c28eb8c4f73aafbf4280d6c38 100644 |
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc |
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc |
@@ -16,10 +16,12 @@ namespace { |
const char kPlatformNotSupported[] = |
"This operation is not supported on your platform"; |
-scoped_refptr<device::BluetoothAdapter> GetAdapter(Profile* profile) { |
+void RunCallbackOnAdapterReady( |
+ const device::BluetoothAdapterFactory::AdapterCallback callback, |
+ Profile* profile) { |
extensions::ExtensionBluetoothEventRouter* event_router = |
extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); |
- return event_router->GetAdapter(); |
+ event_router->RunCallbackOnAdapterReady(callback); |
} |
} // namespace |
@@ -28,22 +30,30 @@ namespace extensions { |
namespace api { |
-BluetoothExtensionFunction::BluetoothExtensionFunction() { |
+BluetoothExtensionFunction::BluetoothExtensionFunction() |
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
} |
BluetoothExtensionFunction::~BluetoothExtensionFunction() { |
} |
bool BluetoothExtensionFunction::RunImpl() { |
- scoped_refptr<device::BluetoothAdapter> adapter = GetAdapter(profile()); |
- if (!adapter) { |
+ if (!device::BluetoothAdapterFactory::IsBluetoothSupported()) { |
SetError(kPlatformNotSupported); |
return false; |
} |
- DoWork(adapter); |
+ RunCallbackOnAdapterReady( |
+ base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ profile()); |
return true; |
} |
+void BluetoothExtensionFunction::RunOnAdapterReady( |
+ scoped_refptr<device::BluetoothAdapter> adapter) { |
+ DoWork(adapter); |
+} |
+ |
} // namespace api |
} // namespace extensions |