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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <utility>
6
7 #include "base/memory/ptr_util.h"
8 #include "device/bluetooth/adapter.h"
9 #include "device/bluetooth/adapter_factory.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
12
13 namespace bluetooth {
14
15 AdapterFactory::AdapterFactory() : weak_ptr_factory_(this) {}
16 AdapterFactory::~AdapterFactory() {}
17
18 // static
19 void AdapterFactory::Create(mojom::AdapterFactoryRequest request) {
20 mojo::MakeStrongBinding(base::MakeUnique<AdapterFactory>(),
21 std::move(request));
22 }
23
24 void AdapterFactory::GetAdapter(mojom::AdapterRequest request,
25 mojom::AdapterClientPtr client,
26 const GetAdapterCallback& callback) {
27 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
28 device::BluetoothAdapterFactory::GetAdapter(base::Bind(
29 &AdapterFactory::OnGetAdapter, weak_ptr_factory_.GetWeakPtr(),
30 base::Passed(&request), base::Passed(&client), callback));
31 } else {
32 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.
33 }
34 }
35
36 void AdapterFactory::OnGetAdapter(
37 mojom::AdapterRequest request,
38 mojom::AdapterClientPtr client,
39 const GetAdapterCallback& callback,
40 scoped_refptr<device::BluetoothAdapter> adapter) {
41 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.
42 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.
43 callback.Run(true);
44 } else {
45 callback.Run(false);
46 }
47 }
48
49 } // namespace bluetooth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698