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_device.h"
16 #include "device/bluetooth/bluetooth_socket.h"
19 class BluetoothAdapter
;
26 namespace pairing_chromeos
{
28 class BluetoothHostPairingController
29 : public HostPairingController
,
30 public ProtoDecoder::Observer
,
31 public device::BluetoothDevice::PairingDelegate
{
33 typedef HostPairingController::Observer Observer
;
35 BluetoothHostPairingController();
36 virtual ~BluetoothHostPairingController();
39 void ChangeStage(Stage new_stage
);
40 void SendHostStatus();
41 void AbortWithError(int code
, const std::string
& message
);
44 void OnGetAdapter(scoped_refptr
<device::BluetoothAdapter
> adapter
);
47 void OnCreateService(scoped_refptr
<device::BluetoothSocket
> socket
);
48 void OnSetDiscoverable(bool change_stage
);
49 void OnAccept(const device::BluetoothDevice
* device
,
50 scoped_refptr
<device::BluetoothSocket
> socket
);
51 void OnSendComplete(int bytes_sent
);
52 void OnReceiveComplete(int bytes
, scoped_refptr
<net::IOBuffer
> io_buffer
);
54 void OnCreateServiceError(const std::string
& message
);
56 void OnAcceptError(const std::string
& error_message
);
57 void OnSendError(const std::string
& error_message
);
58 void OnReceiveError(device::BluetoothSocket::ErrorReason reason
,
59 const std::string
& error_message
);
61 // HostPairingController:
62 virtual void AddObserver(Observer
* observer
) OVERRIDE
;
63 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
;
64 virtual Stage
GetCurrentStage() OVERRIDE
;
65 virtual void StartPairing() OVERRIDE
;
66 virtual std::string
GetDeviceName() OVERRIDE
;
67 virtual std::string
GetConfirmationCode() OVERRIDE
;
68 virtual std::string
GetEnrollmentDomain() OVERRIDE
;
69 virtual void OnUpdateStatusChanged(UpdateStatus update_status
) OVERRIDE
;
71 // ProtoDecoder::Observer:
72 virtual void OnHostStatusMessage(
73 const pairing_api::HostStatus
& message
) OVERRIDE
;
74 virtual void OnConfigureHostMessage(
75 const pairing_api::ConfigureHost
& message
) OVERRIDE
;
76 virtual void OnPairDevicesMessage(
77 const pairing_api::PairDevices
& message
) OVERRIDE
;
78 virtual void OnCompleteSetupMessage(
79 const pairing_api::CompleteSetup
& message
) OVERRIDE
;
80 virtual void OnErrorMessage(const pairing_api::Error
& message
) OVERRIDE
;
82 // device::BluetoothDevice::PairingDelegate:
83 virtual void RequestPinCode(device::BluetoothDevice
* device
) OVERRIDE
;
84 virtual void RequestPasskey(device::BluetoothDevice
* device
) OVERRIDE
;
85 virtual void DisplayPinCode(device::BluetoothDevice
* device
,
86 const std::string
& pincode
) OVERRIDE
;
87 virtual void DisplayPasskey(device::BluetoothDevice
* device
,
88 uint32 passkey
) OVERRIDE
;
89 virtual void KeysEntered(device::BluetoothDevice
* device
,
90 uint32 entered
) OVERRIDE
;
91 virtual void ConfirmPasskey(device::BluetoothDevice
* device
,
92 uint32 passkey
) OVERRIDE
;
93 virtual void AuthorizePairing(device::BluetoothDevice
* device
) OVERRIDE
;
96 std::string device_name_
;
97 std::string confirmation_code_
;
98 std::string enrollment_domain_
;
100 scoped_refptr
<device::BluetoothAdapter
> adapter_
;
101 device::BluetoothDevice
* device_
;
102 scoped_refptr
<device::BluetoothSocket
> service_socket_
;
103 scoped_refptr
<device::BluetoothSocket
> controller_socket_
;
104 scoped_ptr
<ProtoDecoder
> proto_decoder_
;
106 base::ThreadChecker thread_checker_
;
107 ObserverList
<Observer
> observers_
;
108 base::WeakPtrFactory
<BluetoothHostPairingController
> ptr_factory_
;
110 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController
);
113 } // namespace pairing_chromeos
115 #endif // CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_