Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/arc_kiosk_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/time/time.h" | |
| 9 #include "base/timer/timer.h" | |
| 10 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" | |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 12 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 16 #include "chromeos/login/auth/user_context.h" | |
| 17 #include "components/session_manager/core/session_manager.h" | |
| 18 #include "components/signin/core/account_id/account_id.h" | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 // ARC++ Kiosk splash screen minimum show time. | |
| 23 constexpr base::TimeDelta kArcKioskSplashScreenMinTime = | |
| 24 base::TimeDelta::FromSeconds(3); | |
| 25 | |
| 26 ArcKioskController::ArcKioskController(LoginDisplayHost* host, OobeUI* oobe_ui) | |
| 27 : host_(host), | |
| 28 arc_kiosk_splash_screen_actor_(oobe_ui->GetArcKioskSplashScreenActor()), | |
| 29 weak_ptr_factory_(this) {} | |
| 30 | |
| 31 ArcKioskController::~ArcKioskController() { | |
| 32 arc_kiosk_splash_screen_actor_->SetDelegate(nullptr); | |
| 33 } | |
| 34 | |
| 35 void ArcKioskController::StartArcKiosk(const AccountId& account_id) { | |
| 36 DVLOG(1) << "Starting ARC Kiosk..."; | |
| 
 
achuithb
2017/02/03 00:35:00
Does it make sense to log the account_id?
 
Sergey Poromov
2017/02/03 15:15:36
Done.
 
 | |
| 37 | |
| 38 host_->GetWebUILoginView()->SetUIEnabled(true); | |
| 39 | |
| 40 arc_kiosk_splash_screen_actor_->SetDelegate(this); | |
| 41 arc_kiosk_splash_screen_actor_->Show(); | |
| 42 splash_wait_timer_.Start(FROM_HERE, kArcKioskSplashScreenMinTime, | |
| 43 base::Bind(&ArcKioskController::CloseSplashScreen, | |
| 44 weak_ptr_factory_.GetWeakPtr())); | |
| 45 | |
| 46 login_performer_ = base::MakeUnique<ChromeLoginPerformer>(this); | |
| 47 login_performer_->LoginAsArcKioskAccount(account_id); | |
| 48 } | |
| 49 | |
| 50 void ArcKioskController::CleanUp() { | |
| 51 splash_wait_timer_.Stop(); | |
| 52 // Delegate is registered only when |profile_| is set. | |
| 53 if (profile_) | |
| 54 ArcKioskAppService::Get(profile_)->SetDelegate(nullptr); | |
| 55 if (host_) | |
| 56 host_->Finalize(); | |
| 57 } | |
| 58 | |
| 59 void ArcKioskController::CloseSplashScreen() { | |
| 60 if (!launched_) | |
| 61 return; | |
| 62 CleanUp(); | |
| 63 session_manager::SessionManager::Get()->SessionStarted(); | |
| 64 } | |
| 65 | |
| 66 void ArcKioskController::OnAuthFailure(const AuthFailure& error) { | |
| 67 LOG(ERROR) << "ARC Kiosk launch failed. Will now shut down, error=" | |
| 68 << error.GetErrorString(); | |
| 69 chrome::AttemptUserExit(); | |
| 70 CleanUp(); | |
| 71 } | |
| 72 | |
| 73 void ArcKioskController::OnAuthSuccess(const UserContext& user_context) { | |
| 74 // LoginPerformer instance will delete itself in case of successful auth. | |
| 75 login_performer_->set_delegate(nullptr); | |
| 76 ignore_result(login_performer_.release()); | |
| 77 | |
| 78 UserSessionManager::GetInstance()->StartSession( | |
| 79 user_context, UserSessionManager::PRIMARY_USER_SESSION, | |
| 80 false, // has_auth_cookies | |
| 81 false, // Start session for user. | |
| 82 this); | |
| 83 } | |
| 84 | |
| 85 void ArcKioskController::WhiteListCheckFailed(const std::string& email) { | |
| 86 NOTREACHED(); | |
| 87 } | |
| 88 | |
| 89 void ArcKioskController::PolicyLoadFailed() { | |
| 90 LOG(ERROR) << "Policy load failed. Will now shut down"; | |
| 91 chrome::AttemptUserExit(); | |
| 
 
achuithb
2017/02/03 00:35:00
Shouldn't the order be reversed here and below?
 
Sergey Poromov
2017/02/03 15:15:36
Done.
This was done as in AppLaunchController::OnL
 
 | |
| 92 CleanUp(); | |
| 93 } | |
| 94 | |
| 95 void ArcKioskController::SetAuthFlowOffline(bool offline) { | |
| 96 NOTREACHED(); | |
| 97 } | |
| 98 | |
| 99 void ArcKioskController::OnProfilePrepared(Profile* profile, | |
| 100 bool browser_launched) { | |
| 101 DVLOG(1) << "Profile loaded... Starting app launch."; | |
| 102 profile_ = profile; | |
| 103 // This object could be deleted any time after successfully reporting | |
| 104 // a profile load, so invalidate the delegate now. | |
| 105 UserSessionManager::GetInstance()->DelegateDeleted(this); | |
| 106 ArcKioskAppService::Get(profile_)->SetDelegate(this); | |
| 107 arc_kiosk_splash_screen_actor_->UpdateArcKioskState( | |
| 108 ArcKioskSplashScreenActor::ArcKioskState::WAITING_APP_LAUNCH); | |
| 109 } | |
| 110 | |
| 111 void ArcKioskController::OnAppStarted() { | |
| 112 DVLOG(1) << "ARC Kiosk launch succeeded, wait for app window."; | |
| 113 arc_kiosk_splash_screen_actor_->UpdateArcKioskState( | |
| 114 ArcKioskSplashScreenActor::ArcKioskState::WAITING_APP_WINDOW); | |
| 115 } | |
| 116 | |
| 117 void ArcKioskController::OnAppWindowLaunched() { | |
| 118 DVLOG(1) << "App window created, closing splash screen."; | |
| 119 launched_ = true; | |
| 120 if (splash_wait_timer_.IsRunning()) | |
| 
 
achuithb
2017/02/03 00:35:00
A comment here might be useful
 
Sergey Poromov
2017/02/03 15:15:36
Done.
 
 | |
| 121 return; | |
| 122 CloseSplashScreen(); | |
| 123 } | |
| 124 | |
| 125 void ArcKioskController::OnCancelArcKioskLaunch() { | |
| 126 chrome::AttemptUserExit(); | |
| 127 CleanUp(); | |
| 128 } | |
| 129 | |
| 130 } // namespace chromeos | |
| OLD | NEW |