Chromium Code Reviews| 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 "components/pairing/controller_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" | |
| 18 | |
| 19 namespace net { | |
| 20 class IOBuffer; | |
| 21 } | |
| 22 | |
| 23 namespace pairing_chromeos { | |
| 24 | |
| 25 class BluetoothControllerPairingController | |
| 26 : public ControllerPairingController, | |
| 27 public ProtoDecoder::Observer, | |
| 28 public device::BluetoothAdapter::Observer, | |
| 29 public device::BluetoothDevice::PairingDelegate { | |
| 30 public: | |
| 31 BluetoothControllerPairingController(); | |
| 32 virtual ~BluetoothControllerPairingController(); | |
| 33 | |
| 34 private: | |
| 35 void ChangeStage(Stage new_stage); | |
| 36 void Reset(); | |
| 37 void DeviceFound(device::BluetoothDevice* device); | |
| 38 void DeviceLost(device::BluetoothDevice* device); | |
| 39 | |
| 40 void OnSetPowered(); | |
| 41 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
| 42 void OnStartDiscoverySession( | |
| 43 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | |
| 44 void OnConnect(); | |
| 45 void OnConnectToService(scoped_refptr<device::BluetoothSocket> socket); | |
| 46 void OnSendComplete(int bytes_sent); | |
| 47 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer); | |
| 48 | |
| 49 void OnError(); | |
| 50 void OnErrorWithMessage(const std::string& message); | |
| 51 void OnConnectError(device::BluetoothDevice::ConnectErrorCode error_code); | |
| 52 void OnReceiveError(device::BluetoothSocket::ErrorReason reason, | |
| 53 const std::string& error_message); | |
| 54 | |
| 55 // ControllerPairingController: | |
| 56 virtual void AddObserver( | |
| 57 ControllerPairingController::Observer* observer) OVERRIDE; | |
| 58 virtual void RemoveObserver( | |
| 59 ControllerPairingController::Observer* observer) OVERRIDE; | |
| 60 virtual Stage GetCurrentStage() OVERRIDE; | |
| 61 virtual void StartPairing() OVERRIDE; | |
| 62 virtual DeviceIdList GetDiscoveredDevices() OVERRIDE; | |
| 63 virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE; | |
| 64 virtual void RepeatDiscovery() OVERRIDE; | |
| 65 virtual std::string GetConfirmationCode() OVERRIDE; | |
| 66 virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE; | |
| 67 virtual void OnAuthenticationDone( | |
| 68 const chromeos::UserContext& user_context, | |
| 69 content::BrowserContext* browser_context) OVERRIDE; | |
| 70 virtual void StartSession() OVERRIDE; | |
| 71 | |
| 72 // ProtoDecoder::Observer: | |
| 73 virtual void OnHostStatusMessage( | |
| 74 const pairing_api::HostStatus& message) OVERRIDE; | |
| 75 virtual void OnConfigureHostMessage( | |
| 76 const pairing_api::ConfigureHost& message) OVERRIDE; | |
| 77 virtual void OnPairDevicesMessage( | |
| 78 const pairing_api::PairDevices& message) OVERRIDE; | |
| 79 virtual void OnCompleteSetupMessage( | |
| 80 const pairing_api::CompleteSetup& message) OVERRIDE; | |
| 81 virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE; | |
| 82 | |
| 83 // BluetoothAdapter::Observer: | |
| 84 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | |
| 85 device::BluetoothDevice* device) OVERRIDE; | |
| 86 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, | |
| 87 device::BluetoothDevice* device) OVERRIDE; | |
| 88 | |
| 89 // device::BluetoothDevice::PairingDelegate: | |
| 90 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; | |
| 91 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; | |
| 92 virtual void DisplayPinCode(device::BluetoothDevice* device, | |
| 93 const std::string& pincode) OVERRIDE; | |
| 94 virtual void DisplayPasskey(device::BluetoothDevice* device, | |
| 95 uint32 passkey) OVERRIDE; | |
| 96 virtual void KeysEntered(device::BluetoothDevice* device, | |
| 97 uint32 entered) OVERRIDE; | |
| 98 virtual void ConfirmPasskey(device::BluetoothDevice* device, | |
| 99 uint32 passkey) OVERRIDE; | |
| 100 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; | |
| 101 | |
| 102 base::WeakPtrFactory<BluetoothControllerPairingController> ptr_factory_; | |
|
achuithb
2014/08/20 21:52:33
I believe this should be the last member of this l
Zachary Kuznia
2014/08/21 00:42:07
Done.
| |
| 103 ObserverList<ControllerPairingController::Observer> observers_; | |
|
achuithb
2014/08/20 21:52:33
I would also move this further down the list, mayb
Zachary Kuznia
2014/08/21 00:42:07
Done.
| |
| 104 | |
| 105 Stage current_stage_; | |
| 106 bool got_initial_status_; | |
| 107 scoped_refptr<device::BluetoothAdapter> adapter_; | |
| 108 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; | |
| 109 device::BluetoothDevice* device_; | |
|
achuithb
2014/08/20 21:52:33
What is the expected lifetime of device_? This nak
Zachary Kuznia
2014/08/21 00:42:07
Storing the device id instead of the device pointe
| |
| 110 scoped_refptr<device::BluetoothSocket> socket_; | |
| 111 | |
| 112 std::string confirmation_code_; | |
| 113 std::set<std::string> discovered_devices_; | |
| 114 | |
| 115 scoped_ptr<ProtoDecoder> proto_decoder_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(BluetoothControllerPairingController); | |
| 118 }; | |
| 119 | |
| 120 } // namespace pairing_chromeos | |
| 121 | |
| 122 #endif // CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ | |
| OLD | NEW |