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

Unified Diff: device/bluetooth/adapter.cc

Issue 2379573006: bluetooth: Standardize Bluetooth adapter access in Adapter service. (Closed)
Patch Set: dcheng fixes Created 4 years, 2 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/adapter.h ('k') | device/bluetooth/adapter_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/adapter.cc
diff --git a/device/bluetooth/adapter.cc b/device/bluetooth/adapter.cc
index 2f7aff0be4c195e18a1570e55852ea00b95a5268..537e84c36c8d2f578a222ca5ed25e90052cfe86f 100644
--- a/device/bluetooth/adapter.cc
+++ b/device/bluetooth/adapter.cc
@@ -9,40 +9,30 @@
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "device/bluetooth/adapter.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "mojo/public/cpp/bindings/string.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace bluetooth {
-Adapter::Adapter() : client_(nullptr), weak_ptr_factory_(this) {}
-
-Adapter::~Adapter() {
- if (adapter_) {
- adapter_->RemoveObserver(this);
- adapter_ = nullptr;
- }
+Adapter::Adapter(scoped_refptr<device::BluetoothAdapter> adapter)
+ : adapter_(std::move(adapter)), client_(nullptr), weak_ptr_factory_(this) {
+ adapter_->AddObserver(this);
}
-// static
-void Adapter::Create(mojom::AdapterRequest request) {
- mojo::MakeStrongBinding(base::MakeUnique<Adapter>(), std::move(request));
+Adapter::~Adapter() {
+ adapter_->RemoveObserver(this);
+ adapter_ = nullptr;
}
void Adapter::GetDevices(const GetDevicesCallback& callback) {
- if (!adapter_) {
- if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
- base::Closure c = base::Bind(&Adapter::GetDevicesImpl,
- weak_ptr_factory_.GetWeakPtr(), callback);
+ std::vector<mojom::DeviceInfoPtr> devices;
- device::BluetoothAdapterFactory::GetAdapter(base::Bind(
- &Adapter::OnGetAdapter, weak_ptr_factory_.GetWeakPtr(), c));
- return;
- }
- callback.Run(std::vector<mojom::DeviceInfoPtr>());
- return;
+ for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
+ mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device);
+ devices.push_back(std::move(device_info));
}
- GetDevicesImpl(callback);
+
+ callback.Run(std::move(devices));
}
void Adapter::SetClient(mojom::AdapterClientPtr client) {
@@ -65,8 +55,9 @@ void Adapter::DeviceRemoved(device::BluetoothAdapter* adapter,
}
}
+// static
mojom::DeviceInfoPtr Adapter::ConstructDeviceInfoStruct(
- const device::BluetoothDevice* device) const {
+ const device::BluetoothDevice* device) {
mojom::DeviceInfoPtr device_info = mojom::DeviceInfo::New();
device_info->name = device->GetName();
@@ -78,25 +69,4 @@ mojom::DeviceInfoPtr Adapter::ConstructDeviceInfoStruct(
return device_info;
}
-void Adapter::GetDevicesImpl(const GetDevicesCallback& callback) {
- std::vector<mojom::DeviceInfoPtr> devices;
-
- for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
- mojom::DeviceInfoPtr device_info = ConstructDeviceInfoStruct(device);
- devices.push_back(std::move(device_info));
- }
-
- callback.Run(std::move(devices));
-}
-
-void Adapter::OnGetAdapter(const base::Closure& continuation,
- scoped_refptr<device::BluetoothAdapter> adapter) {
- if (!adapter_) {
- VLOG(1) << "Adapter acquired";
- adapter_ = adapter;
- adapter_->AddObserver(this);
- }
- continuation.Run();
-}
-
} // namespace bluetooth
« no previous file with comments | « device/bluetooth/adapter.h ('k') | device/bluetooth/adapter_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698