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 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Possible ui-states for device-blocks. | 22 // Possible ui-states for device-blocks. |
23 const char kSearchingState[] = "searching"; | 23 const char kSearchingState[] = "searching"; |
24 const char kUSBState[] = "usb"; | 24 const char kUSBState[] = "usb"; |
25 const char kConnectedState[] = "connected"; | 25 const char kConnectedState[] = "connected"; |
26 const char kBTPairedState[] = "paired"; | 26 const char kBTPairedState[] = "paired"; |
27 const char kBTPairingState[] = "pairing"; | 27 const char kBTPairingState[] = "pairing"; |
28 | 28 |
29 // Standard length of pincode for pairing BT keyboards. | 29 // Standard length of pincode for pairing BT keyboards. |
30 const int kPincodeLength = 6; | 30 const int kPincodeLength = 6; |
31 | 31 |
32 bool DeviceIsPointing(device::BluetoothDevice::DeviceType device_type) { | 32 bool DeviceIsPointing(device::BluetoothDeviceType device_type) { |
33 return device_type == device::BluetoothDevice::DEVICE_MOUSE || | 33 return device_type == device::BluetoothDeviceType::MOUSE || |
34 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO || | 34 device_type == device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO || |
35 device_type == device::BluetoothDevice::DEVICE_TABLET; | 35 device_type == device::BluetoothDeviceType::TABLET; |
36 } | 36 } |
37 | 37 |
38 bool DeviceIsPointing(const device::InputServiceLinux::InputDeviceInfo& info) { | 38 bool DeviceIsPointing(const device::InputServiceLinux::InputDeviceInfo& info) { |
39 return info.is_mouse || info.is_touchpad || info.is_touchscreen || | 39 return info.is_mouse || info.is_touchpad || info.is_touchscreen || |
40 info.is_tablet; | 40 info.is_tablet; |
41 } | 41 } |
42 | 42 |
43 bool DeviceIsKeyboard(device::BluetoothDevice::DeviceType device_type) { | 43 bool DeviceIsKeyboard(device::BluetoothDeviceType device_type) { |
44 return device_type == device::BluetoothDevice::DEVICE_KEYBOARD || | 44 return device_type == device::BluetoothDeviceType::KEYBOARD || |
45 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO; | 45 device_type == device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 namespace chromeos { | 50 namespace chromeos { |
51 | 51 |
52 HIDDetectionScreen::HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate, | 52 HIDDetectionScreen::HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate, |
53 HIDDetectionView* view) | 53 HIDDetectionView* view) |
54 : HIDDetectionModel(base_screen_delegate), | 54 : HIDDetectionModel(base_screen_delegate), |
55 view_(view), | 55 view_(view), |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 !keyboard_is_pairing_) { | 251 !keyboard_is_pairing_) { |
252 ConnectBTDevice(device); | 252 ConnectBTDevice(device); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 void HIDDetectionScreen::ConnectBTDevice(device::BluetoothDevice* device) { | 256 void HIDDetectionScreen::ConnectBTDevice(device::BluetoothDevice* device) { |
257 bool device_busy = (device->IsConnected() && device->IsPaired()) || | 257 bool device_busy = (device->IsConnected() && device->IsPaired()) || |
258 device->IsConnecting(); | 258 device->IsConnecting(); |
259 if (!device->IsPairable() || device_busy) | 259 if (!device->IsPairable() || device_busy) |
260 return; | 260 return; |
261 device::BluetoothDevice::DeviceType device_type = device->GetDeviceType(); | 261 device::BluetoothDeviceType device_type = device->GetDeviceType(); |
262 | 262 |
263 if (device_type == device::BluetoothDevice::DEVICE_MOUSE || | 263 if (device_type == device::BluetoothDeviceType::MOUSE || |
264 device_type == device::BluetoothDevice::DEVICE_TABLET) { | 264 device_type == device::BluetoothDeviceType::TABLET) { |
265 if (mouse_is_pairing_) | 265 if (mouse_is_pairing_) |
266 return; | 266 return; |
267 mouse_is_pairing_ = true; | 267 mouse_is_pairing_ = true; |
268 } else if (device_type == device::BluetoothDevice::DEVICE_KEYBOARD) { | 268 } else if (device_type == device::BluetoothDeviceType::KEYBOARD) { |
269 if (keyboard_is_pairing_) | 269 if (keyboard_is_pairing_) |
270 return; | 270 return; |
271 keyboard_is_pairing_ = true; | 271 keyboard_is_pairing_ = true; |
272 } else if (device_type == | 272 } else if (device_type == device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO) { |
273 device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO) { | |
274 if (mouse_is_pairing_ && keyboard_is_pairing_) | 273 if (mouse_is_pairing_ && keyboard_is_pairing_) |
275 return; | 274 return; |
276 mouse_is_pairing_ = true; | 275 mouse_is_pairing_ = true; |
277 keyboard_is_pairing_ = true; | 276 keyboard_is_pairing_ = true; |
278 } | 277 } |
279 device->Connect(this, | 278 device->Connect(this, |
280 base::Bind(&HIDDetectionScreen::BTConnected, | 279 base::Bind(&HIDDetectionScreen::BTConnected, |
281 weak_ptr_factory_.GetWeakPtr(), device_type), | 280 weak_ptr_factory_.GetWeakPtr(), device_type), |
282 base::Bind(&HIDDetectionScreen::BTConnectError, | 281 base::Bind(&HIDDetectionScreen::BTConnectError, |
283 weak_ptr_factory_.GetWeakPtr(), | 282 weak_ptr_factory_.GetWeakPtr(), |
284 device->GetAddress(), device_type)); | 283 device->GetAddress(), device_type)); |
285 } | 284 } |
286 | 285 |
287 void HIDDetectionScreen::BTConnected( | 286 void HIDDetectionScreen::BTConnected(device::BluetoothDeviceType device_type) { |
288 device::BluetoothDevice::DeviceType device_type) { | |
289 if (DeviceIsPointing(device_type)) | 287 if (DeviceIsPointing(device_type)) |
290 mouse_is_pairing_ = false; | 288 mouse_is_pairing_ = false; |
291 if (DeviceIsKeyboard(device_type)) { | 289 if (DeviceIsKeyboard(device_type)) { |
292 keyboard_is_pairing_ = false; | 290 keyboard_is_pairing_ = false; |
293 GetContextEditor() | 291 GetContextEditor() |
294 .SetBoolean(kContextKeyNumKeysEnteredExpected, false) | 292 .SetBoolean(kContextKeyNumKeysEnteredExpected, false) |
295 .SetString(kContextKeyPinCode, ""); | 293 .SetString(kContextKeyPinCode, ""); |
296 SendKeyboardDeviceNotification(); | 294 SendKeyboardDeviceNotification(); |
297 } | 295 } |
298 } | 296 } |
299 | 297 |
300 void HIDDetectionScreen::BTConnectError( | 298 void HIDDetectionScreen::BTConnectError( |
301 const std::string& address, | 299 const std::string& address, |
302 device::BluetoothDevice::DeviceType device_type, | 300 device::BluetoothDeviceType device_type, |
303 device::BluetoothDevice::ConnectErrorCode error_code) { | 301 device::BluetoothDevice::ConnectErrorCode error_code) { |
304 LOG(WARNING) << "BTConnectError while connecting " << address | 302 LOG(WARNING) << "BTConnectError while connecting " << address |
305 << " error code = " << error_code; | 303 << " error code = " << error_code; |
306 if (DeviceIsPointing(device_type)) | 304 if (DeviceIsPointing(device_type)) |
307 mouse_is_pairing_ = false; | 305 mouse_is_pairing_ = false; |
308 if (DeviceIsKeyboard(device_type)) { | 306 if (DeviceIsKeyboard(device_type)) { |
309 keyboard_is_pairing_ = false; | 307 keyboard_is_pairing_ = false; |
310 GetContextEditor() | 308 GetContextEditor() |
311 .SetInteger(kContextKeyNumKeysEnteredExpected, false) | 309 .SetInteger(kContextKeyNumKeysEnteredExpected, false) |
312 .SetString(kContextKeyPinCode, ""); | 310 .SetString(kContextKeyPinCode, ""); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 void HIDDetectionScreen::SetPoweredOffError() { | 544 void HIDDetectionScreen::SetPoweredOffError() { |
547 LOG(ERROR) << "Failed to power off BT adapter"; | 545 LOG(ERROR) << "Failed to power off BT adapter"; |
548 } | 546 } |
549 | 547 |
550 void HIDDetectionScreen::FindDevicesError() { | 548 void HIDDetectionScreen::FindDevicesError() { |
551 VLOG(1) << "Failed to start Bluetooth discovery."; | 549 VLOG(1) << "Failed to start Bluetooth discovery."; |
552 } | 550 } |
553 | 551 |
554 | 552 |
555 } // namespace chromeos | 553 } // namespace chromeos |
OLD | NEW |