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

Unified Diff: device/bluetooth/adapter_factory.cc

Issue 2379573006: bluetooth: Standardize Bluetooth adapter access in Adapter service. (Closed)
Patch Set: Comment updates 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
Index: device/bluetooth/adapter_factory.cc
diff --git a/device/bluetooth/adapter_factory.cc b/device/bluetooth/adapter_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8723b20587991cf2ce1339a18aa3c4d9e159072f
--- /dev/null
+++ b/device/bluetooth/adapter_factory.cc
@@ -0,0 +1,49 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <utility>
+
+#include "base/memory/ptr_util.h"
+#include "device/bluetooth/adapter.h"
+#include "device/bluetooth/adapter_factory.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+
+namespace bluetooth {
+
+AdapterFactory::AdapterFactory() : weak_ptr_factory_(this) {}
+AdapterFactory::~AdapterFactory() {}
+
+// static
+void AdapterFactory::Create(mojom::AdapterFactoryRequest request) {
+ mojo::MakeStrongBinding(base::MakeUnique<AdapterFactory>(),
+ std::move(request));
+}
+
+void AdapterFactory::GetAdapter(mojom::AdapterRequest request,
+ mojom::AdapterClientPtr client,
+ const GetAdapterCallback& callback) {
+ if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
+ device::BluetoothAdapterFactory::GetAdapter(base::Bind(
+ &AdapterFactory::OnGetAdapter, weak_ptr_factory_.GetWeakPtr(),
+ base::Passed(&request), base::Passed(&client), callback));
+ } else {
+ callback.Run(false);
ortuno 2016/10/05 02:07:51 nit: You should always add comments to booleans an
mbrunson 2016/10/05 17:59:04 Done.
+ }
+}
+
+void AdapterFactory::OnGetAdapter(
+ mojom::AdapterRequest request,
+ mojom::AdapterClientPtr client,
+ const GetAdapterCallback& callback,
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ if (adapter) {
ortuno 2016/10/05 02:07:51 I think we are always guaranteed to get an adapter
mbrunson 2016/10/05 17:59:04 It seems to be always guaranteed.
+ Adapter::Create(std::move(request), std::move(client), adapter);
ortuno 2016/10/05 02:07:51 We were forced to make a Create method because of
mbrunson 2016/10/05 17:59:04 Done.
+ callback.Run(true);
+ } else {
+ callback.Run(false);
+ }
+}
+
+} // namespace bluetooth

Powered by Google App Engine
This is Rietveld 408576698