[Enhanced Bookmark] Change "Bookmark Bar" to "Bookmark bar" on Android
[chromium-blink-merge.git] / components / pairing / bluetooth_host_pairing_controller.h
blobb99af24d0fd1cfc440665a220427e5a26328f702
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
6 #define CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/pairing/host_pairing_controller.h"
14 #include "components/pairing/proto_decoder.h"
15 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_device.h"
17 #include "device/bluetooth/bluetooth_socket.h"
19 namespace device {
20 class BluetoothAdapter;
23 namespace net {
24 class IOBuffer;
27 namespace pairing_chromeos {
29 class BluetoothHostPairingController
30 : public HostPairingController,
31 public ProtoDecoder::Observer,
32 public device::BluetoothAdapter::Observer,
33 public device::BluetoothDevice::PairingDelegate {
34 public:
35 typedef HostPairingController::Observer Observer;
37 BluetoothHostPairingController();
38 ~BluetoothHostPairingController() override;
40 private:
41 void ChangeStage(Stage new_stage);
42 void SendHostStatus();
43 void AbortWithError(int code, const std::string& message);
44 void Reset();
46 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
47 void SetName();
48 void OnSetName();
49 void OnSetPowered();
50 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket);
51 void OnSetDiscoverable(bool change_stage);
52 void OnAccept(const device::BluetoothDevice* device,
53 scoped_refptr<device::BluetoothSocket> socket);
54 void OnSendComplete(int bytes_sent);
55 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer);
57 void OnCreateServiceError(const std::string& message);
58 void OnSetError();
59 void OnAcceptError(const std::string& error_message);
60 void OnSendError(const std::string& error_message);
61 void OnReceiveError(device::BluetoothSocket::ErrorReason reason,
62 const std::string& error_message);
64 // HostPairingController:
65 void AddObserver(Observer* observer) override;
66 void RemoveObserver(Observer* observer) override;
67 Stage GetCurrentStage() override;
68 void StartPairing() override;
69 std::string GetDeviceName() override;
70 std::string GetConfirmationCode() override;
71 std::string GetEnrollmentDomain() override;
72 void OnUpdateStatusChanged(UpdateStatus update_status) override;
73 void OnEnrollmentStatusChanged(EnrollmentStatus enrollment_status) override;
75 // ProtoDecoder::Observer:
76 void OnHostStatusMessage(const pairing_api::HostStatus& message) override;
77 void OnConfigureHostMessage(
78 const pairing_api::ConfigureHost& message) override;
79 void OnPairDevicesMessage(const pairing_api::PairDevices& message) override;
80 void OnCompleteSetupMessage(
81 const pairing_api::CompleteSetup& message) override;
82 void OnErrorMessage(const pairing_api::Error& message) override;
84 // BluetoothAdapter::Observer:
85 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
86 bool present) override;
88 // device::BluetoothDevice::PairingDelegate:
89 void RequestPinCode(device::BluetoothDevice* device) override;
90 void RequestPasskey(device::BluetoothDevice* device) override;
91 void DisplayPinCode(device::BluetoothDevice* device,
92 const std::string& pincode) override;
93 void DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) override;
94 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override;
95 void ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) override;
96 void AuthorizePairing(device::BluetoothDevice* device) override;
98 Stage current_stage_;
99 std::string device_name_;
100 std::string confirmation_code_;
101 std::string enrollment_domain_;
102 UpdateStatus update_status_;
103 EnrollmentStatus enrollment_status_;
105 scoped_refptr<device::BluetoothAdapter> adapter_;
106 scoped_refptr<device::BluetoothSocket> service_socket_;
107 scoped_refptr<device::BluetoothSocket> controller_socket_;
108 scoped_ptr<ProtoDecoder> proto_decoder_;
110 base::ThreadChecker thread_checker_;
111 ObserverList<Observer> observers_;
112 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_;
114 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController);
117 } // namespace pairing_chromeos
119 #endif // CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_