| 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_auth_context.h" | 19 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 20 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 23 #include "chrome/browser/chromeos/arc/arc_util.h" | 23 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" | 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
| 25 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" |
| 25 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 26 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 26 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 27 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 27 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
| 28 #include "chrome/browser/policy/profile_policy_connector.h" | 30 #include "chrome/browser/policy/profile_policy_connector.h" |
| 29 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 31 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 30 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 32 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 34 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 35 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
| 36 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // only. | 118 // only. |
| 117 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); | 119 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); |
| 118 registry->RegisterBooleanPref(prefs::kArcEnabled, false); | 120 registry->RegisterBooleanPref(prefs::kArcEnabled, false); |
| 119 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 121 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
| 120 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); | 122 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); |
| 121 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 123 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); |
| 122 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); | 124 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); |
| 123 } | 125 } |
| 124 | 126 |
| 125 // static | 127 // static |
| 128 bool ArcSessionManager::IsOobeOptInActive() { |
| 129 // ARC OOBE OptIn is optional for now. Test if it exists and login host is |
| 130 // active. |
| 131 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) |
| 132 return false; |
| 133 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 134 chromeos::switches::kEnableArcOOBEOptIn)) |
| 135 return false; |
| 136 if (!chromeos::LoginDisplayHost::default_host()) |
| 137 return false; |
| 138 return true; |
| 139 } |
| 140 |
| 141 // static |
| 126 void ArcSessionManager::DisableUIForTesting() { | 142 void ArcSessionManager::DisableUIForTesting() { |
| 127 g_disable_ui_for_testing = true; | 143 g_disable_ui_for_testing = true; |
| 128 } | 144 } |
| 129 | 145 |
| 130 // static | 146 // static |
| 131 void ArcSessionManager::SetShelfDelegateForTesting( | 147 void ArcSessionManager::SetShelfDelegateForTesting( |
| 132 ash::ShelfDelegate* shelf_delegate) { | 148 ash::ShelfDelegate* shelf_delegate) { |
| 133 g_shelf_delegate_for_testing = shelf_delegate; | 149 g_shelf_delegate_for_testing = shelf_delegate; |
| 134 } | 150 } |
| 135 | 151 |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 } | 596 } |
| 581 | 597 |
| 582 // If it is marked that the Terms of service is accepted already, | 598 // If it is marked that the Terms of service is accepted already, |
| 583 // just skip the negotiation with user, and start Android management | 599 // just skip the negotiation with user, and start Android management |
| 584 // check directly. | 600 // check directly. |
| 585 // This happens, e.g., when; | 601 // This happens, e.g., when; |
| 586 // 1) User accepted the Terms of service on OOBE flow. | 602 // 1) User accepted the Terms of service on OOBE flow. |
| 587 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 603 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
| 588 // before ARC sign in procedure was done. Then, logs in again. | 604 // before ARC sign in procedure was done. Then, logs in again. |
| 589 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 605 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 590 support_host_->ShowArcLoading(); | 606 // Don't show UI for this progress if it was not shown. |
| 607 if (support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) |
| 608 support_host_->ShowArcLoading(); |
| 591 StartArcAndroidManagementCheck(); | 609 StartArcAndroidManagementCheck(); |
| 592 return; | 610 return; |
| 593 } | 611 } |
| 594 | 612 |
| 595 // Need user's explicit Terms Of Service agreement. | 613 // Need user's explicit Terms Of Service agreement. Prevent race condition |
| 596 StartTermsOfServiceNegotiation(); | 614 // when ARC can be enabled before profile is synced. In last case |
| 615 // OnOptInPreferenceChanged is called twice. |
| 616 // TODO (crbug.com/687185) |
| 617 if (state_ != State::SHOWING_TERMS_OF_SERVICE) |
| 618 StartTermsOfServiceNegotiation(); |
| 597 } | 619 } |
| 598 | 620 |
| 599 void ArcSessionManager::ShutdownSession() { | 621 void ArcSessionManager::ShutdownSession() { |
| 600 arc_sign_in_timer_.Stop(); | 622 arc_sign_in_timer_.Stop(); |
| 601 playstore_launcher_.reset(); | 623 playstore_launcher_.reset(); |
| 602 terms_of_service_negotiator_.reset(); | 624 terms_of_service_negotiator_.reset(); |
| 603 android_management_checker_.reset(); | 625 android_management_checker_.reset(); |
| 604 arc_session_runner_->RequestStop(); | 626 arc_session_runner_->RequestStop(); |
| 605 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 627 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
| 606 // still be running when we return from this function. Do not set the | 628 // still be running when we return from this function. Do not set the |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // running the user should not be able to continue until the ARC instance | 774 // running the user should not be able to continue until the ARC instance |
| 753 // has stopped. | 775 // has stopped. |
| 754 if (support_host_) { | 776 if (support_host_) { |
| 755 support_host_->ShowError( | 777 support_host_->ShowError( |
| 756 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 778 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 757 } | 779 } |
| 758 return; | 780 return; |
| 759 } | 781 } |
| 760 | 782 |
| 761 SetState(State::SHOWING_TERMS_OF_SERVICE); | 783 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 762 if (support_host_) { | 784 if (IsOobeOptInActive()) { |
| 785 VLOG(1) << "Use OOBE negotiator."; |
| 763 terms_of_service_negotiator_ = | 786 terms_of_service_negotiator_ = |
| 764 base::MakeUnique<ArcTermsOfServiceNegotiator>(profile_->GetPrefs(), | 787 base::MakeUnique<ArcTermsOfServiceOobeNegotiator>(); |
| 765 support_host_.get()); | 788 } else if (support_host_) { |
| 789 VLOG(1) << "Use default negotiator."; |
| 790 terms_of_service_negotiator_ = |
| 791 base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>( |
| 792 profile_->GetPrefs(), support_host_.get()); |
| 793 } |
| 794 |
| 795 if (terms_of_service_negotiator_) { |
| 766 terms_of_service_negotiator_->StartNegotiation( | 796 terms_of_service_negotiator_->StartNegotiation( |
| 767 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, | 797 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, |
| 768 weak_ptr_factory_.GetWeakPtr())); | 798 weak_ptr_factory_.GetWeakPtr())); |
| 769 } | 799 } |
| 770 } | 800 } |
| 771 | 801 |
| 772 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { | 802 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { |
| 773 DCHECK(terms_of_service_negotiator_); | 803 DCHECK(terms_of_service_negotiator_); |
| 774 terms_of_service_negotiator_.reset(); | 804 terms_of_service_negotiator_.reset(); |
| 775 | 805 |
| 776 if (!accepted) { | 806 if (!accepted) { |
| 777 // To cancel, user needs to close the window. Note that clicking "Cancel" | 807 // To cancel, user needs to close the window. Note that clicking "Cancel" |
| 778 // button effectively just closes the window. | 808 // button effectively just closes the window. |
| 779 CancelAuthCode(); | 809 CancelAuthCode(); |
| 780 return; | 810 return; |
| 781 } | 811 } |
| 782 | 812 |
| 783 // Terms were accepted. | 813 // Terms were accepted. |
| 784 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 814 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 785 | 815 |
| 786 support_host_->ShowArcLoading(); | 816 // Don't show UI for this progress if it was not shown. |
| 817 if (support_host_ && |
| 818 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) |
| 819 support_host_->ShowArcLoading(); |
| 787 StartArcAndroidManagementCheck(); | 820 StartArcAndroidManagementCheck(); |
| 788 } | 821 } |
| 789 | 822 |
| 790 void ArcSessionManager::StartArcAndroidManagementCheck() { | 823 void ArcSessionManager::StartArcAndroidManagementCheck() { |
| 791 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 824 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 792 DCHECK(arc_session_runner_->IsStopped()); | 825 DCHECK(arc_session_runner_->IsStopped()); |
| 793 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 826 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 794 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 827 state_ == State::CHECKING_ANDROID_MANAGEMENT || |
| 828 (state_ == State::STOPPED && |
| 829 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted))); |
| 795 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 830 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 796 | 831 |
| 797 android_management_checker_.reset(new ArcAndroidManagementChecker( | 832 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 798 profile_, context_->token_service(), context_->account_id(), | 833 profile_, context_->token_service(), context_->account_id(), |
| 799 false /* retry_on_error */)); | 834 false /* retry_on_error */)); |
| 800 android_management_checker_->StartCheck( | 835 android_management_checker_->StartCheck( |
| 801 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 836 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 802 weak_ptr_factory_.GetWeakPtr())); | 837 weak_ptr_factory_.GetWeakPtr())); |
| 803 } | 838 } |
| 804 | 839 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 return os << "ACTIVE"; | 976 return os << "ACTIVE"; |
| 942 } | 977 } |
| 943 | 978 |
| 944 // Some compiler reports an error even if all values of an enum-class are | 979 // Some compiler reports an error even if all values of an enum-class are |
| 945 // covered indivisually in a switch statement. | 980 // covered indivisually in a switch statement. |
| 946 NOTREACHED(); | 981 NOTREACHED(); |
| 947 return os; | 982 return os; |
| 948 } | 983 } |
| 949 | 984 |
| 950 } // namespace arc | 985 } // namespace arc |
| OLD | NEW |