Extensions: Store disable reasons in Sync
[chromium-blink-merge.git] / device / bluetooth / bluetooth_pairing_chromeos.h
blobb50a328eed564e0ecad837be55f6a81ba0bdbde5
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 DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_
8 #include "chromeos/dbus/bluetooth_agent_service_provider.h"
9 #include "device/bluetooth/bluetooth_device.h"
11 namespace chromeos {
13 class BluetoothDeviceChromeOS;
15 // The BluetoothPairingChromeOS class encapsulates the logic for an individual
16 // device pairing, acting as a bridge between BluetoothAdapterChromeOS which
17 // communicates with the underlying Controller and Host Subsystem, and
18 // BluetoothDeviceChromeOS which presents the pairing logic to the application.
19 class BluetoothPairingChromeOS {
20 public:
21 BluetoothPairingChromeOS(
22 BluetoothDeviceChromeOS* device,
23 device::BluetoothDevice::PairingDelegate* pairing_delegate);
24 ~BluetoothPairingChromeOS();
26 // Indicates whether the device is currently pairing and expecting a
27 // Passkey to be returned.
28 bool ExpectingPasskey() const;
30 // Indicates whether the device is currently pairing and expecting
31 // confirmation of a displayed passkey.
32 bool ExpectingConfirmation() const;
34 // Requests a PIN code for the current device from the current pairing
35 // delegate, the SetPinCode(), RejectPairing() and CancelPairing() method
36 // calls on this object are translated into the appropriate response to
37 // |callback|.
38 void RequestPinCode(
39 const BluetoothAgentServiceProvider::Delegate::PinCodeCallback& callback);
41 // Indicates whether the device is currently pairing and expecting a
42 // PIN Code to be returned.
43 bool ExpectingPinCode() const;
45 // Sends the PIN code |pincode| to the remote device during pairing.
47 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
48 // for which there is no automatic pairing or special handling.
49 void SetPinCode(const std::string& pincode);
51 // Requests a PIN code for the current device be displayed by the current
52 // pairing delegate. No response is expected from the delegate.
53 void DisplayPinCode(const std::string& pincode);
55 // Requests a Passkey for the current device from the current pairing
56 // delegate, the SetPasskey(), RejectPairing() and CancelPairing() method
57 // calls on this object are translated into the appropriate response to
58 // |callback|.
59 void RequestPasskey(
60 const BluetoothAgentServiceProvider::Delegate::PasskeyCallback& callback);
62 // Sends the Passkey |passkey| to the remote device during pairing.
64 // Passkeys are generally required for Bluetooth 2.1 and later devices
65 // which cannot provide input or display on their own, and don't accept
66 // passkey-less pairing, and are a numeric in the range 0-999999.
67 void SetPasskey(uint32 passkey);
69 // Requests a Passkey for the current device be displayed by the current
70 // pairing delegate. No response is expected from the delegate.
71 void DisplayPasskey(uint32 passkey);
73 // Informs the current pairing delegate that |entered| keys have been
74 // provided to the remote device since the DisplayPasskey() call. No
75 // response is expected from the delegate.
76 void KeysEntered(uint16 entered);
78 // Requests confirmation that |passkey| is displayed on the current device
79 // from the current pairing delegate. The ConfirmPairing(), RejectPairing()
80 // and CancelPairing() method calls on this object are translated into the
81 // appropriate response to |callback|.
82 void RequestConfirmation(
83 uint32 passkey,
84 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback&
85 callback);
87 // Requests authorization that the current device be allowed to pair with
88 // this device from the current pairing delegate. The ConfirmPairing(),
89 // RejectPairing() and CancelPairing() method calls on this object are
90 // translated into the appropriate response to |callback|.
91 void RequestAuthorization(
92 const BluetoothAgentServiceProvider::Delegate::ConfirmationCallback&
93 callback);
95 // Confirms to the remote device during pairing that a passkey provided by
96 // the ConfirmPasskey() delegate call is displayed on both devices.
97 void ConfirmPairing();
99 // Rejects a pairing or connection request from a remote device, returns
100 // false if there was no way to reject the pairing.
101 bool RejectPairing();
103 // Cancels a pairing or connection attempt to a remote device, returns
104 // false if there was no way to cancel the pairing.
105 bool CancelPairing();
107 // Returns the pairing delegate being used by this pairing object.
108 device::BluetoothDevice::PairingDelegate* GetPairingDelegate() const;
110 private:
111 // Internal method to reset the current set of callbacks because a new
112 // request has arrived that supersedes them.
113 void ResetCallbacks();
115 // Internal method to respond to the relevant callback for a RejectPairing
116 // or CancelPairing call.
117 bool RunPairingCallbacks(
118 BluetoothAgentServiceProvider::Delegate::Status status);
120 // The underlying BluetoothDeviceChromeOS that owns this pairing context.
121 BluetoothDeviceChromeOS* device_;
123 // UI Pairing Delegate to make method calls on, this must live as long as
124 // the object capturing the PairingContext.
125 device::BluetoothDevice::PairingDelegate* pairing_delegate_;
127 // Flag to indicate whether any pairing delegate method has been called
128 // during pairing. Used to determine whether we need to log the
129 // "no pairing interaction" metric.
130 bool pairing_delegate_used_;
132 // During pairing these callbacks are set to those provided by method calls
133 // made on the BluetoothAdapterChromeOS instance by its respective
134 // BluetoothAgentServiceProvider instance, and are called by our own
135 // method calls such as SetPinCode() and SetPasskey().
136 BluetoothAgentServiceProvider::Delegate::PinCodeCallback pincode_callback_;
137 BluetoothAgentServiceProvider::Delegate::PasskeyCallback passkey_callback_;
138 BluetoothAgentServiceProvider::Delegate::ConfirmationCallback
139 confirmation_callback_;
141 DISALLOW_COPY_AND_ASSIGN(BluetoothPairingChromeOS);
144 } // namespace chromeos
146 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PAIRING_CHROMEOS_H_