Blink roll a6d61dbff0a4bce30fce5b29c2efb77a94ddc3ee:a11635f657e0f1ce75179fd7336a309a6...
[chromium-blink-merge.git] / components / pairing / bluetooth_controller_pairing_controller.h
blob7458154c7136cc4e1b9d2623de395716a0409240
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_CONTROLLER_PAIRING_FLOW_H_
6 #define CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_
8 #include <set>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/threading/thread_checker.h"
14 #include "components/pairing/controller_pairing_controller.h"
15 #include "components/pairing/proto_decoder.h"
16 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_socket.h"
20 namespace net {
21 class IOBuffer;
24 namespace pairing_chromeos {
26 class BluetoothControllerPairingController
27 : public ControllerPairingController,
28 public ProtoDecoder::Observer,
29 public device::BluetoothAdapter::Observer,
30 public device::BluetoothDevice::PairingDelegate {
31 public:
32 BluetoothControllerPairingController();
33 virtual ~BluetoothControllerPairingController();
35 private:
36 void ChangeStage(Stage new_stage);
37 device::BluetoothDevice* GetController();
38 void Reset();
39 void DeviceFound(device::BluetoothDevice* device);
40 void DeviceLost(device::BluetoothDevice* device);
42 void OnSetPowered();
43 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
44 void OnStartDiscoverySession(
45 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
46 void OnConnect();
47 void OnConnectToService(scoped_refptr<device::BluetoothSocket> socket);
48 void OnSendComplete(int bytes_sent);
49 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer);
51 void OnError();
52 void OnErrorWithMessage(const std::string& message);
53 void OnConnectError(device::BluetoothDevice::ConnectErrorCode error_code);
54 void OnReceiveError(device::BluetoothSocket::ErrorReason reason,
55 const std::string& error_message);
57 // ControllerPairingController:
58 virtual void AddObserver(
59 ControllerPairingController::Observer* observer) OVERRIDE;
60 virtual void RemoveObserver(
61 ControllerPairingController::Observer* observer) OVERRIDE;
62 virtual Stage GetCurrentStage() OVERRIDE;
63 virtual void StartPairing() OVERRIDE;
64 virtual DeviceIdList GetDiscoveredDevices() OVERRIDE;
65 virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE;
66 virtual void RepeatDiscovery() OVERRIDE;
67 virtual std::string GetConfirmationCode() OVERRIDE;
68 virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE;
69 virtual void SetHostConfiguration(
70 bool accepted_eula,
71 const std::string& lang,
72 const std::string& timezone,
73 bool send_reports,
74 const std::string& keyboard_layout) OVERRIDE;
75 virtual void OnAuthenticationDone(const std::string& domain,
76 const std::string& auth_token) OVERRIDE;
77 virtual void StartSession() OVERRIDE;
79 // ProtoDecoder::Observer:
80 virtual void OnHostStatusMessage(
81 const pairing_api::HostStatus& message) OVERRIDE;
82 virtual void OnConfigureHostMessage(
83 const pairing_api::ConfigureHost& message) OVERRIDE;
84 virtual void OnPairDevicesMessage(
85 const pairing_api::PairDevices& message) OVERRIDE;
86 virtual void OnCompleteSetupMessage(
87 const pairing_api::CompleteSetup& message) OVERRIDE;
88 virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE;
90 // BluetoothAdapter::Observer:
91 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
92 device::BluetoothDevice* device) OVERRIDE;
93 virtual void DeviceRemoved(device::BluetoothAdapter* adapter,
94 device::BluetoothDevice* device) OVERRIDE;
96 // device::BluetoothDevice::PairingDelegate:
97 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE;
98 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE;
99 virtual void DisplayPinCode(device::BluetoothDevice* device,
100 const std::string& pincode) OVERRIDE;
101 virtual void DisplayPasskey(device::BluetoothDevice* device,
102 uint32 passkey) OVERRIDE;
103 virtual void KeysEntered(device::BluetoothDevice* device,
104 uint32 entered) OVERRIDE;
105 virtual void ConfirmPasskey(device::BluetoothDevice* device,
106 uint32 passkey) OVERRIDE;
107 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE;
109 Stage current_stage_;
110 bool got_initial_status_;
111 scoped_refptr<device::BluetoothAdapter> adapter_;
112 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_;
113 scoped_refptr<device::BluetoothSocket> socket_;
114 std::string controller_device_id_;
116 std::string confirmation_code_;
117 std::set<std::string> discovered_devices_;
119 scoped_ptr<ProtoDecoder> proto_decoder_;
121 base::ThreadChecker thread_checker_;
122 ObserverList<ControllerPairingController::Observer> observers_;
123 base::WeakPtrFactory<BluetoothControllerPairingController> ptr_factory_;
125 DISALLOW_COPY_AND_ASSIGN(BluetoothControllerPairingController);
128 } // namespace pairing_chromeos
130 #endif // CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_