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

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

Issue 2561023002: arc: ARC loading progress should not be shown when started from OOBE. (Closed)
Patch Set: refactored Created 3 years, 10 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
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"
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ash::ShelfDelegate* GetShelfDelegate() { 77 ash::ShelfDelegate* GetShelfDelegate() {
76 if (g_shelf_delegate_for_testing) 78 if (g_shelf_delegate_for_testing)
77 return g_shelf_delegate_for_testing; 79 return g_shelf_delegate_for_testing;
78 if (ash::WmShell::HasInstance()) { 80 if (ash::WmShell::HasInstance()) {
79 DCHECK(ash::WmShell::Get()->shelf_delegate()); 81 DCHECK(ash::WmShell::Get()->shelf_delegate());
80 return ash::WmShell::Get()->shelf_delegate(); 82 return ash::WmShell::Get()->shelf_delegate();
81 } 83 }
82 return nullptr; 84 return nullptr;
83 } 85 }
84 86
87 bool IsOobeOptInActive() {
hidehiko 2017/01/30 10:12:35 Could you add a unittest for this method? I think
khmel 2017/01/31 02:47:08 Done.
88 // ARC OOBE OptIn is optional for now. Test if it exists and login host is
89 // active.
90 if (!user_manager::UserManager::Get()->IsCurrentUserNew())
91 return false;
92 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
93 chromeos::switches::kEnableArcOOBEOptIn))
94 return false;
95 chromeos::LoginDisplayHost* host = chromeos::LoginDisplayHost::default_host();
hidehiko 2017/01/30 10:12:35 nit: if (!chromeos::LoginDisplayHost::default_hos
khmel 2017/01/31 02:47:08 Done.
96 if (!host)
97 return false;
98 return true;
99 }
100
85 } // namespace 101 } // namespace
86 102
87 ArcSessionManager::ArcSessionManager( 103 ArcSessionManager::ArcSessionManager(
88 std::unique_ptr<ArcSessionRunner> arc_session_runner) 104 std::unique_ptr<ArcSessionRunner> arc_session_runner)
89 : arc_session_runner_(std::move(arc_session_runner)), 105 : arc_session_runner_(std::move(arc_session_runner)),
90 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), 106 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)),
91 weak_ptr_factory_(this) { 107 weak_ptr_factory_(this) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
93 DCHECK(!g_arc_session_manager); 109 DCHECK(!g_arc_session_manager);
94 g_arc_session_manager = this; 110 g_arc_session_manager = this;
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 661 }
646 662
647 // If it is marked that the Terms of service is accepted already, 663 // If it is marked that the Terms of service is accepted already,
648 // just skip the negotiation with user, and start Android management 664 // just skip the negotiation with user, and start Android management
649 // check directly. 665 // check directly.
650 // This happens, e.g., when; 666 // This happens, e.g., when;
651 // 1) User accepted the Terms of service on OOBE flow. 667 // 1) User accepted the Terms of service on OOBE flow.
652 // 2) User accepted the Terms of service on Opt-in flow, but logged out 668 // 2) User accepted the Terms of service on Opt-in flow, but logged out
653 // before ARC sign in procedure was done. Then, logs in again. 669 // before ARC sign in procedure was done. Then, logs in again.
654 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { 670 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) {
655 support_host_->ShowArcLoading(); 671 // Don't show UI for this progress if it was not shown.
672 if (support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE)
673 support_host_->ShowArcLoading();
656 StartArcAndroidManagementCheck(); 674 StartArcAndroidManagementCheck();
657 return; 675 return;
658 } 676 }
659 677
660 // Need user's explicit Terms Of Service agreement. 678 // Need user's explicit Terms Of Service agreement. Prevent race condition
hidehiko 2017/01/30 10:12:35 Could you elaborate the race condition more? For w
khmel 2017/01/31 02:47:08 This legacy problem actually. It is less visible i
hidehiko 2017/01/31 13:55:30 Thank you for detailed explanation! It's much clea
khmel 2017/01/31 15:25:22 Done.
661 StartTermsOfServiceNegotiation(); 679 // when ARC can be enabled before profile is synced. In last case
680 // OnOptInPreferenceChanged is called twice.
681 if (state_ != State::SHOWING_TERMS_OF_SERVICE)
682 StartTermsOfServiceNegotiation();
662 } 683 }
663 684
664 void ArcSessionManager::ShutdownSession() { 685 void ArcSessionManager::ShutdownSession() {
665 arc_sign_in_timer_.Stop(); 686 arc_sign_in_timer_.Stop();
666 playstore_launcher_.reset(); 687 playstore_launcher_.reset();
667 terms_of_service_negotiator_.reset(); 688 terms_of_service_negotiator_.reset();
668 android_management_checker_.reset(); 689 android_management_checker_.reset();
669 arc_session_runner_->RequestStop(); 690 arc_session_runner_->RequestStop();
670 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might 691 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might
671 // still be running when we return from this function. Do not set the 692 // 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
817 // running the user should not be able to continue until the ARC instance 838 // running the user should not be able to continue until the ARC instance
818 // has stopped. 839 // has stopped.
819 if (support_host_) { 840 if (support_host_) {
820 support_host_->ShowError( 841 support_host_->ShowError(
821 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); 842 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false);
822 } 843 }
823 return; 844 return;
824 } 845 }
825 846
826 SetState(State::SHOWING_TERMS_OF_SERVICE); 847 SetState(State::SHOWING_TERMS_OF_SERVICE);
827 if (support_host_) { 848 if (!IsOobeOptInActive()) {
hidehiko 2017/01/30 10:12:35 nit: Let's reduce the indent level. if (IsOobeOpt
khmel 2017/01/31 02:47:08 Done.
849 if (support_host_) {
850 VLOG(1) << "Use default negotiator.";
851 terms_of_service_negotiator_ =
852 base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>(
853 profile_->GetPrefs(), support_host_.get());
854 }
855 } else {
856 VLOG(1) << "Use OOBE negotiator.";
828 terms_of_service_negotiator_ = 857 terms_of_service_negotiator_ =
829 base::MakeUnique<ArcTermsOfServiceNegotiator>(profile_->GetPrefs(), 858 base::MakeUnique<ArcTermsOfServiceOobeNegotiator>();
830 support_host_.get()); 859 }
860
861 if (terms_of_service_negotiator_) {
831 terms_of_service_negotiator_->StartNegotiation( 862 terms_of_service_negotiator_->StartNegotiation(
832 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated, 863 base::Bind(&ArcSessionManager::OnTermsOfServiceNegotiated,
833 weak_ptr_factory_.GetWeakPtr())); 864 weak_ptr_factory_.GetWeakPtr()));
834 } 865 }
835 } 866 }
836 867
837 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) { 868 void ArcSessionManager::OnTermsOfServiceNegotiated(bool accepted) {
838 DCHECK(terms_of_service_negotiator_); 869 DCHECK(terms_of_service_negotiator_);
839 terms_of_service_negotiator_.reset(); 870 terms_of_service_negotiator_.reset();
840 871
841 if (!accepted) { 872 if (!accepted) {
842 // To cancel, user needs to close the window. Note that clicking "Cancel" 873 // To cancel, user needs to close the window. Note that clicking "Cancel"
843 // button effectively just closes the window. 874 // button effectively just closes the window.
844 CancelAuthCode(); 875 CancelAuthCode();
845 return; 876 return;
846 } 877 }
847 878
848 // Terms were accepted. 879 // Terms were accepted.
849 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); 880 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true);
850 881
851 support_host_->ShowArcLoading(); 882 // Don't show UI for this progress if it was not shown.
883 if (support_host_ &&
884 support_host_->ui_page() != ArcSupportHost::UIPage::NO_PAGE)
885 support_host_->ShowArcLoading();
852 StartArcAndroidManagementCheck(); 886 StartArcAndroidManagementCheck();
853 } 887 }
854 888
855 void ArcSessionManager::StartArcAndroidManagementCheck() { 889 void ArcSessionManager::StartArcAndroidManagementCheck() {
856 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 890 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
857 DCHECK(arc_session_runner_->IsStopped()); 891 DCHECK(arc_session_runner_->IsStopped());
858 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || 892 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE ||
859 state_ == State::CHECKING_ANDROID_MANAGEMENT); 893 state_ == State::CHECKING_ANDROID_MANAGEMENT ||
894 (state_ == State::STOPPED &&
895 profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)));
860 SetState(State::CHECKING_ANDROID_MANAGEMENT); 896 SetState(State::CHECKING_ANDROID_MANAGEMENT);
861 897
862 android_management_checker_.reset(new ArcAndroidManagementChecker( 898 android_management_checker_.reset(new ArcAndroidManagementChecker(
863 profile_, context_->token_service(), context_->account_id(), 899 profile_, context_->token_service(), context_->account_id(),
864 false /* retry_on_error */)); 900 false /* retry_on_error */));
865 android_management_checker_->StartCheck( 901 android_management_checker_->StartCheck(
866 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, 902 base::Bind(&ArcSessionManager::OnAndroidManagementChecked,
867 weak_ptr_factory_.GetWeakPtr())); 903 weak_ptr_factory_.GetWeakPtr()));
868 } 904 }
869 905
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 return os << "ACTIVE"; 1042 return os << "ACTIVE";
1007 } 1043 }
1008 1044
1009 // Some compiler reports an error even if all values of an enum-class are 1045 // Some compiler reports an error even if all values of an enum-class are
1010 // covered indivisually in a switch statement. 1046 // covered indivisually in a switch statement.
1011 NOTREACHED(); 1047 NOTREACHED();
1012 return os; 1048 return os;
1013 } 1049 }
1014 1050
1015 } // namespace arc 1051 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698