Chromium Code Reviews| Index: chrome/browser/chromeos/login/arc_kiosk_controller.cc |
| diff --git a/chrome/browser/chromeos/login/arc_kiosk_controller.cc b/chrome/browser/chromeos/login/arc_kiosk_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f0ef22bbeabefbcab5bb61272e56616eba80123 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/arc_kiosk_controller.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/arc_kiosk_controller.h" |
| + |
| +#include "base/time/time.h" |
| +#include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" |
| +#include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| +#include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
| +#include "chrome/browser/lifetime/application_lifetime.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| +#include "chromeos/login/auth/user_context.h" |
| +#include "components/session_manager/core/session_manager.h" |
| +#include "components/signin/core/account_id/account_id.h" |
| + |
| +namespace chromeos { |
| + |
| +// ARC++ Kiosk splash screen minimum show time in milliseconds. |
| +const int kArcKioskSplashScreenMinTimeMS = 3000; |
|
Luis Héctor Chávez
2017/01/25 17:46:39
nit:
constexpr base::TimeDelta kArcKioskSplashScr
Sergey Poromov
2017/01/26 17:08:52
Done.
|
| + |
| +ArcKioskController::ArcKioskController(LoginDisplayHost* host, OobeUI* oobe_ui) |
| + : host_(host), |
| + arc_kiosk_splash_screen_actor_(oobe_ui->GetArcKioskSplashScreenActor()) {} |
| + |
| +ArcKioskController::~ArcKioskController() { |
| + arc_kiosk_splash_screen_actor_->SetDelegate(nullptr); |
| +} |
| + |
| +void ArcKioskController::StartArcKiosk(const AccountId& account_id) { |
| + DVLOG(1) << "Starting ARC Kiosk..."; |
| + |
| + host_->GetWebUILoginView()->SetUIEnabled(true); |
| + |
| + arc_kiosk_splash_screen_actor_->SetDelegate(this); |
| + arc_kiosk_splash_screen_actor_->Show(); |
| + launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); |
| + |
| + login_performer_ = base::MakeUnique<ChromeLoginPerformer>(this); |
| + login_performer_->LoginAsArcKioskAccount(account_id); |
| +} |
| + |
| +void ArcKioskController::CleanUp() { |
| + splash_wait_timer_.Stop(); |
| + // Delegate is registered only when |profile_| is set. |
| + if (profile_) |
| + ArcKioskAppService::Get(profile_)->SetDelegate(nullptr); |
| + if (host_) |
| + host_->Finalize(); |
| +} |
| + |
| +void ArcKioskController::OnAuthFailure(const AuthFailure& error) { |
| + LOG(ERROR) << "ARC Kiosk launch failed. Will now shut down, error=" |
| + << error.GetErrorString(); |
| + chrome::AttemptUserExit(); |
| + CleanUp(); |
| +} |
| + |
| +void ArcKioskController::OnAuthSuccess(const UserContext& user_context) { |
| + // LoginPerformer instance will delete itself in case of successful auth. |
| + login_performer_->set_delegate(nullptr); |
| + ignore_result(login_performer_.release()); |
| + |
| + UserSessionManager::GetInstance()->StartSession( |
| + user_context, UserSessionManager::PRIMARY_USER_SESSION, |
| + false, // has_auth_cookies |
| + false, // Start session for user. |
| + this); |
| +} |
| + |
| +void ArcKioskController::WhiteListCheckFailed(const std::string& email) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ArcKioskController::PolicyLoadFailed() { |
| + LOG(ERROR) << "Policy load failed. Will now shut down"; |
| + chrome::AttemptUserExit(); |
| + CleanUp(); |
| +} |
| + |
| +void ArcKioskController::SetAuthFlowOffline(bool offline) { |
| + NOTREACHED(); |
| +} |
| + |
| +void ArcKioskController::OnProfilePrepared(Profile* profile, |
| + bool browser_launched) { |
| + DVLOG(1) << "Profile loaded... Starting app launch."; |
| + profile_ = profile; |
| + // This object could be deleted any time after successfully reporting |
| + // a profile load, so invalidate the delegate now. |
| + UserSessionManager::GetInstance()->DelegateDeleted(this); |
| + ArcKioskAppService::Get(profile_)->SetDelegate(this); |
| + arc_kiosk_splash_screen_actor_->UpdateArcKioskState( |
| + ArcKioskSplashScreenActor::ARC_KIOSK_STATE_WAITING_APP_LAUNCH); |
| +} |
| + |
| +void ArcKioskController::OnAppStarted() { |
| + DVLOG(1) << "ARC Kiosk launch succeeded, wait for app window."; |
| + arc_kiosk_splash_screen_actor_->UpdateArcKioskState( |
| + ArcKioskSplashScreenActor::ARC_KIOSK_STATE_WAITING_APP_WINDOW); |
| +} |
| + |
| +void ArcKioskController::OnAppWindowLaunched() { |
| + DVLOG(1) << "App window created, closing splash screen."; |
| + |
| + if (splash_wait_timer_.IsRunning()) |
| + return; |
| + const int64_t time_taken_ms = |
|
Luis Héctor Chávez
2017/01/25 17:46:40
nit:
const base::TimeDelta delta = base::TimeTick
Sergey Poromov
2017/01/26 17:08:52
Done.
|
| + (base::TimeTicks::Now() - |
| + base::TimeTicks::FromInternalValue(launch_splash_start_time_)) |
| + .InMilliseconds(); |
| + if (time_taken_ms < kArcKioskSplashScreenMinTimeMS) { |
| + // Do not remove splash screen for a few more seconds |
| + // to give the user ability to exit ARC++ kiosk. |
| + splash_wait_timer_.Start( |
|
Luis Héctor Chávez
2017/01/25 17:46:40
I wonder if it's cleaner overall to unconditionall
Sergey Poromov
2017/01/26 17:08:52
Done.
|
| + FROM_HERE, base::TimeDelta::FromMilliseconds( |
| + kArcKioskSplashScreenMinTimeMS - time_taken_ms), |
| + this, &ArcKioskController::OnAppWindowLaunched); |
| + return; |
| + } |
| + |
| + CleanUp(); |
| + session_manager::SessionManager::Get()->SessionStarted(); |
| +} |
| + |
| +void ArcKioskController::OnCancelArcKioskLaunch() { |
| + chrome::AttemptUserExit(); |
| + CleanUp(); |
| +} |
| + |
| +} // namespace chromeos |