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 "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 15 #include "chrome/browser/extensions/install_observer.h" |
14 #include "google_apis/gaia/oauth2_token_service.h" | 16 #include "google_apis/gaia/oauth2_token_service.h" |
15 | 17 |
16 class Profile; | 18 class Profile; |
17 | 19 |
18 namespace extensions { | 20 namespace extensions { |
19 class WebstoreStandaloneInstaller; | 21 class CrxInstaller; |
20 } | 22 } |
21 | 23 |
22 namespace chromeos { | 24 namespace chromeos { |
23 | 25 |
24 // Launches the app at startup. The flow roughly looks like this: | 26 // Launches the app at startup. The flow roughly looks like this: |
25 // First call Initialize(): | 27 // First call Initialize(): |
26 // - Attempts to load oauth token file. Stores the loaded tokens in | 28 // - Attempts to load oauth token file. Stores the loaded tokens in |
27 // |auth_params_|. | 29 // |auth_params_|. |
28 // - Initialize token service and inject |auth_params_| if needed. | 30 // - Initialize token service and inject |auth_params_| if needed. |
29 // - Initialize network if app is not installed or not offline_enabled. | 31 // - Initialize network if app is not installed or not offline_enabled. |
30 // - If network is online, install or update the app as needed. | 32 // - If network is online, install or update the app as needed. |
31 // - After the app is installed/updated, launch it and finish the flow; | 33 // - After the app is installed/updated, launch it and finish the flow; |
32 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: | 34 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: |
33 // - If all goes good, launches the app and finish the flow; | 35 // - If all goes good, launches the app and finish the flow; |
34 class StartupAppLauncher | 36 class StartupAppLauncher : public base::SupportsWeakPtr<StartupAppLauncher>, |
35 : public base::SupportsWeakPtr<StartupAppLauncher>, | 37 public OAuth2TokenService::Observer, |
36 public OAuth2TokenService::Observer { | 38 public extensions::InstallObserver, |
| 39 public KioskAppManagerObserver { |
37 public: | 40 public: |
38 class Delegate { | 41 class Delegate { |
39 public: | 42 public: |
40 // Invoked to perform actual network initialization work. Note the app | 43 // Invoked to perform actual network initialization work. Note the app |
41 // launch flow is paused until ContinueWithNetworkReady is called. | 44 // launch flow is paused until ContinueWithNetworkReady is called. |
42 virtual void InitializeNetwork() = 0; | 45 virtual void InitializeNetwork() = 0; |
43 | 46 |
44 // Returns true if Internet is online. | 47 // Returns true if Internet is online. |
45 virtual bool IsNetworkReady() = 0; | 48 virtual bool IsNetworkReady() = 0; |
46 | 49 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 88 |
86 void OnLaunchSuccess(); | 89 void OnLaunchSuccess(); |
87 void OnLaunchFailure(KioskAppLaunchError::Error error); | 90 void OnLaunchFailure(KioskAppLaunchError::Error error); |
88 | 91 |
89 void MaybeInstall(); | 92 void MaybeInstall(); |
90 | 93 |
91 // Callbacks from ExtensionUpdater. | 94 // Callbacks from ExtensionUpdater. |
92 void OnUpdateCheckFinished(); | 95 void OnUpdateCheckFinished(); |
93 | 96 |
94 void BeginInstall(); | 97 void BeginInstall(); |
95 void InstallCallback(bool success, const std::string& error); | 98 scoped_refptr<extensions::CrxInstaller> CreateCrxInstaller(Profile* profile); |
96 void OnReadyToLaunch(); | 99 void OnReadyToLaunch(); |
97 void UpdateAppData(); | 100 void UpdateAppData(); |
98 | 101 |
99 void InitializeTokenService(); | 102 void InitializeTokenService(); |
100 void MaybeInitializeNetwork(); | 103 void MaybeInitializeNetwork(); |
101 | 104 |
102 void StartLoadingOAuthFile(); | 105 void StartLoadingOAuthFile(); |
103 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); | 106 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params); |
104 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); | 107 void OnOAuthFileLoaded(KioskOAuthParams* auth_params); |
105 | 108 |
| 109 void OnKioskAppDataLoadStatusChanged(const std::string& app_id); |
| 110 |
106 // OAuth2TokenService::Observer overrides. | 111 // OAuth2TokenService::Observer overrides. |
107 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 112 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
108 virtual void OnRefreshTokensLoaded() OVERRIDE; | 113 virtual void OnRefreshTokensLoaded() OVERRIDE; |
109 | 114 |
| 115 // extensions::InstallObserver overrides. |
| 116 virtual void OnFinishCrxInstall(const std::string& extension_id, |
| 117 bool success) OVERRIDE; |
| 118 |
| 119 // KioskAppManagerObserver overrides. |
| 120 virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE; |
| 121 virtual void OnKioskAppDataLoadFailure(const std::string& app_id) OVERRIDE; |
| 122 |
110 Profile* profile_; | 123 Profile* profile_; |
111 const std::string app_id_; | 124 const std::string app_id_; |
112 const bool diagnostic_mode_; | 125 const bool diagnostic_mode_; |
113 Delegate* delegate_; | 126 Delegate* delegate_; |
114 bool network_ready_handled_; | 127 bool network_ready_handled_; |
115 int install_attempt_; | 128 int download_attempt_; |
| 129 int launch_attempt_; |
116 bool ready_to_launch_; | 130 bool ready_to_launch_; |
| 131 bool update_check_pending_; |
| 132 bool crx_cache_pending_; |
117 | 133 |
118 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_; | 134 scoped_refptr<extensions::CrxInstaller> crx_installer_; |
119 KioskOAuthParams auth_params_; | 135 KioskOAuthParams auth_params_; |
120 | 136 |
121 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); | 137 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher); |
122 }; | 138 }; |
123 | 139 |
124 } // namespace chromeos | 140 } // namespace chromeos |
125 | 141 |
126 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ | 142 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_ |
OLD | NEW |