Chromium Code Reviews| 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 581 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 582 | 582 |
| 583 // If it is marked that sign in has been successfully done, then directly | 583 // If it is marked that sign in has been successfully done, then directly |
| 584 // start ARC. | 584 // start ARC. |
| 585 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. | 585 // For testing, and for Kiosk mode, we also skip ToS negotiation procedure. |
| 586 // For backward compatibility, this check needs to be prior to the | 586 // For backward compatibility, this check needs to be prior to the |
| 587 // kArcTermsAccepted check below. | 587 // kArcTermsAccepted check below. |
| 588 if (prefs->GetBoolean(prefs::kArcSignedIn) || | 588 if (prefs->GetBoolean(prefs::kArcSignedIn) || |
| 589 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { | 589 IsArcOptInVerificationDisabled() || IsArcKioskMode()) { |
| 590 StartArc(); | 590 StartArc(); |
| 591 | |
| 592 // Skip Android management check for testing. | |
| 593 // We also skip if Android management check for Kiosk mode, | |
| 594 // because there are no managed human users for Kiosk exist. | |
| 595 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | |
| 596 (g_disable_ui_for_testing && | |
| 597 !g_enable_check_android_management_for_testing)) { | |
| 598 return; | |
| 599 } | |
| 600 | |
| 601 // Check Android management in parallel. | 591 // Check Android management in parallel. |
| 602 // Note: Because the callback may be called in synchronous way (i.e. called | 592 // Note: The callback OnBackgroundAndroidManagementChecked() can be called |
|
Yusuke Sato
2017/03/06 22:11:49
nit: 'StartBackgroundAndroidManagementCheck() may
hidehiko
2017/03/07 05:09:59
Done.
| |
| 603 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 593 // synchronously or asynchronously. In the callback, Google Play Store |
| 604 // Otherwise, SetArcPlayStoreEnabledForProfile() which may be called in | 594 // enabled preference can be set to false if managed, and it triggers |
| 605 // OnBackgroundAndroidManagementChecked() could be ignored. | 595 // RequestDisable() via ArcPlayStoreEnabledPreferenceHandler. |
| 606 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | 596 // Thus, StartArc() should be called so that disabling should work even |
| 607 profile_, context_->token_service(), context_->account_id(), | 597 // if synchronous call case. |
| 608 true /* retry_on_error */); | 598 StartBackgroundAndroidManagementCheck(); |
| 609 android_management_checker_->StartCheck( | |
| 610 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, | |
| 611 weak_ptr_factory_.GetWeakPtr())); | |
| 612 return; | 599 return; |
| 613 } | 600 } |
| 614 | 601 |
| 615 // If it is marked that the Terms of service is accepted already, | 602 // If it is marked that the Terms of service is accepted already, |
| 616 // just skip the negotiation with user, and start Android management | 603 // just skip the negotiation with user, and start Android management |
| 617 // check directly. | 604 // check directly. |
| 618 // This happens, e.g., when; | 605 // This happens, e.g., when; |
| 619 // 1) User accepted the Terms of service on OOBE flow. | 606 // 1) User accepted the Terms of service on OOBE flow. |
| 620 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 607 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
| 621 // before ARC sign in procedure was done. Then, logs in again. | 608 // before ARC sign in procedure was done. Then, logs in again. |
| 622 if (prefs->GetBoolean(prefs::kArcTermsAccepted)) { | 609 if (prefs->GetBoolean(prefs::kArcTermsAccepted)) { |
| 623 // Don't show UI for this progress if it was not shown. | 610 // Don't show UI for this progress if it was not shown. |
| 624 if (support_host_ && | 611 if (support_host_ && |
| 625 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) { | 612 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) { |
| 626 support_host_->ShowArcLoading(); | 613 support_host_->ShowArcLoading(); |
| 627 } | 614 } |
| 628 StartArcAndroidManagementCheck(); | 615 StartAndroidManagementCheck(); |
| 629 return; | 616 return; |
| 630 } | 617 } |
| 631 | 618 |
| 632 StartTermsOfServiceNegotiation(); | 619 StartTermsOfServiceNegotiation(); |
| 633 } | 620 } |
| 634 | 621 |
| 635 void ArcSessionManager::RequestDisable() { | 622 void ArcSessionManager::RequestDisable() { |
| 636 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 623 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 637 DCHECK(profile_); | 624 DCHECK(profile_); |
| 638 | 625 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 return; | 681 return; |
| 695 } | 682 } |
| 696 | 683 |
| 697 // Terms were accepted. | 684 // Terms were accepted. |
| 698 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 685 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 699 | 686 |
| 700 // Don't show UI for this progress if it was not shown. | 687 // Don't show UI for this progress if it was not shown. |
| 701 if (support_host_ && | 688 if (support_host_ && |
| 702 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) | 689 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) |
| 703 support_host_->ShowArcLoading(); | 690 support_host_->ShowArcLoading(); |
| 704 StartArcAndroidManagementCheck(); | 691 StartAndroidManagementCheck(); |
| 705 } | 692 } |
| 706 | 693 |
| 707 bool ArcSessionManager::AreArcAllOptInPreferencesManaged() const { | 694 bool ArcSessionManager::AreArcAllOptInPreferencesManaged() const { |
| 708 return IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_) && | 695 return IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_) && |
| 709 profile_->GetPrefs()->IsManagedPreference( | 696 profile_->GetPrefs()->IsManagedPreference( |
| 710 prefs::kArcBackupRestoreEnabled) && | 697 prefs::kArcBackupRestoreEnabled) && |
| 711 profile_->GetPrefs()->IsManagedPreference( | 698 profile_->GetPrefs()->IsManagedPreference( |
| 712 prefs::kArcLocationServiceEnabled); | 699 prefs::kArcLocationServiceEnabled); |
| 713 } | 700 } |
| 714 | 701 |
| 715 void ArcSessionManager::StartArcAndroidManagementCheck() { | 702 void ArcSessionManager::StartAndroidManagementCheck() { |
| 716 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 703 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 717 DCHECK(arc_session_runner_->IsStopped()); | 704 DCHECK(arc_session_runner_->IsStopped()); |
| 718 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 705 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 719 state_ == State::CHECKING_ANDROID_MANAGEMENT || | 706 state_ == State::CHECKING_ANDROID_MANAGEMENT || |
| 720 (state_ == State::STOPPED && | 707 (state_ == State::STOPPED && |
| 721 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted))); | 708 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted))); |
| 709 DCHECK(!android_management_checker_); | |
| 722 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 710 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 723 | 711 |
| 724 android_management_checker_.reset(new ArcAndroidManagementChecker( | 712 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( |
| 725 profile_, context_->token_service(), context_->account_id(), | 713 profile_, context_->token_service(), context_->account_id(), |
| 726 false /* retry_on_error */)); | 714 false /* retry_on_error */); |
| 727 android_management_checker_->StartCheck( | 715 android_management_checker_->StartCheck( |
| 728 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 716 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 729 weak_ptr_factory_.GetWeakPtr())); | 717 weak_ptr_factory_.GetWeakPtr())); |
| 730 } | 718 } |
| 731 | 719 |
| 732 void ArcSessionManager::OnAndroidManagementChecked( | 720 void ArcSessionManager::OnAndroidManagementChecked( |
| 733 policy::AndroidManagementClient::Result result) { | 721 policy::AndroidManagementClient::Result result) { |
| 734 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 735 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 723 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
| 724 DCHECK(android_management_checker_); | |
| 725 android_management_checker_.reset(); | |
| 736 | 726 |
| 737 switch (result) { | 727 switch (result) { |
| 738 case policy::AndroidManagementClient::Result::UNMANAGED: | 728 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 739 VLOG(1) << "Starting ARC for first sign in."; | 729 VLOG(1) << "Starting ARC for first sign in."; |
| 740 sign_in_start_time_ = base::Time::Now(); | 730 sign_in_start_time_ = base::Time::Now(); |
| 741 arc_sign_in_timer_.Start( | 731 arc_sign_in_timer_.Start( |
| 742 FROM_HERE, kArcSignInTimeout, | 732 FROM_HERE, kArcSignInTimeout, |
| 743 base::Bind(&ArcSessionManager::OnArcSignInTimeout, | 733 base::Bind(&ArcSessionManager::OnArcSignInTimeout, |
| 744 weak_ptr_factory_.GetWeakPtr())); | 734 weak_ptr_factory_.GetWeakPtr())); |
| 745 StartArc(); | 735 StartArc(); |
| 746 break; | 736 break; |
| 747 case policy::AndroidManagementClient::Result::MANAGED: | 737 case policy::AndroidManagementClient::Result::MANAGED: |
| 748 ShutdownSession(); | |
| 749 if (support_host_) { | 738 if (support_host_) { |
| 750 support_host_->ShowError( | 739 support_host_->ShowError( |
| 751 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); | 740 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); |
| 752 } | 741 } |
| 753 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 742 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 754 break; | 743 break; |
| 755 case policy::AndroidManagementClient::Result::ERROR: | 744 case policy::AndroidManagementClient::Result::ERROR: |
| 756 ShutdownSession(); | |
| 757 if (support_host_) { | 745 if (support_host_) { |
| 758 support_host_->ShowError( | 746 support_host_->ShowError( |
| 759 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); | 747 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); |
| 760 } | 748 } |
| 761 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 749 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 762 break; | 750 break; |
| 763 } | 751 } |
| 764 } | 752 } |
| 765 | 753 |
| 754 void ArcSessionManager::StartBackgroundAndroidManagementCheck() { | |
| 755 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 756 DCHECK_EQ(state_, State::ACTIVE); | |
| 757 DCHECK(!android_management_checker_); | |
| 758 | |
| 759 // Skip Android management check for testing. | |
| 760 // We also skip if Android management check for Kiosk mode, | |
| 761 // because there are no managed human users for Kiosk exist. | |
| 762 if (IsArcOptInVerificationDisabled() || IsArcKioskMode() || | |
| 763 (g_disable_ui_for_testing && | |
| 764 !g_enable_check_android_management_for_testing)) { | |
| 765 return; | |
| 766 } | |
| 767 | |
| 768 android_management_checker_ = base::MakeUnique<ArcAndroidManagementChecker>( | |
| 769 profile_, context_->token_service(), context_->account_id(), | |
| 770 true /* retry_on_error */); | |
| 771 android_management_checker_->StartCheck( | |
| 772 base::Bind(&ArcSessionManager::OnBackgroundAndroidManagementChecked, | |
| 773 weak_ptr_factory_.GetWeakPtr())); | |
| 774 } | |
| 775 | |
| 766 void ArcSessionManager::OnBackgroundAndroidManagementChecked( | 776 void ArcSessionManager::OnBackgroundAndroidManagementChecked( |
| 767 policy::AndroidManagementClient::Result result) { | 777 policy::AndroidManagementClient::Result result) { |
| 768 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 778 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 779 DCHECK(android_management_checker_); | |
| 780 android_management_checker_.reset(); | |
| 781 | |
| 769 switch (result) { | 782 switch (result) { |
| 770 case policy::AndroidManagementClient::Result::UNMANAGED: | 783 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 771 // Do nothing. ARC should be started already. | 784 // Do nothing. ARC should be started already. |
| 772 break; | 785 break; |
| 773 case policy::AndroidManagementClient::Result::MANAGED: | 786 case policy::AndroidManagementClient::Result::MANAGED: |
| 774 SetArcPlayStoreEnabledForProfile(profile_, false); | 787 SetArcPlayStoreEnabledForProfile(profile_, false); |
| 775 break; | 788 break; |
| 776 case policy::AndroidManagementClient::Result::ERROR: | 789 case policy::AndroidManagementClient::Result::ERROR: |
| 777 // This code should not be reached. For background check, | 790 // This code should not be reached. For background check, |
| 778 // retry_on_error should be set. | 791 // retry_on_error should be set. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 ShutdownSession(); | 856 ShutdownSession(); |
| 844 reenable_arc_ = true; | 857 reenable_arc_ = true; |
| 845 } else if (state_ == State::ACTIVE) { | 858 } else if (state_ == State::ACTIVE) { |
| 846 // This case is handled in ArcAuthService. | 859 // This case is handled in ArcAuthService. |
| 847 // Do nothing. | 860 // Do nothing. |
| 848 } else { | 861 } else { |
| 849 // Otherwise, we restart ARC. Note: this is the first boot case. | 862 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 850 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 863 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 851 // case must hit. | 864 // case must hit. |
| 852 support_host_->ShowArcLoading(); | 865 support_host_->ShowArcLoading(); |
| 853 StartArcAndroidManagementCheck(); | 866 StartAndroidManagementCheck(); |
| 854 } | 867 } |
| 855 } | 868 } |
| 856 | 869 |
| 857 void ArcSessionManager::OnSendFeedbackClicked() { | 870 void ArcSessionManager::OnSendFeedbackClicked() { |
| 858 DCHECK(support_host_); | 871 DCHECK(support_host_); |
| 859 chrome::OpenFeedbackDialog(nullptr); | 872 chrome::OpenFeedbackDialog(nullptr); |
| 860 } | 873 } |
| 861 | 874 |
| 862 void ArcSessionManager::SetArcSessionRunnerForTesting( | 875 void ArcSessionManager::SetArcSessionRunnerForTesting( |
| 863 std::unique_ptr<ArcSessionRunner> arc_session_runner) { | 876 std::unique_ptr<ArcSessionRunner> arc_session_runner) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 892 | 905 |
| 893 #undef MAP_STATE | 906 #undef MAP_STATE |
| 894 | 907 |
| 895 // Some compilers report an error even if all values of an enum-class are | 908 // Some compilers report an error even if all values of an enum-class are |
| 896 // covered exhaustively in a switch statement. | 909 // covered exhaustively in a switch statement. |
| 897 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 910 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 898 return os; | 911 return os; |
| 899 } | 912 } |
| 900 | 913 |
| 901 } // namespace arc | 914 } // namespace arc |
| OLD | NEW |