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