Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / bluetooth_options_handler.h
blobe82b3716056d720d5447455bae9e5c554390bf7a
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 CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/ui/webui/options/options_ui.h"
15 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_device.h"
17 #include "device/bluetooth/bluetooth_discovery_session.h"
19 namespace base {
20 class DictionaryValue;
23 namespace chromeos {
24 namespace options {
26 // Handler for Bluetooth options on the system options page.
27 class BluetoothOptionsHandler
28 : public ::options::OptionsPageUIHandler,
29 public device::BluetoothAdapter::Observer,
30 public device::BluetoothDevice::PairingDelegate {
31 public:
32 BluetoothOptionsHandler();
33 ~BluetoothOptionsHandler() override;
35 // OptionsPageUIHandler implementation.
36 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
37 void RegisterMessages() override;
38 void InitializeHandler() override;
39 void InitializePage() override;
41 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
43 // Sends a notification to the Web UI of the status of a Bluetooth device.
44 // |device| is the Bluetooth device.
45 // |params| is an optional set of parameters.
46 void SendDeviceNotification(const device::BluetoothDevice* device,
47 base::DictionaryValue* params);
49 // device::BluetoothDevice::PairingDelegate override.
51 // This method will be called when the Bluetooth daemon requires a
52 // PIN Code for authentication of the device |device|, the UI will display
53 // a blank entry form to obtain the PIN code from the user.
55 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
56 // for which there is no automatic pairing or special handling.
57 void RequestPinCode(device::BluetoothDevice* device) override;
59 // device::BluetoothDevice::PairingDelegate override.
61 // This method will be called when the Bluetooth daemon requires a
62 // Passkey for authentication of the device |device|, the UI will display
63 // a blank entry form to obtain the passkey from the user (a numeric in the
64 // range 0-999999).
66 // Passkeys are generally required for Bluetooth 2.1 and later devices
67 // which cannot provide input or display on their own, and don't accept
68 // passkey-less pairing.
69 void RequestPasskey(device::BluetoothDevice* device) override;
71 // device::BluetoothDevice::PairingDelegate override.
73 // This method will be called when the Bluetooth daemon requires that the
74 // user enter the PIN code |pincode| into the device |device| so that it
75 // may be authenticated, the UI will display the PIN code with accompanying
76 // instructions.
78 // This is used for Bluetooth 2.0 and earlier keyboard devices, the
79 // |pincode| will always be a six-digit numeric in the range 000000-999999
80 // for compatibilty with later specifications.
81 void DisplayPinCode(device::BluetoothDevice* device,
82 const std::string& pincode) override;
84 // device::BluetoothDevice::PairingDelegate override.
86 // This method will be called when the Bluetooth daemon requires that the
87 // user enter the Passkey |passkey| into the device |device| so that it
88 // may be authenticated, the UI will display the passkey with accompanying
89 // instructions.
91 // This is used for Bluetooth 2.1 and later devices that support input
92 // but not display, such as keyboards. The Passkey is a numeric in the
93 // range 0-999999 and should be always presented zero-padded to six
94 // digits.
95 void DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) override;
97 // device::BluetoothDevice::PairingDelegate override.
99 // This method will be called when the Bluetooth daemon gets a notification
100 // of a key entered on the device |device| while pairing with the device
101 // using a PIN code or a Passkey.
103 // The UI will show a visual indication that a given key was pressed in the
104 // same pairing overlay where the PIN code or Passkey is displayed.
106 // A first call with |entered| as 0 will indicate that this notification
107 // mechanism is supported by the device allowing the UI to display this fact.
108 // A last call with |entered| as the length of the key plus one will indicate
109 // that the [enter] key was pressed.
110 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override;
112 // device::BluetoothDevice::PairingDelegate override.
114 // This method will be called when the Bluetooth daemon requires that the
115 // user confirm that the Passkey |passkey| is displayed on the screen
116 // of the device |device| so that it may be authenticated, the UI will
117 // display the passkey with accompanying instructions.
119 // This is used for Bluetooth 2.1 and later devices that support display,
120 // such as other computers or phones. The Passkey is a numeric in the
121 // range 0-999999 and should be always present zero-padded to six
122 // digits.
123 void ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) override;
125 // device::BluetoothDevice::PairingDelegate override.
126 void AuthorizePairing(device::BluetoothDevice* device) override;
128 // Displays a Bluetooth error.
129 // |error| maps to a localized resource for the error message.
130 // |address| is the address of the Bluetooth device. May be an empty
131 // string if the error is not specific to a single device.
132 void ReportError(const std::string& error, const std::string& address);
134 // device::BluetoothAdapter::Observer implementation.
135 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
136 bool present) override;
137 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
138 bool powered) override;
139 void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter,
140 bool discovering) override;
141 void DeviceAdded(device::BluetoothAdapter* adapter,
142 device::BluetoothDevice* device) override;
143 void DeviceChanged(device::BluetoothAdapter* adapter,
144 device::BluetoothDevice* device) override;
145 void DeviceRemoved(device::BluetoothAdapter* adapter,
146 device::BluetoothDevice* device) override;
148 private:
149 // Displays in the UI a connecting to the device |device| message.
150 void DeviceConnecting(device::BluetoothDevice* device);
152 // Called by device::BluetoothAdapter in response to a failure to
153 // change the power status of the adapter.
154 void EnableChangeError();
156 // Called by device::BluetoothAdapter in response to a successful request
157 // to initiate a discovery session.
158 void OnStartDiscoverySession(
159 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
161 // Called by device::BluetoothAdapter in response to a failure to
162 // initiate a discovery session.
163 void FindDevicesError();
165 // Called by device::BluetoothAdapter in response to a failure to
166 // terminate a discovery session.
167 void StopDiscoveryError();
169 // Called by device::BluetoothDevice on a successful pairing and connection
170 // to a device.
171 void Connected();
173 // Called by device::BluetoothDevice in response to a failure to
174 // connect to the device with bluetooth address |address| due to an error
175 // encoded in |error_code|.
176 void ConnectError(const std::string& address,
177 device::BluetoothDevice::ConnectErrorCode error_code);
179 // Called by device::BluetoothDevice in response to a failure to
180 // disconnect the device with bluetooth address |address|.
181 void DisconnectError(const std::string& address);
183 // Called by device::BluetoothDevice in response to a failure to
184 // disconnect and unpair the device with bluetooth address |address|.
185 void ForgetError(const std::string& address);
187 // Called when the 'Enable bluetooth' checkbox value is changed.
188 // |args| will contain the checkbox checked state as a string
189 // ("true" or "false").
190 void EnableChangeCallback(const base::ListValue* args);
192 // Called when the 'Find Devices' button is pressed from the Bluetooth
193 // ssettings.
194 // |args| will be an empty list.
195 void FindDevicesCallback(const base::ListValue* args);
197 // Called when the user requests to connect to or disconnect from a Bluetooth
198 // device.
199 // |args| will be a list containing two or three arguments, the first argument
200 // is the device ID and the second is the requested action. If a third
201 // argument is present, it is the passkey for pairing confirmation.
202 void UpdateDeviceCallback(const base::ListValue* args);
204 // Called when the "Add a device" dialog closes to stop the discovery
205 // process.
206 // |args| will be an empty list.
207 void StopDiscoveryCallback(const base::ListValue* args);
209 // Called when the list of paired devices is initialized in order to
210 // populate the list.
211 // |args| will be an empty list.
212 void GetPairedDevicesCallback(const base::ListValue* args);
214 // Default bluetooth adapter, used for all operations.
215 scoped_refptr<device::BluetoothAdapter> adapter_;
217 // True, if the UI has requested device discovery. False, if either no device
218 // discovery was requested or the dialog responsible for device discovery was
219 // dismissed.
220 bool should_run_device_discovery_;
222 // The current device discovery session. Only one active discovery session is
223 // kept at a time and the instance that |discovery_session_| points to gets
224 // replaced by a new one when a new discovery session is initiated.
225 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_;
227 // Cached information about the current pairing device, if any.
228 std::string pairing_device_address_;
229 std::string pairing_device_pairing_;
230 std::string pairing_device_pincode_;
231 int pairing_device_passkey_;
232 int pairing_device_entered_;
234 // Weak pointer factory for generating 'this' pointers that might live longer
235 // than this object does.
236 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_;
238 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler);
241 } // namespace options
242 } // namespace chromeos
244 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_