| 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/ui/webui/chromeos/login/hid_detection_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/device/input_service_proxy_factory.h" |
| 17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 18 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 21 #include "components/login/localized_values_builder.h" | 22 #include "components/login/localized_values_builder.h" |
| 22 #include "device/bluetooth/bluetooth_adapter_factory.h" | 23 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } // namespace | 71 } // namespace |
| 71 | 72 |
| 72 namespace chromeos { | 73 namespace chromeos { |
| 73 | 74 |
| 74 HIDDetectionScreenHandler::HIDDetectionScreenHandler( | 75 HIDDetectionScreenHandler::HIDDetectionScreenHandler( |
| 75 CoreOobeActor* core_oobe_actor) | 76 CoreOobeActor* core_oobe_actor) |
| 76 : BaseScreenHandler(kJsScreenPath), | 77 : BaseScreenHandler(kJsScreenPath), |
| 77 delegate_(NULL), | 78 delegate_(NULL), |
| 78 core_oobe_actor_(core_oobe_actor), | 79 core_oobe_actor_(core_oobe_actor), |
| 79 show_on_init_(false), | 80 show_on_init_(false), |
| 81 input_service_proxy_(InputServiceProxyFactory::GetProxy()), |
| 80 mouse_is_pairing_(false), | 82 mouse_is_pairing_(false), |
| 81 pointing_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN), | 83 pointing_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN), |
| 82 keyboard_is_pairing_(false), | 84 keyboard_is_pairing_(false), |
| 83 keyboard_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN), | 85 keyboard_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN), |
| 84 switch_on_adapter_when_ready_(false), | 86 switch_on_adapter_when_ready_(false), |
| 85 weak_ptr_factory_(this) { | 87 weak_ptr_factory_(this) { |
| 86 } | 88 } |
| 87 | 89 |
| 88 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { | 90 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { |
| 89 adapter_initially_powered_.reset(); | 91 adapter_initially_powered_.reset(); |
| 90 if (adapter_.get()) | 92 if (adapter_.get()) |
| 91 adapter_->RemoveObserver(this); | 93 adapter_->RemoveObserver(this); |
| 92 input_service_proxy_.RemoveObserver(this); | 94 input_service_proxy_->RemoveObserver(this); |
| 93 if (delegate_) | 95 if (delegate_) |
| 94 delegate_->OnActorDestroyed(this); | 96 delegate_->OnActorDestroyed(this); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void HIDDetectionScreenHandler::OnStartDiscoverySession( | 99 void HIDDetectionScreenHandler::OnStartDiscoverySession( |
| 98 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 100 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 99 VLOG(1) << "BT Discovery session started"; | 101 VLOG(1) << "BT Discovery session started"; |
| 100 discovery_session_ = discovery_session.Pass(); | 102 discovery_session_ = discovery_session.Pass(); |
| 101 UpdateDevices(); | 103 UpdateDevices(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void HIDDetectionScreenHandler::SetPoweredError() { | 106 void HIDDetectionScreenHandler::SetPoweredError() { |
| 105 LOG(ERROR) << "Failed to power BT adapter"; | 107 LOG(ERROR) << "Failed to power BT adapter"; |
| 106 } | 108 } |
| 107 | 109 |
| 108 void HIDDetectionScreenHandler::SetPoweredOffError() { | 110 void HIDDetectionScreenHandler::SetPoweredOffError() { |
| 109 LOG(ERROR) << "Failed to power off BT adapter"; | 111 LOG(ERROR) << "Failed to power off BT adapter"; |
| 110 } | 112 } |
| 111 | 113 |
| 112 void HIDDetectionScreenHandler::FindDevicesError() { | 114 void HIDDetectionScreenHandler::FindDevicesError() { |
| 113 VLOG(1) << "Failed to start Bluetooth discovery."; | 115 VLOG(1) << "Failed to start Bluetooth discovery."; |
| 114 } | 116 } |
| 115 | 117 |
| 116 void HIDDetectionScreenHandler::Show() { | 118 void HIDDetectionScreenHandler::Show() { |
| 117 if (!page_is_ready()) { | 119 if (!page_is_ready()) { |
| 118 show_on_init_ = true; | 120 show_on_init_ = true; |
| 119 return; | 121 return; |
| 120 } | 122 } |
| 121 core_oobe_actor_->InitDemoModeDetection(); | 123 core_oobe_actor_->InitDemoModeDetection(); |
| 122 input_service_proxy_.AddObserver(this); | 124 input_service_proxy_->AddObserver(this); |
| 123 UpdateDevices(); | 125 UpdateDevices(); |
| 124 | 126 |
| 125 PrefService* local_state = g_browser_process->local_state(); | 127 PrefService* local_state = g_browser_process->local_state(); |
| 126 int num_of_times_dialog_was_shown = local_state->GetInteger( | 128 int num_of_times_dialog_was_shown = local_state->GetInteger( |
| 127 prefs::kTimesHIDDialogShown); | 129 prefs::kTimesHIDDialogShown); |
| 128 local_state->SetInteger(prefs::kTimesHIDDialogShown, | 130 local_state->SetInteger(prefs::kTimesHIDDialogShown, |
| 129 num_of_times_dialog_was_shown + 1); | 131 num_of_times_dialog_was_shown + 1); |
| 130 | 132 |
| 131 ShowScreen(OobeUI::kScreenHIDDetection, NULL); | 133 ShowScreen(OobeUI::kScreenHIDDetection, NULL); |
| 132 SendPointingDeviceNotification(); | 134 SendPointingDeviceNotification(); |
| 133 SendKeyboardDeviceNotification(NULL); | 135 SendKeyboardDeviceNotification(NULL); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void HIDDetectionScreenHandler::Hide() { | 138 void HIDDetectionScreenHandler::Hide() { |
| 137 if (adapter_.get()) | 139 if (adapter_.get()) |
| 138 adapter_->RemoveObserver(this); | 140 adapter_->RemoveObserver(this); |
| 139 input_service_proxy_.RemoveObserver(this); | 141 input_service_proxy_->RemoveObserver(this); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { | 144 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { |
| 143 delegate_ = delegate; | 145 delegate_ = delegate; |
| 144 if (page_is_ready()) | 146 if (page_is_ready()) |
| 145 Initialize(); | 147 Initialize(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void HIDDetectionScreenHandler::CheckIsScreenRequired( | 150 void HIDDetectionScreenHandler::CheckIsScreenRequired( |
| 149 const base::Callback<void(bool)>& on_check_done) { | 151 const base::Callback<void(bool)>& on_check_done) { |
| 150 input_service_proxy_.GetDevices( | 152 input_service_proxy_->GetDevices( |
| 151 base::Bind(&HIDDetectionScreenHandler::OnGetInputDevicesListForCheck, | 153 base::Bind(&HIDDetectionScreenHandler::OnGetInputDevicesListForCheck, |
| 152 weak_ptr_factory_.GetWeakPtr(), | 154 weak_ptr_factory_.GetWeakPtr(), |
| 153 on_check_done)); | 155 on_check_done)); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void HIDDetectionScreenHandler::DeclareLocalizedValues( | 158 void HIDDetectionScreenHandler::DeclareLocalizedValues( |
| 157 ::login::LocalizedValuesBuilder* builder) { | 159 ::login::LocalizedValuesBuilder* builder) { |
| 158 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); | 160 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); |
| 159 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); | 161 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); |
| 160 builder->Add("hidDetectionPrerequisites", | 162 builder->Add("hidDetectionPrerequisites", |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 UpdateDevices(); | 398 UpdateDevices(); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| 400 // static | 402 // static |
| 401 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 403 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
| 402 registry->RegisterIntegerPref(prefs::kTimesHIDDialogShown, 0); | 404 registry->RegisterIntegerPref(prefs::kTimesHIDDialogShown, 0); |
| 403 } | 405 } |
| 404 | 406 |
| 405 void HIDDetectionScreenHandler::UpdateDevices() { | 407 void HIDDetectionScreenHandler::UpdateDevices() { |
| 406 input_service_proxy_.GetDevices( | 408 input_service_proxy_->GetDevices( |
| 407 base::Bind(&HIDDetectionScreenHandler::OnGetInputDevicesList, | 409 base::Bind(&HIDDetectionScreenHandler::OnGetInputDevicesList, |
| 408 weak_ptr_factory_.GetWeakPtr())); | 410 weak_ptr_factory_.GetWeakPtr())); |
| 409 } | 411 } |
| 410 | 412 |
| 411 void HIDDetectionScreenHandler::UpdateBTDevices() { | 413 void HIDDetectionScreenHandler::UpdateBTDevices() { |
| 412 if (!adapter_.get() || !adapter_->IsPresent() || !adapter_->IsPowered()) | 414 if (!adapter_.get() || !adapter_->IsPresent() || !adapter_->IsPowered()) |
| 413 return; | 415 return; |
| 414 | 416 |
| 415 // If no connected devices found as pointing device and keyboard, we try to | 417 // If no connected devices found as pointing device and keyboard, we try to |
| 416 // connect some type-suitable active bluetooth device. | 418 // connect some type-suitable active bluetooth device. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 l10n_util::GetStringFUTF16( | 587 l10n_util::GetStringFUTF16( |
| 586 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, | 588 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, |
| 587 base::UTF8ToUTF16(keyboard_device_name_))); | 589 base::UTF8ToUTF16(keyboard_device_name_))); |
| 588 } else { | 590 } else { |
| 589 state_info.SetString("state", kUSBConnectedState); | 591 state_info.SetString("state", kUSBConnectedState); |
| 590 } | 592 } |
| 591 CallJS("setKeyboardDeviceState", state_info); | 593 CallJS("setKeyboardDeviceState", state_info); |
| 592 } | 594 } |
| 593 | 595 |
| 594 } // namespace chromeos | 596 } // namespace chromeos |
| OLD | NEW |