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 "google_apis/gaia/oauth2_token_service.h"
18 namespace extensions {
19 class WebstoreStandaloneInstaller;
24 // Launches the app at startup. The flow roughly looks like this:
25 // First call Initialize():
26 // - Attempts to load oauth token file. Stores the loaded tokens in
28 // - Initialize token service and inject |auth_params_| if needed.
29 // - Initialize network if app is not installed or not offline_enabled.
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;
32 // Report OnLauncherInitialized() or OnLaunchFailed() to observers:
33 // - If all goes good, launches the app and finish the flow;
34 class StartupAppLauncher
35 : public base::SupportsWeakPtr<StartupAppLauncher>,
36 public OAuth2TokenService::Observer {
40 // Invoked to perform actual network initialization work. Note the app
41 // launch flow is paused until ContinueWithNetworkReady is called.
42 virtual void InitializeNetwork() = 0;
44 // Returns true if Internet is online.
45 virtual bool IsNetworkReady() = 0;
47 virtual void OnLoadingOAuthFile() = 0;
48 virtual void OnInitializingTokenService() = 0;
49 virtual void OnInstallingApp() = 0;
50 virtual void OnReadyToLaunch() = 0;
51 virtual void OnLaunchSucceeded() = 0;
52 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0;
55 virtual ~Delegate() {}
58 StartupAppLauncher(Profile* profile,
59 const std::string& app_id,
63 virtual ~StartupAppLauncher();
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 // OAuth parameters from /home/chronos/kiosk_auth file.
76 struct KioskOAuthParams {
77 std::string refresh_token;
78 std::string client_id;
79 std::string client_secret;
82 void OnLaunchSuccess();
83 void OnLaunchFailure(KioskAppLaunchError::Error error);
87 // Callbacks from ExtensionUpdater.
88 void OnUpdateCheckFinished();
91 void InstallCallback(bool success, const std::string& error);
92 void OnReadyToLaunch();
95 void InitializeTokenService();
96 void MaybeInitializeNetwork();
98 void StartLoadingOAuthFile();
99 static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params);
100 void OnOAuthFileLoaded(KioskOAuthParams* auth_params);
102 // OAuth2TokenService::Observer overrides.
103 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
104 virtual void OnRefreshTokensLoaded() OVERRIDE;
107 const std::string app_id_;
108 const bool diagnostic_mode_;
110 bool install_attempted_;
111 bool ready_to_launch_;
113 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_;
114 KioskOAuthParams auth_params_;
116 DISALLOW_COPY_AND_ASSIGN(StartupAppLauncher);
119 } // namespace chromeos
121 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_STARTUP_APP_LAUNCHER_H_