OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
| 6 #define CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 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" |
| 19 |
| 20 namespace net { |
| 21 class IOBuffer; |
| 22 } |
| 23 |
| 24 namespace pairing_chromeos { |
| 25 |
| 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(); |
| 34 |
| 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); |
| 41 |
| 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); |
| 50 |
| 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); |
| 56 |
| 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 OnAuthenticationDone( |
| 70 const chromeos::UserContext& user_context, |
| 71 content::BrowserContext* browser_context) OVERRIDE; |
| 72 virtual void StartSession() OVERRIDE; |
| 73 |
| 74 // ProtoDecoder::Observer: |
| 75 virtual void OnHostStatusMessage( |
| 76 const pairing_api::HostStatus& message) OVERRIDE; |
| 77 virtual void OnConfigureHostMessage( |
| 78 const pairing_api::ConfigureHost& message) OVERRIDE; |
| 79 virtual void OnPairDevicesMessage( |
| 80 const pairing_api::PairDevices& message) OVERRIDE; |
| 81 virtual void OnCompleteSetupMessage( |
| 82 const pairing_api::CompleteSetup& message) OVERRIDE; |
| 83 virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE; |
| 84 |
| 85 // BluetoothAdapter::Observer: |
| 86 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
| 87 device::BluetoothDevice* device) OVERRIDE; |
| 88 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 89 device::BluetoothDevice* device) OVERRIDE; |
| 90 |
| 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; |
| 103 |
| 104 Stage current_stage_; |
| 105 bool got_initial_status_; |
| 106 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 107 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 108 scoped_refptr<device::BluetoothSocket> socket_; |
| 109 std::string controller_device_id_; |
| 110 |
| 111 std::string confirmation_code_; |
| 112 std::set<std::string> discovered_devices_; |
| 113 |
| 114 scoped_ptr<ProtoDecoder> proto_decoder_; |
| 115 |
| 116 base::ThreadChecker thread_checker_; |
| 117 ObserverList<ControllerPairingController::Observer> observers_; |
| 118 base::WeakPtrFactory<BluetoothControllerPairingController> ptr_factory_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(BluetoothControllerPairingController); |
| 121 }; |
| 122 |
| 123 } // namespace pairing_chromeos |
| 124 |
| 125 #endif // CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
OLD | NEW |