Chromium Code Reviews| Index: components/pairing/bluetooth_controller_pairing_controller.h |
| diff --git a/components/pairing/bluetooth_controller_pairing_controller.h b/components/pairing/bluetooth_controller_pairing_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc38b077b242f6c16e9bea76a093aadd05626443 |
| --- /dev/null |
| +++ b/components/pairing/bluetooth_controller_pairing_controller.h |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
| +#define CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |
| + |
| +#include <set> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "components/pairing/controller_pairing_controller.h" |
| +#include "components/pairing/proto_decoder.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| +#include "device/bluetooth/bluetooth_socket.h" |
| + |
| +namespace net { |
| +class IOBuffer; |
| +} |
| + |
| +namespace pairing_chromeos { |
| + |
| +class BluetoothControllerPairingController |
| + : public ControllerPairingController, |
| + public ProtoDecoder::Observer, |
| + public device::BluetoothAdapter::Observer, |
| + public device::BluetoothDevice::PairingDelegate { |
| + public: |
| + BluetoothControllerPairingController(); |
| + virtual ~BluetoothControllerPairingController(); |
| + |
| + private: |
| + void ChangeStage(Stage new_stage); |
| + void Reset(); |
| + void DeviceFound(device::BluetoothDevice* device); |
| + void DeviceLost(device::BluetoothDevice* device); |
| + |
| + void OnSetPowered(); |
| + void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| + void OnStartDiscoverySession( |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| + void OnConnect(); |
| + void OnConnectToService(scoped_refptr<device::BluetoothSocket> socket); |
| + void OnSendComplete(int bytes_sent); |
| + void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer); |
| + |
| + void OnError(); |
| + void OnErrorWithMessage(const std::string& message); |
| + void OnConnectError(device::BluetoothDevice::ConnectErrorCode error_code); |
| + void OnReceiveError(device::BluetoothSocket::ErrorReason reason, |
| + const std::string& error_message); |
| + |
| + // ControllerPairingController: |
| + virtual void AddObserver( |
| + ControllerPairingController::Observer* observer) OVERRIDE; |
| + virtual void RemoveObserver( |
| + ControllerPairingController::Observer* observer) OVERRIDE; |
| + virtual Stage GetCurrentStage() OVERRIDE; |
| + virtual void StartPairing() OVERRIDE; |
| + virtual DeviceIdList GetDiscoveredDevices() OVERRIDE; |
| + virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE; |
| + virtual void RepeatDiscovery() OVERRIDE; |
| + virtual std::string GetConfirmationCode() OVERRIDE; |
| + virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE; |
| + virtual void OnAuthenticationDone( |
| + const chromeos::UserContext& user_context, |
| + content::BrowserContext* browser_context) OVERRIDE; |
| + virtual void StartSession() OVERRIDE; |
| + |
| + // ProtoDecoder::Observer: |
| + virtual void OnHostStatusMessage( |
| + const pairing_api::HostStatus& message) OVERRIDE; |
| + virtual void OnConfigureHostMessage( |
| + const pairing_api::ConfigureHost& message) OVERRIDE; |
| + virtual void OnPairDevicesMessage( |
| + const pairing_api::PairDevices& message) OVERRIDE; |
| + virtual void OnCompleteSetupMessage( |
| + const pairing_api::CompleteSetup& message) OVERRIDE; |
| + virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE; |
| + |
| + // BluetoothAdapter::Observer: |
| + virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate: |
| + virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; |
| + virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; |
| + virtual void DisplayPinCode(device::BluetoothDevice* device, |
| + const std::string& pincode) OVERRIDE; |
| + virtual void DisplayPasskey(device::BluetoothDevice* device, |
| + uint32 passkey) OVERRIDE; |
| + virtual void KeysEntered(device::BluetoothDevice* device, |
| + uint32 entered) OVERRIDE; |
| + virtual void ConfirmPasskey(device::BluetoothDevice* device, |
| + uint32 passkey) OVERRIDE; |
| + virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; |
| + |
| + 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.
|
| + 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.
|
| + |
| + Stage current_stage_; |
| + bool got_initial_status_; |
| + scoped_refptr<device::BluetoothAdapter> adapter_; |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| + 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
|
| + scoped_refptr<device::BluetoothSocket> socket_; |
| + |
| + std::string confirmation_code_; |
| + std::set<std::string> discovered_devices_; |
| + |
| + scoped_ptr<ProtoDecoder> proto_decoder_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluetoothControllerPairingController); |
| +}; |
| + |
| +} // namespace pairing_chromeos |
| + |
| +#endif // CHROMEOS_PAIRING_BLUETOOTH_CONTROLLER_PAIRING_FLOW_H_ |