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

Unified Diff: device/bluetooth/adapter_factory.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_factory.h ('k') | device/bluetooth/public/interfaces/adapter.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4ac2bd944eff1a066b439c7d44696c565647dd13
--- /dev/null
+++ b/device/bluetooth/adapter_factory.cc
@@ -0,0 +1,43 @@
+// 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(const GetAdapterCallback& callback) {
+ if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
+ device::BluetoothAdapterFactory::GetAdapter(
+ base::Bind(&AdapterFactory::OnGetAdapter,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+ } else {
+ callback.Run(nullptr /* AdapterPtr */);
+ }
+}
+
+void AdapterFactory::OnGetAdapter(
+ const GetAdapterCallback& callback,
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ mojom::AdapterPtr adapter_ptr;
+ mojo::MakeStrongBinding(base::MakeUnique<Adapter>(adapter),
+ mojo::GetProxy(&adapter_ptr));
+ callback.Run(std::move(adapter_ptr));
+}
+
+} // namespace bluetooth
« no previous file with comments | « device/bluetooth/adapter_factory.h ('k') | device/bluetooth/public/interfaces/adapter.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698