Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1296)

Side by Side Diff: chrome/browser/signin/easy_unlock_screenlock_state_handler.cc

Issue 1494153002: This CL replaces e-mail with AccountId in easy signin code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/signin/easy_unlock_metrics.h" 10 #include "chrome/browser/signin/easy_unlock_metrics.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // Returns true iff the |state| corresponds to a locked remote device. 97 // Returns true iff the |state| corresponds to a locked remote device.
98 bool IsLockedState(ScreenlockState state) { 98 bool IsLockedState(ScreenlockState state) {
99 return (state == ScreenlockState::PHONE_LOCKED || 99 return (state == ScreenlockState::PHONE_LOCKED ||
100 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH); 100 state == ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH);
101 } 101 }
102 102
103 } // namespace 103 } // namespace
104 104
105 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( 105 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler(
106 const std::string& user_email, 106 const AccountId& account_id,
107 HardlockState initial_hardlock_state, 107 HardlockState initial_hardlock_state,
108 proximity_auth::ScreenlockBridge* screenlock_bridge) 108 proximity_auth::ScreenlockBridge* screenlock_bridge)
109 : state_(ScreenlockState::INACTIVE), 109 : state_(ScreenlockState::INACTIVE),
110 user_email_(user_email), 110 account_id_(account_id),
111 screenlock_bridge_(screenlock_bridge), 111 screenlock_bridge_(screenlock_bridge),
112 hardlock_state_(initial_hardlock_state), 112 hardlock_state_(initial_hardlock_state),
113 hardlock_ui_shown_(false), 113 hardlock_ui_shown_(false),
114 is_trial_run_(false), 114 is_trial_run_(false),
115 did_see_locked_phone_(false) { 115 did_see_locked_phone_(false) {
116 DCHECK(screenlock_bridge_); 116 DCHECK(screenlock_bridge_);
117 screenlock_bridge_->AddObserver(this); 117 screenlock_bridge_->AddObserver(this);
118 } 118 }
119 119
120 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { 120 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() {
(...skipping 19 matching lines...) Expand all
140 return; 140 return;
141 141
142 state_ = new_state; 142 state_ = new_state;
143 143
144 // If lock screen is not active or it forces offline password, just cache the 144 // If lock screen is not active or it forces offline password, just cache the
145 // current state. The screenlock state will get refreshed in |ScreenDidLock|. 145 // current state. The screenlock state will get refreshed in |ScreenDidLock|.
146 if (!screenlock_bridge_->IsLocked()) 146 if (!screenlock_bridge_->IsLocked())
147 return; 147 return;
148 148
149 // Do nothing when auth type is online. 149 // Do nothing when auth type is online.
150 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == 150 if (screenlock_bridge_->lock_handler()->GetAuthType(account_id_) ==
151 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) { 151 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) {
152 return; 152 return;
153 } 153 }
154 154
155 if (IsLockedState(state_)) 155 if (IsLockedState(state_))
156 did_see_locked_phone_ = true; 156 did_see_locked_phone_ = true;
157 157
158 // No hardlock UI for trial run. 158 // No hardlock UI for trial run.
159 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) { 159 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) {
160 ShowHardlockUI(); 160 ShowHardlockUI();
161 return; 161 return;
162 } 162 }
163 163
164 UpdateScreenlockAuthType(); 164 UpdateScreenlockAuthType();
165 165
166 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon = 166 proximity_auth::ScreenlockBridge::UserPodCustomIcon icon =
167 GetIconForState(state_); 167 GetIconForState(state_);
168 168
169 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { 169 if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) {
170 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); 170 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(account_id_);
171 return; 171 return;
172 } 172 }
173 173
174 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; 174 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options;
175 icon_options.SetIcon(icon); 175 icon_options.SetIcon(icon);
176 176
177 // Don't hardlock on trial run. 177 // Don't hardlock on trial run.
178 if (is_trial_run_) 178 if (is_trial_run_)
179 icon_options.SetTrialRun(); 179 icon_options.SetTrialRun();
180 else if (HardlockOnClick(state_)) 180 else if (HardlockOnClick(state_))
181 icon_options.SetHardlockOnClick(); 181 icon_options.SetHardlockOnClick();
182 182
183 UpdateTooltipOptions(&icon_options); 183 UpdateTooltipOptions(&icon_options);
184 184
185 // For states without tooltips, we still need to set an accessibility label. 185 // For states without tooltips, we still need to set an accessibility label.
186 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) { 186 if (state_ == ScreenlockState::BLUETOOTH_CONNECTING) {
187 icon_options.SetAriaLabel( 187 icon_options.SetAriaLabel(
188 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL)); 188 l10n_util::GetStringUTF16(IDS_SMART_LOCK_SPINNER_ACCESSIBILITY_LABEL));
189 } 189 }
190 190
191 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, 191 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(account_id_,
192 icon_options); 192 icon_options);
193 } 193 }
194 194
195 void EasyUnlockScreenlockStateHandler::SetHardlockState( 195 void EasyUnlockScreenlockStateHandler::SetHardlockState(
196 HardlockState new_state) { 196 HardlockState new_state) {
197 if (hardlock_state_ == new_state) 197 if (hardlock_state_ == new_state)
198 return; 198 return;
199 199
200 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK) 200 if (new_state == LOGIN_FAILED && hardlock_state_ != NO_HARDLOCK)
201 return; 201 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 is_trial_run_ = false; 244 is_trial_run_ = false;
245 245
246 // Upon a successful unlock event, record whether the user's phone was locked 246 // Upon a successful unlock event, record whether the user's phone was locked
247 // at any point while the lock screen was up. 247 // at any point while the lock screen was up.
248 if (state_ == ScreenlockState::AUTHENTICATED) 248 if (state_ == ScreenlockState::AUTHENTICATED)
249 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_); 249 RecordEasyUnlockDidUserManuallyUnlockPhone(did_see_locked_phone_);
250 did_see_locked_phone_ = false; 250 did_see_locked_phone_ = false;
251 } 251 }
252 252
253 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( 253 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged(
254 const std::string& user_id) { 254 const AccountId& account_id) {}
255 }
256 255
257 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() { 256 void EasyUnlockScreenlockStateHandler::RefreshScreenlockState() {
258 ScreenlockState last_state = state_; 257 ScreenlockState last_state = state_;
259 // This should force updating screenlock state. 258 // This should force updating screenlock state.
260 state_ = ScreenlockState::INACTIVE; 259 state_ = ScreenlockState::INACTIVE;
261 ChangeState(last_state); 260 ChangeState(last_state);
262 } 261 }
263 262
264 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { 263 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() {
265 DCHECK(hardlock_state_ != NO_HARDLOCK); 264 DCHECK(hardlock_state_ != NO_HARDLOCK);
266 265
267 if (!screenlock_bridge_->IsLocked()) 266 if (!screenlock_bridge_->IsLocked())
268 return; 267 return;
269 268
270 // Do not override online signin. 269 // Do not override online signin.
271 const proximity_auth::ScreenlockBridge::LockHandler::AuthType 270 const proximity_auth::ScreenlockBridge::LockHandler::AuthType
272 existing_auth_type = 271 existing_auth_type =
273 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); 272 screenlock_bridge_->lock_handler()->GetAuthType(account_id_);
274 if (existing_auth_type == 273 if (existing_auth_type ==
275 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) 274 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN)
276 return; 275 return;
277 276
278 if (existing_auth_type != 277 if (existing_auth_type !=
279 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { 278 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
280 screenlock_bridge_->lock_handler()->SetAuthType( 279 screenlock_bridge_->lock_handler()->SetAuthType(
281 user_email_, 280 account_id_,
282 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 281 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
283 base::string16()); 282 base::string16());
284 } 283 }
285 284
286 if (hardlock_state_ == NO_PAIRING) { 285 if (hardlock_state_ == NO_PAIRING) {
287 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); 286 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(account_id_);
288 hardlock_ui_shown_ = false; 287 hardlock_ui_shown_ = false;
289 return; 288 return;
290 } 289 }
291 290
292 if (hardlock_ui_shown_) 291 if (hardlock_ui_shown_)
293 return; 292 return;
294 293
295 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options; 294 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options;
296 if (hardlock_state_ == LOGIN_FAILED) { 295 if (hardlock_state_ == LOGIN_FAILED) {
297 icon_options.SetIcon( 296 icon_options.SetIcon(
(...skipping 20 matching lines...) Expand all
318 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name, 317 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_ADDED, device_name,
319 device_name); 318 device_name);
320 } else if (hardlock_state_ == LOGIN_FAILED) { 319 } else if (hardlock_state_ == LOGIN_FAILED) {
321 tooltip = l10n_util::GetStringUTF16( 320 tooltip = l10n_util::GetStringUTF16(
322 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE); 321 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_LOGIN_FAILURE);
323 } else { 322 } else {
324 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; 323 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_;
325 } 324 }
326 icon_options.SetTooltip(tooltip, true /* autoshow */); 325 icon_options.SetTooltip(tooltip, true /* autoshow */);
327 326
328 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, 327 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(account_id_,
329 icon_options); 328 icon_options);
330 hardlock_ui_shown_ = true; 329 hardlock_ui_shown_ = true;
331 } 330 }
332 331
333 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( 332 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions(
334 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) { 333 proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) {
335 size_t resource_id = 0; 334 size_t resource_id = 0;
336 base::string16 device_name; 335 base::string16 device_name;
337 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) { 336 if (is_trial_run_ && state_ == ScreenlockState::AUTHENTICATED) {
338 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED; 337 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED;
(...skipping 30 matching lines...) Expand all
369 #endif 368 #endif
370 } 369 }
371 370
372 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { 371 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() {
373 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK) 372 if (!is_trial_run_ && hardlock_state_ != NO_HARDLOCK)
374 return; 373 return;
375 374
376 // Do not override online signin. 375 // Do not override online signin.
377 const proximity_auth::ScreenlockBridge::LockHandler::AuthType 376 const proximity_auth::ScreenlockBridge::LockHandler::AuthType
378 existing_auth_type = 377 existing_auth_type =
379 screenlock_bridge_->lock_handler()->GetAuthType(user_email_); 378 screenlock_bridge_->lock_handler()->GetAuthType(account_id_);
380 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, 379 DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN,
381 existing_auth_type); 380 existing_auth_type);
382 381
383 if (state_ == ScreenlockState::AUTHENTICATED) { 382 if (state_ == ScreenlockState::AUTHENTICATED) {
384 if (existing_auth_type != 383 if (existing_auth_type !=
385 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) { 384 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) {
386 screenlock_bridge_->lock_handler()->SetAuthType( 385 screenlock_bridge_->lock_handler()->SetAuthType(
387 user_email_, 386 account_id_,
388 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, 387 proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK,
389 l10n_util::GetStringUTF16( 388 l10n_util::GetStringUTF16(
390 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); 389 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE));
391 } 390 }
392 } else if (existing_auth_type != 391 } else if (existing_auth_type !=
393 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { 392 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
394 screenlock_bridge_->lock_handler()->SetAuthType( 393 screenlock_bridge_->lock_handler()->SetAuthType(
395 user_email_, 394 account_id_,
396 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 395 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
397 base::string16()); 396 base::string16());
398 } 397 }
399 } 398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698