OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chromeos/arc/arc_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // TODO(hidehiko): Revisit to think about lazy initialization. | 415 // TODO(hidehiko): Revisit to think about lazy initialization. |
416 // | 416 // |
417 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must | 417 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must |
418 // be the kiosk app. In case of error the UI will be useless as well, because | 418 // be the kiosk app. In case of error the UI will be useless as well, because |
419 // in typical use case there will be no one nearby the kiosk device, who can | 419 // in typical use case there will be no one nearby the kiosk device, who can |
420 // do some action to solve the problem be means of UI. | 420 // do some action to solve the problem be means of UI. |
421 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && | 421 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && |
422 !IsArcKioskMode()) { | 422 !IsArcKioskMode()) { |
423 DCHECK(!support_host_); | 423 DCHECK(!support_host_); |
424 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); | 424 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); |
425 support_host_->SetArcManaged(IsArcManaged()); | 425 support_host_->SetArcManaged( |
| 426 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)); |
426 support_host_->AddObserver(this); | 427 support_host_->AddObserver(this); |
427 } | 428 } |
428 | 429 |
429 DCHECK_EQ(State::NOT_INITIALIZED, state_); | 430 DCHECK_EQ(State::NOT_INITIALIZED, state_); |
430 SetState(State::STOPPED); | 431 SetState(State::STOPPED); |
431 | 432 |
432 context_.reset(new ArcAuthContext(profile_)); | 433 context_.reset(new ArcAuthContext(profile_)); |
433 | 434 |
434 if (!g_disable_ui_for_testing || | 435 if (!g_disable_ui_for_testing || |
435 g_enable_check_android_management_for_testing) { | 436 g_enable_check_android_management_for_testing) { |
436 ArcAndroidManagementChecker::StartClient(); | 437 ArcAndroidManagementChecker::StartClient(); |
437 } | 438 } |
438 | 439 |
439 pref_change_registrar_.Init(profile_->GetPrefs()); | 440 pref_change_registrar_.Init(profile_->GetPrefs()); |
440 pref_change_registrar_.Add( | 441 pref_change_registrar_.Add( |
441 prefs::kArcEnabled, | 442 prefs::kArcEnabled, |
442 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 443 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
443 weak_ptr_factory_.GetWeakPtr())); | 444 weak_ptr_factory_.GetWeakPtr())); |
444 | 445 |
445 // Chrome may be shut down before completing ARC data removal. | 446 // Chrome may be shut down before completing ARC data removal. |
446 // In such a case, start removing the data now. | 447 // In such a case, start removing the data now. |
447 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 448 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
448 VLOG(1) << "ARC data removal requested in previous session."; | 449 VLOG(1) << "ARC data removal requested in previous session."; |
449 RemoveArcData(); | 450 RemoveArcData(); |
450 } | 451 } |
451 | 452 |
452 if (IsArcPlayStoreEnabled()) { | 453 if (IsArcPlayStoreEnabledForProfile(profile_)) { |
453 VLOG(1) << "ARC is already enabled."; | 454 VLOG(1) << "ARC is already enabled."; |
454 DCHECK(!enable_requested_); | 455 DCHECK(!enable_requested_); |
455 RequestEnable(); | 456 RequestEnable(); |
456 } else { | 457 } else { |
457 VLOG(1) << "ARC is initially disabled. Removing data."; | 458 VLOG(1) << "ARC is initially disabled. Removing data."; |
458 RemoveArcData(); | 459 RemoveArcData(); |
459 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 460 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
460 OnIsSyncingChanged(); | 461 OnIsSyncingChanged(); |
461 } | 462 } |
462 } | 463 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 507 } |
507 ShutdownSession(); | 508 ShutdownSession(); |
508 if (support_host_) | 509 if (support_host_) |
509 support_host_->Close(); | 510 support_host_->Close(); |
510 } | 511 } |
511 | 512 |
512 void ArcSessionManager::OnOptInPreferenceChanged() { | 513 void ArcSessionManager::OnOptInPreferenceChanged() { |
513 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 514 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
514 DCHECK(profile_); | 515 DCHECK(profile_); |
515 | 516 |
516 const bool arc_enabled = IsArcPlayStoreEnabled(); | 517 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_); |
517 if (!IsArcManaged()) { | 518 const bool is_play_store_managed = |
| 519 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); |
| 520 if (!is_play_store_managed) { |
518 // Update UMA only for non-Managed cases. | 521 // Update UMA only for non-Managed cases. |
519 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 522 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN |
520 : OptInActionType::OPTED_OUT); | 523 : OptInActionType::OPTED_OUT); |
521 | 524 |
522 if (!arc_enabled) { | 525 if (!is_play_store_enabled) { |
523 // Remove the pinned Play Store icon launcher in Shelf. | 526 // Remove the pinned Play Store icon launcher in Shelf. |
524 // This is only for non-Managed cases. In managed cases, it is expected | 527 // This is only for non-Managed cases. In managed cases, it is expected |
525 // to be "disabled" rather than "removed", so keep it here. | 528 // to be "disabled" rather than "removed", so keep it here. |
526 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 529 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); |
527 if (shelf_delegate) | 530 if (shelf_delegate) |
528 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 531 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
529 } | 532 } |
530 } | 533 } |
531 | 534 |
532 if (support_host_) | 535 if (support_host_) |
533 support_host_->SetArcManaged(IsArcManaged()); | 536 support_host_->SetArcManaged(is_play_store_managed); |
534 | 537 |
535 // Hide auth notification if it was opened before and arc.enabled pref was | 538 // Hide auth notification if it was opened before and arc.enabled pref was |
536 // explicitly set to true or false. | 539 // explicitly set to true or false. |
537 if (!g_disable_ui_for_testing && | 540 if (!g_disable_ui_for_testing && |
538 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 541 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
539 ArcAuthNotification::Hide(); | 542 ArcAuthNotification::Hide(); |
540 } | 543 } |
541 | 544 |
542 if (arc_enabled) | 545 if (is_play_store_enabled) |
543 RequestEnable(); | 546 RequestEnable(); |
544 else | 547 else |
545 RequestDisable(); | 548 RequestDisable(); |
546 | 549 |
547 for (auto& observer : observer_list_) | 550 for (auto& observer : observer_list_) |
548 observer.OnArcPlayStoreEnabledChanged(arc_enabled); | 551 observer.OnArcPlayStoreEnabledChanged(is_play_store_enabled); |
549 } | 552 } |
550 | 553 |
551 void ArcSessionManager::ShutdownSession() { | 554 void ArcSessionManager::ShutdownSession() { |
552 arc_sign_in_timer_.Stop(); | 555 arc_sign_in_timer_.Stop(); |
553 playstore_launcher_.reset(); | 556 playstore_launcher_.reset(); |
554 terms_of_service_negotiator_.reset(); | 557 terms_of_service_negotiator_.reset(); |
555 android_management_checker_.reset(); | 558 android_management_checker_.reset(); |
556 arc_session_runner_->RequestStop(); | 559 arc_session_runner_->RequestStop(); |
557 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 560 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
558 // still be running when we return from this function. Do not set the | 561 // still be running when we return from this function. Do not set the |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 } | 643 } |
641 | 644 |
642 // Update UMA with user cancel only if error is not currently shown. | 645 // Update UMA with user cancel only if error is not currently shown. |
643 if (support_host_ && | 646 if (support_host_ && |
644 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE && | 647 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE && |
645 support_host_->ui_page() != ArcSupportHost::UIPage::ERROR) { | 648 support_host_->ui_page() != ArcSupportHost::UIPage::ERROR) { |
646 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 649 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
647 } | 650 } |
648 | 651 |
649 StopArc(); | 652 StopArc(); |
650 SetArcPlayStoreEnabled(false); | 653 SetArcPlayStoreEnabledForProfile(profile_, false); |
651 } | |
652 | |
653 bool ArcSessionManager::IsArcManaged() const { | |
654 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
655 DCHECK(profile_); | |
656 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); | |
657 } | |
658 | |
659 bool ArcSessionManager::IsArcPlayStoreEnabled() const { | |
660 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
661 if (!IsAllowed()) | |
662 return false; | |
663 | |
664 DCHECK(profile_); | |
665 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | |
666 } | |
667 | |
668 void ArcSessionManager::SetArcPlayStoreEnabled(bool enabled) { | |
669 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
670 DCHECK(profile_); | |
671 | |
672 if (IsArcManaged()) { | |
673 VLOG(1) << "Whether Google Play Store is enabled is managed. Do nothing."; | |
674 return; | |
675 } | |
676 | |
677 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); | |
678 } | 654 } |
679 | 655 |
680 void ArcSessionManager::RecordArcState() { | 656 void ArcSessionManager::RecordArcState() { |
681 // Only record Enabled state if ARC is allowed in the first place, so we do | 657 // Only record Enabled state if ARC is allowed in the first place, so we do |
682 // not split the ARC population by devices that cannot run ARC. | 658 // not split the ARC population by devices that cannot run ARC. |
683 if (IsAllowed()) | 659 if (IsAllowed()) |
684 UpdateEnabledStateUMA(enable_requested_); | 660 UpdateEnabledStateUMA(enable_requested_); |
685 } | 661 } |
686 | 662 |
687 void ArcSessionManager::RequestEnable() { | 663 void ArcSessionManager::RequestEnable() { |
(...skipping 27 matching lines...) Expand all Loading... |
715 // For ARC Kiosk we skip ToS because it is very likely that near the device | 691 // For ARC Kiosk we skip ToS because it is very likely that near the device |
716 // there will be no one who is eligible to accept them. | 692 // there will be no one who is eligible to accept them. |
717 // TODO(poromov): Move to more Kiosk dedicated set-up phase. | 693 // TODO(poromov): Move to more Kiosk dedicated set-up phase. |
718 if (IsArcKioskMode()) | 694 if (IsArcKioskMode()) |
719 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 695 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
720 | 696 |
721 // Skip to show UI asking users to enable/disable their preference for | 697 // Skip to show UI asking users to enable/disable their preference for |
722 // backup-restore and location-service, if both are managed by the admin | 698 // backup-restore and location-service, if both are managed by the admin |
723 // policy. Note that the ToS agreement is anyway not shown in the case of the | 699 // policy. Note that the ToS agreement is anyway not shown in the case of the |
724 // managed ARC. | 700 // managed ARC. |
725 if (IsArcManaged() && | 701 if (arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_) && |
726 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && | 702 prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled) && |
727 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { | 703 prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) { |
728 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 704 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
729 } | 705 } |
730 | 706 |
731 // If it is marked that sign in has been successfully done, then directly | 707 // If it is marked that sign in has been successfully done, then directly |
732 // start ARC. | 708 // start ARC. |
733 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. | 709 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. |
734 // For backward compatibility, this check needs to be prior to the | 710 // For backward compatibility, this check needs to be prior to the |
735 // kArcTermsAccepted check below. | 711 // kArcTermsAccepted check below. |
736 if (prefs->GetBoolean(prefs::kArcSignedIn) || | 712 if (prefs->GetBoolean(prefs::kArcSignedIn) || |
737 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { | 713 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { |
738 StartArc(); | 714 StartArc(); |
739 | 715 |
740 // Skip Android management check for testing. | 716 // Skip Android management check for testing. |
741 // We also skip if Android management check for Kiosk mode, | 717 // We also skip if Android management check for Kiosk mode, |
742 // because there are no managed human users for Kiosk exist. | 718 // because there are no managed human users for Kiosk exist. |
743 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | 719 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || |
744 (g_disable_ui_for_testing && | 720 (g_disable_ui_for_testing && |
745 !g_enable_check_android_management_for_testing)) { | 721 !g_enable_check_android_management_for_testing)) { |
746 return; | 722 return; |
747 } | 723 } |
748 | 724 |
749 // Check Android management in parallel. | 725 // Check Android management in parallel. |
750 // Note: Because the callback may be called in synchronous way (i.e. called | 726 // Note: Because the callback may be called in synchronous way (i.e. called |
751 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 727 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
752 // Otherwise, SetArcPlayStoreEnabled() which may be called in | 728 // Otherwise, SetArcPlayStoreEnabledForProfile() which may be called in |
753 // OnBackgroundAndroidManagementChecked() could be ignored. | 729 // OnBackgroundAndroidManagementChecked() could be ignored. |
754 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | 730 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( |
755 profile_, context_->token_service(), context_->account_id(), | 731 profile_, context_->token_service(), context_->account_id(), |
756 true /* retry_on_error */); | 732 true /* retry_on_error */); |
757 android_management_checker_->StartCheck( | 733 android_management_checker_->StartCheck( |
758 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, | 734 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, |
759 weak_ptr_factory_.GetWeakPtr())); | 735 weak_ptr_factory_.GetWeakPtr())); |
760 return; | 736 return; |
761 } | 737 } |
762 | 738 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 880 } |
905 | 881 |
906 void ArcSessionManager::OnBackgroundAndroidManagementChecked( | 882 void ArcSessionManager::OnBackgroundAndroidManagementChecked( |
907 policy::AndroidManagementClient::Result result) { | 883 policy::AndroidManagementClient::Result result) { |
908 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 884 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
909 switch (result) { | 885 switch (result) { |
910 case policy::AndroidManagementClient::Result::UNMANAGED: | 886 case policy::AndroidManagementClient::Result::UNMANAGED: |
911 // Do nothing. ARC should be started already. | 887 // Do nothing. ARC should be started already. |
912 break; | 888 break; |
913 case policy::AndroidManagementClient::Result::MANAGED: | 889 case policy::AndroidManagementClient::Result::MANAGED: |
914 SetArcPlayStoreEnabled(false); | 890 SetArcPlayStoreEnabledForProfile(profile_, false); |
915 break; | 891 break; |
916 case policy::AndroidManagementClient::Result::ERROR: | 892 case policy::AndroidManagementClient::Result::ERROR: |
917 // This code should not be reached. For background check, | 893 // This code should not be reached. For background check, |
918 // retry_on_error should be set. | 894 // retry_on_error should be set. |
919 NOTREACHED(); | 895 NOTREACHED(); |
920 } | 896 } |
921 } | 897 } |
922 | 898 |
923 void ArcSessionManager::OnWindowClosed() { | 899 void ArcSessionManager::OnWindowClosed() { |
924 DCHECK(support_host_); | 900 DCHECK(support_host_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 984 |
1009 #undef MAP_STATE | 985 #undef MAP_STATE |
1010 | 986 |
1011 // Some compilers report an error even if all values of an enum-class are | 987 // Some compilers report an error even if all values of an enum-class are |
1012 // covered exhaustively in a switch statement. | 988 // covered exhaustively in a switch statement. |
1013 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 989 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
1014 return os; | 990 return os; |
1015 } | 991 } |
1016 | 992 |
1017 } // namespace arc | 993 } // namespace arc |
OLD | NEW |