Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / hid_detection_screen.h
blobdf2c7036ad27774895e1c093c68bc179cf081e49
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 CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/chromeos/device/input_service_proxy.h"
17 #include "chrome/browser/chromeos/login/screens/base_screen.h"
18 #include "chrome/browser/chromeos/login/screens/hid_detection_model.h"
19 #include "components/login/screens/screen_context.h"
20 #include "device/bluetooth/bluetooth_adapter.h"
21 #include "device/bluetooth/bluetooth_device.h"
22 #include "device/bluetooth/bluetooth_discovery_session.h"
23 #include "device/hid/input_service_linux.h"
25 namespace chromeos {
27 class HIDDetectionView;
29 // Representation independent class that controls screen showing warning about
30 // HID absence to users.
31 class HIDDetectionScreen : public HIDDetectionModel,
32 public device::BluetoothAdapter::Observer,
33 public device::BluetoothDevice::PairingDelegate,
34 public InputServiceProxy::Observer {
35 public:
36 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo;
38 class Delegate {
39 public:
40 virtual ~Delegate() {}
41 virtual void OnHIDScreenNecessityCheck(bool screen_needed) = 0;
44 HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate,
45 HIDDetectionView* view);
46 ~HIDDetectionScreen() override;
48 // HIDDetectionModel implementation:
49 void PrepareToShow() override;
50 void Show() override;
51 void Hide() override;
52 void Initialize(::login::ScreenContext* context) override;
53 void OnContinueButtonClicked() override;
54 void OnViewDestroyed(HIDDetectionView* view) override;
55 void CheckIsScreenRequired(
56 const base::Callback<void(bool)>& on_check_done) override;
58 // device::BluetoothDevice::PairingDelegate implementation:
59 void RequestPinCode(device::BluetoothDevice* device) override;
60 void RequestPasskey(device::BluetoothDevice* device) override;
61 void DisplayPinCode(device::BluetoothDevice* device,
62 const std::string& pincode) override;
63 void DisplayPasskey(
64 device::BluetoothDevice* device, uint32 passkey) override;
65 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override;
66 void ConfirmPasskey(
67 device::BluetoothDevice* device, uint32 passkey) override;
68 void AuthorizePairing(device::BluetoothDevice* device) override;
70 // device::BluetoothAdapter::Observer implementation.
71 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
72 bool present) override;
73 void DeviceAdded(device::BluetoothAdapter* adapter,
74 device::BluetoothDevice* device) override;
75 void DeviceChanged(device::BluetoothAdapter* adapter,
76 device::BluetoothDevice* device) override;
77 void DeviceRemoved(device::BluetoothAdapter* adapter,
78 device::BluetoothDevice* device) override;
80 // InputServiceProxy::Observer implementation.
81 void OnInputDeviceAdded(const InputDeviceInfo& info) override;
82 void OnInputDeviceRemoved(const std::string& id) override;
84 private:
85 // Types of dialog leaving scenarios for UMA metric.
86 enum ContinueScenarioType {
87 // Only pointing device detected, user pressed 'Continue'.
88 POINTING_DEVICE_ONLY_DETECTED,
90 // Only keyboard detected, user pressed 'Continue'.
91 KEYBOARD_DEVICE_ONLY_DETECTED,
93 // All devices detected.
94 All_DEVICES_DETECTED,
96 // Must be last enum element.
97 CONTINUE_SCENARIO_TYPE_SIZE
100 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
102 void StartBTDiscoverySession();
104 // Updates internal state and UI (if ready) using list of connected devices.
105 void ProcessConnectedDevicesList(
106 const std::vector<InputDeviceInfo>& devices);
108 // Checks for lack of mouse or keyboard. If found starts BT devices update.
109 // Initiates BTAdapter if it's not active and BT devices update required.
110 void TryInitiateBTDevicesUpdate();
112 // Processes list of input devices returned by InputServiceProxy on the check
113 // request. Calls the callback that expects true if screen is required.
114 void OnGetInputDevicesListForCheck(
115 const base::Callback<void(bool)>& on_check_done,
116 const std::vector<InputDeviceInfo>& devices);
118 // Processes list of input devices returned by InputServiceProxy on regular
119 // request.
120 void OnGetInputDevicesList(const std::vector<InputDeviceInfo>& devices);
122 // Called for revision of active devices. If current-placement is available
123 // for mouse or keyboard device, sets one of active devices as current or
124 // tries to connect some BT device if no appropriate devices are connected.
125 void UpdateDevices();
127 // Tries to connect some BT devices if no type-appropriate devices are
128 // connected.
129 void UpdateBTDevices();
131 // Called by device::BluetoothAdapter in response to a successful request
132 // to initiate a discovery session.
133 void OnStartDiscoverySession(
134 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
136 // Called by device::BluetoothAdapter in response to a failure to
137 // initiate a discovery session.
138 void FindDevicesError();
140 // Called by device::BluetoothAdapter in response to a failure to
141 // power BT adapter.
142 void SetPoweredError();
144 // Called by device::BluetoothAdapter in response to a failure to
145 // power off BT adapter.
146 void SetPoweredOffError();
148 // Tries to connect given BT device as pointing one.
149 void TryPairingAsPointingDevice(device::BluetoothDevice* device);
151 // Tries to connect given BT device as keyboard.
152 void TryPairingAsKeyboardDevice(device::BluetoothDevice* device);
154 // Tries to connect given BT device.
155 void ConnectBTDevice(device::BluetoothDevice* device);
157 // Called by device::BluetoothDevice on a successful pairing and connection
158 // to a device.
159 void BTConnected(device::BluetoothDevice::DeviceType device_type);
161 // Called by device::BluetoothDevice in response to a failure to
162 // connect to the device with bluetooth address |address| due to an error
163 // encoded in |error_code|.
164 void BTConnectError(const std::string& address,
165 device::BluetoothDevice::DeviceType device_type,
166 device::BluetoothDevice::ConnectErrorCode error_code);
168 // Sends a notification to the Web UI of the status of available Bluetooth/USB
169 // pointing device.
170 void SendPointingDeviceNotification();
172 // Sends a notification to the Web UI of the status of available Bluetooth/USB
173 // keyboard device.
174 void SendKeyboardDeviceNotification();
176 // Helper method. Sets device name or placeholder if the name is empty.
177 void SetKeyboardDeviceName_(std::string name);
180 HIDDetectionView* view_;
182 // Default bluetooth adapter, used for all operations.
183 scoped_refptr<device::BluetoothAdapter> adapter_;
185 InputServiceProxy input_service_proxy_;
187 // The current device discovery session. Only one active discovery session is
188 // kept at a time and the instance that |discovery_session_| points to gets
189 // replaced by a new one when a new discovery session is initiated.
190 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_;
192 // Current pointing device, if any. Device name is kept in screen context.
193 std::string pointing_device_id_;
194 bool mouse_is_pairing_;
195 InputDeviceInfo::Type pointing_device_connect_type_;
197 // Current keyboard device, if any. Device name is kept in screen context.
198 std::string keyboard_device_id_;
199 bool keyboard_is_pairing_;
200 InputDeviceInfo::Type keyboard_device_connect_type_;
201 std::string keyboard_device_name_;
203 // State of BT adapter before screen-initiated changes.
204 scoped_ptr<bool> adapter_initially_powered_;
206 bool switch_on_adapter_when_ready_;
208 bool showing_;
210 base::WeakPtrFactory<HIDDetectionScreen> weak_ptr_factory_;
212 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreen);
215 } // namespace chromeos
217 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_