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

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc

Issue 11819007: Changed DefaultAdapter to RunCallbackOnAdapterReady function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created IsBluetoothSupported in BluetoothEventRouter to fix browser_tests. Created 7 years, 11 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: 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..873e9d8a60a069ad9af3023aa3e68fa5dcce31fe 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc
@@ -16,10 +16,18 @@ namespace {
const char kPlatformNotSupported[] =
"This operation is not supported on your platform";
-scoped_refptr<device::BluetoothAdapter> GetAdapter(Profile* profile) {
- extensions::ExtensionBluetoothEventRouter* event_router =
- extensions::BluetoothAPI::Get(profile)->bluetooth_event_router();
- return event_router->GetAdapter();
+extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) {
+ return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router();
+}
+
+bool IsBluetoothSupported(Profile* profile) {
+ return GetEventRouter(profile)->IsBluetoothSupported();
+}
+
+void RunCallbackOnAdapterReady(
+ const device::BluetoothAdapterFactory::AdapterCallback callback,
+ Profile* profile) {
+ GetEventRouter(profile)->RunCallbackOnAdapterReady(callback);
}
} // namespace
@@ -28,22 +36,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 (!IsBluetoothSupported(profile())) {
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

Powered by Google App Engine
This is Rietveld 408576698