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

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

Issue 79113002: kiosk: Network connectivity test during launch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hide spacer for non-kiosk error Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/login/app_launch_controller.h" 5 #include "chrome/browser/chromeos/login/app_launch_controller.h"
6 6
7 #include "apps/shell_window_registry.h" 7 #include "apps/shell_window_registry.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" 15 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
15 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 16 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
16 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h" 17 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
17 #include "chrome/browser/chromeos/login/login_display_host.h" 18 #include "chrome/browser/chromeos/login/login_display_host.h"
18 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 19 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
19 #include "chrome/browser/chromeos/login/oobe_display.h" 20 #include "chrome/browser/chromeos/login/oobe_display.h"
20 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h" 21 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h"
21 #include "chrome/browser/chromeos/login/webui_login_view.h" 22 #include "chrome/browser/chromeos/login/webui_login_view.h"
22 #include "chrome/browser/lifetime/application_lifetime.h" 23 #include "chrome/browser/lifetime/application_lifetime.h"
24 #include "chrome/browser/policy/browser_policy_connector.h"
23 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle r.h" 26 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle r.h"
25 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 27 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
28 #include "net/base/network_change_notifier.h" 30 #include "net/base/network_change_notifier.h"
29 31
30 namespace chromeos { 32 namespace chromeos {
31 33
32 namespace { 34 namespace {
33 35
34 // Application install splash screen minimum show time in milliseconds. 36 // Application install splash screen minimum show time in milliseconds.
35 const int kAppInstallSplashScreenMinTimeMS = 3000; 37 const int kAppInstallSplashScreenMinTimeMS = 3000;
36 38
37 } // namespace 39 } // namespace
38 40
39 // static 41 // static
40 bool AppLaunchController::skip_splash_wait_ = false; 42 bool AppLaunchController::skip_splash_wait_ = false;
41 int AppLaunchController::network_wait_time_ = 10; 43 int AppLaunchController::network_wait_time_ = 10;
42 base::Closure* AppLaunchController::network_timeout_callback_ = NULL; 44 base::Closure* AppLaunchController::network_timeout_callback_ = NULL;
43 AppLaunchController::CanConfigureNetworkCallback* 45 AppLaunchController::ReturnBoolCallback*
44 AppLaunchController::can_configure_network_callback_ = NULL; 46 AppLaunchController::can_configure_network_callback_ = NULL;
47 AppLaunchController::ReturnBoolCallback*
48 AppLaunchController::need_owner_auth_to_configure_network_callback_ = NULL;
45 49
46 //////////////////////////////////////////////////////////////////////////////// 50 ////////////////////////////////////////////////////////////////////////////////
47 // AppLaunchController::AppWindowWatcher 51 // AppLaunchController::AppWindowWatcher
48 52
49 class AppLaunchController::AppWindowWatcher 53 class AppLaunchController::AppWindowWatcher
50 : public apps::ShellWindowRegistry::Observer { 54 : public apps::ShellWindowRegistry::Observer {
51 public: 55 public:
52 explicit AppWindowWatcher(AppLaunchController* controller) 56 explicit AppWindowWatcher(AppLaunchController* controller)
53 : controller_(controller), 57 : controller_(controller),
54 window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)) { 58 window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)) {
(...skipping 26 matching lines...) Expand all
81 85
82 AppLaunchController::AppLaunchController(const std::string& app_id, 86 AppLaunchController::AppLaunchController(const std::string& app_id,
83 LoginDisplayHost* host, 87 LoginDisplayHost* host,
84 OobeDisplay* oobe_display) 88 OobeDisplay* oobe_display)
85 : profile_(NULL), 89 : profile_(NULL),
86 app_id_(app_id), 90 app_id_(app_id),
87 host_(host), 91 host_(host),
88 oobe_display_(oobe_display), 92 oobe_display_(oobe_display),
89 app_launch_splash_screen_actor_( 93 app_launch_splash_screen_actor_(
90 oobe_display_->GetAppLaunchSplashScreenActor()), 94 oobe_display_->GetAppLaunchSplashScreenActor()),
91 error_screen_actor_(oobe_display_->GetErrorScreenActor()),
92 webui_visible_(false), 95 webui_visible_(false),
93 launcher_ready_(false), 96 launcher_ready_(false),
94 waiting_for_network_(false), 97 waiting_for_network_(false),
95 network_wait_timedout_(false), 98 network_wait_timedout_(false),
96 showing_network_dialog_(false), 99 showing_network_dialog_(false),
97 launch_splash_start_time_(0) { 100 launch_splash_start_time_(0) {
98 signin_screen_.reset(new AppLaunchSigninScreen(
99 static_cast<OobeUI*>(oobe_display_), this));
100 } 101 }
101 102
102 AppLaunchController::~AppLaunchController() { 103 AppLaunchController::~AppLaunchController() {
103 app_launch_splash_screen_actor_->SetDelegate(NULL); 104 app_launch_splash_screen_actor_->SetDelegate(NULL);
104 } 105 }
105 106
106 void AppLaunchController::StartAppLaunch() { 107 void AppLaunchController::StartAppLaunch() {
107 DVLOG(1) << "Starting kiosk mode..."; 108 DVLOG(1) << "Starting kiosk mode...";
108 109
109 webui_visible_ = host_->GetWebUILoginView()->webui_visible(); 110 webui_visible_ = host_->GetWebUILoginView()->webui_visible();
110 if (!webui_visible_) { 111 if (!webui_visible_) {
111 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 112 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
112 content::NotificationService::AllSources()); 113 content::NotificationService::AllSources());
113 } 114 }
114 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); 115 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue();
115 116
116 // TODO(tengs): Add a loading profile app launch state. 117 // TODO(tengs): Add a loading profile app launch state.
117 app_launch_splash_screen_actor_->SetDelegate(this); 118 app_launch_splash_screen_actor_->SetDelegate(this);
118 app_launch_splash_screen_actor_->Show(app_id_); 119 app_launch_splash_screen_actor_->Show(app_id_);
119 120
120 kiosk_profile_loader_.reset( 121 kiosk_profile_loader_.reset(
121 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this)); 122 new KioskProfileLoader(KioskAppManager::Get(), app_id_, this));
122 kiosk_profile_loader_->Start(); 123 kiosk_profile_loader_->Start();
123 } 124 }
124 125
126 // static
125 void AppLaunchController::SkipSplashWaitForTesting() { 127 void AppLaunchController::SkipSplashWaitForTesting() {
126 skip_splash_wait_ = true; 128 skip_splash_wait_ = true;
127 } 129 }
128 130
131 // static
129 void AppLaunchController::SetNetworkWaitForTesting(int wait_time_secs) { 132 void AppLaunchController::SetNetworkWaitForTesting(int wait_time_secs) {
130 network_wait_time_ = wait_time_secs; 133 network_wait_time_ = wait_time_secs;
131 } 134 }
132 135
136 // static
133 void AppLaunchController::SetNetworkTimeoutCallbackForTesting( 137 void AppLaunchController::SetNetworkTimeoutCallbackForTesting(
134 base::Closure* callback) { 138 base::Closure* callback) {
135 network_timeout_callback_ = callback; 139 network_timeout_callback_ = callback;
136 } 140 }
137 141
142 // static
138 void AppLaunchController::SetCanConfigureNetworkCallbackForTesting( 143 void AppLaunchController::SetCanConfigureNetworkCallbackForTesting(
139 CanConfigureNetworkCallback* can_configure_network_callback) { 144 ReturnBoolCallback* can_configure_network_callback) {
140 can_configure_network_callback_ = can_configure_network_callback; 145 can_configure_network_callback_ = can_configure_network_callback;
141 } 146 }
142 147
148 // static
149 void AppLaunchController::SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
150 ReturnBoolCallback* need_owner_auth_callback) {
151 need_owner_auth_to_configure_network_callback_ = need_owner_auth_callback;
152 }
153
143 void AppLaunchController::OnConfigureNetwork() { 154 void AppLaunchController::OnConfigureNetwork() {
144 DCHECK(profile_); 155 DCHECK(profile_);
145 showing_network_dialog_ = true; 156 showing_network_dialog_ = true;
146 if (CanConfigureNetwork()) { 157 if (CanConfigureNetwork() && NeedOwnerAuthToConfigureNetwork()) {
158 signin_screen_.reset(new AppLaunchSigninScreen(
159 static_cast<OobeUI*>(oobe_display_), this));
147 signin_screen_->Show(); 160 signin_screen_->Show();
148 } else { 161 } else {
149 // If kiosk mode was configured through enterprise policy, we may 162 // If kiosk mode was configured through enterprise policy, we may
150 // not have an owner user. 163 // not have an owner user.
151 // TODO(tengs): We need to figure out the appropriate security meausres 164 // TODO(tengs): We need to figure out the appropriate security meausres
152 // for this case. 165 // for this case.
153 NOTREACHED(); 166 NOTREACHED();
154 } 167 }
155 } 168 }
156 169
157 void AppLaunchController::OnOwnerSigninSuccess() { 170 void AppLaunchController::OnOwnerSigninSuccess() {
158 error_screen_actor_->SetErrorState( 171 app_launch_splash_screen_actor_->ShowNetworkConfigureUI();
159 ErrorScreen::ERROR_STATE_OFFLINE, std::string());
160 error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_KIOSK_MODE);
161
162 error_screen_actor_->Show(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH, NULL);
163
164 signin_screen_.reset(); 172 signin_screen_.reset();
165 } 173 }
166 174
167 void AppLaunchController::Observe( 175 void AppLaunchController::Observe(
168 int type, 176 int type,
169 const content::NotificationSource& source, 177 const content::NotificationSource& source,
170 const content::NotificationDetails& details) { 178 const content::NotificationDetails& details) {
171 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, type); 179 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, type);
172 DCHECK(!webui_visible_); 180 DCHECK(!webui_visible_);
173 webui_visible_ = true; 181 webui_visible_ = true;
174 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); 182 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue();
175 if (launcher_ready_) 183 if (launcher_ready_)
176 OnReadyToLaunch(); 184 OnReadyToLaunch();
177 } 185 }
178 186
179 void AppLaunchController::OnCancelAppLaunch() { 187 void AppLaunchController::OnCancelAppLaunch() {
180 if (KioskAppManager::Get()->GetDisableBailoutShortcut()) 188 if (KioskAppManager::Get()->GetDisableBailoutShortcut())
181 return; 189 return;
182 190
183 OnLaunchFailed(KioskAppLaunchError::USER_CANCEL); 191 OnLaunchFailed(KioskAppLaunchError::USER_CANCEL);
184 } 192 }
185 193
194 void AppLaunchController::OnNetworkStateChanged(bool online) {
195 if (!waiting_for_network_)
196 return;
197
198 if (online)
Tim Song 2013/11/21 01:12:17 If the network comes up automatically when the err
xiyuan 2013/11/21 22:39:39 Yes, this will be called when network state change
199 startup_app_launcher_->ContinueWithNetworkReady();
200 else
201 MaybeShowNetworkConfigureUI();
202 }
203
186 void AppLaunchController::OnProfileLoaded(Profile* profile) { 204 void AppLaunchController::OnProfileLoaded(Profile* profile) {
187 DVLOG(1) << "Profile loaded... Starting app launch."; 205 DVLOG(1) << "Profile loaded... Starting app launch.";
188 profile_ = profile; 206 profile_ = profile;
189 207
190 kiosk_profile_loader_.reset(); 208 kiosk_profile_loader_.reset();
191 startup_app_launcher_.reset(new StartupAppLauncher(profile_, app_id_)); 209 startup_app_launcher_.reset(new StartupAppLauncher(profile_, app_id_));
192 startup_app_launcher_->AddObserver(this); 210 startup_app_launcher_->AddObserver(this);
193 startup_app_launcher_->Initialize(); 211 startup_app_launcher_->Initialize();
194 } 212 }
195 213
196 void AppLaunchController::OnProfileLoadFailed( 214 void AppLaunchController::OnProfileLoadFailed(
197 KioskAppLaunchError::Error error) { 215 KioskAppLaunchError::Error error) {
198 OnLaunchFailed(error); 216 OnLaunchFailed(error);
199 } 217 }
200 218
201 void AppLaunchController::CleanUp() { 219 void AppLaunchController::CleanUp() {
202 kiosk_profile_loader_.reset(); 220 kiosk_profile_loader_.reset();
203 startup_app_launcher_.reset(); 221 startup_app_launcher_.reset();
204 222
205 if (host_) 223 if (host_)
206 host_->Finalize(); 224 host_->Finalize();
207 } 225 }
208 226
209 void AppLaunchController::OnNetworkWaitTimedout() { 227 void AppLaunchController::OnNetworkWaitTimedout() {
210 DCHECK(waiting_for_network_); 228 DCHECK(waiting_for_network_);
211 LOG(WARNING) << "OnNetworkWaitTimedout... connection = " 229 LOG(WARNING) << "OnNetworkWaitTimedout... connection = "
212 << net::NetworkChangeNotifier::GetConnectionType(); 230 << net::NetworkChangeNotifier::GetConnectionType();
213 network_wait_timedout_ = true; 231 network_wait_timedout_ = true;
214 232
215 if (CanConfigureNetwork()) { 233 MaybeShowNetworkConfigureUI();
216 app_launch_splash_screen_actor_->ToggleNetworkConfig(true);
217 } else {
218 app_launch_splash_screen_actor_->UpdateAppLaunchState(
219 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT);
220 }
221 234
222 if (network_timeout_callback_) 235 if (network_timeout_callback_)
223 network_timeout_callback_->Run(); 236 network_timeout_callback_->Run();
224 } 237 }
225 238
226 void AppLaunchController::OnAppWindowCreated() { 239 void AppLaunchController::OnAppWindowCreated() {
227 DVLOG(1) << "App window created, closing splash screen."; 240 DVLOG(1) << "App window created, closing splash screen.";
228 CleanUp(); 241 CleanUp();
229 } 242 }
230 243
231 bool AppLaunchController::CanConfigureNetwork() { 244 bool AppLaunchController::CanConfigureNetwork() {
Tim Song 2013/11/21 01:12:17 Won't this function always return true now?
xiyuan 2013/11/21 22:39:39 Nope, it returns false for consumer kiosk mode wit
232 if (can_configure_network_callback_) 245 if (can_configure_network_callback_)
233 return can_configure_network_callback_->Run(); 246 return can_configure_network_callback_->Run();
234 247
235 return !UserManager::Get()->GetOwnerEmail().empty(); 248 return g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ||
249 !UserManager::Get()->GetOwnerEmail().empty();
250 }
251
252 bool AppLaunchController::NeedOwnerAuthToConfigureNetwork() {
253 if (need_owner_auth_to_configure_network_callback_)
254 return need_owner_auth_to_configure_network_callback_->Run();
255
256 return !g_browser_process->browser_policy_connector()->IsEnterpriseManaged();
257 }
258
259 void AppLaunchController::MaybeShowNetworkConfigureUI() {
260 if (CanConfigureNetwork()) {
261 if (NeedOwnerAuthToConfigureNetwork()) {
262 app_launch_splash_screen_actor_->ToggleNetworkConfig(true);
263 } else {
Tim Song 2013/11/21 01:12:17 indent
xiyuan 2013/11/21 22:39:39 Done.
264 showing_network_dialog_ = true;
265 app_launch_splash_screen_actor_->ShowNetworkConfigureUI();
Tim Song 2013/11/21 01:12:17 Do we want to show the network UI immediately? One
xiyuan 2013/11/21 22:39:39 I can understand not showing up the owner signin s
266 }
267 } else {
268 app_launch_splash_screen_actor_->UpdateAppLaunchState(
269 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT);
270 }
236 } 271 }
237 272
238 void AppLaunchController::OnLoadingOAuthFile() { 273 void AppLaunchController::OnLoadingOAuthFile() {
239 app_launch_splash_screen_actor_->UpdateAppLaunchState( 274 app_launch_splash_screen_actor_->UpdateAppLaunchState(
240 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE); 275 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE);
241 } 276 }
242 277
243 void AppLaunchController::OnInitializingTokenService() { 278 void AppLaunchController::OnInitializingTokenService() {
244 app_launch_splash_screen_actor_->UpdateAppLaunchState( 279 app_launch_splash_screen_actor_->UpdateAppLaunchState(
245 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE); 280 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE);
246 } 281 }
247 282
248 void AppLaunchController::OnInitializingNetwork() { 283 void AppLaunchController::OnInitializingNetwork() {
249 app_launch_splash_screen_actor_->UpdateAppLaunchState(
250 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK);
251
252 // Show the network configration dialog if network is not initialized 284 // Show the network configration dialog if network is not initialized
253 // after a brief wait time. 285 // after a brief wait time.
254 waiting_for_network_ = true; 286 waiting_for_network_ = true;
255 network_wait_timer_.Start( 287 network_wait_timer_.Start(
256 FROM_HERE, 288 FROM_HERE,
257 base::TimeDelta::FromSeconds(network_wait_time_), 289 base::TimeDelta::FromSeconds(network_wait_time_),
258 this, &AppLaunchController::OnNetworkWaitTimedout); 290 this, &AppLaunchController::OnNetworkWaitTimedout);
291
292 app_launch_splash_screen_actor_->UpdateAppLaunchState(
293 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK);
259 } 294 }
260 295
261 void AppLaunchController::OnInstallingApp() { 296 void AppLaunchController::OnInstallingApp() {
262 app_launch_splash_screen_actor_->UpdateAppLaunchState( 297 app_launch_splash_screen_actor_->UpdateAppLaunchState(
263 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION); 298 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION);
264 299
300 waiting_for_network_ = false;
265 network_wait_timer_.Stop(); 301 network_wait_timer_.Stop();
266 app_launch_splash_screen_actor_->ToggleNetworkConfig(false); 302 app_launch_splash_screen_actor_->ToggleNetworkConfig(false);
267 303
268 // We have connectivity at this point, so we can skip the network 304 // We have connectivity at this point, so we can skip the network
269 // configuration dialog if it is being shown. 305 // configuration dialog if it is being shown.
270 if (showing_network_dialog_) { 306 if (showing_network_dialog_) {
271 app_launch_splash_screen_actor_->Show(app_id_); 307 app_launch_splash_screen_actor_->Show(app_id_);
272 showing_network_dialog_ = false; 308 showing_network_dialog_ = false;
273 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue(); 309 launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue();
274 } 310 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 LOG(ERROR) << "Kiosk launch failed. Will now shut down."; 347 LOG(ERROR) << "Kiosk launch failed. Will now shut down.";
312 DCHECK_NE(KioskAppLaunchError::NONE, error); 348 DCHECK_NE(KioskAppLaunchError::NONE, error);
313 349
314 // Saves the error and ends the session to go back to login screen. 350 // Saves the error and ends the session to go back to login screen.
315 KioskAppLaunchError::Save(error); 351 KioskAppLaunchError::Save(error);
316 chrome::AttemptUserExit(); 352 chrome::AttemptUserExit();
317 CleanUp(); 353 CleanUp();
318 } 354 }
319 355
320 } // namespace chromeos 356 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698