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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698