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 void Reset(); |
| 38 void DeviceFound(device::BluetoothDevice* device); |
| 39 void DeviceLost(device::BluetoothDevice* device); |
| 40 |
| 41 void OnSetPowered(); |
| 42 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 43 void OnStartDiscoverySession( |
| 44 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| 45 void OnConnect(); |
| 46 void OnConnectToService(scoped_refptr<device::BluetoothSocket> socket); |
| 47 void OnSendComplete(int bytes_sent); |
| 48 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer); |
| 49 |
| 50 void OnError(); |
| 51 void OnErrorWithMessage(const std::string& message); |
| 52 void OnConnectError(device::BluetoothDevice::ConnectErrorCode error_code); |
| 53 void OnReceiveError(device::BluetoothSocket::ErrorReason reason, |
| 54 const std::string& error_message); |
| 55 |
| 56 // ControllerPairingController: |
| 57 virtual void AddObserver( |
| 58 ControllerPairingController::Observer* observer) OVERRIDE; |
| 59 virtual void RemoveObserver( |
| 60 ControllerPairingController::Observer* observer) OVERRIDE; |
| 61 virtual Stage GetCurrentStage() OVERRIDE; |
| 62 virtual void StartPairing() OVERRIDE; |
| 63 virtual DeviceIdList GetDiscoveredDevices() OVERRIDE; |
| 64 virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE; |
| 65 virtual void RepeatDiscovery() OVERRIDE; |
| 66 virtual std::string GetConfirmationCode() OVERRIDE; |
| 67 virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE; |
| 68 virtual void OnAuthenticationDone( |
| 69 const chromeos::UserContext& user_context, |
| 70 content::BrowserContext* browser_context) OVERRIDE; |
| 71 virtual void StartSession() OVERRIDE; |
| 72 |
| 73 // ProtoDecoder::Observer: |
| 74 virtual void OnHostStatusMessage( |
| 75 const pairing_api::HostStatus& message) OVERRIDE; |
| 76 virtual void OnConfigureHostMessage( |
| 77 const pairing_api::ConfigureHost& message) OVERRIDE; |
| 78 virtual void OnPairDevicesMessage( |
| 79 const pairing_api::PairDevices& message) OVERRIDE; |
| 80 virtual void OnCompleteSetupMessage( |
| 81 const pairing_api::CompleteSetup& message) OVERRIDE; |
| 82 virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE; |
| 83 |
| 84 // BluetoothAdapter::Observer: |
| 85 virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
| 86 device::BluetoothDevice* device) OVERRIDE; |
| 87 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 88 device::BluetoothDevice* device) OVERRIDE; |
| 89 |
| 90 // device::BluetoothDevice::PairingDelegate: |
| 91 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; |
| 92 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; |
| 93 virtual void DisplayPinCode(device::BluetoothDevice* device, |
| 94 const std::string& pincode) OVERRIDE; |
| 95 virtual void DisplayPasskey(device::BluetoothDevice* device, |
| 96 uint32 passkey) OVERRIDE; |
| 97 virtual void KeysEntered(device::BluetoothDevice* device, |
| 98 uint32 entered) OVERRIDE; |
| 99 virtual void ConfirmPasskey(device::BluetoothDevice* device, |
| 100 uint32 passkey) OVERRIDE; |
| 101 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; |
| 102 |
| 103 Stage current_stage_; |
| 104 bool got_initial_status_; |
| 105 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 106 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 107 scoped_refptr<device::BluetoothSocket> socket_; |
| 108 std::string controller_device_id_; |
| 109 |
| 110 std::string confirmation_code_; |
| 111 std::set<std::string> discovered_devices_; |
| 112 |
| 113 scoped_ptr<ProtoDecoder> proto_decoder_; |
| 114 |
| 115 base::ThreadChecker thread_checker_; |
| 116 ObserverList<ControllerPairingController::Observer> observers_; |
| 117 base::WeakPtrFactory<BluetoothControllerPairingController> ptr_factory_; |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(BluetoothControllerPairingController); |
| 120 }; |
| 121 |
| 122 } // namespace pairing_chromeos |
| 123 |
| 124 #endif // CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
OLD | NEW |