| 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/optin/arc_terms_of_service_negotiator.h" | 23 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
| 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" |
| 24 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 25 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 25 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 26 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 26 #include "chrome/browser/chromeos/login/user_flow.h" | 28 #include "chrome/browser/chromeos/login/user_flow.h" |
| 27 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 29 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 30 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 29 #include "chrome/browser/lifetime/application_lifetime.h" | 31 #include "chrome/browser/lifetime/application_lifetime.h" |
| 30 #include "chrome/browser/policy/profile_policy_connector.h" | 32 #include "chrome/browser/policy/profile_policy_connector.h" |
| 31 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 33 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 32 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 36 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 37 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // only. | 124 // only. |
| 123 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); | 125 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); |
| 124 registry->RegisterBooleanPref(prefs::kArcEnabled, false); | 126 registry->RegisterBooleanPref(prefs::kArcEnabled, false); |
| 125 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 127 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
| 126 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); | 128 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); |
| 127 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 129 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); |
| 128 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); | 130 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // static | 133 // static |
| 134 bool ArcSessionManager::IsOobeOptInActive() { |
| 135 // ARC OOBE OptIn is optional for now. Test if it exists and login host is |
| 136 // active. |
| 137 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) |
| 138 return false; |
| 139 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 140 chromeos::switches::kEnableArcOOBEOptIn)) |
| 141 return false; |
| 142 if (!chromeos::LoginDisplayHost::default_host()) |
| 143 return false; |
| 144 return true; |
| 145 } |
| 146 |
| 147 // static |
| 132 void ArcSessionManager::DisableUIForTesting() { | 148 void ArcSessionManager::DisableUIForTesting() { |
| 133 g_disable_ui_for_testing = true; | 149 g_disable_ui_for_testing = true; |
| 134 } | 150 } |
| 135 | 151 |
| 136 // static | 152 // static |
| 137 void ArcSessionManager::SetShelfDelegateForTesting( | 153 void ArcSessionManager::SetShelfDelegateForTesting( |
| 138 ash::ShelfDelegate* shelf_delegate) { | 154 ash::ShelfDelegate* shelf_delegate) { |
| 139 g_shelf_delegate_for_testing = shelf_delegate; | 155 g_shelf_delegate_for_testing = shelf_delegate; |
| 140 } | 156 } |
| 141 | 157 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 675 } |
| 660 | 676 |
| 661 // If it is marked that the Terms of service is accepted already, | 677 // If it is marked that the Terms of service is accepted already, |
| 662 // just skip the negotiation with user, and start Android management | 678 // just skip the negotiation with user, and start Android management |
| 663 // check directly. | 679 // check directly. |
| 664 // This happens, e.g., when; | 680 // This happens, e.g., when; |
| 665 // 1) User accepted the Terms of service on OOBE flow. | 681 // 1) User accepted the Terms of service on OOBE flow. |
| 666 // 2) User accepted the Terms of service on Opt-in flow, but logged out | 682 // 2) User accepted the Terms of service on Opt-in flow, but logged out |
| 667 // before ARC sign in procedure was done. Then, logs in again. | 683 // before ARC sign in procedure was done. Then, logs in again. |
| 668 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 684 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 669 support_host_->ShowArcLoading(); | 685 // Don't show UI for this progress if it was not shown. |
| 686 if (support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) |
| 687 support_host_->ShowArcLoading(); |
| 670 StartArcAndroidManagementCheck(); | 688 StartArcAndroidManagementCheck(); |
| 671 return; | 689 return; |
| 672 } | 690 } |
| 673 | 691 |
| 674 // Need user's explicit Terms Of Service agreement. | 692 // Need user's explicit Terms Of Service agreement. Prevent race condition |
| 675 StartTermsOfServiceNegotiation(); | 693 // when ARC can be enabled before profile is synced. In last case |
| 694 // OnOptInPreferenceChanged is called twice. |
| 695 if (state_ != State::SHOWING_TERMS_OF_SERVICE) |
| 696 StartTermsOfServiceNegotiation(); |
| 676 } | 697 } |
| 677 | 698 |
| 678 void ArcSessionManager::ShutdownSession() { | 699 void ArcSessionManager::ShutdownSession() { |
| 679 arc_sign_in_timer_.Stop(); | 700 arc_sign_in_timer_.Stop(); |
| 680 playstore_launcher_.reset(); | 701 playstore_launcher_.reset(); |
| 681 terms_of_service_negotiator_.reset(); | 702 terms_of_service_negotiator_.reset(); |
| 682 android_management_checker_.reset(); | 703 android_management_checker_.reset(); |
| 683 arc_session_runner_->RequestStop(); | 704 arc_session_runner_->RequestStop(); |
| 684 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 705 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
| 685 // still be running when we return from this function. Do not set the | 706 // 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... |
| 831 // running the user should not be able to continue until the ARC instance | 852 // running the user should not be able to continue until the ARC instance |
| 832 // has stopped. | 853 // has stopped. |
| 833 if (support_host_) { | 854 if (support_host_) { |
| 834 support_host_->ShowError( | 855 support_host_->ShowError( |
| 835 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 856 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 836 } | 857 } |
| 837 return; | 858 return; |
| 838 } | 859 } |
| 839 | 860 |
| 840 SetState(State::SHOWING_TERMS_OF_SERVICE); | 861 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 841 if (support_host_) { | 862 if (IsOobeOptInActive()) { |
| 863 VLOG(1) << "Use OOBE negotiator."; |
| 842 terms_of_service_negotiator_ = | 864 terms_of_service_negotiator_ = |
| 843 base::MakeUnique<ArcTermsOfServiceNegotiator>(profile_->GetPrefs(), | 865 base::MakeUnique<ArcTermsOfServiceOobeNegotiator>(); |
| 844 support_host_.get()); | 866 } else if (support_host_) { |
| 867 VLOG(1) << "Use default negotiator."; |
| 868 terms_of_service_negotiator_ = |
| 869 base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>( |
| 870 profile_->GetPrefs(), support_host_.get()); |
| 871 } |
| 872 |
| 873 if (terms_of_service_negotiator_) { |
| 845 terms_of_service_negotiator_->StartNegotiation( | 874 terms_of_service_negotiator_->StartNegotiation( |
| 846 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, | 875 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, |
| 847 weak_ptr_factory_.GetWeakPtr())); | 876 weak_ptr_factory_.GetWeakPtr())); |
| 848 } | 877 } |
| 849 } | 878 } |
| 850 | 879 |
| 851 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { | 880 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { |
| 852 DCHECK(terms_of_service_negotiator_); | 881 DCHECK(terms_of_service_negotiator_); |
| 853 terms_of_service_negotiator_.reset(); | 882 terms_of_service_negotiator_.reset(); |
| 854 | 883 |
| 855 if (!accepted) { | 884 if (!accepted) { |
| 856 // To cancel, user needs to close the window. Note that clicking "Cancel" | 885 // To cancel, user needs to close the window. Note that clicking "Cancel" |
| 857 // button effectively just closes the window. | 886 // button effectively just closes the window. |
| 858 CancelAuthCode(); | 887 CancelAuthCode(); |
| 859 return; | 888 return; |
| 860 } | 889 } |
| 861 | 890 |
| 862 // Terms were accepted. | 891 // Terms were accepted. |
| 863 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 892 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 864 | 893 |
| 865 support_host_->ShowArcLoading(); | 894 // Don't show UI for this progress if it was not shown. |
| 895 if (support_host_ && |
| 896 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE) |
| 897 support_host_->ShowArcLoading(); |
| 866 StartArcAndroidManagementCheck(); | 898 StartArcAndroidManagementCheck(); |
| 867 } | 899 } |
| 868 | 900 |
| 869 void ArcSessionManager::StartArcAndroidManagementCheck() { | 901 void ArcSessionManager::StartArcAndroidManagementCheck() { |
| 870 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 902 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 871 DCHECK(arc_session_runner_->IsStopped()); | 903 DCHECK(arc_session_runner_->IsStopped()); |
| 872 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 904 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 873 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 905 state_ == State::CHECKING_ANDROID_MANAGEMENT || |
| 906 (state_ == State::STOPPED && |
| 907 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted))); |
| 874 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 908 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 875 | 909 |
| 876 android_management_checker_.reset(new ArcAndroidManagementChecker( | 910 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 877 profile_, context_->token_service(), context_->account_id(), | 911 profile_, context_->token_service(), context_->account_id(), |
| 878 false /* retry_on_error */)); | 912 false /* retry_on_error */)); |
| 879 android_management_checker_->StartCheck( | 913 android_management_checker_->StartCheck( |
| 880 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 914 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 881 weak_ptr_factory_.GetWeakPtr())); | 915 weak_ptr_factory_.GetWeakPtr())); |
| 882 } | 916 } |
| 883 | 917 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 return os << "ACTIVE"; | 1054 return os << "ACTIVE"; |
| 1021 } | 1055 } |
| 1022 | 1056 |
| 1023 // Some compiler reports an error even if all values of an enum-class are | 1057 // Some compiler reports an error even if all values of an enum-class are |
| 1024 // covered indivisually in a switch statement. | 1058 // covered indivisually in a switch statement. |
| 1025 NOTREACHED(); | 1059 NOTREACHED(); |
| 1026 return os; | 1060 return os; |
| 1027 } | 1061 } |
| 1028 | 1062 |
| 1029 } // namespace arc | 1063 } // namespace arc |
| OLD | NEW |