| 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_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/values.h" | 11 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/device/input_service_proxy.h" | 12 #include "chrome/browser/chromeos/login/screens/hid_detection_view.h" |
| 17 #include "chrome/browser/chromeos/login/screens/hid_detection_screen_actor.h" | |
| 18 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" | 13 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
| 19 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 20 #include "device/bluetooth/bluetooth_adapter.h" | |
| 21 #include "device/bluetooth/bluetooth_device.h" | |
| 22 #include "device/bluetooth/bluetooth_discovery_session.h" | |
| 23 | 15 |
| 24 namespace base { | 16 namespace base { |
| 25 class DictionaryValue; | 17 class DictionaryValue; |
| 26 } | 18 } |
| 27 | 19 |
| 28 namespace chromeos { | 20 namespace chromeos { |
| 29 | 21 |
| 30 class CoreOobeActor; | 22 class CoreOobeActor; |
| 31 | 23 |
| 32 // WebUI implementation of HIDDetectionScreenActor. | 24 // WebUI implementation of HIDDetectionScreenView. |
| 33 class HIDDetectionScreenHandler | 25 class HIDDetectionScreenHandler |
| 34 : public HIDDetectionScreenActor, | 26 : public HIDDetectionView, |
| 35 public BaseScreenHandler, | 27 public BaseScreenHandler { |
| 36 public device::BluetoothAdapter::Observer, | |
| 37 public device::BluetoothDevice::PairingDelegate, | |
| 38 public InputServiceProxy::Observer { | |
| 39 public: | 28 public: |
| 40 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; | |
| 41 | 29 |
| 42 explicit HIDDetectionScreenHandler(CoreOobeActor* core_oobe_actor); | 30 explicit HIDDetectionScreenHandler(CoreOobeActor* core_oobe_actor); |
| 43 ~HIDDetectionScreenHandler() override; | 31 ~HIDDetectionScreenHandler() override; |
| 44 | 32 |
| 45 // HIDDetectionScreenActor implementation: | 33 // HIDDetectionView implementation: |
| 34 void PrepareToShow() override; |
| 46 void Show() override; | 35 void Show() override; |
| 47 void Hide() override; | 36 void Hide() override; |
| 48 void SetDelegate(Delegate* delegate) override; | 37 void Bind(HIDDetectionModel& model) override; |
| 38 void Unbind() override; |
| 49 void CheckIsScreenRequired( | 39 void CheckIsScreenRequired( |
| 50 const base::Callback<void(bool)>& on_check_done) override; | 40 const base::Callback<void(bool)>& on_check_done) override; |
| 51 | 41 |
| 52 // BaseScreenHandler implementation: | 42 // BaseScreenHandler implementation: |
| 53 void DeclareLocalizedValues(LocalizedValuesBuilder* builder) override; | 43 void DeclareLocalizedValues(LocalizedValuesBuilder* builder) override; |
| 44 void DeclareJSCallbacks() override; |
| 54 void Initialize() override; | 45 void Initialize() override; |
| 55 | 46 |
| 56 // WebUIMessageHandler implementation: | |
| 57 void RegisterMessages() override; | |
| 58 | |
| 59 // device::BluetoothDevice::PairingDelegate implementation: | |
| 60 void RequestPinCode(device::BluetoothDevice* device) override; | |
| 61 void RequestPasskey(device::BluetoothDevice* device) override; | |
| 62 void DisplayPinCode(device::BluetoothDevice* device, | |
| 63 const std::string& pincode) override; | |
| 64 void DisplayPasskey(device::BluetoothDevice* device, uint32 passkey) override; | |
| 65 void KeysEntered(device::BluetoothDevice* device, uint32 entered) override; | |
| 66 void ConfirmPasskey(device::BluetoothDevice* device, uint32 passkey) override; | |
| 67 void AuthorizePairing(device::BluetoothDevice* device) override; | |
| 68 | |
| 69 // device::BluetoothAdapter::Observer implementation. | |
| 70 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | |
| 71 bool present) override; | |
| 72 void DeviceAdded(device::BluetoothAdapter* adapter, | |
| 73 device::BluetoothDevice* device) override; | |
| 74 void DeviceChanged(device::BluetoothAdapter* adapter, | |
| 75 device::BluetoothDevice* device) override; | |
| 76 void DeviceRemoved(device::BluetoothAdapter* adapter, | |
| 77 device::BluetoothDevice* device) override; | |
| 78 | |
| 79 // InputServiceProxy::Observer implementation. | |
| 80 void OnInputDeviceAdded(const InputDeviceInfo& info) override; | |
| 81 void OnInputDeviceRemoved(const std::string& id) override; | |
| 82 | |
| 83 // Registers the preference for derelict state. | 47 // Registers the preference for derelict state. |
| 84 static void RegisterPrefs(PrefRegistrySimple* registry); | 48 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 85 | 49 |
| 86 private: | 50 private: |
| 87 // Types of dialog leaving scenarios for UMA metric. | |
| 88 enum ContinueScenarioType { | |
| 89 // Only pointing device detected, user pressed 'Continue'. | |
| 90 POINTING_DEVICE_ONLY_DETECTED, | |
| 91 | |
| 92 // Only keyboard detected, user pressed 'Continue'. | |
| 93 KEYBOARD_DEVICE_ONLY_DETECTED, | |
| 94 | |
| 95 // All devices detected. | |
| 96 All_DEVICES_DETECTED, | |
| 97 | |
| 98 // Must be last enum element. | |
| 99 CONTINUE_SCENARIO_TYPE_SIZE | |
| 100 }; | |
| 101 | |
| 102 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
| 103 | |
| 104 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 105 // pointing device. | |
| 106 void SendPointingDeviceNotification(); | |
| 107 | |
| 108 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 109 // keyboard device. | |
| 110 void SendKeyboardDeviceNotification(base::DictionaryValue* params); | |
| 111 | |
| 112 // Updates internal state and UI (if ready) using list of connected devices. | |
| 113 void ProcessConnectedDevicesList(const std::vector<InputDeviceInfo>& devices); | |
| 114 | |
| 115 // Checks for lack of mouse or keyboard. If found starts BT devices update. | |
| 116 // Initiates BTAdapter if it's not active and BT devices update required. | |
| 117 void TryInitiateBTDevicesUpdate(); | |
| 118 | |
| 119 // Processes list of input devices returned by InputServiceProxy on the check | |
| 120 // request. Calls the callback that expects true if screen is required. | |
| 121 void OnGetInputDevicesListForCheck( | |
| 122 const base::Callback<void(bool)>& on_check_done, | |
| 123 const std::vector<InputDeviceInfo>& devices); | |
| 124 | |
| 125 // Processes list of input devices returned by InputServiceProxy on regular | |
| 126 // request. | |
| 127 void OnGetInputDevicesList(const std::vector<InputDeviceInfo>& devices); | |
| 128 | |
| 129 void StartBTDiscoverySession(); | |
| 130 | |
| 131 // Called by device::BluetoothDevice on a successful pairing and connection | |
| 132 // to a device. | |
| 133 void BTConnected(device::BluetoothDevice::DeviceType device_type); | |
| 134 | |
| 135 // Called by device::BluetoothDevice in response to a failure to | |
| 136 // connect to the device with bluetooth address |address| due to an error | |
| 137 // encoded in |error_code|. | |
| 138 void BTConnectError(const std::string& address, | |
| 139 device::BluetoothDevice::DeviceType device_type, | |
| 140 device::BluetoothDevice::ConnectErrorCode error_code); | |
| 141 | |
| 142 // JS messages handlers. | 51 // JS messages handlers. |
| 143 void HandleOnContinue(); | 52 void HandleOnContinue(); |
| 144 | 53 |
| 145 Delegate* delegate_; | 54 HIDDetectionModel* model_; |
| 146 | 55 |
| 147 CoreOobeActor* core_oobe_actor_; | 56 CoreOobeActor* core_oobe_actor_; |
| 148 | 57 |
| 149 // Keeps whether screen should be shown right after initialization. | 58 // Keeps whether screen should be shown right after initialization. |
| 150 bool show_on_init_; | 59 bool show_on_init_; |
| 151 | 60 |
| 152 // Displays in the UI a connecting to the device |device| message. | |
| 153 void DeviceConnecting(device::BluetoothDevice* device); | |
| 154 | |
| 155 // Called by device::BluetoothAdapter in response to a successful request | |
| 156 // to initiate a discovery session. | |
| 157 void OnStartDiscoverySession( | |
| 158 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | |
| 159 | |
| 160 // Called by device::BluetoothAdapter in response to a failure to | |
| 161 // initiate a discovery session. | |
| 162 void FindDevicesError(); | |
| 163 | |
| 164 // Called by device::BluetoothAdapter in response to a failure to | |
| 165 // power BT adapter. | |
| 166 void SetPoweredError(); | |
| 167 | |
| 168 // Called by device::BluetoothAdapter in response to a failure to | |
| 169 // power off BT adapter. | |
| 170 void SetPoweredOffError(); | |
| 171 | |
| 172 // Called for revision of active devices. If current-placement is available | |
| 173 // for mouse or keyboard device, sets one of active devices as current or | |
| 174 // tries to connect some BT device if no appropriate devices are connected. | |
| 175 void UpdateDevices(); | |
| 176 | |
| 177 // Tries to connect some BT devices if no type-appropriate devices are | |
| 178 // connected. | |
| 179 void UpdateBTDevices(); | |
| 180 | |
| 181 // Tries to connect given BT device. | |
| 182 void ConnectBTDevice(device::BluetoothDevice* device); | |
| 183 | |
| 184 // Tries to connect given BT device as pointing one. | |
| 185 void TryPairingAsPointingDevice(device::BluetoothDevice* device); | |
| 186 | |
| 187 // Tries to connect given BT device as keyboard. | |
| 188 void TryPairingAsKeyboardDevice(device::BluetoothDevice* device); | |
| 189 | |
| 190 // Default bluetooth adapter, used for all operations. | |
| 191 scoped_refptr<device::BluetoothAdapter> adapter_; | |
| 192 | |
| 193 InputServiceProxy input_service_proxy_; | |
| 194 | |
| 195 // The current device discovery session. Only one active discovery session is | |
| 196 // kept at a time and the instance that |discovery_session_| points to gets | |
| 197 // replaced by a new one when a new discovery session is initiated. | |
| 198 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; | |
| 199 | |
| 200 // Current pointing device, if any. | |
| 201 std::string pointing_device_name_; | |
| 202 std::string pointing_device_id_; | |
| 203 bool mouse_is_pairing_; | |
| 204 InputDeviceInfo::Type pointing_device_connect_type_; | |
| 205 | |
| 206 // Current keyboard device, if any. | |
| 207 std::string keyboard_device_name_; | |
| 208 std::string keyboard_device_id_; | |
| 209 bool keyboard_is_pairing_; | |
| 210 InputDeviceInfo::Type keyboard_device_connect_type_; | |
| 211 | |
| 212 bool switch_on_adapter_when_ready_; | |
| 213 | |
| 214 // State of BT adapter before screen-initiated changes. | |
| 215 scoped_ptr<bool> adapter_initially_powered_; | |
| 216 | |
| 217 base::WeakPtrFactory<HIDDetectionScreenHandler> weak_ptr_factory_; | |
| 218 | |
| 219 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler); | 61 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler); |
| 220 }; | 62 }; |
| 221 | 63 |
| 222 } // namespace chromeos | 64 } // namespace chromeos |
| 223 | 65 |
| 224 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H
_ | 66 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H
_ |
| 225 | 67 |
| OLD | NEW |