OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ | 5 #ifndef COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ |
6 #define COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ | 6 #define COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "components/pairing/host_pairing_controller.h" | 17 #include "components/pairing/host_pairing_controller.h" |
18 #include "components/pairing/proto_decoder.h" | 18 #include "components/pairing/proto_decoder.h" |
19 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
20 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
21 #include "device/bluetooth/bluetooth_socket.h" | 21 #include "device/bluetooth/bluetooth_socket.h" |
| 22 #include "device/hid/input_service_linux.h" |
22 | 23 |
23 namespace device { | 24 namespace device { |
24 class BluetoothAdapter; | 25 class BluetoothAdapter; |
25 } | 26 } |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 class IOBuffer; | 29 class IOBuffer; |
29 } | 30 } |
30 | 31 |
31 namespace pairing_chromeos { | 32 namespace pairing_chromeos { |
32 | 33 |
33 class BluetoothHostPairingController | 34 class BluetoothHostPairingController |
34 : public HostPairingController, | 35 : public HostPairingController, |
35 public ProtoDecoder::Observer, | 36 public ProtoDecoder::Observer, |
36 public device::BluetoothAdapter::Observer, | 37 public device::BluetoothAdapter::Observer, |
37 public device::BluetoothDevice::PairingDelegate { | 38 public device::BluetoothDevice::PairingDelegate { |
38 public: | 39 public: |
39 typedef HostPairingController::Observer Observer; | 40 using Observer = HostPairingController::Observer; |
| 41 using InputDeviceInfo = device::InputServiceLinux::InputDeviceInfo; |
40 | 42 |
41 BluetoothHostPairingController(); | 43 explicit BluetoothHostPairingController( |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner); |
42 ~BluetoothHostPairingController() override; | 45 ~BluetoothHostPairingController() override; |
43 | 46 |
44 private: | 47 private: |
45 void ChangeStage(Stage new_stage); | 48 void ChangeStage(Stage new_stage); |
46 void SendHostStatus(); | 49 void SendHostStatus(); |
47 void Reset(); | 50 void Reset(); |
48 | 51 |
49 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | 52 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
50 void SetName(); | 53 void SetName(); |
51 void OnSetName(); | 54 void OnSetName(); |
52 void OnSetPowered(); | 55 void OnSetPowered(); |
53 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); | 56 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); |
54 void OnSetDiscoverable(bool change_stage); | 57 void OnSetDiscoverable(bool change_stage); |
55 void OnAccept(const device::BluetoothDevice* device, | 58 void OnAccept(const device::BluetoothDevice* device, |
56 scoped_refptr<device::BluetoothSocket> socket); | 59 scoped_refptr<device::BluetoothSocket> socket); |
57 void OnSendComplete(int bytes_sent); | 60 void OnSendComplete(int bytes_sent); |
58 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer); | 61 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer); |
59 | 62 |
60 void OnCreateServiceError(const std::string& message); | 63 void OnCreateServiceError(const std::string& message); |
61 void OnSetError(); | 64 void OnSetError(); |
62 void OnAcceptError(const std::string& error_message); | 65 void OnAcceptError(const std::string& error_message); |
63 void OnSendError(const std::string& error_message); | 66 void OnSendError(const std::string& error_message); |
64 void OnReceiveError(device::BluetoothSocket::ErrorReason reason, | 67 void OnReceiveError(device::BluetoothSocket::ErrorReason reason, |
65 const std::string& error_message); | 68 const std::string& error_message); |
| 69 void PowerOffAdapterIfApplicable(const std::vector<InputDeviceInfo>& devices); |
66 | 70 |
67 // HostPairingController: | 71 // HostPairingController: |
68 void AddObserver(Observer* observer) override; | 72 void AddObserver(Observer* observer) override; |
69 void RemoveObserver(Observer* observer) override; | 73 void RemoveObserver(Observer* observer) override; |
70 Stage GetCurrentStage() override; | 74 Stage GetCurrentStage() override; |
71 void StartPairing() override; | 75 void StartPairing() override; |
72 std::string GetDeviceName() override; | 76 std::string GetDeviceName() override; |
73 std::string GetConfirmationCode() override; | 77 std::string GetConfirmationCode() override; |
74 std::string GetEnrollmentDomain() override; | 78 std::string GetEnrollmentDomain() override; |
75 void OnNetworkConnectivityChanged(Connectivity connectivity_status) override; | 79 void OnNetworkConnectivityChanged(Connectivity connectivity_status) override; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 UpdateStatus update_status_; | 115 UpdateStatus update_status_; |
112 EnrollmentStatus enrollment_status_; | 116 EnrollmentStatus enrollment_status_; |
113 std::string permanent_id_; | 117 std::string permanent_id_; |
114 bool was_powered_ = false; | 118 bool was_powered_ = false; |
115 | 119 |
116 scoped_refptr<device::BluetoothAdapter> adapter_; | 120 scoped_refptr<device::BluetoothAdapter> adapter_; |
117 scoped_refptr<device::BluetoothSocket> service_socket_; | 121 scoped_refptr<device::BluetoothSocket> service_socket_; |
118 scoped_refptr<device::BluetoothSocket> controller_socket_; | 122 scoped_refptr<device::BluetoothSocket> controller_socket_; |
119 std::unique_ptr<ProtoDecoder> proto_decoder_; | 123 std::unique_ptr<ProtoDecoder> proto_decoder_; |
120 | 124 |
| 125 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
121 base::ThreadChecker thread_checker_; | 126 base::ThreadChecker thread_checker_; |
122 base::ObserverList<Observer> observers_; | 127 base::ObserverList<Observer> observers_; |
123 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_; | 128 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_; |
124 | 129 |
125 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController); | 130 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController); |
126 }; | 131 }; |
127 | 132 |
128 } // namespace pairing_chromeos | 133 } // namespace pairing_chromeos |
129 | 134 |
130 #endif // COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ | 135 #endif // COMPONENTS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_ |
OLD | NEW |