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" | |
14 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
15 #include "google_apis/gaia/oauth2_token_service.h" | 14 #include "google_apis/gaia/oauth2_token_service.h" |
16 #include "net/base/network_change_notifier.h" | |
17 | 15 |
18 class Profile; | 16 class Profile; |
19 | 17 |
20 namespace extensions { | 18 namespace extensions { |
21 class WebstoreStandaloneInstaller; | 19 class WebstoreStandaloneInstaller; |
22 } | 20 } |
23 | 21 |
24 namespace chromeos { | 22 namespace chromeos { |
25 | 23 |
26 // Launches the app at startup. The flow roughly looks like this: | 24 // Launches the app at startup. The flow roughly looks like this: |
27 // First call Initialize(): | 25 // First call Initialize(): |
28 // - Checks if the app is installed in user profile (aka app profile); | 26 // - Checks if the app is installed in user profile (aka app profile); |
29 // - If the app is installed, launch it and finish the flow; | 27 // - If the app is installed, launch it and finish the flow; |
30 // - If not installed, prepare to start install by checking network online | 28 // - If not installed, prepare to start install by checking network online |
31 // state; | 29 // state; |
32 // - If network gets online, start to install the app from web store; | 30 // - If network gets online, start to install the app from web store; |
33 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: | 31 // Report OnLauncherInitialized() or OnLaunchFailed() to observers: |
34 // - If all goes good, launches the app and finish the flow; | 32 // - If all goes good, launches the app and finish the flow; |
35 class StartupAppLauncher | 33 class StartupAppLauncher |
36 : public base::SupportsWeakPtr<StartupAppLauncher>, | 34 : public base::SupportsWeakPtr<StartupAppLauncher>, |
37 public OAuth2TokenService::Observer, | 35 public OAuth2TokenService::Observer { |
38 public net::NetworkChangeNotifier::NetworkChangeObserver { | |
39 public: | 36 public: |
40 class Observer { | 37 class Delegate { |
41 public: | 38 public: |
| 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; |
| 42 |
42 virtual void OnLoadingOAuthFile() = 0; | 43 virtual void OnLoadingOAuthFile() = 0; |
43 virtual void OnInitializingTokenService() = 0; | 44 virtual void OnInitializingTokenService() = 0; |
44 virtual void OnInitializingNetwork() = 0; | |
45 virtual void OnInstallingApp() = 0; | 45 virtual void OnInstallingApp() = 0; |
46 virtual void OnReadyToLaunch() = 0; | 46 virtual void OnReadyToLaunch() = 0; |
47 virtual void OnLaunchSucceeded() = 0; | 47 virtual void OnLaunchSucceeded() = 0; |
48 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; | 48 virtual void OnLaunchFailed(KioskAppLaunchError::Error error) = 0; |
49 | 49 |
50 protected: | 50 protected: |
51 virtual ~Observer() {} | 51 virtual ~Delegate() {} |
52 }; | 52 }; |
53 | 53 |
54 StartupAppLauncher(Profile* profile, const std::string& app_id); | 54 StartupAppLauncher(Profile* profile, |
| 55 const std::string& app_id, |
| 56 Delegate* delegate); |
55 | 57 |
56 virtual ~StartupAppLauncher(); | 58 virtual ~StartupAppLauncher(); |
57 | 59 |
58 // Prepares the environment for an app launch. | 60 // Prepares the environment for an app launch. |
59 void Initialize(); | 61 void Initialize(); |
60 | 62 |
| 63 // Continues the initialization after network is ready. |
| 64 void ContinueWithNetworkReady(); |
| 65 |
61 // Launches the app after the initialization is successful. | 66 // Launches the app after the initialization is successful. |
62 void LaunchApp(); | 67 void LaunchApp(); |
63 | 68 |
64 // Add and remove observers for app launch procedure. | |
65 void AddObserver(Observer* observer); | |
66 void RemoveObserver(Observer* observer); | |
67 | |
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 { |
71 std::string refresh_token; | 72 std::string refresh_token; |
72 std::string client_id; | 73 std::string client_id; |
73 std::string client_secret; | 74 std::string client_secret; |
74 }; | 75 }; |
75 | 76 |
76 void OnLaunchSuccess(); | 77 void OnLaunchSuccess(); |
77 void OnLaunchFailure(KioskAppLaunchError::Error error); | 78 void OnLaunchFailure(KioskAppLaunchError::Error error); |
78 | 79 |
79 void BeginInstall(); | 80 void BeginInstall(); |
80 void InstallCallback(bool success, const std::string& error); | 81 void InstallCallback(bool success, const std::string& error); |
81 void OnReadyToLaunch(); | 82 void OnReadyToLaunch(); |
82 | 83 |
83 void InitializeTokenService(); | 84 void InitializeTokenService(); |
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 Delegate* delegate_; |
| 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 |