| 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_APP_MODE_STARTUP_APP_LAUNCHER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_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 "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 14 #include "google_apis/gaia/oauth2_token_service.h" | 14 #include "google_apis/gaia/oauth2_token_service.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 class WebstoreStandaloneInstaller; | 19 class WebstoreStandaloneInstaller; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 // Launches the app at startup. The flow roughly looks like this: | 24 // Launches the app at startup. The flow roughly looks like this: |
| 25 // First call Initialize(): | 25 // First call Initialize(): |
| 26 // - Checks if the app is installed in user profile (aka app profile); | 26 // - Attempts to load oauth token file. Stores the loaded tokens in |
| 27 // - If the app is installed, launch it and finish the flow; | 27 // |auth_params_|. |
| 28 // - If not installed, prepare to start install by checking network online | 28 // - Initialize token service and inject |auth_params_| if needed. |
| 29 // state; | 29 // - Initialize network if app is not installed or not offline_enabled. |
| 30 // - If network gets online, start to install the app from web store; | 30 // - If network is online, install or update the app as needed. |
| 31 // - After the app is installed/updated, launch it and finish the flow; |
| 31 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: | 32 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: |
| 32 // - If all goes good, launches the app and finish the flow; | 33 // - If all goes good, launches the app and finish the flow; |
| 33 class StartupAppLauncher | 34 class StartupAppLauncher |
| 34 : public base::SupportsWeakPtr<StartupAppLauncher>, | 35 : public base::SupportsWeakPtr<StartupAppLauncher>, |
| 35 public OAuth2TokenService::Observer { | 36 public OAuth2TokenService::Observer { |
| 36 public: | 37 public: |
| 37 class Delegate { | 38 class Delegate { |
| 38 public: | 39 public: |
| 39 // Invoked to perform actual network initialization work. Note the app | 40 // Invoked to perform actual network initialization work. Note the app |
| 40 // launch flow is paused until ContinueWithNetworkReady is called. | 41 // launch flow is paused until ContinueWithNetworkReady is called. |
| 41 virtual void InitializeNetwork() = 0; | 42 virtual void InitializeNetwork() = 0; |
| 42 | 43 |
| 44 // Returns true if Internet is online. |
| 45 virtual bool IsNetworkReady() = 0; |
| 46 |
| 43 virtual void OnLoadingOAuthFile() = 0; | 47 virtual void OnLoadingOAuthFile() = 0; |
| 44 virtual void OnInitializingTokenService() = 0; | 48 virtual void OnInitializingTokenService() = 0; |
| 45 virtual void OnInstallingApp() = 0; | 49 virtual void OnInstallingApp() = 0; |
| 46 virtual void OnReadyToLaunch() = 0; | 50 virtual void OnReadyToLaunch() = 0; |
| 47 virtual void OnLaunchSucceeded() = 0; | 51 virtual void OnLaunchSucceeded() = 0; |
| 48 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; | 52 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; |
| 49 | 53 |
| 50 protected: | 54 protected: |
| 51 virtual ~Delegate() {} | 55 virtual ~Delegate() {} |
| 52 }; | 56 }; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 void OnUpdateCheckNotInstalled(); | 93 void OnUpdateCheckNotInstalled(); |
| 90 void OnUpdateCheckUpdateAvailable(); | 94 void OnUpdateCheckUpdateAvailable(); |
| 91 void OnUpdateCheckNoUpdate(); | 95 void OnUpdateCheckNoUpdate(); |
| 92 | 96 |
| 93 void BeginInstall(); | 97 void BeginInstall(); |
| 94 void InstallCallback(bool success, const std::string& error); | 98 void InstallCallback(bool success, const std::string& error); |
| 95 void OnReadyToLaunch(); | 99 void OnReadyToLaunch(); |
| 96 void UpdateAppData(); | 100 void UpdateAppData(); |
| 97 | 101 |
| 98 void InitializeTokenService(); | 102 void InitializeTokenService(); |
| 99 void InitializeNetwork(); | 103 void MaybeInitializeNetwork(); |
| 100 | 104 |
| 101 void StartLoadingOAuthFile(); | 105 void StartLoadingOAuthFile(); |
| 102 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); | 106 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); |
| 103 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); | 107 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); |
| 104 | 108 |
| 105 // OAuth2TokenService::Observer overrides. | 109 // OAuth2TokenService::Observer overrides. |
| 106 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 110 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 107 virtual void OnRefreshTokensLoaded() OVERRIDE; | 111 virtual void OnRefreshTokensLoaded() OVERRIDE; |
| 108 | 112 |
| 109 Profile* profile_; | 113 Profile* profile_; |
| 110 const std::string app_id_; | 114 const std::string app_id_; |
| 111 const bool diagnostic_mode_; | 115 const bool diagnostic_mode_; |
| 112 Delegate* delegate_; | 116 Delegate* delegate_; |
| 113 bool install_attempted_; | 117 bool install_attempted_; |
| 114 bool ready_to_launch_; | 118 bool ready_to_launch_; |
| 115 | 119 |
| 116 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; | 120 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; |
| 117 KioskOAuthParams auth_params_; | 121 KioskOAuthParams auth_params_; |
| 118 | 122 |
| 119 scoped_ptr<AppUpdateChecker> update_checker_; | 123 scoped_ptr<AppUpdateChecker> update_checker_; |
| 120 | 124 |
| 121 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); | 125 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 } // namespace chromeos | 128 } // namespace chromeos |
| 125 | 129 |
| 126 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 130 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ |
| OLD | NEW |