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

Side by Side Diff: chrome/browser/chromeos/login/arc_kiosk_controller.cc

Issue 2649103006: arc: Add splash screen for ARC++ Kiosk startup (Closed)
Patch Set: fix comments - better use of base::Time 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
(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/time/time.h"
8 #include "base/timer/timer.h"
9 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h"
10 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
11 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
12 #include "chrome/browser/lifetime/application_lifetime.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
15 #include "chromeos/login/auth/user_context.h"
16 #include "components/session_manager/core/session_manager.h"
17 #include "components/signin/core/account_id/account_id.h"
18
19 namespace chromeos {
20
21 // ARC++ Kiosk splash screen minimum show time in milliseconds.
22 constexpr base::TimeDelta kArcKioskSplashScreenMinTimeMS =
Luis Héctor Chávez 2017/01/26 17:37:45 Please drop the "in milliseconds" from the comment
Sergey Poromov 2017/01/26 18:30:22 Done.
23 base::TimeDelta::FromSeconds(3);
24
25 ArcKioskController::ArcKioskController(LoginDisplayHost* host, OobeUI* oobe_ui)
26 : host_(host),
27 arc_kiosk_splash_screen_actor_(oobe_ui->GetArcKioskSplashScreenActor()) {}
28
29 ArcKioskController::~ArcKioskController() {
30 arc_kiosk_splash_screen_actor_->SetDelegate(nullptr);
31 }
32
33 void ArcKioskController::StartArcKiosk(const AccountId& account_id) {
34 DVLOG(1) << "Starting ARC Kiosk...";
35
36 host_->GetWebUILoginView()->SetUIEnabled(true);
37
38 arc_kiosk_splash_screen_actor_->SetDelegate(this);
39 arc_kiosk_splash_screen_actor_->Show();
40 launch_splash_start_time_ = base::TimeTicks::Now();
Luis Héctor Chávez 2017/01/26 17:37:45 The idea was to start the timer here unconditional
Sergey Poromov 2017/01/26 18:30:22 Done.
41
42 login_performer_ = base::MakeUnique<ChromeLoginPerformer>(this);
43 login_performer_->LoginAsArcKioskAccount(account_id);
44 }
45
46 void ArcKioskController::CleanUp() {
47 splash_wait_timer_.Stop();
48 // Delegate is registered only when |profile_| is set.
49 if (profile_)
50 ArcKioskAppService::Get(profile_)->SetDelegate(nullptr);
51 if (host_)
52 host_->Finalize();
53 }
54
55 void ArcKioskController::CloseSplashScreen() {
56 const base::TimeDelta time_taken_ms =
Luis Héctor Chávez 2017/01/26 17:37:45 same, drop the "_ms" suffix
Sergey Poromov 2017/01/26 18:30:22 Done.
57 base::TimeTicks::Now() - launch_splash_start_time_;
58 if (time_taken_ms < kArcKioskSplashScreenMinTimeMS) {
Luis Héctor Chávez 2017/01/26 17:37:45 and then this implementation would be if (!launch
Sergey Poromov 2017/01/26 18:30:22 Could it be that this method is launched by timer
Luis Héctor Chávez 2017/01/26 19:05:48 Timer callbacks are always run in the same thread
59 // Do not remove splash screen for a few more seconds
60 // to give the user ability to exit ARC++ kiosk.
61 splash_wait_timer_.Start(FROM_HERE,
62 kArcKioskSplashScreenMinTimeMS - time_taken_ms,
63 this, &ArcKioskController::CloseSplashScreen);
64 return;
65 }
66
67 CleanUp();
68 session_manager::SessionManager::Get()->SessionStarted();
69 }
70
71 void ArcKioskController::OnAuthFailure(const AuthFailure& error) {
72 LOG(ERROR) << "ARC Kiosk launch failed. Will now shut down, error="
73 << error.GetErrorString();
74 chrome::AttemptUserExit();
75 CleanUp();
76 }
77
78 void ArcKioskController::OnAuthSuccess(const UserContext& user_context) {
79 // LoginPerformer instance will delete itself in case of successful auth.
80 login_performer_->set_delegate(nullptr);
81 ignore_result(login_performer_.release());
82
83 UserSessionManager::GetInstance()->StartSession(
84 user_context, UserSessionManager::PRIMARY_USER_SESSION,
85 false, // has_auth_cookies
86 false, // Start session for user.
87 this);
88 }
89
90 void ArcKioskController::WhiteListCheckFailed(const std::string& email) {
91 NOTREACHED();
92 }
93
94 void ArcKioskController::PolicyLoadFailed() {
95 LOG(ERROR) << "Policy load failed. Will now shut down";
96 chrome::AttemptUserExit();
97 CleanUp();
98 }
99
100 void ArcKioskController::SetAuthFlowOffline(bool offline) {
101 NOTREACHED();
102 }
103
104 void ArcKioskController::OnProfilePrepared(Profile* profile,
105 bool browser_launched) {
106 DVLOG(1) << "Profile loaded... Starting app launch.";
107 profile_ = profile;
108 // This object could be deleted any time after successfully reporting
109 // a profile load, so invalidate the delegate now.
110 UserSessionManager::GetInstance()->DelegateDeleted(this);
111 ArcKioskAppService::Get(profile_)->SetDelegate(this);
112 arc_kiosk_splash_screen_actor_->UpdateArcKioskState(
113 ArcKioskSplashScreenActor::ARC_KIOSK_STATE_WAITING_APP_LAUNCH);
114 }
115
116 void ArcKioskController::OnAppStarted() {
117 DVLOG(1) << "ARC Kiosk launch succeeded, wait for app window.";
118 arc_kiosk_splash_screen_actor_->UpdateArcKioskState(
119 ArcKioskSplashScreenActor::ARC_KIOSK_STATE_WAITING_APP_WINDOW);
120 }
121
122 void ArcKioskController::OnAppWindowLaunched() {
123 DVLOG(1) << "App window created, closing splash screen.";
124
Luis Héctor Chávez 2017/01/26 17:37:45 and this implementation would be launched_ = true
Sergey Poromov 2017/01/26 18:30:22 Done.
125 if (splash_wait_timer_.IsRunning())
126 return;
127 CloseSplashScreen();
128 }
129
130 void ArcKioskController::OnCancelArcKioskLaunch() {
131 chrome::AttemptUserExit();
132 CleanUp();
133 }
134
135 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698