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

Side by Side Diff: device/bluetooth/adapter.h

Issue 2379573006: bluetooth: Standardize Bluetooth adapter access in Adapter service. (Closed)
Patch Set: Simplify WithAdapter logic 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
« no previous file with comments | « no previous file | device/bluetooth/adapter.cc » ('j') | device/bluetooth/adapter.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_BLUETOOTH_ADAPTER_H_ 5 #ifndef DEVICE_BLUETOOTH_ADAPTER_H_
6 #define DEVICE_BLUETOOTH_ADAPTER_H_ 6 #define DEVICE_BLUETOOTH_ADAPTER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h"
10 #include "device/bluetooth/public/interfaces/adapter.mojom.h" 11 #include "device/bluetooth/public/interfaces/adapter.mojom.h"
11 12
12 namespace bluetooth { 13 namespace bluetooth {
13 14
14 // Implementation of Mojo BluetoothAdapter located in 15 // Implementation of Mojo BluetoothAdapter located in
15 // device/bluetooth/public/interfaces/bluetooth.mojom. 16 // device/bluetooth/public/interfaces/bluetooth.mojom.
16 // It handles requests for Bluetooth adapter capabilities 17 // It handles requests for Bluetooth adapter capabilities
17 // and devices and uses the platform abstraction of device/bluetooth. 18 // and devices and uses the platform abstraction of device/bluetooth.
18 class Adapter : public mojom::Adapter, 19 class Adapter : public mojom::Adapter,
19 public device::BluetoothAdapter::Observer { 20 public device::BluetoothAdapter::Observer {
20 public: 21 public:
21 Adapter(); 22 Adapter();
22 ~Adapter() override; 23 ~Adapter() override;
23 24
24 // Creates an Adapter with a strong Mojo binding to |request| 25 // Creates an Adapter with a strong Mojo binding to |request|.
25 static void Create(mojom::AdapterRequest request); 26 static void Create(mojom::AdapterRequest request);
26 27
27 // mojom::Adapter overrides: 28 // mojom::Adapter overrides:
28 void GetDevices(const GetDevicesCallback& callback) override; 29 void GetDevices(const GetDevicesCallback& callback) override;
29 void SetClient(mojom::AdapterClientPtr client) override; 30 void SetClient(mojom::AdapterClientPtr client) override;
30 31
31 // device::BluetoothAdapter::Observer overrides: 32 // device::BluetoothAdapter::Observer overrides:
32 void DeviceAdded(device::BluetoothAdapter* adapter, 33 void DeviceAdded(device::BluetoothAdapter* adapter,
33 device::BluetoothDevice* device) override; 34 device::BluetoothDevice* device) override;
34 void DeviceRemoved(device::BluetoothAdapter* adapter, 35 void DeviceRemoved(device::BluetoothAdapter* adapter,
35 device::BluetoothDevice* device) override; 36 device::BluetoothDevice* device) override;
36 37
37 private: 38 private:
38 mojom::DeviceInfoPtr ConstructDeviceInfoStruct( 39 // Creates a mojom::DeviceInfo using info from the given |device|.
39 const device::BluetoothDevice* device) const; 40 static mojom::DeviceInfoPtr ConstructDeviceInfoStruct(
41 const device::BluetoothDevice* const device);
40 42
41 void GetDevicesImpl(const GetDevicesCallback& callback); 43 // Gets a BluetoothAdapter, adds this as an observer, then executes |action|.
44 void WithAdapter(
45 const device::BluetoothAdapterFactory::AdapterCallback& action);
42 46
43 void OnGetAdapter(const base::Closure& continuation, 47 // Stores |adapter| in adapter_ and sets this as an observer of |adapter|.
44 scoped_refptr<device::BluetoothAdapter> adapter); 48 void OnGetAdapter(
49 const device::BluetoothAdapterFactory::AdapterCallback& continuation,
50 scoped_refptr<device::BluetoothAdapter> adapter);
51
45 // The current Bluetooth adapter. 52 // The current Bluetooth adapter.
46 scoped_refptr<device::BluetoothAdapter> adapter_; 53 scoped_refptr<device::BluetoothAdapter> adapter_;
47 54
48 // The adapter client that listens to this service. 55 // The adapter client that listens to this service.
49 mojom::AdapterClientPtr client_; 56 mojom::AdapterClientPtr client_;
50 57
51 base::WeakPtrFactory<Adapter> weak_ptr_factory_; 58 base::WeakPtrFactory<Adapter> weak_ptr_factory_;
52 59
53 DISALLOW_COPY_AND_ASSIGN(Adapter); 60 DISALLOW_COPY_AND_ASSIGN(Adapter);
54 }; 61 };
55 62
56 } // namespace bluetooth 63 } // namespace bluetooth
57 64
58 #endif // DEVICE_BLUETOOTH_ADAPTER_H_ 65 #endif // DEVICE_BLUETOOTH_ADAPTER_H_
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/adapter.cc » ('j') | device/bluetooth/adapter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698