Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 #include <vector> |
| 10 | |
| 11 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 11 #include "base/macros.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" | |
| 12 #include "chrome/browser/chromeos/login/screens/base_screen.h" | 17 #include "chrome/browser/chromeos/login/screens/base_screen.h" |
| 13 #include "chrome/browser/chromeos/login/screens/hid_detection_screen_actor.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" | |
| 14 | 24 |
| 15 namespace chromeos { | 25 namespace chromeos { |
| 16 | 26 |
| 27 class HIDDetectionView; | |
| 28 | |
| 17 // Representation independent class that controls screen showing warning about | 29 // Representation independent class that controls screen showing warning about |
| 18 // HID absence to users. | 30 // HID absence to users. |
| 19 class HIDDetectionScreen : public BaseScreen, | 31 class HIDDetectionScreen : public HIDDetectionModel, |
| 20 public HIDDetectionScreenActor::Delegate { | 32 public device::BluetoothAdapter::Observer, |
| 33 public device::BluetoothDevice::PairingDelegate, | |
| 34 public InputServiceProxy::Observer { | |
| 21 public: | 35 public: |
| 36 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; | |
| 37 | |
| 38 class Delegate { | |
| 39 public: | |
| 40 virtual ~Delegate() {} | |
| 41 virtual void OnHIDScreenNecessityCheck(bool screen_needed) = 0; | |
| 42 }; | |
| 43 | |
| 22 HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate, | 44 HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate, |
| 23 HIDDetectionScreenActor* actor); | 45 HIDDetectionView* view); |
| 24 ~HIDDetectionScreen() override; | 46 ~HIDDetectionScreen() override; |
| 25 | 47 |
| 26 // BaseScreen implementation: | 48 // HIDDetectionModel implementation: |
| 27 void PrepareToShow() override; | 49 void PrepareToShow() override; |
| 28 void Show() override; | 50 void Show() override; |
| 29 void Hide() override; | 51 void Hide() override; |
| 30 std::string GetName() const override; | 52 void Initialize(::login::ScreenContext* context) override; |
| 31 | 53 void OnContinueButtonClicked() override; |
| 32 // HIDDetectionScreenActor::Delegate implementation: | 54 void OnViewDestroyed(HIDDetectionView* view) override; |
| 33 void OnExit() override; | 55 void CheckIsScreenRequired( |
| 34 void OnActorDestroyed(HIDDetectionScreenActor* actor) override; | 56 const base::Callback<void(bool)>& on_check_done) override; |
| 57 | |
| 58 // device::BluetoothDevice::PairingDelegate implementation: | |
| 59 void RequestPinCode(device::BluetoothDevice* device) override; | |
|
Denis Kuznetsov (DE-MUC)
2015/02/03 13:31:42
Please use consistent naming across CL: Pincode vs
merkulova
2015/02/03 14:41:01
Done.
| |
| 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; | |
| 69 | |
| 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; | |
| 79 | |
| 80 // InputServiceProxy::Observer implementation. | |
| 81 void OnInputDeviceAdded(const InputDeviceInfo& info) override; | |
| 82 void OnInputDeviceRemoved(const std::string& id) override; | |
| 35 | 83 |
| 36 private: | 84 private: |
| 37 HIDDetectionScreenActor* actor_; | 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, | |
| 89 | |
| 90 // Only keyboard detected, user pressed 'Continue'. | |
| 91 KEYBOARD_DEVICE_ONLY_DETECTED, | |
| 92 | |
| 93 // All devices detected. | |
| 94 All_DEVICES_DETECTED, | |
| 95 | |
| 96 // Must be last enum element. | |
| 97 CONTINUE_SCENARIO_TYPE_SIZE | |
| 98 }; | |
| 99 | |
| 100 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
| 101 | |
| 102 void StartBTDiscoverySession(); | |
| 103 | |
| 104 // Updates internal state and UI (if ready) using list of connected devices. | |
| 105 void ProcessConnectedDevicesList( | |
| 106 const std::vector<InputDeviceInfo>& devices); | |
| 107 | |
| 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(); | |
| 111 | |
| 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); | |
| 117 | |
| 118 // Processes list of input devices returned by InputServiceProxy on regular | |
| 119 // request. | |
| 120 void OnGetInputDevicesList(const std::vector<InputDeviceInfo>& devices); | |
| 121 | |
| 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(); | |
| 126 | |
| 127 // Tries to connect some BT devices if no type-appropriate devices are | |
| 128 // connected. | |
| 129 void UpdateBTDevices(); | |
| 130 | |
| 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); | |
| 135 | |
| 136 // Called by device::BluetoothAdapter in response to a failure to | |
| 137 // initiate a discovery session. | |
| 138 void FindDevicesError(); | |
| 139 | |
| 140 // Called by device::BluetoothAdapter in response to a failure to | |
| 141 // power BT adapter. | |
| 142 void SetPoweredError(); | |
| 143 | |
| 144 // Called by device::BluetoothAdapter in response to a failure to | |
| 145 // power off BT adapter. | |
| 146 void SetPoweredOffError(); | |
| 147 | |
| 148 // Tries to connect given BT device as pointing one. | |
| 149 void TryPairingAsPointingDevice(device::BluetoothDevice* device); | |
| 150 | |
| 151 // Tries to connect given BT device as keyboard. | |
| 152 void TryPairingAsKeyboardDevice(device::BluetoothDevice* device); | |
| 153 | |
| 154 // Tries to connect given BT device. | |
| 155 void ConnectBTDevice(device::BluetoothDevice* device); | |
| 156 | |
| 157 // Called by device::BluetoothDevice on a successful pairing and connection | |
| 158 // to a device. | |
| 159 void BTConnected(device::BluetoothDevice::DeviceType device_type); | |
| 160 | |
| 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); | |
| 167 | |
| 168 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 169 // pointing device. | |
| 170 void SendPointingDeviceNotification(); | |
| 171 | |
| 172 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 173 // keyboard device. | |
| 174 void SendKeyboardDeviceNotification(); | |
| 175 | |
| 176 // Helper method. Sets device name or placeholder if the name is empty. | |
| 177 void SetKeyboardDeviceName_(std::string name); | |
| 178 | |
| 179 | |
| 180 HIDDetectionView* view_; | |
| 181 | |
| 182 // Default bluetooth adapter, used for all operations. | |
| 183 scoped_refptr<device::BluetoothAdapter> adapter_; | |
| 184 | |
| 185 InputServiceProxy input_service_proxy_; | |
| 186 | |
| 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_; | |
| 191 | |
| 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_; | |
| 196 | |
| 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_; | |
| 202 | |
| 203 // State of BT adapter before screen-initiated changes. | |
| 204 scoped_ptr<bool> adapter_initially_powered_; | |
| 205 | |
| 206 bool switch_on_adapter_when_ready_; | |
| 207 | |
| 208 bool showing_; | |
| 209 | |
| 210 base::WeakPtrFactory<HIDDetectionScreen> weak_ptr_factory_; | |
| 38 | 211 |
| 39 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreen); | 212 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreen); |
| 40 }; | 213 }; |
| 41 | 214 |
| 42 } // namespace chromeos | 215 } // namespace chromeos |
| 43 | 216 |
| 44 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ | 217 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_HID_DETECTION_SCREEN_H_ |
| OLD | NEW |