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

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_event_router.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_event_router.cc
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
index bb0a492dc8c6b3c3fa4e9257786b90d981571394..99caaac4acdafe39546ebe34ef16db0a69212bfb 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
@@ -29,7 +29,8 @@ ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile)
profile_(profile),
adapter_(NULL),
num_event_listeners_(0),
- next_socket_id_(1) {
+ next_socket_id_(1),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
DCHECK(profile_);
}
@@ -41,12 +42,19 @@ ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() {
}
}
-scoped_refptr<device::BluetoothAdapter>
-ExtensionBluetoothEventRouter::GetAdapter() {
- if (adapter_)
- return adapter_;
+bool ExtensionBluetoothEventRouter::IsBluetoothSupported() const {
+ return adapter_ ||
+ device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable();
+}
+
+void ExtensionBluetoothEventRouter::RunCallbackOnAdapterReady(
+ const device::BluetoothAdapterFactory::AdapterCallback& callback) {
+ if (adapter_) {
+ callback.Run(scoped_refptr<device::BluetoothAdapter>(adapter_));
+ return;
+ }
- return device::BluetoothAdapterFactory::DefaultAdapter();
+ device::BluetoothAdapterFactory::RunCallbackOnAdapterReady(callback);
}
void ExtensionBluetoothEventRouter::OnListenerAdded() {
@@ -178,11 +186,19 @@ void ExtensionBluetoothEventRouter::DeviceAdded(
void ExtensionBluetoothEventRouter::InitializeAdapterIfNeeded() {
if (!adapter_) {
- adapter_ = GetAdapter();
- adapter_->AddObserver(this);
+ RunCallbackOnAdapterReady(
+ base::Bind(&ExtensionBluetoothEventRouter::InitializeAdapter,
+ weak_ptr_factory_.GetWeakPtr()));
}
}
+void ExtensionBluetoothEventRouter::InitializeAdapter(
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ adapter_ = adapter;
+ if (adapter_)
+ adapter_->AddObserver(this);
+}
+
void ExtensionBluetoothEventRouter::MaybeReleaseAdapter() {
if (adapter_ && num_event_listeners_ == 0) {
adapter_->RemoveObserver(this);

Powered by Google App Engine
This is Rietveld 408576698