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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.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"
16 #include "google_apis/gaia/oauth2_token_service.h"
22 // Launches the app at startup. The flow roughly looks like this:
23 // First call Initialize():
24 // - Attempts to load oauth token file. Stores the loaded tokens in
26 // - Initialize token service and inject |auth_params_| if needed.
27 // - Initialize network if app is not installed or not offline_enabled.
28 // - If network is online, install or update the app as needed.
29 // - After the app is installed/updated, launch it and finish the flow;
30 // Report OnLauncherInitialized() or OnLaunchFailed() to observers:
31 // - If all goes good, launches the app and finish the flow;
32 class StartupAppLauncher
: public base::SupportsWeakPtr
<StartupAppLauncher
>,
33 public OAuth2TokenService::Observer
,
34 public extensions::InstallObserver
,
35 public KioskAppManagerObserver
{
39 // Invoked to perform actual network initialization work. Note the app
40 // launch flow is paused until ContinueWithNetworkReady is called.
41 virtual void InitializeNetwork() = 0;
43 // Returns true if Internet is online.
44 virtual bool IsNetworkReady() = 0;
46 virtual void OnLoadingOAuthFile() = 0;
47 virtual void OnInitializingTokenService() = 0;
48 virtual void OnInstallingApp() = 0;
49 virtual void OnReadyToLaunch() = 0;
50 virtual void OnLaunchSucceeded() = 0;
51 virtual void OnLaunchFailed(KioskAppLaunchError::Error error
) = 0;
52 virtual bool IsShowingNetworkConfigScreen() = 0;
55 virtual ~Delegate() {}
58 StartupAppLauncher(Profile
* profile
,
59 const std::string
& app_id
,
63 ~StartupAppLauncher() override
;
65 // Prepares the environment for an app launch.
68 // Continues the initialization after network is ready.
69 void ContinueWithNetworkReady();
71 // Launches the app after the initialization is successful.
75 void RestartLauncher();
78 // OAuth parameters from /home/chronos/kiosk_auth file.
79 struct KioskOAuthParams
{
80 std::string refresh_token
;
81 std::string client_id
;
82 std::string client_secret
;
85 void OnLaunchSuccess();
86 void OnLaunchFailure(KioskAppLaunchError::Error error
);
89 void OnReadyToLaunch();
92 void InitializeTokenService();
93 void MaybeInitializeNetwork();
94 void MaybeLaunchApp();
96 void StartLoadingOAuthFile();
97 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams
* auth_params
);
98 void OnOAuthFileLoaded(KioskOAuthParams
* auth_params
);
100 void OnKioskAppDataLoadStatusChanged(const std::string
& app_id
);
102 // OAuth2TokenService::Observer overrides.
103 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
104 void OnRefreshTokensLoaded() override
;
106 // extensions::InstallObserver overrides.
107 void OnFinishCrxInstall(const std::string
& extension_id
,
108 bool success
) override
;
110 // KioskAppManagerObserver overrides.
111 void OnKioskExtensionLoadedInCache(const std::string
& app_id
) override
;
112 void OnKioskExtensionDownloadFailed(const std::string
& app_id
) override
;
115 const std::string app_id_
;
116 const bool diagnostic_mode_
;
118 bool network_ready_handled_
;
120 bool ready_to_launch_
;
121 bool wait_for_crx_update_
;
123 KioskOAuthParams auth_params_
;
125 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher
);
128 } // namespace chromeos
130 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_