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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/metrics/histogram.h" | |
11 #include "base/prefs/pref_service.h" | |
10 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | |
13 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 16 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
17 #include "chrome/common/pref_names.h" | |
14 #include "device/bluetooth/bluetooth_adapter_factory.h" | 18 #include "device/bluetooth/bluetooth_adapter_factory.h" |
15 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
16 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
18 | 22 |
19 namespace { | 23 namespace { |
20 | 24 |
21 const char kJsScreenPath[] = "login.HIDDetectionScreen"; | 25 const char kJsScreenPath[] = "login.HIDDetectionScreen"; |
22 | 26 |
23 // Variants of pairing state. | 27 // Variants of pairing state. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 64 |
61 namespace chromeos { | 65 namespace chromeos { |
62 | 66 |
63 HIDDetectionScreenHandler::HIDDetectionScreenHandler() | 67 HIDDetectionScreenHandler::HIDDetectionScreenHandler() |
64 : BaseScreenHandler(kJsScreenPath), | 68 : BaseScreenHandler(kJsScreenPath), |
65 delegate_(NULL), | 69 delegate_(NULL), |
66 show_on_init_(false), | 70 show_on_init_(false), |
67 mouse_is_pairing_(false), | 71 mouse_is_pairing_(false), |
68 keyboard_is_pairing_(false), | 72 keyboard_is_pairing_(false), |
69 switch_on_adapter_when_ready_(false), | 73 switch_on_adapter_when_ready_(false), |
70 skip_screen_if_devices_present_(true), | 74 first_time_screen_show_(true), |
71 weak_ptr_factory_(this) { | 75 weak_ptr_factory_(this) { |
72 } | 76 } |
73 | 77 |
74 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { | 78 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { |
75 if (adapter_.get()) | 79 if (adapter_.get()) |
76 adapter_->RemoveObserver(this); | 80 adapter_->RemoveObserver(this); |
77 input_service_proxy_.RemoveObserver(this); | 81 input_service_proxy_.RemoveObserver(this); |
78 if (delegate_) | 82 if (delegate_) |
79 delegate_->OnActorDestroyed(this); | 83 delegate_->OnActorDestroyed(this); |
80 } | 84 } |
(...skipping 11 matching lines...) Expand all Loading... | |
92 | 96 |
93 void HIDDetectionScreenHandler::FindDevicesError() { | 97 void HIDDetectionScreenHandler::FindDevicesError() { |
94 VLOG(1) << "Failed to start Bluetooth discovery."; | 98 VLOG(1) << "Failed to start Bluetooth discovery."; |
95 } | 99 } |
96 | 100 |
97 void HIDDetectionScreenHandler::Show() { | 101 void HIDDetectionScreenHandler::Show() { |
98 if (!page_is_ready()) { | 102 if (!page_is_ready()) { |
99 show_on_init_ = true; | 103 show_on_init_ = true; |
100 return; | 104 return; |
101 } | 105 } |
106 PrefService* const local_state = g_browser_process->local_state(); | |
107 int num_of_times_dialog_was_shown = local_state->GetInteger( | |
108 prefs::kTimesHIDDialogShown); | |
109 local_state->SetInteger(prefs::kTimesHIDDialogShown, | |
110 num_of_times_dialog_was_shown + 1); | |
111 local_state->CommitPendingWrite(); | |
Mattias Nissler (ping if slow)
2014/05/12 11:10:02
This should not be necessary.
merkulova
2014/05/13 07:18:01
Done.
| |
112 | |
102 input_service_proxy_.AddObserver(this); | 113 input_service_proxy_.AddObserver(this); |
103 skip_screen_if_devices_present_ = true; | 114 first_time_screen_show_ = true; |
104 UpdateDevices(); | 115 UpdateDevices(); |
105 ShowScreen(OobeUI::kScreenHIDDetection, NULL); | 116 ShowScreen(OobeUI::kScreenHIDDetection, NULL); |
106 } | 117 } |
107 | 118 |
108 void HIDDetectionScreenHandler::Hide() { | 119 void HIDDetectionScreenHandler::Hide() { |
109 if (adapter_.get()) | 120 if (adapter_.get()) |
110 adapter_->RemoveObserver(this); | 121 adapter_->RemoveObserver(this); |
111 input_service_proxy_.RemoveObserver(this); | 122 input_service_proxy_.RemoveObserver(this); |
112 } | 123 } |
113 | 124 |
114 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { | 125 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { |
115 delegate_ = delegate; | 126 delegate_ = delegate; |
116 if (page_is_ready()) | 127 if (page_is_ready()) |
117 Initialize(); | 128 Initialize(); |
118 } | 129 } |
119 | 130 |
131 // static | |
132 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | |
133 registry->RegisterIntegerPref(prefs::kTimesHIDDialogShown, 0); | |
134 } | |
135 | |
120 void HIDDetectionScreenHandler::DeclareLocalizedValues( | 136 void HIDDetectionScreenHandler::DeclareLocalizedValues( |
121 LocalizedValuesBuilder* builder) { | 137 LocalizedValuesBuilder* builder) { |
122 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); | 138 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); |
123 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); | 139 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); |
124 builder->Add("hidDetectionPrerequisites", | 140 builder->Add("hidDetectionPrerequisites", |
125 IDS_HID_DETECTION_PRECONDITION_TEXT); | 141 IDS_HID_DETECTION_PRECONDITION_TEXT); |
126 builder->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE); | 142 builder->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE); |
127 builder->Add("hidDetectionKeyboardSearching", | 143 builder->Add("hidDetectionKeyboardSearching", |
128 IDS_HID_DETECTION_SEARCHING_KEYBOARD); | 144 IDS_HID_DETECTION_SEARCHING_KEYBOARD); |
129 builder->Add("hidDetectionUSBMouseConnected", | 145 builder->Add("hidDetectionUSBMouseConnected", |
(...skipping 18 matching lines...) Expand all Loading... | |
148 show_on_init_ = false; | 164 show_on_init_ = false; |
149 } | 165 } |
150 } | 166 } |
151 | 167 |
152 void HIDDetectionScreenHandler::RegisterMessages() { | 168 void HIDDetectionScreenHandler::RegisterMessages() { |
153 AddCallback( | 169 AddCallback( |
154 "HIDDetectionOnContinue", &HIDDetectionScreenHandler::HandleOnContinue); | 170 "HIDDetectionOnContinue", &HIDDetectionScreenHandler::HandleOnContinue); |
155 } | 171 } |
156 | 172 |
157 void HIDDetectionScreenHandler::HandleOnContinue() { | 173 void HIDDetectionScreenHandler::HandleOnContinue() { |
174 if (!first_time_screen_show_) { | |
175 // Continue button pressed. | |
176 int scenario_type; | |
177 if (!pointing_device_id_.empty() && !keyboard_device_id_.empty()) | |
178 scenario_type = hid::All_DEVICES_DETECTED; | |
179 else if (pointing_device_id_.empty()) | |
180 scenario_type = hid::KEYBOARD_DEVICE_ONLY_DETECTED; | |
181 else | |
182 scenario_type = hid::POINTING_DEVICE_ONLY_DETECTED; | |
183 | |
184 UMA_HISTOGRAM_ENUMERATION( | |
185 "HIDDetection.OOBEDevicesDetectedOnContinuePressed", | |
186 scenario_type, | |
187 hid::CONTINUE_SCENARIO_TYPE_SIZE); | |
188 } else { | |
189 // Screen not shown as devices were autodetected. | |
190 PrefService* local_state = g_browser_process->local_state(); | |
191 int num_of_times_dialog_was_shown = local_state->GetInteger( | |
192 prefs::kTimesHIDDialogShown); | |
193 local_state->SetInteger(prefs::kTimesHIDDialogShown, | |
194 num_of_times_dialog_was_shown - 1); | |
195 local_state->CommitPendingWrite(); | |
Mattias Nissler (ping if slow)
2014/05/12 11:10:02
not necessary.
merkulova
2014/05/13 07:18:01
Done.
| |
196 } | |
158 if (delegate_) | 197 if (delegate_) |
159 delegate_->OnExit(); | 198 delegate_->OnExit(); |
160 } | 199 } |
161 | 200 |
162 void HIDDetectionScreenHandler::InitializeAdapter( | 201 void HIDDetectionScreenHandler::InitializeAdapter( |
163 scoped_refptr<device::BluetoothAdapter> adapter) { | 202 scoped_refptr<device::BluetoothAdapter> adapter) { |
164 adapter_ = adapter; | 203 adapter_ = adapter; |
165 CHECK(adapter_.get()); | 204 CHECK(adapter_.get()); |
166 | 205 |
167 adapter_->AddObserver(this); | 206 adapter_->AddObserver(this); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 pointing_device_connect_type_ = it->type; | 404 pointing_device_connect_type_ = it->type; |
366 SendPointingDeviceNotification(); | 405 SendPointingDeviceNotification(); |
367 } | 406 } |
368 if (keyboard_device_id_.empty() && it->is_keyboard) { | 407 if (keyboard_device_id_.empty() && it->is_keyboard) { |
369 keyboard_device_id_ = it->id; | 408 keyboard_device_id_ = it->id; |
370 keyboard_device_name_ = it->name; | 409 keyboard_device_name_ = it->name; |
371 keyboard_device_connect_type_ = it->type; | 410 keyboard_device_connect_type_ = it->type; |
372 SendKeyboardDeviceNotification(NULL); | 411 SendKeyboardDeviceNotification(NULL); |
373 } | 412 } |
374 } | 413 } |
375 // Skip screen if both devices are present and skip was requested. | 414 |
376 if (!pointing_device_id_.empty() && | 415 if (first_time_screen_show_) { |
377 !keyboard_device_id_.empty() && | 416 // Skip screen if both devices are present and it's first show. |
378 skip_screen_if_devices_present_) { | 417 bool all_devices_autodetected = !pointing_device_id_.empty() && |
379 HandleOnContinue(); | 418 !keyboard_device_id_.empty(); |
419 UMA_HISTOGRAM_BOOLEAN("HIDDetection.OOBEDialogShown", | |
420 !all_devices_autodetected); | |
421 if (all_devices_autodetected) | |
422 HandleOnContinue(); | |
380 } | 423 } |
381 // Skip requested only once on dialog show. | 424 |
382 skip_screen_if_devices_present_ = false; | 425 first_time_screen_show_ = false; |
383 if ((pointing_device_id_.empty() || keyboard_device_id_.empty()) && | 426 if ((pointing_device_id_.empty() || keyboard_device_id_.empty()) && |
384 adapter_) { | 427 adapter_) { |
385 if (!adapter_->IsPresent()) { | 428 if (!adapter_->IsPresent()) { |
386 // Switch on BT adapter later when it's available. | 429 // Switch on BT adapter later when it's available. |
387 switch_on_adapter_when_ready_ = true; | 430 switch_on_adapter_when_ready_ = true; |
388 } else if (!adapter_->IsPowered()) { | 431 } else if (!adapter_->IsPowered()) { |
389 adapter_->SetPowered( | 432 adapter_->SetPowered( |
390 true, | 433 true, |
391 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession, | 434 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession, |
392 weak_ptr_factory_.GetWeakPtr()), | 435 weak_ptr_factory_.GetWeakPtr()), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 l10n_util::GetStringFUTF16( | 535 l10n_util::GetStringFUTF16( |
493 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, | 536 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, |
494 base::UTF8ToUTF16(keyboard_device_name_))); | 537 base::UTF8ToUTF16(keyboard_device_name_))); |
495 } else { | 538 } else { |
496 state_info.SetString("state", kUSBConnectedState); | 539 state_info.SetString("state", kUSBConnectedState); |
497 } | 540 } |
498 CallJS("setKeyboardDeviceState", state_info); | 541 CallJS("setKeyboardDeviceState", state_info); |
499 } | 542 } |
500 | 543 |
501 } // namespace chromeos | 544 } // namespace chromeos |
OLD | NEW |