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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ 7 8 #include <string> 9 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" 20 21 class Profile; 22 23 namespace chromeos { 24 25 class LoginDisplayHost; 26 class OobeDisplay; 27 class UserManager; 28 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 { 38 public: 39 typedef base::Callback<bool()> ReturnBoolCallback; 40 41 AppLaunchController(const std::string& app_id, 42 bool diagnostic_mode, 43 LoginDisplayHost* host, 44 OobeDisplay* oobe_display); 45 46 virtual ~AppLaunchController(); 47 48 void StartAppLaunch(); 49 50 bool waiting_for_network() { return waiting_for_network_; } 51 bool network_wait_timedout() { return network_wait_timedout_; } 52 bool showing_network_dialog() { return showing_network_dialog_; } 53 54 // Customize controller for testing purposes. 55 static void SkipSplashWaitForTesting(); 56 static void SetNetworkTimeoutCallbackForTesting(base::Closure* callback); 57 static void SetNetworkWaitForTesting(int wait_time_secs); 58 static void SetCanConfigureNetworkCallbackForTesting( 59 ReturnBoolCallback* can_configure_network_callback); 60 static void SetNeedOwnerAuthToConfigureNetworkCallbackForTesting( 61 ReturnBoolCallback* need_owner_auth_callback); 62 63 private: 64 // A class to watch app window creation. 65 class AppWindowWatcher; 66 67 void CleanUp(); 68 void OnNetworkWaitTimedout(); 69 70 // Callback of AppWindowWatcher to notify an app window is created. 71 void OnAppWindowCreated(); 72 73 // Whether the network could be configured during launching. 74 bool CanConfigureNetwork(); 75 76 // Whether the owner password is needed to configure network. 77 bool NeedOwnerAuthToConfigureNetwork(); 78 79 // Show network configuration UI if it is allowed. For consumer mode, 80 // owner password might be checked before showing the network configure UI. 81 void MaybeShowNetworkConfigureUI(); 82 83 // KioskProfileLoader::Delegate overrides: 84 virtual void OnProfileLoaded(Profile* profile) OVERRIDE; 85 virtual void OnProfileLoadFailed(KioskAppLaunchError::Error error) OVERRIDE; 86 87 // AppLaunchSplashScreenActor::Delegate overrides: 88 virtual void OnConfigureNetwork() OVERRIDE; 89 virtual void OnCancelAppLaunch() OVERRIDE; 90 virtual void OnNetworkConfigRequested(bool requested) OVERRIDE; 91 virtual void OnNetworkStateChanged(bool online) OVERRIDE; 92 93 // StartupAppLauncher::Delegate overrides: 94 virtual void InitializeNetwork() OVERRIDE; 95 virtual bool IsNetworkReady() OVERRIDE; 96 virtual void OnLoadingOAuthFile() OVERRIDE; 97 virtual void OnInitializingTokenService() OVERRIDE; 98 virtual void OnInstallingApp() OVERRIDE; 99 virtual void OnReadyToLaunch() OVERRIDE; 100 virtual void OnLaunchSucceeded() OVERRIDE; 101 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) OVERRIDE; 102 virtual bool IsShowingNetworkConfigScreen() OVERRIDE; 103 104 // AppLaunchSigninScreen::Delegate overrides: 105 virtual void OnOwnerSigninSuccess() OVERRIDE; 106 107 // content::NotificationObserver overrides: 108 virtual void Observe(int type, 109 const content::NotificationSource& source, 110 const content::NotificationDetails& details) OVERRIDE; 111 112 Profile* profile_; 113 const std::string app_id_; 114 const bool diagnostic_mode_; 115 LoginDisplayHost* host_; 116 OobeDisplay* oobe_display_; 117 AppLaunchSplashScreenActor* app_launch_splash_screen_actor_; 118 scoped_ptr<KioskProfileLoader> kiosk_profile_loader_; 119 scoped_ptr<StartupAppLauncher> startup_app_launcher_; 120 scoped_ptr<AppLaunchSigninScreen> signin_screen_; 121 scoped_ptr<AppWindowWatcher> app_window_watcher_; 122 123 content::NotificationRegistrar registrar_; 124 bool webui_visible_; 125 bool launcher_ready_; 126 127 // A timer to ensure the app splash is shown for a minimum amount of time. 128 base::OneShotTimer<AppLaunchController> splash_wait_timer_; 129 130 base::OneShotTimer<AppLaunchController> network_wait_timer_; 131 bool waiting_for_network_; 132 bool network_wait_timedout_; 133 bool showing_network_dialog_; 134 bool network_config_requested_; 135 int64 launch_splash_start_time_; 136 137 static bool skip_splash_wait_; 138 static int network_wait_time_; 139 static base::Closure* network_timeout_callback_; 140 static ReturnBoolCallback* can_configure_network_callback_; 141 static ReturnBoolCallback* need_owner_auth_to_configure_network_callback_; 142 143 DISALLOW_COPY_AND_ASSIGN(AppLaunchController); 144 }; 145 146 } // namespace chromeos 147 148 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ 149