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

Side by Side Diff: chrome/browser/signin/easy_unlock_service.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: Bugfix in original easy unlock code' 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_service.h" 5 #include "chrome/browser/signin/easy_unlock_service.h"
6 6
7 #include "apps/app_lifetime_monitor.h" 7 #include "apps/app_lifetime_monitor.h"
8 #include "apps/app_lifetime_monitor_factory.h" 8 #include "apps/app_lifetime_monitor_factory.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { 296 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) {
297 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string()); 297 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string());
298 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); 298 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState);
299 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); 299 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs);
300 #if defined(OS_CHROMEOS) 300 #if defined(OS_CHROMEOS)
301 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); 301 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry);
302 #endif 302 #endif
303 } 303 }
304 304
305 // static 305 // static
306 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { 306 void EasyUnlockService::ResetLocalStateForUser(const AccountId& account_id) {
307 DCHECK(!user_id.empty()); 307 DCHECK(account_id.is_valid());
308 308
309 PrefService* local_state = GetLocalState(); 309 PrefService* local_state = GetLocalState();
310 if (!local_state) 310 if (!local_state)
311 return; 311 return;
312 312
313 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); 313 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState);
314 update->RemoveWithoutPathExpansion(user_id, NULL); 314 update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), NULL);
315 315
316 #if defined(OS_CHROMEOS) 316 #if defined(OS_CHROMEOS)
317 EasyUnlockTpmKeyManager::ResetLocalStateForUser(user_id); 317 EasyUnlockTpmKeyManager::ResetLocalStateForUser(account_id);
318 #endif 318 #endif
319 } 319 }
320 320
321 // static 321 // static
322 EasyUnlockService::UserSettings EasyUnlockService::GetUserSettings( 322 EasyUnlockService::UserSettings EasyUnlockService::GetUserSettings(
323 const std::string& user_id) { 323 const AccountId& account_id) {
324 DCHECK(!user_id.empty()); 324 DCHECK(account_id.is_valid());
325 UserSettings user_settings; 325 UserSettings user_settings;
326 326
327 PrefService* local_state = GetLocalState(); 327 PrefService* local_state = GetLocalState();
328 if (!local_state) 328 if (!local_state)
329 return user_settings; 329 return user_settings;
330 330
331 const base::DictionaryValue* all_user_prefs_dict = 331 const base::DictionaryValue* all_user_prefs_dict =
332 local_state->GetDictionary(prefs::kEasyUnlockLocalStateUserPrefs); 332 local_state->GetDictionary(prefs::kEasyUnlockLocalStateUserPrefs);
333 if (!all_user_prefs_dict) 333 if (!all_user_prefs_dict)
334 return user_settings; 334 return user_settings;
335 335
336 const base::DictionaryValue* user_prefs_dict; 336 const base::DictionaryValue* user_prefs_dict;
337 if (!all_user_prefs_dict->GetDictionaryWithoutPathExpansion(user_id, 337 if (!all_user_prefs_dict->GetDictionaryWithoutPathExpansion(
338 &user_prefs_dict)) 338 account_id.GetUserEmail(), &user_prefs_dict))
339 return user_settings; 339 return user_settings;
340 340
341 user_prefs_dict->GetBooleanWithoutPathExpansion( 341 user_prefs_dict->GetBooleanWithoutPathExpansion(
342 prefs::kEasyUnlockProximityRequired, 342 prefs::kEasyUnlockProximityRequired,
343 &user_settings.require_close_proximity); 343 &user_settings.require_close_proximity);
344 344
345 return user_settings; 345 return user_settings;
346 } 346 }
347 347
348 // static 348 // static
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 const base::ListValue* devices = GetRemoteDevices(); 390 const base::ListValue* devices = GetRemoteDevices();
391 return devices && !devices->empty(); 391 return devices && !devices->empty();
392 } 392 }
393 393
394 void EasyUnlockService::OpenSetupApp() { 394 void EasyUnlockService::OpenSetupApp() {
395 app_manager_->LaunchSetup(); 395 app_manager_->LaunchSetup();
396 } 396 }
397 397
398 void EasyUnlockService::SetHardlockState( 398 void EasyUnlockService::SetHardlockState(
399 EasyUnlockScreenlockStateHandler::HardlockState state) { 399 EasyUnlockScreenlockStateHandler::HardlockState state) {
400 const std::string user_id = GetUserEmail(); 400 const AccountId& account_id = GetAccountId();
401 if (user_id.empty()) 401 if (!account_id.is_valid())
402 return; 402 return;
403 403
404 if (state == GetHardlockState()) 404 if (state == GetHardlockState())
405 return; 405 return;
406 406
407 SetHardlockStateForUser(user_id, state); 407 SetHardlockStateForUser(account_id, state);
408 } 408 }
409 409
410 EasyUnlockScreenlockStateHandler::HardlockState 410 EasyUnlockScreenlockStateHandler::HardlockState
411 EasyUnlockService::GetHardlockState() const { 411 EasyUnlockService::GetHardlockState() const {
412 EasyUnlockScreenlockStateHandler::HardlockState state; 412 EasyUnlockScreenlockStateHandler::HardlockState state;
413 if (GetPersistedHardlockState(&state)) 413 if (GetPersistedHardlockState(&state))
414 return state; 414 return state;
415 415
416 return EasyUnlockScreenlockStateHandler::NO_HARDLOCK; 416 return EasyUnlockScreenlockStateHandler::NO_HARDLOCK;
417 } 417 }
418 418
419 bool EasyUnlockService::GetPersistedHardlockState( 419 bool EasyUnlockService::GetPersistedHardlockState(
420 EasyUnlockScreenlockStateHandler::HardlockState* state) const { 420 EasyUnlockScreenlockStateHandler::HardlockState* state) const {
421 std::string user_id = GetUserEmail(); 421 const AccountId& account_id = GetAccountId();
422 if (user_id.empty()) 422 if (!account_id.is_valid())
423 return false; 423 return false;
424 424
425 PrefService* local_state = GetLocalState(); 425 PrefService* local_state = GetLocalState();
426 if (!local_state) 426 if (!local_state)
427 return false; 427 return false;
428 428
429 const base::DictionaryValue* dict = 429 const base::DictionaryValue* dict =
430 local_state->GetDictionary(prefs::kEasyUnlockHardlockState); 430 local_state->GetDictionary(prefs::kEasyUnlockHardlockState);
431 int state_int; 431 int state_int;
432 if (dict && dict->GetIntegerWithoutPathExpansion(user_id, &state_int)) { 432 if (dict &&
433 dict->GetIntegerWithoutPathExpansion(account_id.GetUserEmail(),
434 &state_int)) {
433 *state = 435 *state =
434 static_cast<EasyUnlockScreenlockStateHandler::HardlockState>(state_int); 436 static_cast<EasyUnlockScreenlockStateHandler::HardlockState>(state_int);
435 return true; 437 return true;
436 } 438 }
437 439
438 return false; 440 return false;
439 } 441 }
440 442
441 void EasyUnlockService::ShowInitialUserState() { 443 void EasyUnlockService::ShowInitialUserState() {
442 if (!GetScreenlockStateHandler()) 444 if (!GetScreenlockStateHandler())
(...skipping 11 matching lines...) Expand all
454 screenlock_state_handler_->MaybeShowHardlockUI(); 456 screenlock_state_handler_->MaybeShowHardlockUI();
455 } 457 }
456 } 458 }
457 459
458 EasyUnlockScreenlockStateHandler* 460 EasyUnlockScreenlockStateHandler*
459 EasyUnlockService::GetScreenlockStateHandler() { 461 EasyUnlockService::GetScreenlockStateHandler() {
460 if (!IsAllowed()) 462 if (!IsAllowed())
461 return NULL; 463 return NULL;
462 if (!screenlock_state_handler_) { 464 if (!screenlock_state_handler_) {
463 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( 465 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler(
464 GetUserEmail(), GetHardlockState(), 466 GetAccountId(), GetHardlockState(),
465 proximity_auth::ScreenlockBridge::Get())); 467 proximity_auth::ScreenlockBridge::Get()));
466 } 468 }
467 return screenlock_state_handler_.get(); 469 return screenlock_state_handler_.get();
468 } 470 }
469 471
470 bool EasyUnlockService::UpdateScreenlockState(ScreenlockState state) { 472 bool EasyUnlockService::UpdateScreenlockState(ScreenlockState state) {
471 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); 473 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler();
472 if (!handler) 474 if (!handler)
473 return false; 475 return false;
474 476
475 handler->ChangeState(state); 477 handler->ChangeState(state);
476 478
477 if (state == ScreenlockState::AUTHENTICATED) { 479 if (state == ScreenlockState::AUTHENTICATED) {
478 #if defined(OS_CHROMEOS) 480 #if defined(OS_CHROMEOS)
479 if (power_monitor_) 481 if (power_monitor_)
480 power_monitor_->RecordStartUpTime(); 482 power_monitor_->RecordStartUpTime();
481 #endif 483 #endif
482 } else if (auth_attempt_.get()) { 484 } else if (auth_attempt_.get()) {
483 // Clean up existing auth attempt if we can no longer authenticate the 485 // Clean up existing auth attempt if we can no longer authenticate the
484 // remote device. 486 // remote device.
485 auth_attempt_.reset(); 487 auth_attempt_.reset();
486 488
487 if (!handler->InStateValidOnRemoteAuthFailure()) 489 if (!handler->InStateValidOnRemoteAuthFailure())
488 HandleAuthFailure(GetUserEmail()); 490 HandleAuthFailure(GetAccountId());
489 } 491 }
490 492
491 FOR_EACH_OBSERVER( 493 FOR_EACH_OBSERVER(
492 EasyUnlockServiceObserver, observers_, OnScreenlockStateChanged(state)); 494 EasyUnlockServiceObserver, observers_, OnScreenlockStateChanged(state));
493 return true; 495 return true;
494 } 496 }
495 497
496 ScreenlockState EasyUnlockService::GetScreenlockState() { 498 ScreenlockState EasyUnlockService::GetScreenlockState() {
497 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); 499 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler();
498 if (!handler) 500 if (!handler)
499 return ScreenlockState::INACTIVE; 501 return ScreenlockState::INACTIVE;
500 502
501 return handler->state(); 503 return handler->state();
502 } 504 }
503 505
504 void EasyUnlockService::AttemptAuth(const std::string& user_id) { 506 void EasyUnlockService::AttemptAuth(const AccountId& account_id) {
505 AttemptAuth(user_id, AttemptAuthCallback()); 507 AttemptAuth(account_id, AttemptAuthCallback());
506 } 508 }
507 509
508 void EasyUnlockService::AttemptAuth(const std::string& user_id, 510 void EasyUnlockService::AttemptAuth(const AccountId& account_id,
509 const AttemptAuthCallback& callback) { 511 const AttemptAuthCallback& callback) {
510 const EasyUnlockAuthAttempt::Type auth_attempt_type = 512 const EasyUnlockAuthAttempt::Type auth_attempt_type =
511 GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK 513 GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK
512 : EasyUnlockAuthAttempt::TYPE_SIGNIN; 514 : EasyUnlockAuthAttempt::TYPE_SIGNIN;
513 const std::string user_email = GetUserEmail(); 515 if (!GetAccountId().is_valid()) {
514 if (user_email.empty()) { 516 LOG(ERROR) << "Empty user account. Refresh token might go bad.";
515 LOG(ERROR) << "Empty user email. Refresh token might go bad.";
516 if (!callback.is_null()) { 517 if (!callback.is_null()) {
517 const bool kFailure = false; 518 const bool kFailure = false;
518 callback.Run(auth_attempt_type, kFailure, user_id, std::string(), 519 callback.Run(auth_attempt_type, kFailure, account_id, std::string(),
519 std::string()); 520 std::string());
520 } 521 }
521 return; 522 return;
522 } 523 }
523 524
524 CHECK_EQ(GetUserEmail(), user_id); 525 CHECK(GetAccountId() == account_id)
526 << "Check failed: " << GetAccountId().Serialize() << " vs "
527 << account_id.Serialize();
525 528
526 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id, 529 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), account_id,
527 auth_attempt_type, callback)); 530 auth_attempt_type, callback));
528 if (!auth_attempt_->Start()) 531 if (!auth_attempt_->Start())
529 auth_attempt_.reset(); 532 auth_attempt_.reset();
530 533
531 // TODO(tengs): We notify ProximityAuthSystem whenever unlock attempts are 534 // TODO(tengs): We notify ProximityAuthSystem whenever unlock attempts are
532 // attempted. However, we ideally should refactor the auth attempt logic to 535 // attempted. However, we ideally should refactor the auth attempt logic to
533 // the proximity_auth component. 536 // the proximity_auth component.
534 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 537 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
535 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && 538 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) &&
536 proximity_auth_system_) { 539 proximity_auth_system_) {
537 proximity_auth_system_->OnAuthAttempted(user_id); 540 proximity_auth_system_->OnAuthAttempted(account_id);
538 } 541 }
539 } 542 }
540 543
541 void EasyUnlockService::FinalizeUnlock(bool success) { 544 void EasyUnlockService::FinalizeUnlock(bool success) {
542 if (!auth_attempt_.get()) 545 if (!auth_attempt_.get())
543 return; 546 return;
544 547
545 this->OnWillFinalizeUnlock(success); 548 this->OnWillFinalizeUnlock(success);
546 auth_attempt_->FinalizeUnlock(GetUserEmail(), success); 549 auth_attempt_->FinalizeUnlock(GetAccountId(), success);
547 auth_attempt_.reset(); 550 auth_attempt_.reset();
548 // TODO(isherman): If observing screen unlock events, is there a race 551 // TODO(isherman): If observing screen unlock events, is there a race
549 // condition in terms of reading the service's state vs. the app setting the 552 // condition in terms of reading the service's state vs. the app setting the
550 // state? 553 // state?
551 554
552 // Make sure that the lock screen is updated on failure. 555 // Make sure that the lock screen is updated on failure.
553 if (!success) { 556 if (!success) {
554 RecordEasyUnlockScreenUnlockEvent(EASY_UNLOCK_FAILURE); 557 RecordEasyUnlockScreenUnlockEvent(EASY_UNLOCK_FAILURE);
555 HandleAuthFailure(GetUserEmail()); 558 HandleAuthFailure(GetAccountId());
556 } 559 }
557 } 560 }
558 561
559 void EasyUnlockService::FinalizeSignin(const std::string& key) { 562 void EasyUnlockService::FinalizeSignin(const std::string& key) {
560 if (!auth_attempt_.get()) 563 if (!auth_attempt_.get())
561 return; 564 return;
562 std::string wrapped_secret = GetWrappedSecret(); 565 std::string wrapped_secret = GetWrappedSecret();
563 if (!wrapped_secret.empty()) 566 if (!wrapped_secret.empty())
564 auth_attempt_->FinalizeSignin(GetUserEmail(), wrapped_secret, key); 567 auth_attempt_->FinalizeSignin(GetAccountId(), wrapped_secret, key);
565 auth_attempt_.reset(); 568 auth_attempt_.reset();
566 569
567 // Processing empty key is equivalent to auth cancellation. In this case the 570 // Processing empty key is equivalent to auth cancellation. In this case the
568 // signin request will not actually be processed by login stack, so the lock 571 // signin request will not actually be processed by login stack, so the lock
569 // screen state should be set from here. 572 // screen state should be set from here.
570 if (key.empty()) 573 if (key.empty())
571 HandleAuthFailure(GetUserEmail()); 574 HandleAuthFailure(GetAccountId());
572 } 575 }
573 576
574 void EasyUnlockService::HandleAuthFailure(const std::string& user_id) { 577 void EasyUnlockService::HandleAuthFailure(const AccountId& account_id) {
575 if (user_id != GetUserEmail()) 578 if (account_id != GetAccountId())
576 return; 579 return;
577 580
578 if (!screenlock_state_handler_.get()) 581 if (!screenlock_state_handler_.get())
579 return; 582 return;
580 583
581 screenlock_state_handler_->SetHardlockState( 584 screenlock_state_handler_->SetHardlockState(
582 EasyUnlockScreenlockStateHandler::LOGIN_FAILED); 585 EasyUnlockScreenlockStateHandler::LOGIN_FAILED);
583 } 586 }
584 587
585 void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() { 588 void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() {
586 #if defined(OS_CHROMEOS) 589 #if defined(OS_CHROMEOS)
587 std::string user_id = GetUserEmail(); 590 const AccountId& account_id = GetAccountId();
588 if (user_id.empty()) 591 if (!account_id.is_valid())
589 return; 592 return;
590 593
591 const base::ListValue* device_list = GetRemoteDevices(); 594 const base::ListValue* device_list = GetRemoteDevices();
592 std::set<std::string> paired_devices; 595 std::set<std::string> paired_devices;
593 if (device_list) { 596 if (device_list) {
594 chromeos::EasyUnlockDeviceKeyDataList parsed_paired; 597 chromeos::EasyUnlockDeviceKeyDataList parsed_paired;
595 chromeos::EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList( 598 chromeos::EasyUnlockKeyManager::RemoteDeviceListToDeviceDataList(
596 *device_list, &parsed_paired); 599 *device_list, &parsed_paired);
597 for (const auto& device_key_data : parsed_paired) 600 for (const auto& device_key_data : parsed_paired)
598 paired_devices.insert(device_key_data.psk); 601 paired_devices.insert(device_key_data.psk);
599 } 602 }
600 if (paired_devices.empty()) { 603 if (paired_devices.empty()) {
601 SetHardlockState(EasyUnlockScreenlockStateHandler::NO_PAIRING); 604 SetHardlockState(EasyUnlockScreenlockStateHandler::NO_PAIRING);
602 return; 605 return;
603 } 606 }
604 607
605 // No need to compare if a change is already recorded. 608 // No need to compare if a change is already recorded.
606 if (GetHardlockState() == EasyUnlockScreenlockStateHandler::PAIRING_CHANGED || 609 if (GetHardlockState() == EasyUnlockScreenlockStateHandler::PAIRING_CHANGED ||
607 GetHardlockState() == EasyUnlockScreenlockStateHandler::PAIRING_ADDED) { 610 GetHardlockState() == EasyUnlockScreenlockStateHandler::PAIRING_ADDED) {
608 return; 611 return;
609 } 612 }
610 613
611 chromeos::EasyUnlockKeyManager* key_manager = 614 chromeos::EasyUnlockKeyManager* key_manager =
612 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); 615 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
613 DCHECK(key_manager); 616 DCHECK(key_manager);
614 617
615 key_manager->GetDeviceDataList( 618 key_manager->GetDeviceDataList(
616 chromeos::UserContext(AccountId::FromUserEmail(user_id)), 619 chromeos::UserContext(account_id),
617 base::Bind(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking, 620 base::Bind(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking,
618 weak_ptr_factory_.GetWeakPtr(), user_id, paired_devices)); 621 weak_ptr_factory_.GetWeakPtr(), account_id, paired_devices));
619 #endif 622 #endif
620 } 623 }
621 624
622 void EasyUnlockService::SetTrialRun() { 625 void EasyUnlockService::SetTrialRun() {
623 DCHECK_EQ(GetType(), TYPE_REGULAR); 626 DCHECK_EQ(GetType(), TYPE_REGULAR);
624 627
625 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); 628 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler();
626 if (handler) 629 if (handler)
627 handler->SetTrialRun(); 630 handler->SetTrialRun();
628 } 631 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 #endif 700 #endif
698 } 701 }
699 } 702 }
700 } 703 }
701 704
702 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { 705 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() {
703 app_manager_->DisableAppIfLoaded(); 706 app_manager_->DisableAppIfLoaded();
704 } 707 }
705 708
706 void EasyUnlockService::NotifyUserUpdated() { 709 void EasyUnlockService::NotifyUserUpdated() {
707 std::string user_id = GetUserEmail(); 710 const AccountId& account_id = GetAccountId();
708 if (user_id.empty()) 711 if (!account_id.is_valid())
709 return; 712 return;
710 713
711 // Notify the easy unlock app that the user info changed. 714 // Notify the easy unlock app that the user info changed.
712 bool logged_in = GetType() == TYPE_REGULAR; 715 bool logged_in = GetType() == TYPE_REGULAR;
713 bool data_ready = logged_in || GetRemoteDevices() != NULL; 716 bool data_ready = logged_in || GetRemoteDevices() != NULL;
714 app_manager_->SendUserUpdatedEvent(user_id, logged_in, data_ready); 717 app_manager_->SendUserUpdatedEvent(account_id.GetUserEmail(), logged_in,
718 data_ready);
715 } 719 }
716 720
717 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { 721 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
718 FOR_EACH_OBSERVER( 722 FOR_EACH_OBSERVER(
719 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); 723 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
720 } 724 }
721 725
722 void EasyUnlockService::ResetScreenlockState() { 726 void EasyUnlockService::ResetScreenlockState() {
723 screenlock_state_handler_.reset(); 727 screenlock_state_handler_.reset();
724 auth_attempt_.reset(); 728 auth_attempt_.reset();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 bttype = BT_NORMAL; 761 bttype = BT_NORMAL;
758 } 762 }
759 #endif 763 #endif
760 } 764 }
761 UMA_HISTOGRAM_ENUMERATION( 765 UMA_HISTOGRAM_ENUMERATION(
762 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE); 766 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE);
763 } 767 }
764 } 768 }
765 769
766 void EasyUnlockService::SetHardlockStateForUser( 770 void EasyUnlockService::SetHardlockStateForUser(
767 const std::string& user_id, 771 const AccountId& account_id,
768 EasyUnlockScreenlockStateHandler::HardlockState state) { 772 EasyUnlockScreenlockStateHandler::HardlockState state) {
769 DCHECK(!user_id.empty()); 773 DCHECK(account_id.is_valid());
770 774
771 PrefService* local_state = GetLocalState(); 775 PrefService* local_state = GetLocalState();
772 if (!local_state) 776 if (!local_state)
773 return; 777 return;
774 778
775 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); 779 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState);
776 update->SetIntegerWithoutPathExpansion(user_id, static_cast<int>(state)); 780 update->SetIntegerWithoutPathExpansion(account_id.GetUserEmail(),
781 static_cast<int>(state));
777 782
778 if (GetUserEmail() == user_id) 783 if (GetAccountId() == account_id)
779 SetScreenlockHardlockedState(state); 784 SetScreenlockHardlockedState(state);
780 } 785 }
781 786
782 EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const { 787 EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const {
783 DCHECK(IsEnabled()); 788 DCHECK(IsEnabled());
784 789
785 if (GetHardlockState() != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { 790 if (GetHardlockState() != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) {
786 switch (GetHardlockState()) { 791 switch (GetHardlockState()) {
787 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK: 792 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK:
788 NOTREACHED(); 793 NOTREACHED();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 case ScreenlockState::AUTHENTICATED: 832 case ScreenlockState::AUTHENTICATED:
828 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; 833 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE;
829 } 834 }
830 } 835 }
831 836
832 NOTREACHED(); 837 NOTREACHED();
833 return EASY_UNLOCK_AUTH_EVENT_COUNT; 838 return EASY_UNLOCK_AUTH_EVENT_COUNT;
834 } 839 }
835 840
836 void EasyUnlockService::SetProximityAuthDevices( 841 void EasyUnlockService::SetProximityAuthDevices(
837 const std::string& user_id, 842 const AccountId& account_id,
838 const proximity_auth::RemoteDeviceList& remote_devices) { 843 const proximity_auth::RemoteDeviceList& remote_devices) {
839 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 844 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
840 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) 845 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery))
841 return; 846 return;
842 847
843 if (!proximity_auth_system_) { 848 if (!proximity_auth_system_) {
844 PA_LOG(INFO) << "Creating ProximityAuthSystem."; 849 PA_LOG(INFO) << "Creating ProximityAuthSystem.";
845 proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem( 850 proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem(
846 GetType() == TYPE_SIGNIN 851 GetType() == TYPE_SIGNIN
847 ? proximity_auth::ProximityAuthSystem::SIGN_IN 852 ? proximity_auth::ProximityAuthSystem::SIGN_IN
848 : proximity_auth::ProximityAuthSystem::SESSION_LOCK, 853 : proximity_auth::ProximityAuthSystem::SESSION_LOCK,
849 proximity_auth_client())); 854 proximity_auth_client()));
850 } 855 }
851 856
852 proximity_auth_system_->SetRemoteDevicesForUser(user_id, remote_devices); 857 proximity_auth_system_->SetRemoteDevicesForUser(account_id, remote_devices);
853 proximity_auth_system_->Start(); 858 proximity_auth_system_->Start();
854 } 859 }
855 860
856 #if defined(OS_CHROMEOS) 861 #if defined(OS_CHROMEOS)
857 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( 862 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking(
858 const std::string& user_id, 863 const AccountId& account_id,
859 const std::set<std::string> paired_devices, 864 const std::set<std::string> paired_devices,
860 bool success, 865 bool success,
861 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { 866 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) {
862 DCHECK(!user_id.empty() && !paired_devices.empty()); 867 DCHECK(account_id.is_valid() && !paired_devices.empty());
863 868
864 if (!success) { 869 if (!success) {
865 SetHardlockStateForUser(user_id, 870 SetHardlockStateForUser(account_id,
866 EasyUnlockScreenlockStateHandler::NO_PAIRING); 871 EasyUnlockScreenlockStateHandler::NO_PAIRING);
867 return; 872 return;
868 } 873 }
869 874
870 std::set<std::string> devices_in_cryptohome; 875 std::set<std::string> devices_in_cryptohome;
871 for (const auto& device_key_data : key_data_list) 876 for (const auto& device_key_data : key_data_list)
872 devices_in_cryptohome.insert(device_key_data.psk); 877 devices_in_cryptohome.insert(device_key_data.psk);
873 878
874 if (paired_devices != devices_in_cryptohome || 879 if (paired_devices != devices_in_cryptohome ||
875 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 880 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
876 SetHardlockStateForUser( 881 SetHardlockStateForUser(
877 user_id, 882 account_id, devices_in_cryptohome.empty()
878 devices_in_cryptohome.empty() 883 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED
879 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED 884 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
880 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
881 } 885 }
882 } 886 }
883 #endif 887 #endif
884 888
885 void EasyUnlockService::PrepareForSuspend() { 889 void EasyUnlockService::PrepareForSuspend() {
886 app_manager_->DisableAppIfLoaded(); 890 app_manager_->DisableAppIfLoaded();
887 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) 891 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive())
888 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); 892 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING);
889 if (proximity_auth_system_) 893 if (proximity_auth_system_)
890 proximity_auth_system_->OnSuspend(); 894 proximity_auth_system_->OnSuspend();
891 } 895 }
892 896
893 void EasyUnlockService::OnSuspendDone() { 897 void EasyUnlockService::OnSuspendDone() {
894 if (proximity_auth_system_) 898 if (proximity_auth_system_)
895 proximity_auth_system_->OnSuspendDone(); 899 proximity_auth_system_->OnSuspendDone();
896 } 900 }
897 901
898 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { 902 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() {
899 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || 903 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetAccountId().empty() ||
900 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 904 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
901 return; 905 return;
902 } 906 }
903 907
904 #if defined(OS_CHROMEOS) 908 #if defined(OS_CHROMEOS)
905 // If this is called before the session is started, the chances are Chrome 909 // If this is called before the session is started, the chances are Chrome
906 // is restarting in order to apply user flags. Don't check TPM keys in this 910 // is restarting in order to apply user flags. Don't check TPM keys in this
907 // case. 911 // case.
908 if (!user_manager::UserManager::Get() || 912 if (!user_manager::UserManager::Get() ||
909 !user_manager::UserManager::Get()->IsSessionStarted()) 913 !user_manager::UserManager::Get()->IsSessionStarted())
910 return; 914 return;
911 915
912 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt 916 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt
913 // failed. 917 // failed.
914 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) 918 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)
915 ->PrepareTpmKey(true /* check_private_key */, 919 ->PrepareTpmKey(true /* check_private_key */,
916 base::Closure()); 920 base::Closure());
917 #endif // defined(OS_CHROMEOS) 921 #endif // defined(OS_CHROMEOS)
918 922
919 tpm_key_checked_ = true; 923 tpm_key_checked_ = true;
920 } 924 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service.h ('k') | chrome/browser/signin/easy_unlock_service_regular.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698