Reenable NullOpenerRedirectForksProcess, as the offending patch has been reverted
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_agent_service_provider.h
blobfbf4dacccf69a69cc9594dc18456c299e2426aab
1 // Copyright (c) 2012 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_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "dbus/bus.h"
14 #include "dbus/object_path.h"
16 namespace chromeos {
18 // BluetoothAgentServiceProvider is used to provide a D-Bus object that BlueZ
19 // can communicate with during a remote device pairing request.
21 // Instantiate with a chosen D-Bus object path and delegate object, and pass
22 // the D-Bus object path as the |agent_path| argument to the
23 // chromeos::BluetoothAdapterClient::CreatePairedDevice() method. Calls made
24 // to the agent by the Bluetooth daemon will be passed on to your Delegate
25 // object for handling, and responses returned using the callbacks supplied
26 // to those methods.
27 class CHROMEOS_EXPORT BluetoothAgentServiceProvider {
28 public:
29 // Interface for reacting to agent requests.
30 class Delegate {
31 public:
32 virtual ~Delegate() {}
34 // Possible status values that may be returned to callbacks. Success
35 // indicates that a pincode or passkey has been obtained, or permission
36 // granted; rejected indicates the user rejected the request or denied
37 // permission; cancelled indicates the user cancelled the request
38 // without confirming either way.
39 enum Status {
40 SUCCESS,
41 REJECTED,
42 CANCELLED
45 // Possible values for the |mode| parameter of the ConfirmModeChange()
46 // method. Off indicates that the adapter is to be turned off, connectable
47 // indicates that the adapter is to be turned on and accept incoming
48 // connections, and discoverable indicates the adapter is to be turned
49 // on and discoverable by remote devices.
50 enum Mode {
51 OFF,
52 CONNECTABLE,
53 DISCOVERABLE
56 // The PinCodeCallback is used for the RequestPinCode() method, it should
57 // be called with two arguments, the |status| of the request (success,
58 // rejected or cancelled) and the |pincode| requested.
59 typedef base::Callback<void(Status, const std::string&)> PinCodeCallback;
61 // The PasskeyCallback is used for the RequestPasskey() method, it should
62 // be called with two arguments, the |status| of the request (success,
63 // rejected or cancelled) and the |passkey| requested, a numeric in the
64 // range 0-999999,
65 typedef base::Callback<void(Status, uint32)> PasskeyCallback;
67 // The ConfirmationCallback is used for methods which request confirmation
68 // or authorization, it should be called with one argument, the |status|
69 // of the request (success, rejected or cancelled).
70 typedef base::Callback<void(Status)> ConfirmationCallback;
72 // This method will be called when the agent is unregistered from the
73 // Bluetooth daemon, generally at the end of a pairing request. It may be
74 // used to perform cleanup tasks.
75 virtual void Release() = 0;
77 // This method will be called when the Bluetooth daemon requires a
78 // PIN Code for authentication of the device with object path |device_path|,
79 // the agent should obtain the code from the user and call |callback|
80 // to provide it, or indicate rejection or cancellation of the request.
82 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
83 // for which there is no automatic pairing or special handling.
84 virtual void RequestPinCode(const dbus::ObjectPath& device_path,
85 const PinCodeCallback& callback) = 0;
87 // This method will be called when the Bluetooth daemon requires a
88 // Passkey for authentication of the device with object path |device_path|,
89 // the agent should obtain the passkey from the user (a numeric in the
90 // range 0-999999) and call |callback| to provide it, or indicate
91 // rejection or cancellation of the request.
93 // Passkeys are generally required for Bluetooth 2.1 and later devices
94 // which cannot provide input or display on their own, and don't accept
95 // passkey-less pairing.
96 virtual void RequestPasskey(const dbus::ObjectPath& device_path,
97 const PasskeyCallback& callback) = 0;
99 // This method will be called when the Bluetooth daemon requires that the
100 // user enter the PIN code |pincode| into the device with object path
101 // |device_path| so that it may be authenticated. The Cancel() method
102 // will be called to dismiss the display once pairing is complete or
103 // cancelled.
105 // This is used for Bluetooth 2.0 and earlier keyboard devices, the
106 // |pincode| will always be a six-digit numeric in the range 000000-999999
107 // for compatibilty with later specifications.
108 virtual void DisplayPinCode(const dbus::ObjectPath& device_path,
109 const std::string& pincode) = 0;
111 // This method will be called when the Bluetooth daemon requires that the
112 // user enter the Passkey |passkey| into the device with object path
113 // |device_path| so that it may be authenticated. The Cancel() method
114 // will be called to dismiss the display once pairing is complete or
115 // cancelled.
117 // This is used for Bluetooth 2.1 and later devices that support input
118 // but not display, such as keyboards. The Passkey is a numeric in the
119 // range 0-999999 and should be always presented zero-padded to six
120 // digits.
121 virtual void DisplayPasskey(const dbus::ObjectPath& device_path,
122 uint32 passkey) = 0;
124 // This method will be called when the Bluetooth daemon requires that the
125 // user confirm that the Passkey |passkey| is displayed on the screen
126 // of the device with object path |object_path| so that it may be
127 // authenticated. The agent should display to the user and ask for
128 // confirmation, then call |callback| to provide their response (success,
129 // rejected or cancelled).
131 // This is used for Bluetooth 2.1 and later devices that support display,
132 // such as other computers or phones. The Passkey is a numeric in the
133 // range 0-999999 and should be always present zero-padded to six
134 // digits.
135 virtual void RequestConfirmation(const dbus::ObjectPath& device_path,
136 uint32 passkey,
137 const ConfirmationCallback& callback) = 0;
139 // This method will be called when the Bluetooth daemon requires that the
140 // user confirm that the device with object path |object_path| is
141 // authorized to connect to the service with UUID |uuid|. The agent should
142 // confirm with the user and call |callback| to provide their response
143 // (success, rejected or cancelled).
144 virtual void Authorize(const dbus::ObjectPath& device_path,
145 const std::string& uuid,
146 const ConfirmationCallback& callback) = 0;
148 // This method will be called when the Bluetooth daemon requires that the
149 // user confirm that the device adapter may switch to mode |mode|. The
150 // agent should confirm with the user and call |callback| to provide
151 // their response (success, rejected or cancelled).
152 virtual void ConfirmModeChange(Mode mode,
153 const ConfirmationCallback& callback) = 0;
155 // This method will be called by the Bluetooth daemon to indicate that
156 // the request failed before a reply was returned from the device.
157 virtual void Cancel() = 0;
160 virtual ~BluetoothAgentServiceProvider();
162 // Creates the instance where |bus| is the D-Bus bus connection to export
163 // the object onto, |object_path| is the object path that it should have
164 // and |delegate| is the object to which all method calls will be passed
165 // and responses generated from.
166 static BluetoothAgentServiceProvider* Create(
167 dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate);
169 protected:
170 BluetoothAgentServiceProvider();
172 private:
173 DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProvider);
176 } // namespace chromeos
178 #endif // CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_