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

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: Update after review. 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 #endif 696 #endif
694 } 697 }
695 } 698 }
696 } 699 }
697 700
698 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { 701 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() {
699 app_manager_->DisableAppIfLoaded(); 702 app_manager_->DisableAppIfLoaded();
700 } 703 }
701 704
702 void EasyUnlockService::NotifyUserUpdated() { 705 void EasyUnlockService::NotifyUserUpdated() {
703 std::string user_id = GetUserEmail(); 706 const AccountId& account_id = GetAccountId();
704 if (user_id.empty()) 707 if (!account_id.is_valid())
705 return; 708 return;
706 709
707 // Notify the easy unlock app that the user info changed. 710 // Notify the easy unlock app that the user info changed.
708 bool logged_in = GetType() == TYPE_REGULAR; 711 bool logged_in = GetType() == TYPE_REGULAR;
709 bool data_ready = logged_in || GetRemoteDevices() != NULL; 712 bool data_ready = logged_in || GetRemoteDevices() != NULL;
710 app_manager_->SendUserUpdatedEvent(user_id, logged_in, data_ready); 713 app_manager_->SendUserUpdatedEvent(account_id.GetUserEmail(), logged_in,
714 data_ready);
711 } 715 }
712 716
713 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { 717 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
714 FOR_EACH_OBSERVER( 718 FOR_EACH_OBSERVER(
715 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); 719 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
716 } 720 }
717 721
718 void EasyUnlockService::ResetScreenlockState() { 722 void EasyUnlockService::ResetScreenlockState() {
719 screenlock_state_handler_.reset(); 723 screenlock_state_handler_.reset();
720 auth_attempt_.reset(); 724 auth_attempt_.reset();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 bttype = BT_NORMAL; 757 bttype = BT_NORMAL;
754 } 758 }
755 #endif 759 #endif
756 } 760 }
757 UMA_HISTOGRAM_ENUMERATION( 761 UMA_HISTOGRAM_ENUMERATION(
758 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE); 762 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE);
759 } 763 }
760 } 764 }
761 765
762 void EasyUnlockService::SetHardlockStateForUser( 766 void EasyUnlockService::SetHardlockStateForUser(
763 const std::string& user_id, 767 const AccountId& account_id,
764 EasyUnlockScreenlockStateHandler::HardlockState state) { 768 EasyUnlockScreenlockStateHandler::HardlockState state) {
765 DCHECK(!user_id.empty()); 769 DCHECK(account_id.is_valid());
766 770
767 PrefService* local_state = GetLocalState(); 771 PrefService* local_state = GetLocalState();
768 if (!local_state) 772 if (!local_state)
769 return; 773 return;
770 774
771 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); 775 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState);
772 update->SetIntegerWithoutPathExpansion(user_id, static_cast<int>(state)); 776 update->SetIntegerWithoutPathExpansion(account_id.GetUserEmail(),
777 static_cast<int>(state));
773 778
774 if (GetUserEmail() == user_id) 779 if (GetAccountId() == account_id)
775 SetScreenlockHardlockedState(state); 780 SetScreenlockHardlockedState(state);
776 } 781 }
777 782
778 EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const { 783 EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const {
779 DCHECK(IsEnabled()); 784 DCHECK(IsEnabled());
780 785
781 if (GetHardlockState() != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { 786 if (GetHardlockState() != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) {
782 switch (GetHardlockState()) { 787 switch (GetHardlockState()) {
783 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK: 788 case EasyUnlockScreenlockStateHandler::NO_HARDLOCK:
784 NOTREACHED(); 789 NOTREACHED();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 *remote_device, proximity_auth_client())); 849 *remote_device, proximity_auth_client()));
845 proximity_auth_system_->Start(); 850 proximity_auth_system_->Start();
846 } else { 851 } else {
847 PA_LOG(INFO) << "Remote device removed, destroying ProximityAuthSystem."; 852 PA_LOG(INFO) << "Remote device removed, destroying ProximityAuthSystem.";
848 proximity_auth_system_.reset(); 853 proximity_auth_system_.reset();
849 } 854 }
850 } 855 }
851 856
852 #if defined(OS_CHROMEOS) 857 #if defined(OS_CHROMEOS)
853 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( 858 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking(
854 const std::string& user_id, 859 const AccountId& account_id,
855 const std::set<std::string> paired_devices, 860 const std::set<std::string> paired_devices,
856 bool success, 861 bool success,
857 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { 862 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) {
858 DCHECK(!user_id.empty() && !paired_devices.empty()); 863 DCHECK(account_id.is_valid() && !paired_devices.empty());
859 864
860 if (!success) { 865 if (!success) {
861 SetHardlockStateForUser(user_id, 866 SetHardlockStateForUser(account_id,
862 EasyUnlockScreenlockStateHandler::NO_PAIRING); 867 EasyUnlockScreenlockStateHandler::NO_PAIRING);
863 return; 868 return;
864 } 869 }
865 870
866 std::set<std::string> devices_in_cryptohome; 871 std::set<std::string> devices_in_cryptohome;
867 for (const auto& device_key_data : key_data_list) 872 for (const auto& device_key_data : key_data_list)
868 devices_in_cryptohome.insert(device_key_data.psk); 873 devices_in_cryptohome.insert(device_key_data.psk);
869 874
870 if (paired_devices != devices_in_cryptohome || 875 if (paired_devices != devices_in_cryptohome ||
871 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 876 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
872 SetHardlockStateForUser( 877 SetHardlockStateForUser(
873 user_id, 878 account_id, devices_in_cryptohome.empty()
874 devices_in_cryptohome.empty() 879 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED
875 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED 880 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
876 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
877 } 881 }
878 } 882 }
879 #endif 883 #endif
880 884
881 void EasyUnlockService::PrepareForSuspend() { 885 void EasyUnlockService::PrepareForSuspend() {
882 app_manager_->DisableAppIfLoaded(); 886 app_manager_->DisableAppIfLoaded();
883 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) 887 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive())
884 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); 888 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING);
885 if (proximity_auth_system_) 889 if (proximity_auth_system_)
886 proximity_auth_system_->OnSuspend(); 890 proximity_auth_system_->OnSuspend();
887 } 891 }
888 892
889 void EasyUnlockService::OnSuspendDone() { 893 void EasyUnlockService::OnSuspendDone() {
890 if (proximity_auth_system_) 894 if (proximity_auth_system_)
891 proximity_auth_system_->OnSuspendDone(); 895 proximity_auth_system_->OnSuspendDone();
892 } 896 }
893 897
894 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { 898 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() {
895 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || 899 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetAccountId().empty() ||
896 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 900 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
897 return; 901 return;
898 } 902 }
899 903
900 #if defined(OS_CHROMEOS) 904 #if defined(OS_CHROMEOS)
901 // If this is called before the session is started, the chances are Chrome 905 // If this is called before the session is started, the chances are Chrome
902 // is restarting in order to apply user flags. Don't check TPM keys in this 906 // is restarting in order to apply user flags. Don't check TPM keys in this
903 // case. 907 // case.
904 if (!user_manager::UserManager::Get() || 908 if (!user_manager::UserManager::Get() ||
905 !user_manager::UserManager::Get()->IsSessionStarted()) 909 !user_manager::UserManager::Get()->IsSessionStarted())
906 return; 910 return;
907 911
908 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt 912 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt
909 // failed. 913 // failed.
910 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) 914 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)
911 ->PrepareTpmKey(true /* check_private_key */, 915 ->PrepareTpmKey(true /* check_private_key */,
912 base::Closure()); 916 base::Closure());
913 #endif // defined(OS_CHROMEOS) 917 #endif // defined(OS_CHROMEOS)
914 918
915 tpm_key_checked_ = true; 919 tpm_key_checked_ = true;
916 } 920 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698