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/signin/easy_unlock_screenlock_state_handler.h" | 5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/chromeos_utils.h" | 10 #include "chrome/browser/chromeos/chromeos_utils.h" |
| 11 #include "chrome/browser/signin/easy_unlock_metrics.h" |
11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 ScreenlockBridge::UserPodCustomIcon GetIconForState( | 17 ScreenlockBridge::UserPodCustomIcon GetIconForState( |
17 EasyUnlockScreenlockStateHandler::State state) { | 18 EasyUnlockScreenlockStateHandler::State state) { |
18 switch (state) { | 19 switch (state) { |
19 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 20 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
20 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 21 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 148 |
148 if (icon == ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { | 149 if (icon == ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { |
149 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 150 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
150 return; | 151 return; |
151 } | 152 } |
152 | 153 |
153 ScreenlockBridge::UserPodCustomIconOptions icon_options; | 154 ScreenlockBridge::UserPodCustomIconOptions icon_options; |
154 icon_options.SetIcon(icon); | 155 icon_options.SetIcon(icon); |
155 | 156 |
156 // Don't hardlock on trial run. | 157 // Don't hardlock on trial run. |
157 if (!is_trial_run_ && HardlockOnClick(state_)) | 158 if (is_trial_run_) |
| 159 icon_options.SetTrialRun(); |
| 160 else if (HardlockOnClick(state_)) |
158 icon_options.SetHardlockOnClick(); | 161 icon_options.SetHardlockOnClick(); |
159 | 162 |
160 UpdateTooltipOptions(is_trial_run_, &icon_options); | 163 UpdateTooltipOptions(&icon_options); |
161 | 164 |
162 // For states without tooltips, we still need to set an accessibility label. | 165 // For states without tooltips, we still need to set an accessibility label. |
163 if (state_ == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING) { | 166 if (state_ == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING) { |
164 icon_options.SetAriaLabel( | 167 icon_options.SetAriaLabel( |
165 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); | 168 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); |
166 } | 169 } |
167 | 170 |
168 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 171 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
169 icon_options); | 172 icon_options); |
170 } | 173 } |
(...skipping 20 matching lines...) Expand all Loading... |
191 void EasyUnlockScreenlockStateHandler::MaybeShowHardlockUI() { | 194 void EasyUnlockScreenlockStateHandler::MaybeShowHardlockUI() { |
192 if (hardlock_state_ != NO_HARDLOCK) | 195 if (hardlock_state_ != NO_HARDLOCK) |
193 ShowHardlockUI(); | 196 ShowHardlockUI(); |
194 } | 197 } |
195 | 198 |
196 void EasyUnlockScreenlockStateHandler::SetTrialRun() { | 199 void EasyUnlockScreenlockStateHandler::SetTrialRun() { |
197 if (is_trial_run_) | 200 if (is_trial_run_) |
198 return; | 201 return; |
199 is_trial_run_ = true; | 202 is_trial_run_ = true; |
200 RefreshScreenlockState(); | 203 RefreshScreenlockState(); |
| 204 RecordEasyUnlockTrialRunEvent(EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED); |
| 205 } |
| 206 |
| 207 void EasyUnlockScreenlockStateHandler::RecordClickOnLockIcon() { |
| 208 if (!is_trial_run_) |
| 209 return; |
| 210 RecordEasyUnlockTrialRunEvent(EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON); |
201 } | 211 } |
202 | 212 |
203 void EasyUnlockScreenlockStateHandler::OnScreenDidLock( | 213 void EasyUnlockScreenlockStateHandler::OnScreenDidLock( |
204 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 214 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
205 RefreshScreenlockState(); | 215 RefreshScreenlockState(); |
206 } | 216 } |
207 | 217 |
208 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock( | 218 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock( |
209 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 219 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
210 if (hardlock_state_ == LOGIN_FAILED) | 220 if (hardlock_state_ == LOGIN_FAILED) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; | 292 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; |
283 } | 293 } |
284 icon_options.SetTooltip(tooltip, true /* autoshow */); | 294 icon_options.SetTooltip(tooltip, true /* autoshow */); |
285 | 295 |
286 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 296 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
287 icon_options); | 297 icon_options); |
288 hardlock_ui_shown_ = true; | 298 hardlock_ui_shown_ = true; |
289 } | 299 } |
290 | 300 |
291 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 301 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
292 bool trial_run, | |
293 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 302 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
294 size_t resource_id = 0; | 303 size_t resource_id = 0; |
295 base::string16 device_name; | 304 base::string16 device_name; |
296 if (trial_run && state_ == STATE_AUTHENTICATED) { | 305 if (is_trial_run_ && state_ == STATE_AUTHENTICATED) { |
297 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; | 306 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; |
298 } else { | 307 } else { |
299 resource_id = GetTooltipResourceId(state_); | 308 resource_id = GetTooltipResourceId(state_); |
300 if (TooltipContainsDeviceType(state_)) | 309 if (TooltipContainsDeviceType(state_)) |
301 device_name = GetDeviceName(); | 310 device_name = GetDeviceName(); |
302 } | 311 } |
303 | 312 |
304 if (!resource_id) | 313 if (!resource_id) |
305 return; | 314 return; |
306 | 315 |
307 base::string16 tooltip; | 316 base::string16 tooltip; |
308 if (device_name.empty()) { | 317 if (device_name.empty()) { |
309 tooltip = l10n_util::GetStringUTF16(resource_id); | 318 tooltip = l10n_util::GetStringUTF16(resource_id); |
310 } else { | 319 } else { |
311 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name); | 320 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name); |
312 } | 321 } |
313 | 322 |
314 if (tooltip.empty()) | 323 if (tooltip.empty()) |
315 return; | 324 return; |
316 | 325 |
317 icon_options->SetTooltip( | 326 icon_options->SetTooltip( |
318 tooltip, | 327 tooltip, |
319 trial_run || (state_ != STATE_AUTHENTICATED) /* autoshow tooltip */); | 328 is_trial_run_ || (state_ != STATE_AUTHENTICATED) /* autoshow tooltip */); |
320 } | 329 } |
321 | 330 |
322 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { | 331 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { |
323 #if defined(OS_CHROMEOS) | 332 #if defined(OS_CHROMEOS) |
324 return chromeos::GetChromeDeviceType(); | 333 return chromeos::GetChromeDeviceType(); |
325 #else | 334 #else |
326 // TODO(tbarzic): Figure out the name for non Chrome OS case. | 335 // TODO(tbarzic): Figure out the name for non Chrome OS case. |
327 return base::ASCIIToUTF16("Chrome"); | 336 return base::ASCIIToUTF16("Chrome"); |
328 #endif | 337 #endif |
329 } | 338 } |
(...skipping 16 matching lines...) Expand all Loading... |
346 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 355 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
347 } | 356 } |
348 } else if (existing_auth_type != | 357 } else if (existing_auth_type != |
349 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 358 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
350 screenlock_bridge_->lock_handler()->SetAuthType( | 359 screenlock_bridge_->lock_handler()->SetAuthType( |
351 user_email_, | 360 user_email_, |
352 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 361 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
353 base::string16()); | 362 base::string16()); |
354 } | 363 } |
355 } | 364 } |
OLD | NEW |