Revert of Drive: Let DriveUploader use batch request API. (patchset #7 id:120001...
[chromium-blink-merge.git] / components / pairing / bluetooth_host_pairing_controller.h
blob187393535887fba671113beaa260dbc4288272dd
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_HOST_PAIRING_CONTROLLER_H_
6 #define CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/pairing/host_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"
19 namespace device {
20 class BluetoothAdapter;
23 namespace net {
24 class IOBuffer;
27 namespace pairing_chromeos {
29 class BluetoothHostPairingController
30 : public HostPairingController,
31 public ProtoDecoder::Observer,
32 public device::BluetoothAdapter::Observer,
33 public device::BluetoothDevice::PairingDelegate {
34 public:
35 typedef HostPairingController::Observer Observer;
37 BluetoothHostPairingController();
38 ~BluetoothHostPairingController() override;
40 private:
41 void ChangeStage(Stage new_stage);
42 void SendHostStatus();
43 void AbortWithError(int code, const std::string& message);
44 void Reset();
46 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
47 void SetName();
48 void OnSetName();
49 void OnSetPowered();
50 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket);
51 void OnSetDiscoverable(bool change_stage);
52 void OnAccept(const device::BluetoothDevice* device,
53 scoped_refptr<device::BluetoothSocket> socket);
54 void OnSendComplete(int bytes_sent);
55 void OnReceiveComplete(int bytes, scoped_refptr<net::IOBuffer> io_buffer);
57 void OnCreateServiceError(const std::string& message);
58 void OnSetError();
59 void OnAcceptError(const std::string& error_message);
60 void OnSendError(const std::string& error_message);
61 void OnReceiveError(device::BluetoothSocket::ErrorReason reason,
62 const std::string& error_message);
64 // HostPairingController:
65 void AddObserver(Observer* observer) override;
66 void RemoveObserver(Observer* observer) override;
67 Stage GetCurrentStage() override;
68 void StartPairing() override;
69 std::string GetDeviceName() override;
70 std::string GetConfirmationCode() override;
71 std::string GetEnrollmentDomain() override;
72 void OnUpdateStatusChanged(UpdateStatus update_status) override;
73 void OnEnrollmentStatusChanged(EnrollmentStatus enrollment_status) override;
74 void SetPermanentId(const std::string& permanent_id) override;
76 // ProtoDecoder::Observer:
77 void OnHostStatusMessage(const pairing_api::HostStatus& message) override;
78 void OnConfigureHostMessage(
79 const pairing_api::ConfigureHost& message) override;
80 void OnPairDevicesMessage(const pairing_api::PairDevices& message) override;
81 void OnCompleteSetupMessage(
82 const pairing_api::CompleteSetup& message) override;
83 void OnErrorMessage(const pairing_api::Error& message) override;
84 void OnAddNetworkMessage(const pairing_api::AddNetwork& message) override;
86 // BluetoothAdapter::Observer:
87 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
88 bool present) override;
90 // device::BluetoothDevice::PairingDelegate:
91 void RequestPinCode(device::BluetoothDevice* device) override;
92 void RequestPasskey(device::BluetoothDevice* device) override;
93 void DisplayPinCode(device::BluetoothDevice* device,
94 const std::string& pincode) override;
95 void DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) override;
96 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override;
97 void ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) override;
98 void AuthorizePairing(device::BluetoothDevice* device) override;
100 Stage current_stage_;
101 std::string device_name_;
102 std::string confirmation_code_;
103 std::string enrollment_domain_;
104 UpdateStatus update_status_;
105 EnrollmentStatus enrollment_status_;
106 std::string permanent_id_;
108 scoped_refptr<device::BluetoothAdapter> adapter_;
109 scoped_refptr<device::BluetoothSocket> service_socket_;
110 scoped_refptr<device::BluetoothSocket> controller_socket_;
111 scoped_ptr<ProtoDecoder> proto_decoder_;
113 base::ThreadChecker thread_checker_;
114 ObserverList<Observer> observers_;
115 base::WeakPtrFactory<BluetoothHostPairingController> ptr_factory_;
117 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingController);
120 } // namespace pairing_chromeos
122 #endif // CHROMEOS_PAIRING_BLUETOOTH_HOST_PAIRING_CONTROLLER_H_