Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 15 #include "chrome/browser/chromeos/app_mode/kiosk_profile_loader.h" | |
| 16 #include "chrome/browser/chromeos/login/screens/app_launch_splash_screen_actor.h " | |
| 15 #include "chrome/browser/signin/oauth2_token_service.h" | 17 #include "chrome/browser/signin/oauth2_token_service.h" |
| 16 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
| 17 #include "ui/base/events/event_handler.h" | |
| 18 | 19 |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 class WebstoreStandaloneInstaller; | 23 class WebstoreStandaloneInstaller; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 // Launches the app at startup. The flow roughly looks like this: | 28 class LoginDisplayHost; |
| 29 class OobeDisplay; | |
| 30 | |
| 31 // Controls the launch of a kiosk app. The flow roughly looks like this: | |
| 28 // - Starts the app launch splash screen; | 32 // - Starts the app launch splash screen; |
| 33 // - Loads the user's profile; | |
| 29 // - Checks if the app is installed in user profile (aka app profile); | 34 // - Checks if the app is installed in user profile (aka app profile); |
| 30 // - If the app is installed, launch it and finish the flow; | 35 // - If the app is installed, launch it and finish the flow; |
| 31 // - If not installed, prepare to start install by checking network online | 36 // - If not installed, prepare to start install by checking network online |
| 32 // state; | 37 // state; |
| 33 // - If network gets online in time, start to install the app from web store; | 38 // - If network gets online in time, start to install the app from web store; |
| 34 // - If all goes good, launches the app and finish the flow; | 39 // - If all goes good, launches the app and finish the flow; |
| 35 // If anything goes wrong, it exits app mode and goes back to login screen. | 40 // If anything goes wrong, it exits app mode and goes back to login screen. |
| 36 class StartupAppLauncher | 41 class AppLaunchController |
| 37 : public base::SupportsWeakPtr<StartupAppLauncher>, | 42 : public base::SupportsWeakPtr<AppLaunchController>, |
| 38 public OAuth2TokenService::Observer, | 43 public OAuth2TokenService::Observer, |
| 39 public net::NetworkChangeNotifier::NetworkChangeObserver, | 44 public AppLaunchSplashScreenActor::Delegate, |
| 40 public ui::EventHandler { | 45 public KioskProfileLoader::Delegate, |
| 46 public net::NetworkChangeNotifier::NetworkChangeObserver { | |
| 41 public: | 47 public: |
| 42 StartupAppLauncher(Profile* profile, const std::string& app_id); | 48 AppLaunchController(const std::string& app_id, |
| 49 LoginDisplayHost* host, | |
| 50 OobeDisplay* oobe_display); | |
| 43 | 51 |
| 44 // Starts app launcher. If |skip_auth_setup| is set, we will skip | 52 virtual ~AppLaunchController(); |
| 45 // TokenService initialization. | 53 |
| 46 void Start(); | 54 void StartAppLaunch(); |
| 47 | 55 |
| 48 private: | 56 private: |
| 49 // OAuth parameters from /home/chronos/kiosk_auth file. | 57 // OAuth parameters from /home/chronos/kiosk_auth file. |
| 50 struct KioskOAuthParams { | 58 struct KioskOAuthParams { |
| 51 std::string refresh_token; | 59 std::string refresh_token; |
| 52 std::string client_id; | 60 std::string client_id; |
| 53 std::string client_secret; | 61 std::string client_secret; |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 // Private dtor because this class manages its own lifetime. | 64 // KioskProfileLoader::Delegate overrides: |
| 57 virtual ~StartupAppLauncher(); | 65 void OnProfileLoaded(Profile* profile); |
| 66 void OnProfileLoadFailed(KioskAppLaunchError::Error error); | |
|
xiyuan
2013/08/15 18:19:42
nit: virtual ... OVERRIDE;
Tim Song
2013/08/16 19:07:59
Done.
| |
| 58 | 67 |
| 59 void Cleanup(); | 68 void Cleanup(); |
| 60 void OnLaunchSuccess(); | 69 void OnLaunchSuccess(); |
| 61 void OnLaunchFailure(KioskAppLaunchError::Error error); | 70 void OnLaunchFailure(KioskAppLaunchError::Error error); |
| 62 | 71 |
| 63 void Launch(); | 72 void Launch(); |
| 64 | 73 |
| 65 void BeginInstall(); | 74 void BeginInstall(); |
| 66 void InstallCallback(bool success, const std::string& error); | 75 void InstallCallback(bool success, const std::string& error); |
| 67 | 76 |
| 68 void InitializeTokenService(); | 77 void InitializeTokenService(); |
| 69 void InitializeNetwork(); | 78 void InitializeNetwork(); |
| 70 | 79 |
| 71 void OnNetworkWaitTimedout(); | 80 void OnNetworkWaitTimedout(); |
| 72 | 81 |
| 73 void StartLoadingOAuthFile(); | 82 void StartLoadingOAuthFile(); |
| 74 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); | 83 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); |
| 75 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); | 84 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); |
| 76 | 85 |
| 77 // OAuth2TokenService::Observer overrides. | 86 // OAuth2TokenService::Observer overrides: |
| 78 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 87 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 79 virtual void OnRefreshTokensLoaded() OVERRIDE; | 88 virtual void OnRefreshTokensLoaded() OVERRIDE; |
| 80 | 89 |
| 90 // AppLaunchSplashScreenActor::Delegate overrides: | |
| 91 virtual void OnConfigureNetwork() OVERRIDE; | |
| 92 virtual void OnCancelAppLaunch() OVERRIDE; | |
| 93 | |
| 81 // net::NetworkChangeNotifier::NetworkChangeObserver overrides: | 94 // net::NetworkChangeNotifier::NetworkChangeObserver overrides: |
| 82 virtual void OnNetworkChanged( | 95 virtual void OnNetworkChanged( |
| 83 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 96 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 84 | 97 |
| 85 // ui::EventHandler overrides: | |
| 86 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | |
| 87 | |
| 88 Profile* profile_; | 98 Profile* profile_; |
| 89 const std::string app_id_; | 99 std::string app_id_; |
|
xiyuan
2013/08/15 18:19:42
nit: put back const if |app_id_| is not going to c
Tim Song
2013/08/16 19:07:59
Done.
| |
| 100 LoginDisplayHost* host_; | |
| 101 OobeDisplay* oobe_display_; | |
| 102 AppLaunchSplashScreenActor* app_launch_splash_screen_actor_; | |
| 90 | 103 |
| 91 int64 launch_splash_start_time_; | 104 int64 launch_splash_start_time_; |
| 92 | 105 |
| 93 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; | 106 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; |
| 94 base::OneShotTimer<StartupAppLauncher> network_wait_timer_; | 107 base::OneShotTimer<AppLaunchController> network_wait_timer_; |
| 95 KioskOAuthParams auth_params_; | 108 KioskOAuthParams auth_params_; |
| 96 | 109 |
| 97 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); | 110 DISALLOW_COPY_AND_ASSIGN(AppLaunchController); |
| 98 }; | 111 }; |
| 99 | 112 |
| 100 } // namespace chromeos | 113 } // namespace chromeos |
| 101 | 114 |
| 102 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 115 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_APP_LAUNCH_CONTROLLER_H_ |
| OLD | NEW |