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