Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / components / pairing / bluetooth_host_pairing_controller.h
blob5a1dc7443adcab59344044a8951b8431fe2a561a
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 virtual ~BluetoothHostPairingController();
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 virtual void AddObserver(Observer* observer) override;
66 virtual void RemoveObserver(Observer* observer) override;
67 virtual Stage GetCurrentStage() override;
68 virtual void StartPairing() override;
69 virtual std::string GetDeviceName() override;
70 virtual std::string GetConfirmationCode() override;
71 virtual std::string GetEnrollmentDomain() override;
72 virtual void OnUpdateStatusChanged(UpdateStatus update_status) override;
73 virtual void OnEnrollmentStatusChanged(
74 EnrollmentStatus enrollment_status) override;
76 // ProtoDecoder::Observer:
77 virtual void OnHostStatusMessage(
78 const pairing_api::HostStatus& message) override;
79 virtual void OnConfigureHostMessage(
80 const pairing_api::ConfigureHost& message) override;
81 virtual void OnPairDevicesMessage(
82 const pairing_api::PairDevices& message) override;
83 virtual void OnCompleteSetupMessage(
84 const pairing_api::CompleteSetup& message) override;
85 virtual void OnErrorMessage(const pairing_api::Error& message) override;
87 // BluetoothAdapter::Observer:
88 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
89 bool present) override;
91 // device::BluetoothDevice::PairingDelegate:
92 virtual void RequestPinCode(device::BluetoothDevice* device) override;
93 virtual void RequestPasskey(device::BluetoothDevice* device) override;
94 virtual void DisplayPinCode(device::BluetoothDevice* device,
95 const std::string& pincode) override;
96 virtual void DisplayPasskey(device::BluetoothDevice* device,
97 uint32 passkey) override;
98 virtual void KeysEntered(device::BluetoothDevice* device,
99 uint32 entered) override;
100 virtual void ConfirmPasskey(device::BluetoothDevice* device,
101 uint32 passkey) override;
102 virtual void AuthorizePairing(device::BluetoothDevice* device) override;
104 Stage current_stage_;
105 std::string device_name_;
106 std::string confirmation_code_;
107 std::string enrollment_domain_;
108 UpdateStatus update_status_;
109 EnrollmentStatus enrollment_status_;
111 scoped_refptr<device::BluetoothAdapter> adapter_;
112 device::BluetoothDevice* device_;
113 scoped_refptr<device::BluetoothSocket> service_socket_;
114 scoped_refptr<device::BluetoothSocket> controller_socket_;
115 scoped_ptr<ProtoDecoder> proto_decoder_;
117 base::ThreadChecker thread_checker_;
118 ObserverList<Observer> observers_;
119 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_;
121 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController);
124 } // namespace pairing_chromeos
126 #endif // CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_