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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/timer/timer.h"
13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
14 #include "chrome/browser/chromeos/app_mode/kiosk_profile_loader.h"
15 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
16 #include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
17 #include "chrome/browser/chromeos/login/screens/app_launch_splash_screen_actor.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
25 class LoginDisplayHost
;
29 // Controller for the kiosk app launch process, responsible for
30 // coordinating loading the kiosk profile, launching the app, and
31 // updating the splash screen UI.
32 class AppLaunchController
33 : public AppLaunchSplashScreenActor::Delegate
,
34 public KioskProfileLoader::Delegate
,
35 public StartupAppLauncher::Delegate
,
36 public AppLaunchSigninScreen::Delegate
,
37 public content::NotificationObserver
{
39 typedef base::Callback
<bool()> ReturnBoolCallback
;
41 AppLaunchController(const std::string
& app_id
,
42 LoginDisplayHost
* host
,
43 OobeDisplay
* oobe_display
);
45 virtual ~AppLaunchController();
47 void StartAppLaunch();
49 bool waiting_for_network() { return waiting_for_network_
; }
50 bool network_wait_timedout() { return network_wait_timedout_
; }
51 bool showing_network_dialog() { return showing_network_dialog_
; }
53 // Customize controller for testing purposes.
54 static void SkipSplashWaitForTesting();
55 static void SetNetworkTimeoutCallbackForTesting(base::Closure
* callback
);
56 static void SetNetworkWaitForTesting(int wait_time_secs
);
57 static void SetCanConfigureNetworkCallbackForTesting(
58 ReturnBoolCallback
* can_configure_network_callback
);
59 static void SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
60 ReturnBoolCallback
* need_owner_auth_callback
);
63 // A class to watch app window creation.
64 class AppWindowWatcher
;
67 void OnNetworkWaitTimedout();
69 // Callback of AppWindowWatcher to notify an app window is created.
70 void OnAppWindowCreated();
72 // Whether the network could be configured during launching.
73 bool CanConfigureNetwork();
75 // Whether the owner password is needed to configure network.
76 bool NeedOwnerAuthToConfigureNetwork();
78 // Show network configuration UI if it is allowed. For consumer mode,
79 // owner password might be checked before showing the network configure UI.
80 void MaybeShowNetworkConfigureUI();
82 // KioskProfileLoader::Delegate overrides:
83 virtual void OnProfileLoaded(Profile
* profile
) OVERRIDE
;
84 virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error
) OVERRIDE
;
86 // AppLaunchSplashScreenActor::Delegate overrides:
87 virtual void OnConfigureNetwork() OVERRIDE
;
88 virtual void OnCancelAppLaunch() OVERRIDE
;
89 virtual void OnNetworkStateChanged(bool online
) OVERRIDE
;
91 // StartupAppLauncher::Delegate overrides:
92 virtual void InitializeNetwork() OVERRIDE
;
93 virtual void OnLoadingOAuthFile() OVERRIDE
;
94 virtual void OnInitializingTokenService() OVERRIDE
;
95 virtual void OnInstallingApp() OVERRIDE
;
96 virtual void OnReadyToLaunch() OVERRIDE
;
97 virtual void OnLaunchSucceeded() OVERRIDE
;
98 virtual void OnLaunchFailed(KioskAppLaunchError::Error error
) OVERRIDE
;
100 // AppLaunchSigninScreen::Delegate overrides:
101 virtual void OnOwnerSigninSuccess() OVERRIDE
;
103 // content::NotificationObserver overrides:
104 virtual void Observe(int type
,
105 const content::NotificationSource
& source
,
106 const content::NotificationDetails
& details
) OVERRIDE
;
109 const std::string app_id_
;
110 LoginDisplayHost
* host_
;
111 OobeDisplay
* oobe_display_
;
112 AppLaunchSplashScreenActor
* app_launch_splash_screen_actor_
;
113 scoped_ptr
<KioskProfileLoader
> kiosk_profile_loader_
;
114 scoped_ptr
<StartupAppLauncher
> startup_app_launcher_
;
115 scoped_ptr
<AppLaunchSigninScreen
> signin_screen_
;
116 scoped_ptr
<AppWindowWatcher
> app_window_watcher_
;
118 content::NotificationRegistrar registrar_
;
120 bool launcher_ready_
;
122 // A timer to ensure the app splash is shown for a minimum amount of time.
123 base::OneShotTimer
<AppLaunchController
> splash_wait_timer_
;
125 base::OneShotTimer
<AppLaunchController
> network_wait_timer_
;
126 bool waiting_for_network_
;
127 bool network_wait_timedout_
;
128 bool showing_network_dialog_
;
129 int64 launch_splash_start_time_
;
131 static bool skip_splash_wait_
;
132 static int network_wait_time_
;
133 static base::Closure
* network_timeout_callback_
;
134 static ReturnBoolCallback
* can_configure_network_callback_
;
135 static ReturnBoolCallback
* need_owner_auth_to_configure_network_callback_
;
137 DISALLOW_COPY_AND_ASSIGN(AppLaunchController
);
140 } // namespace chromeos
142 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_