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
,
43 LoginDisplayHost
* host
,
44 OobeDisplay
* oobe_display
);
46 ~AppLaunchController() override
;
48 // Starts launching an app - set |auto_launch| to true if the app is being
49 // auto-launched with zero delay.
50 void StartAppLaunch(bool auto_launch
);
52 bool waiting_for_network() { return waiting_for_network_
; }
53 bool network_wait_timedout() { return network_wait_timedout_
; }
54 bool showing_network_dialog() { return showing_network_dialog_
; }
56 // Customize controller for testing purposes.
57 static void SkipSplashWaitForTesting();
58 static void SetNetworkTimeoutCallbackForTesting(base::Closure
* callback
);
59 static void SetNetworkWaitForTesting(int wait_time_secs
);
60 static void SetCanConfigureNetworkCallbackForTesting(
61 ReturnBoolCallback
* can_configure_network_callback
);
62 static void SetNeedOwnerAuthToConfigureNetworkCallbackForTesting(
63 ReturnBoolCallback
* need_owner_auth_callback
);
66 // A class to watch app window creation.
67 class AppWindowWatcher
;
69 void ClearNetworkWaitTimer();
71 void OnNetworkWaitTimedout();
73 // Callback of AppWindowWatcher to notify an app window is created.
74 void OnAppWindowCreated();
76 // Whether the network could be configured during launching.
77 bool CanConfigureNetwork();
79 // Whether the owner password is needed to configure network.
80 bool NeedOwnerAuthToConfigureNetwork();
82 // Show network configuration UI if it is allowed. For consumer mode,
83 // owner password might be checked before showing the network configure UI.
84 void MaybeShowNetworkConfigureUI();
86 // KioskProfileLoader::Delegate overrides:
87 void OnProfileLoaded(Profile
* profile
) override
;
88 void OnProfileLoadFailed(KioskAppLaunchError::Error error
) override
;
90 // AppLaunchSplashScreenActor::Delegate overrides:
91 void OnConfigureNetwork() override
;
92 void OnCancelAppLaunch() override
;
93 void OnNetworkConfigRequested(bool requested
) override
;
94 void OnNetworkStateChanged(bool online
) override
;
96 // StartupAppLauncher::Delegate overrides:
97 void InitializeNetwork() override
;
98 bool IsNetworkReady() override
;
99 void OnLoadingOAuthFile() override
;
100 void OnInitializingTokenService() override
;
101 void OnInstallingApp() override
;
102 void OnReadyToLaunch() override
;
103 void OnLaunchSucceeded() override
;
104 void OnLaunchFailed(KioskAppLaunchError::Error error
) override
;
105 bool IsShowingNetworkConfigScreen() override
;
107 // AppLaunchSigninScreen::Delegate overrides:
108 void OnOwnerSigninSuccess() override
;
110 // content::NotificationObserver overrides:
111 void Observe(int type
,
112 const content::NotificationSource
& source
,
113 const content::NotificationDetails
& details
) override
;
116 const std::string app_id_
;
117 const bool diagnostic_mode_
;
118 LoginDisplayHost
* host_
;
119 OobeDisplay
* oobe_display_
;
120 AppLaunchSplashScreenActor
* app_launch_splash_screen_actor_
;
121 scoped_ptr
<KioskProfileLoader
> kiosk_profile_loader_
;
122 scoped_ptr
<StartupAppLauncher
> startup_app_launcher_
;
123 scoped_ptr
<AppLaunchSigninScreen
> signin_screen_
;
124 scoped_ptr
<AppWindowWatcher
> app_window_watcher_
;
126 content::NotificationRegistrar registrar_
;
128 bool launcher_ready_
;
130 // A timer to ensure the app splash is shown for a minimum amount of time.
131 base::OneShotTimer
<AppLaunchController
> splash_wait_timer_
;
133 base::OneShotTimer
<AppLaunchController
> network_wait_timer_
;
134 bool waiting_for_network_
;
135 bool network_wait_timedout_
;
136 bool showing_network_dialog_
;
137 bool network_config_requested_
;
138 int64 launch_splash_start_time_
;
140 static bool skip_splash_wait_
;
141 static int network_wait_time_
;
142 static base::Closure
* network_timeout_callback_
;
143 static ReturnBoolCallback
* can_configure_network_callback_
;
144 static ReturnBoolCallback
* need_owner_auth_to_configure_network_callback_
;
146 DISALLOW_COPY_AND_ASSIGN(AppLaunchController
);
149 } // namespace chromeos
151 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_