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_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 "base/observer_list.h" | 13 #include "base/observer_list.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 "google_apis/gaia/oauth2_token_service.h" | 15 #include "google_apis/gaia/oauth2_token_service.h" |
| 16 #include "net/base/network_change_notifier.h" | |
| 17 | 16 |
| 18 class Profile; | 17 class Profile; |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 class WebstoreStandaloneInstaller; | 20 class WebstoreStandaloneInstaller; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace chromeos { | 23 namespace chromeos { |
| 25 | 24 |
| 26 // Launches the app at startup. The flow roughly looks like this: | 25 // Launches the app at startup. The flow roughly looks like this: |
| 27 // First call Initialize(): | 26 // First call Initialize(): |
| 28 // - Checks if the app is installed in user profile (aka app profile); | 27 // - Checks if the app is installed in user profile (aka app profile); |
| 29 // - If the app is installed, launch it and finish the flow; | 28 // - If the app is installed, launch it and finish the flow; |
| 30 // - If not installed, prepare to start install by checking network online | 29 // - If not installed, prepare to start install by checking network online |
| 31 // state; | 30 // state; |
| 32 // - If network gets online, start to install the app from web store; | 31 // - If network gets online, start to install the app from web store; |
| 33 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: | 32 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: |
| 34 // - If all goes good, launches the app and finish the flow; | 33 // - If all goes good, launches the app and finish the flow; |
| 35 class StartupAppLauncher | 34 class StartupAppLauncher |
| 36 : public base::SupportsWeakPtr<StartupAppLauncher>, | 35 : public base::SupportsWeakPtr<StartupAppLauncher>, |
| 37 public OAuth2TokenService::Observer, | 36 public OAuth2TokenService::Observer { |
| 38 public net::NetworkChangeNotifier::NetworkChangeObserver { | |
| 39 public: | 37 public: |
| 40 class Observer { | 38 class Observer { |
| 41 public: | 39 public: |
| 42 virtual void OnLoadingOAuthFile() = 0; | 40 virtual void OnLoadingOAuthFile() = 0; |
| 43 virtual void OnInitializingTokenService() = 0; | 41 virtual void OnInitializingTokenService() = 0; |
| 44 virtual void OnInitializingNetwork() = 0; | 42 virtual void OnInitializingNetwork() = 0; |
|
Tim Song
2013/11/21 01:12:17
Please add a comment for this function that Startu
xiyuan
2013/11/21 22:39:39
Done.
- OnInitializingNetwork -> InitializeNetwork
| |
| 45 virtual void OnInstallingApp() = 0; | 43 virtual void OnInstallingApp() = 0; |
| 46 virtual void OnReadyToLaunch() = 0; | 44 virtual void OnReadyToLaunch() = 0; |
| 47 virtual void OnLaunchSucceeded() = 0; | 45 virtual void OnLaunchSucceeded() = 0; |
| 48 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; | 46 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 virtual ~Observer() {} | 49 virtual ~Observer() {} |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 StartupAppLauncher(Profile* profile, const std::string& app_id); | 52 StartupAppLauncher(Profile* profile, const std::string& app_id); |
| 55 | 53 |
| 56 virtual ~StartupAppLauncher(); | 54 virtual ~StartupAppLauncher(); |
| 57 | 55 |
| 58 // Prepares the environment for an app launch. | 56 // Prepares the environment for an app launch. |
| 59 void Initialize(); | 57 void Initialize(); |
| 60 | 58 |
| 59 // Continues the initialization after network is ready. | |
| 60 void ContinueWithNetworkReady(); | |
| 61 | |
| 61 // Launches the app after the initialization is successful. | 62 // Launches the app after the initialization is successful. |
| 62 void LaunchApp(); | 63 void LaunchApp(); |
| 63 | 64 |
| 64 // Add and remove observers for app launch procedure. | 65 // Add and remove observers for app launch procedure. |
| 65 void AddObserver(Observer* observer); | 66 void AddObserver(Observer* observer); |
| 66 void RemoveObserver(Observer* observer); | 67 void RemoveObserver(Observer* observer); |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 // OAuth parameters from /home/chronos/kiosk_auth file. | 70 // OAuth parameters from /home/chronos/kiosk_auth file. |
| 70 struct KioskOAuthParams { | 71 struct KioskOAuthParams { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 84 void InitializeNetwork(); | 85 void InitializeNetwork(); |
| 85 | 86 |
| 86 void StartLoadingOAuthFile(); | 87 void StartLoadingOAuthFile(); |
| 87 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); | 88 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); |
| 88 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); | 89 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); |
| 89 | 90 |
| 90 // OAuth2TokenService::Observer overrides. | 91 // OAuth2TokenService::Observer overrides. |
| 91 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 92 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 92 virtual void OnRefreshTokensLoaded() OVERRIDE; | 93 virtual void OnRefreshTokensLoaded() OVERRIDE; |
| 93 | 94 |
| 94 // net::NetworkChangeNotifier::NetworkChangeObserver overrides: | |
| 95 virtual void OnNetworkChanged( | |
| 96 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
| 97 | |
| 98 Profile* profile_; | 95 Profile* profile_; |
| 99 const std::string app_id_; | 96 const std::string app_id_; |
| 100 ObserverList<Observer> observer_list_; | 97 ObserverList<Observer> observer_list_; |
| 98 bool install_attempted_; | |
| 101 bool ready_to_launch_; | 99 bool ready_to_launch_; |
| 102 | 100 |
| 103 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; | 101 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; |
| 104 KioskOAuthParams auth_params_; | 102 KioskOAuthParams auth_params_; |
| 105 | 103 |
| 106 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); | 104 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 } // namespace chromeos | 107 } // namespace chromeos |
| 110 | 108 |
| 111 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 109 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ |
| OLD | NEW |